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/l2/l2_classify.h>
70 #include <vnet/vxlan/vxlan.h>
71 #include <vnet/gre/gre.h>
72 #include <vnet/l2/l2_vtr.h>
73 #include <vnet/vxlan-gpe/vxlan_gpe.h>
74 #include <vnet/lisp-gpe/lisp_gpe.h>
75 #include <vnet/lisp-cp/control.h>
76 #include <vnet/map/map.h>
77 #include <vnet/cop/cop.h>
78 #include <vnet/ip/ip6_hop_by_hop.h>
79 #include <vnet/devices/af_packet/af_packet.h>
80 #include <vnet/policer/policer.h>
81 #include <vnet/devices/netmap/netmap.h>
82 #include <vnet/flow/flow_report.h>
85 #undef __included_bihash_template_h__
86 #include <vnet/l2/l2_fib.h>
89 #include <vnet/ipsec/ipsec.h>
90 #include <vnet/ipsec/ikev2.h>
93 #include <vnet/devices/virtio/vhost-user.h>
96 #include <stats/stats.h>
99 #include <vnet/ethernet/ethernet.h>
100 #include <vnet/ethernet/arp_packet.h>
101 #include <vnet/interface.h>
103 #include <vnet/l2/l2_fib.h>
104 #include <vnet/l2/l2_bd.h>
105 #include <vpp-api/vpe_msg_enum.h>
107 #define f64_endian(a)
108 #define f64_print(a,b)
110 #define vl_typedefs /* define message structures */
111 #include <vpp-api/vpe_all_api_h.h>
114 #define vl_endianfun /* define message structures */
115 #include <vpp-api/vpe_all_api_h.h>
118 /* instantiate all the print functions we know about */
119 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
121 #include <vpp-api/vpe_all_api_h.h>
124 #define REPLY_MACRO(t) \
126 unix_shared_memory_queue_t * q; \
127 rv = vl_msg_api_pd_handler (mp, rv); \
128 q = vl_api_client_index_to_input_queue (mp->client_index); \
132 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
133 rmp->_vl_msg_id = ntohs((t)); \
134 rmp->context = mp->context; \
135 rmp->retval = ntohl(rv); \
137 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
140 #define REPLY_MACRO2(t, body) \
142 unix_shared_memory_queue_t * q; \
143 rv = vl_msg_api_pd_handler (mp, rv); \
144 q = vl_api_client_index_to_input_queue (mp->client_index); \
148 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
149 rmp->_vl_msg_id = ntohs((t)); \
150 rmp->context = mp->context; \
151 rmp->retval = ntohl(rv); \
152 do {body;} while (0); \
153 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
156 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
158 #define VALIDATE_SW_IF_INDEX(mp) \
159 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
160 vnet_main_t *__vnm = vnet_get_main(); \
161 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
163 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
164 goto bad_sw_if_index; \
168 #define BAD_SW_IF_INDEX_LABEL \
174 #define VALIDATE_RX_SW_IF_INDEX(mp) \
175 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
176 vnet_main_t *__vnm = vnet_get_main(); \
177 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
178 __rx_sw_if_index)) { \
179 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
180 goto bad_rx_sw_if_index; \
184 #define BAD_RX_SW_IF_INDEX_LABEL \
186 bad_rx_sw_if_index: \
190 #define VALIDATE_TX_SW_IF_INDEX(mp) \
191 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
192 vnet_main_t *__vnm = vnet_get_main(); \
193 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
194 __tx_sw_if_index)) { \
195 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
196 goto bad_tx_sw_if_index; \
200 #define BAD_TX_SW_IF_INDEX_LABEL \
202 bad_tx_sw_if_index: \
208 #define VALIDATE_SW_IF_INDEX(mp)
209 #define BAD_SW_IF_INDEX_LABEL
210 #define VALIDATE_RX_SW_IF_INDEX(mp)
211 #define BAD_RX_SW_IF_INDEX_LABEL
212 #define VALIDATE_TX_SW_IF_INDEX(mp)
213 #define BAD_TX_SW_IF_INDEX_LABEL
215 #endif /* CLIB_DEBUG > 0 */
217 #define foreach_vpe_api_msg \
218 _(WANT_INTERFACE_EVENTS, want_interface_events) \
219 _(WANT_OAM_EVENTS, want_oam_events) \
220 _(OAM_ADD_DEL, oam_add_del) \
221 _(SW_INTERFACE_DUMP, sw_interface_dump) \
222 _(SW_INTERFACE_DETAILS, sw_interface_details) \
223 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
224 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
225 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
226 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
227 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
228 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
229 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
230 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
231 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
232 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
233 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
234 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
235 _(L2FIB_ADD_DEL, l2fib_add_del) \
236 _(L2_FLAGS, l2_flags) \
237 _(BRIDGE_FLAGS, bridge_flags) \
238 _(TAP_CONNECT, tap_connect) \
239 _(TAP_MODIFY, tap_modify) \
240 _(TAP_DELETE, tap_delete) \
241 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
242 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
243 _(CREATE_SUBIF, create_subif) \
244 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
245 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
246 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
247 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
248 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
249 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
250 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
251 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
252 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
253 _(RESET_FIB, reset_fib) \
254 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
255 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
256 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
257 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
258 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
259 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
260 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
261 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
262 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
263 sw_interface_ip6_set_link_local_address) \
264 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
265 _(CREATE_LOOPBACK, create_loopback) \
266 _(CONTROL_PING, control_ping) \
267 _(CLI_REQUEST, cli_request) \
268 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
269 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
270 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
271 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
272 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
273 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
274 _(GET_NODE_INDEX, get_node_index) \
275 _(ADD_NODE_NEXT, add_node_next) \
276 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
277 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
278 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
279 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
280 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
281 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
282 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
283 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
284 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
285 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
286 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
287 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
288 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
289 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
290 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
291 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
292 _(IP_ADDRESS_DUMP, ip_address_dump) \
293 _(IP_DUMP, ip_dump) \
294 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
295 _(SHOW_VERSION, show_version) \
296 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
297 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
298 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
299 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
300 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
301 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
302 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
303 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
304 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
305 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
306 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
307 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
308 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
309 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
310 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
311 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
312 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
313 _(DELETE_LOOPBACK, delete_loopback) \
314 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
315 _(MAP_ADD_DOMAIN, map_add_domain) \
316 _(MAP_DEL_DOMAIN, map_del_domain) \
317 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
318 _(MAP_DOMAIN_DUMP, map_domain_dump) \
319 _(MAP_RULE_DUMP, map_rule_dump) \
320 _(MAP_SUMMARY_STATS, map_summary_stats) \
321 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
322 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
323 _(GET_NODE_GRAPH, get_node_graph) \
324 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
325 _(TRACE_PROFILE_ADD, trace_profile_add) \
326 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
327 _(TRACE_PROFILE_DEL, trace_profile_del) \
328 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
329 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
330 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
331 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
332 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
333 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
334 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
335 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
336 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
337 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
338 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
339 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
340 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
341 _(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump) \
342 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
343 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
344 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
345 _(LISP_ENABLE_DISABLE_STATUS_DUMP, \
346 lisp_enable_disable_status_dump) \
347 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
348 lisp_add_del_map_request_itr_rlocs) \
349 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
350 _(SHOW_LISP_PITR, show_lisp_pitr) \
351 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
352 _(AF_PACKET_CREATE, af_packet_create) \
353 _(AF_PACKET_DELETE, af_packet_delete) \
354 _(POLICER_ADD_DEL, policer_add_del) \
355 _(POLICER_DUMP, policer_dump) \
356 _(NETMAP_CREATE, netmap_create) \
357 _(NETMAP_DELETE, netmap_delete) \
358 _(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump) \
359 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
360 _(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump) \
361 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
362 _(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
363 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
364 _(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump) \
365 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
366 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
367 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
368 _(CLASSIFY_TABLE_INFO,classify_table_info) \
369 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
370 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
371 _(IPFIX_ENABLE,ipfix_enable) \
372 _(IPFIX_DUMP,ipfix_dump) \
373 _(GET_NEXT_INDEX, get_next_index)
376 #define QUOTE(x) QUOTE_(x)
378 #define foreach_registration_hash \
379 _(interface_events) \
380 _(to_netconf_server) \
381 _(from_netconf_server) \
382 _(to_netconf_client) \
383 _(from_netconf_client) \
387 RESOLVE_IP4_ADD_DEL_ROUTE=1,
388 RESOLVE_IP6_ADD_DEL_ROUTE,
389 RESOLVE_MPLS_ETHERNET_ADD_DEL,
395 vl_api_ip_add_del_route_t r;
396 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
402 #define _(a) uword *a##_registration_hash; \
403 vpe_client_registration_t * a##_registrations;
404 foreach_registration_hash
407 /* notifications happen really early in the game */
408 u8 link_state_process_up;
410 /* ip4 pending route adds */
411 pending_route_t * pending_routes;
413 /* ip4 arp event registration pool */
414 vl_api_ip4_arp_event_t * arp_events;
417 vlib_main_t * vlib_main;
418 vnet_main_t * vnet_main;
421 static vlib_node_registration_t vpe_resolver_process_node;
422 static vpe_api_main_t vpe_api_main;
424 static void send_sw_interface_flags (vpe_api_main_t * am,
425 unix_shared_memory_queue_t *q,
426 vnet_sw_interface_t * swif);
427 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
428 unix_shared_memory_queue_t *q,
431 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
434 /* Clean up all registrations belonging to the indicated client */
435 int vl_api_memclnt_delete_callback (u32 client_index)
437 vpe_api_main_t * vam = &vpe_api_main;
438 vpe_client_registration_t *rp;
440 int stats_memclnt_delete_callback (u32 client_index);
442 stats_memclnt_delete_callback (client_index);
445 p = hash_get (vam->a##_registration_hash, client_index); \
447 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
448 pool_put (vam->a##_registrations, rp); \
449 hash_unset (vam->a##_registration_hash, client_index); \
451 foreach_registration_hash;
456 #define API_LINK_STATE_EVENT 1
457 #define API_ADMIN_UP_DOWN_EVENT 2
460 event_data_cmp (void * a1, void * a2)
465 return (word) e1[0] - (word) e2[0];
469 link_state_process (vlib_main_t * vm,
470 vlib_node_runtime_t * rt,
473 vpe_api_main_t * vam = &vpe_api_main;
474 vnet_main_t * vnm = vam->vnet_main;
475 vnet_sw_interface_t * swif;
476 uword * event_data = 0;
477 vpe_client_registration_t *reg;
479 u32 prev_sw_if_index;
480 unix_shared_memory_queue_t * q;
482 vam->link_state_process_up = 1;
485 vlib_process_wait_for_event (vm);
487 /* Unified list of changed link or admin state sw_if_indices */
488 vlib_process_get_events_with_type
489 (vm, &event_data, API_LINK_STATE_EVENT);
490 vlib_process_get_events_with_type
491 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
493 /* Sort, so we can eliminate duplicates */
494 vec_sort_with_function (event_data, event_data_cmp);
496 prev_sw_if_index = ~0;
498 for (i = 0; i < vec_len(event_data); i++) {
499 /* Only one message per swif */
500 if (prev_sw_if_index == event_data[i])
502 prev_sw_if_index = event_data[i];
504 pool_foreach(reg, vam->interface_events_registrations,
506 q = vl_api_client_index_to_input_queue (reg->client_index);
508 // sw_interface may be deleted already
509 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
512 swif = vnet_get_sw_interface (vnm, event_data[i]);
513 send_sw_interface_flags (vam, q, swif);
518 vec_reset_length (event_data);
524 static clib_error_t *
525 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
526 static clib_error_t *
527 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
529 VLIB_REGISTER_NODE (link_state_process_node,static) = {
530 .function = link_state_process,
531 .type = VLIB_NODE_TYPE_PROCESS,
532 .name = "vpe-link-state-process",
535 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
536 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
538 static clib_error_t *
539 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
541 vpe_api_main_t * vam = &vpe_api_main;
542 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
544 if (vam->link_state_process_up)
545 vlib_process_signal_event (vam->vlib_main,
546 link_state_process_node.index,
547 API_LINK_STATE_EVENT,
552 static clib_error_t *
553 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
555 vpe_api_main_t * vam = &vpe_api_main;
558 * Note: it's perfectly fair to set a subif admin up / admin down.
559 * Note the subtle distinction between this routine and the previous
562 if (vam->link_state_process_up)
563 vlib_process_signal_event (vam->vlib_main,
564 link_state_process_node.index,
565 API_ADMIN_UP_DOWN_EVENT,
570 #define pub_sub_handler(lca,UCA) \
571 static void vl_api_want_##lca##_t_handler ( \
572 vl_api_want_##lca##_t *mp) \
574 vpe_api_main_t *vam = &vpe_api_main; \
575 vpe_client_registration_t *rp; \
576 vl_api_want_##lca##_reply_t *rmp; \
580 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
582 if (mp->enable_disable) { \
583 clib_warning ("pid %d: already enabled...", mp->pid); \
584 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
587 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
588 pool_put (vam->lca##_registrations, rp); \
589 hash_unset (vam->lca##_registration_hash, \
594 if (mp->enable_disable == 0) { \
595 clib_warning ("pid %d: already disabled...", mp->pid); \
596 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
599 pool_get (vam->lca##_registrations, rp); \
600 rp->client_index = mp->client_index; \
601 rp->client_pid = mp->pid; \
602 hash_set (vam->lca##_registration_hash, rp->client_index, \
603 rp - vam->lca##_registrations); \
606 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
609 pub_sub_handler (interface_events,INTERFACE_EVENTS)
610 pub_sub_handler (oam_events,OAM_EVENTS)
612 #define RESOLUTION_EVENT 1
613 #define RESOLUTION_PENDING_EVENT 2
614 #define IP4_ARP_EVENT 3
616 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
617 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
618 static int mpls_ethernet_add_del_tunnel_2_t_handler
619 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
621 void handle_ip4_arp_event (u32 pool_index)
623 vpe_api_main_t * vam = &vpe_api_main;
624 vnet_main_t * vnm = vam->vnet_main;
625 vlib_main_t * vm = vam->vlib_main;
626 vl_api_ip4_arp_event_t * event;
627 vl_api_ip4_arp_event_t * mp;
628 unix_shared_memory_queue_t * q;
630 /* Client can cancel, die, etc. */
631 if (pool_is_free_index (vam->arp_events, pool_index))
634 event = pool_elt_at_index (vam->arp_events, pool_index);
636 q = vl_api_client_index_to_input_queue (event->client_index);
638 (void) vnet_add_del_ip4_arp_change_event
639 (vnm, arp_change_delete_callback,
640 event->pid, &event->address,
641 vpe_resolver_process_node.index, IP4_ARP_EVENT,
642 ~0 /* pool index, notused */, 0 /* is_add */);
646 if (q->cursize < q->maxsize) {
647 mp = vl_msg_api_alloc (sizeof (*mp));
648 clib_memcpy (mp, event, sizeof (*mp));
649 vl_msg_api_send_shmem (q, (u8 *)&mp);
651 static f64 last_time;
653 * Throttle syslog msgs.
654 * It's pretty tempting to just revoke the registration...
656 if (vlib_time_now (vm) > last_time + 10.0) {
657 clib_warning ("arp event for %U to pid %d: queue stuffed!",
658 format_ip4_address, &event->address, event->pid);
659 last_time = vlib_time_now(vm);
665 resolver_process (vlib_main_t * vm,
666 vlib_node_runtime_t * rt,
670 uword *event_data = 0;
672 vpe_api_main_t * vam = &vpe_api_main;
673 pending_route_t * pr;
674 vl_api_ip_add_del_route_t * adr;
675 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
676 u32 * resolution_failures = 0;
681 vlib_process_wait_for_event_or_clock (vm, timeout);
683 event_type = vlib_process_get_events (vm, &event_data);
685 switch (event_type) {
686 case RESOLUTION_PENDING_EVENT:
690 case RESOLUTION_EVENT:
691 for (i = 0; i < vec_len(event_data); i++) {
693 * Resolution events can occur long after the
694 * original request has timed out. $$$ add a cancel
697 if (pool_is_free_index (vam->pending_routes, event_data[i]))
700 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
704 switch (pr->resolve_type) {
705 case RESOLVE_IP4_ADD_DEL_ROUTE:
706 rv = ip4_add_del_route_t_handler (adr);
707 clib_warning ("resolver: add %U/%d via %U %s",
709 (ip4_address_t *)&(adr->dst_address),
710 adr->dst_address_length,
712 (ip4_address_t *)&(adr->next_hop_address),
713 (rv >= 0) ? "succeeded" : "failed");
716 case RESOLVE_IP6_ADD_DEL_ROUTE:
717 rv = ip6_add_del_route_t_handler (adr);
718 clib_warning ("resolver: add %U/%d via %U %s",
720 (ip6_address_t *)&(adr->dst_address),
721 adr->dst_address_length,
723 (ip6_address_t *)&(adr->next_hop_address),
724 (rv >= 0) ? "succeeded" : "failed");
727 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
728 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
729 clib_warning ("resolver: add mpls-o-e via %U %s",
731 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
732 (rv >= 0) ? "succeeded" : "failed");
736 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
738 pool_put (vam->pending_routes, pr);
743 for (i = 0; i < vec_len(event_data); i++)
744 handle_ip4_arp_event (event_data[i]);
747 case ~0: /* timeout, retry pending resolutions */
748 pool_foreach (pr, vam->pending_routes,
754 /* May fail, e.g. due to interface down */
755 switch (pr->resolve_type) {
756 case RESOLVE_IP4_ADD_DEL_ROUTE:
757 e = ip4_probe_neighbor
758 (vm, (ip4_address_t *)&(adr->next_hop_address),
759 ntohl(adr->next_hop_sw_if_index));
762 case RESOLVE_IP6_ADD_DEL_ROUTE:
763 e = ip6_probe_neighbor
764 (vm, (ip6_address_t *)&(adr->next_hop_address),
765 ntohl(adr->next_hop_sw_if_index));
768 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
770 e = ip4_probe_neighbor
772 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
773 pme->resolve_opaque);
777 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
781 clib_error_report (e);
783 adr->resolve_attempts = 1;
785 pme->resolve_attempts = 1;
789 adr->resolve_attempts -= 1;
790 if (adr->resolve_attempts == 0)
791 vec_add1 (resolution_failures,
792 pr - vam->pending_routes);
794 pme->resolve_attempts -= 1;
795 if (pme->resolve_attempts == 0)
796 vec_add1 (resolution_failures,
797 pr - vam->pending_routes);
801 for (i = 0; i < vec_len (resolution_failures); i++) {
802 pr = pool_elt_at_index (vam->pending_routes,
803 resolution_failures[i]);
807 switch (pr->resolve_type) {
808 case RESOLVE_IP4_ADD_DEL_ROUTE:
809 clib_warning ("resolver: add %U/%d via %U retry failure",
811 (ip4_address_t *)&(adr->dst_address),
812 adr->dst_address_length,
814 (ip4_address_t *)&(adr->next_hop_address));
817 case RESOLVE_IP6_ADD_DEL_ROUTE:
818 clib_warning ("resolver: add %U/%d via %U retry failure",
820 (ip6_address_t *)&(adr->dst_address),
821 adr->dst_address_length,
823 (ip6_address_t *)&(adr->next_hop_address));
826 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
827 clib_warning ("resolver: add mpls-o-e via %U retry failure",
829 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
833 clib_warning ("BUG");
835 pool_put(vam->pending_routes, pr);
837 vec_reset_length (resolution_failures);
840 if (pool_elts (vam->pending_routes) == 0)
842 vec_reset_length (event_data);
844 return 0; /* or not */
847 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
848 .function = resolver_process,
849 .type = VLIB_NODE_TYPE_PROCESS,
850 .name = "vpe-route-resolver-process",
853 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
855 ip4_main_t * im = &ip4_main;
856 ip_lookup_main_t * lm = &im->lookup_main;
857 vnet_classify_main_t * cm = &vnet_classify_main;
858 stats_main_t * sm = &stats_main;
859 ip4_add_del_route_args_t a;
860 ip4_address_t next_hop_address;
862 vpe_api_main_t * vam = &vpe_api_main;
863 vnet_main_t * vnm = vam->vnet_main;
864 vlib_main_t * vm = vlib_get_main();
865 pending_route_t * pr;
866 vl_api_ip_add_del_route_t * adr;
872 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
874 if (mp->create_vrf_if_needed) {
876 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
878 fib_index = f->index;
880 /* No such VRF, and we weren't asked to create one */
881 return VNET_API_ERROR_NO_SUCH_FIB;
887 if (~0 != mp->next_hop_sw_if_index &&
888 pool_is_free_index (vnm->interface_main.sw_interfaces,
889 ntohl(mp->next_hop_sw_if_index)))
890 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
892 clib_memcpy (next_hop_address.data, mp->next_hop_address,
893 sizeof (next_hop_address.data));
895 /* Arp for the next_hop if necessary */
896 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index) {
898 ip_adjacency_t * adj;
900 lookup_result = ip4_fib_lookup_with_table
901 (im, fib_index, &next_hop_address, 1 /* disable default route */);
903 adj = ip_get_adjacency (lm, lookup_result);
905 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
906 pool_get (vam->pending_routes, pr);
907 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
909 clib_memcpy (adr, mp, sizeof (*adr));
910 /* recursion block, "just in case" */
911 adr->resolve_if_needed = 0;
912 adr->resolve_attempts = ntohl(mp->resolve_attempts);
913 vnet_register_ip4_arp_resolution_event
914 (vnm, &next_hop_address, vpe_resolver_process_node.index,
915 RESOLUTION_EVENT, pr - vam->pending_routes);
917 vlib_process_signal_event
918 (vm, vpe_resolver_process_node.index,
919 RESOLUTION_PENDING_EVENT, 0 /* data */);
921 /* The interface may be down, etc. */
922 e = ip4_probe_neighbor
923 (vm, (ip4_address_t *)&(mp->next_hop_address),
924 ntohl(mp->next_hop_sw_if_index));
927 clib_error_report(e);
929 return VNET_API_ERROR_IN_PROGRESS;
933 if (mp->is_multipath) {
936 dslock (sm, 1 /* release hint */, 10 /* tag */);
939 flags = IP4_ROUTE_FLAG_ADD;
941 flags = IP4_ROUTE_FLAG_DEL;
944 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
946 ip4_add_del_route_next_hop (im, flags,
947 (ip4_address_t *) mp->dst_address,
948 (u32) mp->dst_address_length,
949 (ip4_address_t *) mp->next_hop_address,
950 ntohl(mp->next_hop_sw_if_index),
951 (u32) mp->next_hop_weight,
958 memset (&a, 0, sizeof (a));
959 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
961 a.dst_address_length = mp->dst_address_length;
963 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
964 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
965 a.table_index_or_table_id = fib_index;
970 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
972 dslock (sm, 1 /* release hint */, 2 /* tag */);
976 ai = lm->drop_adj_index;
977 else if (mp->is_local)
978 ai = lm->local_adj_index;
979 else if (mp->is_classify) {
980 if (pool_is_free_index (cm->tables, ntohl(mp->classify_table_index))) {
982 return VNET_API_ERROR_NO_SUCH_TABLE;
984 adj = ip_add_adjacency (lm,
989 adj->lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
990 adj->classify.table_index = ntohl(mp->classify_table_index);
992 else if (mp->lookup_in_vrf) {
993 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
995 adj = ip_add_adjacency (lm,
999 adj->explicit_fib_index = p[0];
1003 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1007 ai = ip4_route_get_next_hop_adj (im,
1010 ntohl(mp->next_hop_sw_if_index),
1013 if (ai == lm->miss_adj_index) {
1015 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1018 ip_adjacency_t * adj;
1019 int disable_default_route = 1;
1021 /* Trying to delete the default route? */
1022 if (a.dst_address.as_u32 == 0 &&
1023 a.dst_address_length == 0)
1024 disable_default_route = 0;
1026 ai = ip4_fib_lookup_with_table
1027 (im, fib_index, &a.dst_address, disable_default_route);
1028 if (ai == lm->miss_adj_index) {
1030 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1033 adj = ip_get_adjacency (lm, ai);
1034 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1036 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1041 ip4_add_del_route (im, &a);
1047 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1049 ip6_main_t * im = &ip6_main;
1050 ip_lookup_main_t * lm = &im->lookup_main;
1051 vnet_main_t * vnm = vnet_get_main();
1052 vlib_main_t * vm = vlib_get_main();
1053 vpe_api_main_t * vam = &vpe_api_main;
1054 stats_main_t * sm = &stats_main;
1055 ip6_add_del_route_args_t a;
1056 ip6_address_t next_hop_address;
1057 pending_route_t * pr;
1058 vl_api_ip_add_del_route_t * adr;
1063 ip_adjacency_t *adj = 0;
1066 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1069 if (mp->create_vrf_if_needed) {
1071 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1073 fib_index = f->index;
1075 /* No such VRF, and we weren't asked to create one */
1076 return VNET_API_ERROR_NO_SUCH_FIB;
1082 if (~0 != mp->next_hop_sw_if_index &&
1083 pool_is_free_index (vnm->interface_main.sw_interfaces,
1084 ntohl(mp->next_hop_sw_if_index)))
1085 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1087 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1088 sizeof (next_hop_address.as_u8));
1090 /* Arp for the next_hop if necessary */
1091 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index) {
1093 ip_adjacency_t * adj;
1095 lookup_result = ip6_fib_lookup_with_table
1096 (im, fib_index, &next_hop_address);
1098 adj = ip_get_adjacency (lm, lookup_result);
1100 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1101 pool_get (vam->pending_routes, pr);
1103 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1104 clib_memcpy (adr, mp, sizeof (*adr));
1105 /* recursion block, "just in case" */
1106 adr->resolve_if_needed = 0;
1107 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1108 vnet_register_ip6_neighbor_resolution_event
1109 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1110 RESOLUTION_EVENT, pr - vam->pending_routes);
1112 vlib_process_signal_event
1113 (vm, vpe_resolver_process_node.index,
1114 RESOLUTION_PENDING_EVENT, 0 /* data */);
1116 /* The interface may be down, etc. */
1117 e = ip6_probe_neighbor
1118 (vm, (ip6_address_t *)&(mp->next_hop_address),
1119 ntohl(mp->next_hop_sw_if_index));
1122 clib_error_report(e);
1124 return VNET_API_ERROR_IN_PROGRESS;
1128 if (mp->is_multipath) {
1131 dslock (sm, 1 /* release hint */, 11 /* tag */);
1134 flags = IP6_ROUTE_FLAG_ADD;
1136 flags = IP6_ROUTE_FLAG_DEL;
1139 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1141 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1142 (u32) mp->dst_address_length,
1143 (ip6_address_t *)mp->next_hop_address,
1144 ntohl(mp->next_hop_sw_if_index),
1145 (u32) mp->next_hop_weight,
1152 memset (&a, 0, sizeof (a));
1153 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1155 a.dst_address_length = mp->dst_address_length;
1157 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1158 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1159 a.table_index_or_table_id = fib_index;
1164 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1166 dslock (sm, 1 /* release hint */, 3 /* tag */);
1170 ai = lm->drop_adj_index;
1171 else if (mp->is_local)
1172 ai = lm->local_adj_index;
1173 else if (mp->lookup_in_vrf) {
1174 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1176 adj = ip_add_adjacency (lm,
1180 adj->explicit_fib_index = p[0];
1184 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1188 ai = ip6_route_get_next_hop_adj (im,
1191 ntohl(mp->next_hop_sw_if_index),
1193 if (ai == lm->miss_adj_index) {
1195 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1198 ip_adjacency_t * adj;
1200 ai = ip6_fib_lookup_with_table
1201 (im, fib_index, &a.dst_address);
1202 if (ai == lm->miss_adj_index) {
1204 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1206 adj = ip_get_adjacency (lm, ai);
1207 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1209 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1214 ip6_add_del_route (im, &a);
1220 void vl_api_ip_add_del_route_t_handler (
1221 vl_api_ip_add_del_route_t *mp)
1223 vl_api_ip_add_del_route_reply_t * rmp;
1225 vnet_main_t * vnm = vnet_get_main();
1230 rv = ip6_add_del_route_t_handler (mp);
1232 rv = ip4_add_del_route_t_handler (mp);
1234 rv = (rv == 0) ? vnm->api_errno : rv;
1236 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1239 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1240 u32 sw_if_index, u8 *next_hop_addr)
1242 vl_api_ip_add_del_route_t mp;
1245 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1248 * Configure default IP route:
1249 * - ip route add 0.0.0.0/1 via <GW IP>
1250 * - ip route add 128.0.0.0/1 via <GW IP>
1252 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1254 mp.resolve_attempts = ~0;
1255 mp.resolve_if_needed = 1;
1257 mp.is_ipv6 = is_ipv6;
1258 mp.next_hop_weight = 1;
1260 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1263 rv = ip6_add_del_route_t_handler (&mp);
1266 mp.dst_address_length = 1;
1268 mp.dst_address[0] = 0;
1269 rv = ip4_add_del_route_t_handler (&mp);
1271 mp.dst_address[0] = 128;
1272 rv |= ip4_add_del_route_t_handler (&mp);
1276 clib_error_return (0, "failed to config default IP route");
1281 vl_api_sw_interface_add_del_address_t_handler
1282 (vl_api_sw_interface_add_del_address_t *mp)
1284 vlib_main_t *vm = vlib_get_main();
1285 vl_api_sw_interface_add_del_address_reply_t * rmp;
1289 VALIDATE_SW_IF_INDEX(mp);
1291 is_del = mp->is_add == 0;
1294 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1295 else if (mp->is_ipv6)
1296 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1297 (void *)mp->address,
1298 mp->address_length, is_del);
1300 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1301 (void *) mp->address,
1302 mp->address_length, is_del);
1304 BAD_SW_IF_INDEX_LABEL;
1306 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1310 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1313 u32 table_id = ntohl(mp->vrf_id);
1314 u32 sw_if_index = ntohl(mp->sw_if_index);
1315 vl_api_sw_interface_set_table_reply_t * rmp;
1316 stats_main_t * sm = &stats_main;
1318 VALIDATE_SW_IF_INDEX(mp);
1320 dslock (sm, 1 /* release hint */, 4 /* tag */);
1323 ip6_main_t * im = &ip6_main;
1325 find_ip6_fib_by_table_index_or_id (im, table_id,
1326 IP6_ROUTE_FLAG_TABLE_ID);
1328 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1329 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1331 rv = VNET_API_ERROR_NO_SUCH_FIB;
1334 ip4_main_t * im = &ip4_main;
1335 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1336 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1338 /* Truthfully this can't fail */
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;
1348 BAD_SW_IF_INDEX_LABEL;
1350 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1354 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1356 vlib_main_t *vm = vlib_get_main();
1357 ip4_main_t * im4 = &ip4_main;
1358 ip6_main_t * im6 = &ip6_main;
1359 vl_api_sw_interface_set_vpath_reply_t * rmp;
1362 u32 sw_if_index = ntohl(mp->sw_if_index);
1363 ip4_main_t *ip4m = &ip4_main;
1364 ip6_main_t *ip6m = &ip6_main;
1365 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1366 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1367 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1368 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1369 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1370 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1372 VALIDATE_SW_IF_INDEX(mp);
1374 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1376 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1377 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1379 im4->ip4_unicast_rx_feature_vpath,
1381 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1382 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1383 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1385 im4->ip4_multicast_rx_feature_vpath,
1387 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1388 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1389 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1391 im6->ip6_unicast_rx_feature_vpath,
1393 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1394 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1395 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1397 im6->ip6_multicast_rx_feature_vpath,
1399 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1401 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1402 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1404 im4->ip4_unicast_rx_feature_vpath,
1406 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1407 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1408 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1410 im4->ip4_multicast_rx_feature_vpath,
1412 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1413 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1414 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1416 im6->ip6_unicast_rx_feature_vpath,
1418 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1419 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1420 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1422 im6->ip6_multicast_rx_feature_vpath,
1424 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1427 BAD_SW_IF_INDEX_LABEL;
1429 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1433 vl_api_sw_interface_set_l2_xconnect_t_handler (
1434 vl_api_sw_interface_set_l2_xconnect_t *mp)
1436 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1438 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1439 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1440 vlib_main_t *vm = vlib_get_main();
1441 vnet_main_t *vnm = vnet_get_main();
1443 VALIDATE_RX_SW_IF_INDEX(mp);
1446 VALIDATE_TX_SW_IF_INDEX(mp);
1447 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1448 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1450 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1453 BAD_RX_SW_IF_INDEX_LABEL;
1454 BAD_TX_SW_IF_INDEX_LABEL;
1456 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1460 vl_api_sw_interface_set_l2_bridge_t_handler (
1461 vl_api_sw_interface_set_l2_bridge_t *mp)
1463 bd_main_t * bdm = &bd_main;
1464 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1466 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1467 u32 bd_id = ntohl(mp->bd_id);
1471 vlib_main_t *vm = vlib_get_main();
1472 vnet_main_t *vnm = vnet_get_main();
1474 VALIDATE_RX_SW_IF_INDEX(mp);
1476 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1479 //VALIDATE_TX_SW_IF_INDEX(mp);
1480 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1481 rx_sw_if_index, bd_index, bvi, shg, 0);
1483 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1486 BAD_RX_SW_IF_INDEX_LABEL;
1488 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1492 vl_api_bridge_domain_add_del_t_handler (
1493 vl_api_bridge_domain_add_del_t *mp)
1495 vlib_main_t * vm = vlib_get_main ();
1496 bd_main_t * bdm = &bd_main;
1497 vl_api_bridge_domain_add_del_reply_t * rmp;
1499 u32 enable_flags = 0, disable_flags = 0;
1500 u32 bd_id = ntohl(mp->bd_id);
1504 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1507 enable_flags |= L2_FLOOD;
1509 disable_flags |= L2_FLOOD;
1512 enable_flags |= L2_UU_FLOOD;
1514 disable_flags |= L2_UU_FLOOD;
1517 enable_flags |= L2_FWD;
1519 disable_flags |= L2_FWD;
1522 enable_flags |= L2_ARP_TERM;
1524 disable_flags |= L2_ARP_TERM;
1527 enable_flags |= L2_LEARN;
1529 disable_flags |= L2_LEARN;
1532 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1535 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1538 rv = bd_delete_bd_index(bdm, bd_id);
1540 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1543 static void vl_api_bridge_domain_details_t_handler (
1544 vl_api_bridge_domain_details_t * mp)
1546 clib_warning ("BUG");
1549 static void vl_api_bridge_domain_sw_if_details_t_handler (
1550 vl_api_bridge_domain_sw_if_details_t * mp)
1552 clib_warning ("BUG");
1555 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1556 l2_bridge_domain_t * bd_config,
1560 vl_api_bridge_domain_details_t * mp;
1562 mp = vl_msg_api_alloc (sizeof (*mp));
1563 memset (mp, 0, sizeof (*mp));
1564 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1565 mp->bd_id = ntohl (bd_config->bd_id);
1566 mp->flood = bd_feature_flood (bd_config);
1567 mp->uu_flood = bd_feature_uu_flood (bd_config);
1568 mp->forward = bd_feature_forward (bd_config);
1569 mp->learn = bd_feature_learn (bd_config);
1570 mp->arp_term = bd_feature_arp_term (bd_config);
1571 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1572 mp->n_sw_ifs = ntohl (n_sw_ifs);
1573 mp->context = context;
1575 vl_msg_api_send_shmem (q, (u8 *)&mp);
1578 static void send_bd_sw_if_details (l2input_main_t * l2im,
1579 unix_shared_memory_queue_t *q,
1580 l2_flood_member_t * member, u32 bd_id,
1583 vl_api_bridge_domain_sw_if_details_t * mp;
1584 l2_input_config_t * input_cfg;
1586 mp = vl_msg_api_alloc (sizeof (*mp));
1587 memset (mp, 0, sizeof (*mp));
1588 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1589 mp->bd_id = ntohl (bd_id);
1590 mp->sw_if_index = ntohl (member->sw_if_index);
1591 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1592 mp->shg = input_cfg->shg;
1593 mp->context = context;
1595 vl_msg_api_send_shmem (q, (u8 *)&mp);
1598 static void vl_api_bridge_domain_dump_t_handler (
1599 vl_api_bridge_domain_dump_t *mp)
1601 bd_main_t * bdm = &bd_main;
1602 l2input_main_t * l2im = &l2input_main;
1603 unix_shared_memory_queue_t * q;
1604 l2_bridge_domain_t * bd_config;
1605 u32 bd_id, bd_index;
1608 q = vl_api_client_index_to_input_queue (mp->client_index);
1613 bd_id = ntohl(mp->bd_id);
1615 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1616 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1617 for (; bd_index < end; bd_index++) {
1618 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1619 /* skip dummy bd_id 0 */
1620 if (bd_config && (bd_config->bd_id > 0)) {
1622 l2_flood_member_t * m;
1624 n_sw_ifs = vec_len (bd_config->members);
1625 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1627 vec_foreach (m, bd_config->members) {
1628 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1635 vl_api_l2fib_add_del_t_handler (
1636 vl_api_l2fib_add_del_t *mp)
1638 bd_main_t * bdm = &bd_main;
1639 l2input_main_t * l2im = &l2input_main;
1640 vl_api_l2fib_add_del_reply_t * rmp;
1643 u32 sw_if_index = ntohl(mp->sw_if_index);
1644 u32 bd_id = ntohl(mp->bd_id);
1653 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1655 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1656 goto bad_sw_if_index;
1661 VALIDATE_SW_IF_INDEX(mp);
1662 if (vec_len(l2im->configs) <= sw_if_index) {
1663 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1664 goto bad_sw_if_index;
1666 l2_input_config_t * config;
1667 config = vec_elt_at_index(l2im->configs, sw_if_index);
1668 if (config->bridge == 0) {
1669 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1670 goto bad_sw_if_index;
1673 static_mac = mp->static_mac ? 1 : 0;
1674 filter_mac = mp->filter_mac ? 1 : 0;
1675 bvi_mac = mp->bvi_mac ? 1 : 0;
1676 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1679 l2fib_del_entry(mac, bd_index);
1682 BAD_SW_IF_INDEX_LABEL;
1684 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1688 vl_api_l2_flags_t_handler (
1689 vl_api_l2_flags_t *mp)
1691 vl_api_l2_flags_reply_t * rmp;
1693 u32 sw_if_index = ntohl(mp->sw_if_index);
1694 u32 flags = ntohl(mp->feature_bitmap);
1697 VALIDATE_SW_IF_INDEX(mp);
1700 if (flags & L2INPUT_FEAT_ ## a) \
1701 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1702 foreach_l2input_feat;
1705 BAD_SW_IF_INDEX_LABEL;
1707 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1711 vl_api_bridge_flags_t_handler (
1712 vl_api_bridge_flags_t *mp)
1714 vlib_main_t *vm = vlib_get_main();
1715 bd_main_t * bdm = &bd_main;
1716 vl_api_bridge_flags_reply_t * rmp;
1718 u32 bd_id = ntohl(mp->bd_id);
1720 u32 flags = ntohl(mp->feature_bitmap);
1723 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1725 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1731 bd_set_flags(vm, bd_index, flags, mp->is_set);
1734 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1735 rmp->resulting_feature_bitmap = ntohl(flags));
1739 vl_api_bd_ip_mac_add_del_t_handler (
1740 vl_api_bd_ip_mac_add_del_t *mp)
1742 bd_main_t * bdm = &bd_main;
1743 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1745 u32 bd_id = ntohl(mp->bd_id);
1749 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1751 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1756 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1757 mp->mac_address, mp->is_ipv6, mp->is_add))
1758 rv = VNET_API_ERROR_UNSPECIFIED;
1761 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1765 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1768 vl_api_tap_connect_reply_t * rmp;
1769 unix_shared_memory_queue_t * q;
1770 u32 sw_if_index = (u32)~0;
1772 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1773 mp->use_random_mac ? 0 : mp->mac_address,
1774 &sw_if_index, mp->renumber,
1775 ntohl(mp->custom_dev_instance));
1777 q = vl_api_client_index_to_input_queue (mp->client_index);
1781 rmp = vl_msg_api_alloc (sizeof (*rmp));
1782 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1783 rmp->context = mp->context;
1784 rmp->retval = ntohl(rv);
1785 rmp->sw_if_index = ntohl(sw_if_index);
1787 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1791 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1794 vl_api_tap_modify_reply_t * rmp;
1795 unix_shared_memory_queue_t * q;
1796 u32 sw_if_index = (u32)~0;
1798 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1799 mp->use_random_mac ? 0 : mp->mac_address,
1800 &sw_if_index, mp->renumber,
1801 ntohl(mp->custom_dev_instance));
1803 q = vl_api_client_index_to_input_queue (mp->client_index);
1807 rmp = vl_msg_api_alloc (sizeof (*rmp));
1808 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1809 rmp->context = mp->context;
1810 rmp->retval = ntohl(rv);
1811 rmp->sw_if_index = ntohl(sw_if_index);
1813 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1817 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1820 vpe_api_main_t * vam = &vpe_api_main;
1821 vl_api_tap_delete_reply_t * rmp;
1822 unix_shared_memory_queue_t * q;
1823 u32 sw_if_index = ntohl(mp->sw_if_index);
1825 rv = vnet_tap_delete (vm, sw_if_index);
1827 q = vl_api_client_index_to_input_queue (mp->client_index);
1831 rmp = vl_msg_api_alloc (sizeof (*rmp));
1832 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1833 rmp->context = mp->context;
1834 rmp->retval = ntohl(rv);
1836 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1839 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1843 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1845 vl_api_create_vlan_subif_reply_t * rmp;
1846 vnet_main_t * vnm = vnet_get_main();
1847 u32 hw_if_index, sw_if_index = (u32)~0;
1848 vnet_hw_interface_t * hi;
1851 vnet_sw_interface_t template;
1853 vnet_interface_main_t * im = &vnm->interface_main;
1854 u64 sup_and_sub_key;
1856 unix_shared_memory_queue_t * q;
1857 clib_error_t * error;
1859 VALIDATE_SW_IF_INDEX(mp);
1861 hw_if_index = ntohl(mp->sw_if_index);
1862 hi = vnet_get_hw_interface (vnm, hw_if_index);
1864 id = ntohl(mp->vlan_id);
1865 if (id == 0 || id > 4095) {
1866 rv = VNET_API_ERROR_INVALID_VLAN;
1870 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1872 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1874 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1878 kp = clib_mem_alloc (sizeof (*kp));
1879 *kp = sup_and_sub_key;
1881 memset (&template, 0, sizeof (template));
1882 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1883 template.sup_sw_if_index = hi->sw_if_index;
1884 template.sub.id = id;
1885 template.sub.eth.raw_flags = 0;
1886 template.sub.eth.flags.one_tag = 1;
1887 template.sub.eth.outer_vlan_id = id;
1888 template.sub.eth.flags.exact_match = 1;
1890 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1892 clib_error_report(error);
1893 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1896 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1897 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1899 BAD_SW_IF_INDEX_LABEL;
1902 q = vl_api_client_index_to_input_queue (mp->client_index);
1906 rmp = vl_msg_api_alloc (sizeof (*rmp));
1907 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1908 rmp->context = mp->context;
1909 rmp->retval = ntohl(rv);
1910 rmp->sw_if_index = ntohl(sw_if_index);
1911 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1915 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1917 vl_api_create_subif_reply_t * rmp;
1918 vnet_main_t * vnm = vnet_get_main();
1919 u32 sw_if_index = ~0;
1922 vnet_sw_interface_t *si;
1923 vnet_hw_interface_t *hi;
1924 vnet_sw_interface_t template;
1926 vnet_interface_main_t * im = &vnm->interface_main;
1927 u64 sup_and_sub_key;
1929 clib_error_t * error;
1931 VALIDATE_SW_IF_INDEX(mp);
1933 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1934 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1936 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1937 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1941 sw_if_index = si->sw_if_index;
1942 sub_id = ntohl(mp->sub_id);
1944 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1946 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1949 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1950 sw_if_index, sub_id);
1951 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1955 kp = clib_mem_alloc (sizeof (*kp));
1956 *kp = sup_and_sub_key;
1958 memset (&template, 0, sizeof (template));
1959 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1960 template.sup_sw_if_index = sw_if_index;
1961 template.sub.id = sub_id;
1962 template.sub.eth.flags.no_tags = mp->no_tags;
1963 template.sub.eth.flags.one_tag = mp->one_tag;
1964 template.sub.eth.flags.two_tags = mp->two_tags;
1965 template.sub.eth.flags.dot1ad = mp->dot1ad;
1966 template.sub.eth.flags.exact_match = mp->exact_match;
1967 template.sub.eth.flags.default_sub = mp->default_sub;
1968 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1969 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1970 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1971 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1973 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1975 clib_error_report (error);
1976 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1980 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1981 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1983 BAD_SW_IF_INDEX_LABEL;
1987 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1989 rmp->sw_if_index = ntohl(sw_if_index);
1994 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1996 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1998 stats_main_t * sm = &stats_main;
1999 u32 tunnel_sw_if_index = ~0;
2001 dslock (sm, 1 /* release hint */, 5 /* tag */);
2003 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
2004 (ip4_address_t *)(mp->dst_address),
2005 (ip4_address_t *)(mp->intfc_address),
2006 (u32)(mp->intfc_address_length),
2007 ntohl(mp->inner_vrf_id),
2008 ntohl(mp->outer_vrf_id),
2009 &tunnel_sw_if_index,
2014 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
2016 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2021 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2022 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
2024 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2026 stats_main_t * sm = &stats_main;
2027 u32 tunnel_sw_if_index;
2029 dslock (sm, 1 /* release hint */, 5 /* tag */);
2031 rv = vnet_mpls_ethernet_add_del_tunnel
2032 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
2033 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
2034 ntohl(mp->tx_sw_if_index),
2035 &tunnel_sw_if_index,
2041 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2043 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2048 * This piece of misery brought to you because the control-plane
2049 * can't figure out the tx interface + dst-mac address all by itself
2051 static int mpls_ethernet_add_del_tunnel_2_t_handler
2052 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2054 pending_route_t * pr;
2055 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2056 vnet_main_t * vnm = vnet_get_main();
2057 vlib_main_t * vm = vlib_get_main();
2058 stats_main_t * sm = &stats_main;
2059 vpe_api_main_t * vam = &vpe_api_main;
2060 u32 inner_fib_index, outer_fib_index;
2061 ip4_main_t * im = &ip4_main;
2062 ip_lookup_main_t * lm = &im->lookup_main;
2063 ip_adjacency_t * adj = 0;
2066 u8 * dst_mac_address;
2070 u32 tunnel_sw_if_index;
2072 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2074 return VNET_API_ERROR_NO_SUCH_FIB;
2076 outer_fib_index = p[0];
2079 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2081 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2083 inner_fib_index = p[0];
2085 if (inner_fib_index == outer_fib_index)
2086 return VNET_API_ERROR_INVALID_VALUE;
2088 lookup_result = ip4_fib_lookup_with_table
2089 (im, outer_fib_index,
2090 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2091 1 /* disable default route */);
2093 adj = ip_get_adjacency (lm, lookup_result);
2094 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2096 if (mp->is_add && mp->resolve_if_needed) {
2097 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2098 pool_get (vam->pending_routes, pr);
2099 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2101 clib_memcpy (pme, mp, sizeof (*pme));
2102 /* recursion block, "just in case" */
2103 pme->resolve_if_needed = 0;
2104 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2105 pme->resolve_opaque = tx_sw_if_index;
2106 vnet_register_ip4_arp_resolution_event
2108 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2109 vpe_resolver_process_node.index,
2110 RESOLUTION_EVENT, pr - vam->pending_routes);
2112 vlib_process_signal_event
2113 (vm, vpe_resolver_process_node.index,
2114 RESOLUTION_PENDING_EVENT, 0 /* data */);
2116 /* The interface may be down, etc. */
2117 e = ip4_probe_neighbor
2118 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2122 clib_error_report(e);
2124 return VNET_API_ERROR_IN_PROGRESS;
2128 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2129 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2132 vnet_rewrite_get_data_internal
2133 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2135 dslock (sm, 1 /* release hint */, 10 /* tag */);
2137 rv = vnet_mpls_ethernet_add_del_tunnel
2138 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2139 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2140 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2148 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2149 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2151 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2154 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2156 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2161 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2163 vl_api_mpls_add_del_encap_reply_t * rmp;
2165 static u32 * labels;
2168 vec_reset_length (labels);
2170 for (i = 0; i < mp->nlabels; i++)
2171 vec_add1 (labels, ntohl(mp->labels[i]));
2174 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2175 ntohl(mp->vrf_id), labels,
2176 ~0 /* policy_tunnel_index */,
2177 0 /* no_dst_hash */,
2181 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2185 vl_api_mpls_add_del_decap_t_handler
2186 (vl_api_mpls_add_del_decap_t *mp)
2188 vl_api_mpls_add_del_decap_reply_t * rmp;
2191 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2192 ntohl(mp->label), ntohl(mp->next_index),
2193 mp->s_bit, mp->is_add);
2195 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2199 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2201 vl_api_proxy_arp_add_del_reply_t * rmp;
2204 ip4_main_t * im = &ip4_main;
2205 stats_main_t * sm = &stats_main;
2206 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2207 ip4_address_t *hi_addr,
2208 u32 fib_index, int is_del);
2211 dslock (sm, 1 /* release hint */, 6 /* tag */);
2213 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2216 rv = VNET_API_ERROR_NO_SUCH_FIB;
2222 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2223 (ip4_address_t *)mp->hi_address,
2224 fib_index, mp->is_add == 0);
2228 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2232 vl_api_proxy_arp_intfc_enable_disable_t_handler
2233 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2236 vnet_main_t * vnm = vnet_get_main();
2237 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2238 vnet_sw_interface_t * si;
2241 VALIDATE_SW_IF_INDEX(mp);
2243 sw_if_index = ntohl(mp->sw_if_index);
2245 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2247 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2251 si = vnet_get_sw_interface (vnm, sw_if_index);
2255 if (mp->enable_disable)
2256 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2258 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2260 BAD_SW_IF_INDEX_LABEL;
2263 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2267 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2269 vl_api_ip_neighbor_add_del_reply_t * rmp;
2270 vnet_main_t * vnm = vnet_get_main();
2273 stats_main_t * sm = &stats_main;
2275 VALIDATE_SW_IF_INDEX(mp);
2277 dslock (sm, 1 /* release hint */, 7 /* tag */);
2281 rv = vnet_set_ip6_ethernet_neighbor
2282 (vm, ntohl(mp->sw_if_index),
2283 (ip6_address_t *)(mp->dst_address),
2284 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2286 rv = vnet_unset_ip6_ethernet_neighbor
2287 (vm, ntohl(mp->sw_if_index),
2288 (ip6_address_t *)(mp->dst_address),
2289 mp->mac_address, sizeof(mp->mac_address));
2291 ip4_main_t * im = &ip4_main;
2292 ip_lookup_main_t * lm = &im->lookup_main;
2293 ethernet_arp_ip4_over_ethernet_address_t a;
2295 ip_adjacency_t *nh_adj;
2297 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2299 rv = VNET_API_ERROR_NO_SUCH_FIB;
2305 * Unfortunately, folks have a penchant for
2306 * adding interface addresses to the ARP cache, and
2307 * wondering why the forwarder eventually ASSERTs...
2309 ai = ip4_fib_lookup_with_table
2310 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2311 1 /* disable default route */);
2314 nh_adj = ip_get_adjacency (lm, ai);
2315 /* Never allow manipulation of a local adj! */
2316 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2317 clib_warning("%U matches local adj",
2319 (ip4_address_t *)(mp->dst_address));
2320 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2325 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2326 clib_memcpy (&a.ip4, mp->dst_address, 4);
2329 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2330 fib_index, &a, mp->is_static);
2332 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2336 BAD_SW_IF_INDEX_LABEL;
2339 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2343 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2346 vpe_main_t *rm = &vpe_main;
2347 ip4_main_t *im4 = &ip4_main;
2348 ip6_main_t *im6 = &ip6_main;
2349 ip_lookup_main_t * lm;
2354 u32 adj_index, sw_if_index;
2355 vl_api_is_address_reachable_t *rmp;
2356 ip_adjacency_t * adj;
2357 unix_shared_memory_queue_t *q;
2359 q = vl_api_client_index_to_input_queue (mp->client_index);
2361 increment_missing_api_client_counter (rm->vlib_main);
2365 rmp = vl_msg_api_alloc (sizeof (*rmp));
2366 clib_memcpy (rmp, mp, sizeof (*rmp));
2368 sw_if_index = mp->next_hop_sw_if_index;
2369 clib_memcpy (&addr, mp->address, sizeof (addr));
2371 lm = &im6->lookup_main;
2373 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2375 lm = &im4->lookup_main;
2377 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2379 if (adj_index == ~0) {
2383 adj = ip_get_adjacency (lm, adj_index);
2385 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2386 && adj->rewrite_header.sw_if_index == sw_if_index) {
2389 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2390 && adj->rewrite_header.sw_if_index == sw_if_index) {
2392 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2394 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2395 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2403 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2407 static void vl_api_sw_interface_details_t_handler (
2408 vl_api_sw_interface_details_t * mp)
2410 clib_warning ("BUG");
2413 static void vl_api_sw_interface_set_flags_t_handler (
2414 vl_api_sw_interface_set_flags_t * mp)
2416 vl_api_sw_interface_set_flags_reply_t *rmp;
2417 vnet_main_t * vnm = vnet_get_main();
2419 clib_error_t * error;
2422 VALIDATE_SW_IF_INDEX(mp);
2424 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2426 error = vnet_sw_interface_set_flags (vnm,
2427 ntohl(mp->sw_if_index),
2431 clib_error_report (error);
2434 BAD_SW_IF_INDEX_LABEL;
2435 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2438 static void vl_api_sw_interface_clear_stats_t_handler (
2439 vl_api_sw_interface_clear_stats_t * mp)
2441 vl_api_sw_interface_clear_stats_reply_t *rmp;
2443 vnet_main_t * vnm = vnet_get_main();
2444 vnet_interface_main_t * im = &vnm->interface_main;
2445 vlib_simple_counter_main_t * sm;
2446 vlib_combined_counter_main_t * cm;
2447 static vnet_main_t ** my_vnet_mains;
2448 int i, j, n_counters;
2452 vec_reset_length (my_vnet_mains);
2454 for (i = 0; i < vec_len (vnet_mains); i++)
2457 vec_add1 (my_vnet_mains, vnet_mains[i]);
2460 if (vec_len (vnet_mains) == 0)
2461 vec_add1 (my_vnet_mains, vnm);
2463 n_counters = vec_len (im->combined_sw_if_counters);
2465 for (j = 0; j < n_counters; j++)
2467 for (i = 0; i < vec_len(my_vnet_mains); i++)
2469 im = &my_vnet_mains[i]->interface_main;
2470 cm = im->combined_sw_if_counters + j;
2471 if (mp->sw_if_index == (u32)~0)
2472 vlib_clear_combined_counters (cm);
2474 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2478 n_counters = vec_len (im->sw_if_counters);
2480 for (j = 0; j < n_counters; j++)
2482 for (i = 0; i < vec_len(my_vnet_mains); i++)
2484 im = &my_vnet_mains[i]->interface_main;
2485 sm = im->sw_if_counters + j;
2486 if (mp->sw_if_index == (u32)~0)
2487 vlib_clear_simple_counters (sm);
2489 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2493 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2496 static void send_sw_interface_details (vpe_api_main_t * am,
2497 unix_shared_memory_queue_t *q,
2498 vnet_sw_interface_t * swif,
2499 u8 * interface_name,
2502 vl_api_sw_interface_details_t * mp;
2503 vnet_hw_interface_t * hi;
2505 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2507 mp = vl_msg_api_alloc (sizeof (*mp));
2508 memset (mp, 0, sizeof (*mp));
2509 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2510 mp->sw_if_index = ntohl(swif->sw_if_index);
2511 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2512 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2514 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2516 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2517 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2518 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2519 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2520 mp->link_mtu = ntohs(hi->max_packet_bytes);
2521 mp->context = context;
2523 strncpy ((char *) mp->interface_name,
2524 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2526 /* Send the L2 address for ethernet physical intfcs */
2527 if (swif->sup_sw_if_index == swif->sw_if_index
2528 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2529 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2530 ethernet_interface_t *ei;
2532 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2533 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2534 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2535 mp->l2_address_length = ntohl(sizeof (ei->address));
2536 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2537 vnet_sub_interface_t *sub = &swif->sub;
2538 mp->sub_id = ntohl(sub->id);
2539 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2540 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2541 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2542 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2543 mp->sub_exact_match = sub->eth.flags.exact_match;
2544 mp->sub_default = sub->eth.flags.default_sub;
2545 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2546 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2548 /* vlan tag rewrite data */
2549 u32 vtr_op = L2_VTR_DISABLED;
2550 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2552 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2553 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2554 // error - default to disabled
2555 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2556 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2559 mp->vtr_op = ntohl(vtr_op);
2560 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2561 mp->vtr_tag1 = ntohl(vtr_tag1);
2562 mp->vtr_tag2 = ntohl(vtr_tag2);
2566 vl_msg_api_send_shmem (q, (u8 *)&mp);
2569 static void send_sw_interface_flags (vpe_api_main_t * am,
2570 unix_shared_memory_queue_t *q,
2571 vnet_sw_interface_t * swif)
2573 vl_api_sw_interface_set_flags_t *mp;
2574 vnet_main_t * vnm = am->vnet_main;
2576 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2578 mp = vl_msg_api_alloc (sizeof (*mp));
2579 memset (mp, 0, sizeof (*mp));
2580 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2581 mp->sw_if_index = ntohl(swif->sw_if_index);
2583 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2585 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2587 vl_msg_api_send_shmem (q, (u8 *)&mp);
2590 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2591 unix_shared_memory_queue_t *q,
2593 __attribute__((unused));
2595 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2596 unix_shared_memory_queue_t *q,
2599 vl_api_sw_interface_set_flags_t *mp;
2601 mp = vl_msg_api_alloc (sizeof (*mp));
2602 memset (mp, 0, sizeof (*mp));
2603 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2604 mp->sw_if_index = ntohl(sw_if_index);
2606 mp->admin_up_down = 0;
2607 mp->link_up_down = 0;
2609 vl_msg_api_send_shmem (q, (u8 *)&mp);
2612 static void vl_api_sw_interface_dump_t_handler (
2613 vl_api_sw_interface_dump_t *mp)
2615 vpe_api_main_t * am = &vpe_api_main;
2616 vnet_sw_interface_t * swif;
2617 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2618 u8 * filter_string = 0, * name_string = 0;
2619 unix_shared_memory_queue_t * q;
2620 char * strcasestr (char *, char *); /* lnx hdr file botch */
2622 q = vl_api_client_index_to_input_queue (mp->client_index);
2627 if (mp->name_filter_valid) {
2628 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2629 filter_string = format (0, "%s%c", mp->name_filter, 0);
2632 pool_foreach (swif, im->sw_interfaces,
2634 name_string = format (name_string, "%U%c",
2635 format_vnet_sw_interface_name,
2636 am->vnet_main, swif, 0);
2638 if (mp->name_filter_valid == 0 ||
2639 strcasestr((char *) name_string, (char *) filter_string)) {
2641 send_sw_interface_details (am, q, swif, name_string, mp->context);
2643 _vec_len (name_string) = 0;
2646 vec_free (name_string);
2647 vec_free (filter_string);
2650 void send_oam_event (oam_target_t * t)
2652 vpe_api_main_t * vam = &vpe_api_main;
2653 unix_shared_memory_queue_t * q;
2654 vpe_client_registration_t *reg;
2655 vl_api_oam_event_t * mp;
2657 pool_foreach(reg, vam->oam_events_registrations,
2659 q = vl_api_client_index_to_input_queue (reg->client_index);
2661 mp = vl_msg_api_alloc (sizeof (*mp));
2662 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2663 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2664 mp->state = t->state;
2665 vl_msg_api_send_shmem (q, (u8 *)&mp);
2671 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2673 vl_api_oam_add_del_reply_t * rmp;
2676 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2677 (ip4_address_t *)mp->dst_address,
2681 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2685 vl_api_vnet_get_summary_stats_t_handler (
2686 vl_api_vnet_get_summary_stats_t *mp)
2688 stats_main_t * sm = &stats_main;
2689 vnet_interface_main_t * im = sm->interface_main;
2690 vl_api_vnet_summary_stats_reply_t *rmp;
2691 vlib_combined_counter_main_t * cm;
2694 u64 total_pkts[VLIB_N_RX_TX];
2695 u64 total_bytes[VLIB_N_RX_TX];
2697 unix_shared_memory_queue_t * q =
2698 vl_api_client_index_to_input_queue (mp->client_index);
2703 rmp = vl_msg_api_alloc (sizeof (*rmp));
2704 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2705 rmp->context = mp->context;
2708 memset (total_pkts, 0, sizeof (total_pkts));
2709 memset (total_bytes, 0, sizeof (total_bytes));
2711 vnet_interface_counter_lock (im);
2713 vec_foreach (cm, im->combined_sw_if_counters) {
2714 which = cm - im->combined_sw_if_counters;
2716 for (i = 0; i < vec_len (cm->maxi); i++) {
2717 vlib_get_combined_counter (cm, i, &v);
2718 total_pkts[which] += v.packets;
2719 total_bytes[which] += v.bytes;
2722 vnet_interface_counter_unlock (im);
2724 /* Note: in HOST byte order! */
2725 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2726 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2727 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2728 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2729 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2731 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2734 typedef CLIB_PACKED (struct {
2735 ip4_address_t address;
2737 u32 address_length : 6;
2742 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2744 vnet_main_t * vnm = vnet_get_main();
2745 vnet_interface_main_t * im = &vnm->interface_main;
2746 ip4_main_t * im4 = &ip4_main;
2747 static ip4_route_t * routes;
2748 static u32 * sw_if_indices_to_shut;
2749 stats_main_t * sm = &stats_main;
2754 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2755 u32 target_fib_id = ntohl(mp->vrf_id);
2757 dslock (sm, 1 /* release hint */, 8 /* tag */);
2759 vec_foreach (fib, im4->fibs) {
2760 vnet_sw_interface_t * si;
2762 if (fib->table_id != target_fib_id)
2765 /* remove any mpls/gre tunnels in this fib */
2766 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2768 /* remove any mpls encap/decap labels */
2769 mpls_fib_reset_labels (fib->table_id);
2771 /* remove any proxy arps in this fib */
2772 vnet_proxy_arp_fib_reset (fib->table_id);
2774 /* Set the flow hash for this fib to the default */
2775 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2777 vec_reset_length (sw_if_indices_to_shut);
2779 /* Shut down interfaces in this FIB / clean out intfc routes */
2780 pool_foreach (si, im->sw_interfaces,
2782 u32 sw_if_index = si->sw_if_index;
2784 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2785 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2787 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2790 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2791 sw_if_index = sw_if_indices_to_shut[i];
2792 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2794 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2795 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2796 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2799 vec_reset_length (routes);
2801 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2802 uword * hash = fib->adj_index_by_dst_address[i];
2806 x.address_length = i;
2808 hash_foreach_pair (p, hash,
2810 x.address.data_u32 = p->key;
2811 vec_add1 (routes, x);
2815 vec_foreach (r, routes) {
2816 ip4_add_del_route_args_t a;
2818 memset (&a, 0, sizeof (a));
2819 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2820 a.table_index_or_table_id = fib - im4->fibs;
2821 a.dst_address = r->address;
2822 a.dst_address_length = r->address_length;
2825 ip4_add_del_route (im4, &a);
2826 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2827 IP4_ROUTE_FLAG_FIB_INDEX);
2831 } /* vec_foreach (fib) */
2838 ip6_address_t address;
2845 ip6_route_t ** routep;
2846 } add_routes_in_fib_arg_t;
2848 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2850 add_routes_in_fib_arg_t * ap = arg;
2852 if (kvp->key[2]>>32 == ap->fib_index)
2854 ip6_address_t *addr;
2856 addr = (ip6_address_t *) kvp;
2857 vec_add2 (*ap->routep, r, 1);
2858 r->address = addr[0];
2859 r->address_length = kvp->key[2] & 0xFF;
2860 r->index = kvp->value;
2864 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2866 vnet_main_t * vnm = vnet_get_main();
2867 vnet_interface_main_t * im = &vnm->interface_main;
2868 ip6_main_t * im6 = &ip6_main;
2869 stats_main_t * sm = &stats_main;
2870 static ip6_route_t * routes;
2871 static u32 * sw_if_indices_to_shut;
2876 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2877 u32 target_fib_id = ntohl(mp->vrf_id);
2878 add_routes_in_fib_arg_t _a, *a=&_a;
2879 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2881 dslock (sm, 1 /* release hint */, 9 /* tag */);
2883 vec_foreach (fib, im6->fibs) {
2884 vnet_sw_interface_t * si;
2886 if (fib->table_id != target_fib_id)
2889 vec_reset_length (sw_if_indices_to_shut);
2891 /* Shut down interfaces in this FIB / clean out intfc routes */
2892 pool_foreach (si, im->sw_interfaces,
2894 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2896 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2899 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2900 sw_if_index = sw_if_indices_to_shut[i];
2901 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2903 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2904 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2905 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2908 vec_reset_length (routes);
2910 a->fib_index = fib - im6->fibs;
2911 a->routep = &routes;
2913 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2915 vec_foreach (r, routes) {
2916 ip6_add_del_route_args_t a;
2918 memset (&a, 0, sizeof (a));
2919 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2920 a.table_index_or_table_id = fib - im6->fibs;
2921 a.dst_address = r->address;
2922 a.dst_address_length = r->address_length;
2925 ip6_add_del_route (im6, &a);
2926 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2927 IP6_ROUTE_FLAG_FIB_INDEX);
2930 /* Reinstall the neighbor / router discovery routes */
2931 vnet_ip6_fib_init (im6, fib - im6->fibs);
2933 } /* vec_foreach (fib) */
2939 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2942 vl_api_reset_fib_reply_t * rmp;
2945 rv = ip6_reset_fib_t_handler (mp);
2947 rv = ip4_reset_fib_t_handler (mp);
2949 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2954 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2956 vl_api_dhcp_proxy_config_reply_t * rmp;
2959 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2960 (ip4_address_t *)(&mp->dhcp_src_address),
2961 (u32) ntohl(mp->vrf_id),
2962 (int) mp->insert_circuit_id,
2963 (int) (mp->is_add == 0));
2965 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2970 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2972 vl_api_dhcp_proxy_config_reply_t * rmp;
2975 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2976 (ip6_address_t *)(&mp->dhcp_src_address),
2977 (u32) ntohl(mp->vrf_id),
2978 (int) mp->insert_circuit_id,
2979 (int) (mp->is_add == 0));
2981 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2985 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2987 vl_api_dhcp_proxy_config_reply_t * rmp;
2990 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2991 (ip4_address_t *)(&mp->dhcp_src_address),
2992 (u32) ntohl(mp->rx_vrf_id),
2993 (u32) ntohl(mp->server_vrf_id),
2994 (int) mp->insert_circuit_id,
2995 (int) (mp->is_add == 0));
2997 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3002 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
3004 vl_api_dhcp_proxy_config_reply_t * rmp;
3008 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
3009 (ip6_address_t *)(&mp->dhcp_src_address),
3010 (u32) ntohl(mp->rx_vrf_id),
3011 (u32) ntohl(mp->server_vrf_id),
3012 (int) mp->insert_circuit_id,
3013 (int) (mp->is_add == 0));
3015 rv = VNET_API_ERROR_UNIMPLEMENTED;
3018 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3023 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
3025 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3028 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
3031 (int)mp->is_add == 0);
3033 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
3036 (int)mp->is_add == 0);
3038 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
3042 static void vl_api_dhcp_proxy_config_t_handler
3043 (vl_api_dhcp_proxy_config_t *mp)
3045 if (mp->is_ipv6 == 0)
3046 dhcpv4_proxy_config (mp);
3048 dhcpv6_proxy_config (mp);
3051 static void vl_api_dhcp_proxy_config_2_t_handler
3052 (vl_api_dhcp_proxy_config_2_t *mp)
3054 if (mp->is_ipv6 == 0)
3055 dhcpv4_proxy_config_2 (mp);
3057 dhcpv6_proxy_config_2 (mp);
3060 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3061 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3063 unix_shared_memory_queue_t * q;
3064 vl_api_dhcp_compl_event_t * mp;
3066 q = vl_api_client_index_to_input_queue (client_index);
3070 mp = vl_msg_api_alloc (sizeof (*mp));
3071 mp->client_index = client_index;
3073 mp->is_ipv6 = is_ipv6;
3074 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3075 mp->hostname[vec_len(hostname) + 1] = '\n';
3076 clib_memcpy (&mp->host_address[0], host_address, 16);
3077 clib_memcpy (&mp->router_address[0], router_address, 16);
3078 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3080 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3082 vl_msg_api_send_shmem (q, (u8 *)&mp);
3085 static void vl_api_dhcp_client_config_t_handler
3086 (vl_api_dhcp_client_config_t *mp)
3088 vlib_main_t *vm = vlib_get_main();
3089 vl_api_dhcp_client_config_reply_t * rmp;
3092 VALIDATE_SW_IF_INDEX(mp);
3094 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3095 mp->hostname, mp->is_add, mp->client_index,
3096 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3099 BAD_SW_IF_INDEX_LABEL;
3101 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3105 vl_api_sw_interface_ip6nd_ra_config_t_handler
3106 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3108 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3110 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease, default_router;
3112 is_no = mp->is_no == 1;
3113 suppress = mp->suppress == 1;
3114 managed = mp->managed == 1;
3115 other = mp->other == 1;
3116 ll_option = mp->ll_option == 1;
3117 send_unicast = mp->send_unicast == 1;
3118 cease = mp->cease == 1;
3119 default_router = mp->default_router == 1;
3121 VALIDATE_SW_IF_INDEX(mp);
3123 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3124 suppress, managed, other,
3125 ll_option, send_unicast, cease,
3126 default_router, ntohl (mp->lifetime),
3127 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3128 ntohl(mp->max_interval), ntohl( mp->min_interval),
3131 BAD_SW_IF_INDEX_LABEL;
3133 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3137 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3138 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3140 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3142 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3144 VALIDATE_SW_IF_INDEX(mp);
3146 is_no = mp->is_no == 1;
3147 use_default = mp->use_default == 1;
3148 no_advertise = mp->no_advertise == 1;
3149 off_link = mp->off_link == 1;
3150 no_autoconfig = mp->no_autoconfig == 1;
3151 no_onlink = mp->no_onlink == 1;
3153 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3154 (ip6_address_t *)mp->address, mp->address_length,
3155 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3156 no_advertise, off_link, no_autoconfig, no_onlink,
3159 BAD_SW_IF_INDEX_LABEL;
3160 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3164 vl_api_sw_interface_ip6_enable_disable_t_handler
3165 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3167 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3168 vnet_main_t * vnm = vnet_get_main();
3170 clib_error_t * error;
3174 VALIDATE_SW_IF_INDEX(mp);
3176 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3177 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3180 clib_error_report(error);
3181 rv = VNET_API_ERROR_UNSPECIFIED;
3183 rv = vnm->api_errno;
3186 BAD_SW_IF_INDEX_LABEL;
3188 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3192 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3193 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3195 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3197 clib_error_t * error;
3198 vnet_main_t * vnm = vnet_get_main();
3202 VALIDATE_SW_IF_INDEX(mp);
3204 error = set_ip6_link_local_address(vm,
3205 ntohl(mp->sw_if_index),
3206 (ip6_address_t *)mp->address,
3207 mp->address_length);
3209 clib_error_report(error);
3210 rv = VNET_API_ERROR_UNSPECIFIED;
3212 rv = vnm->api_errno;
3215 BAD_SW_IF_INDEX_LABEL;
3217 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3220 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3222 vl_api_set_ip_flow_hash_reply_t *rmp;
3223 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3225 clib_warning ("unimplemented...");
3227 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3230 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3232 vl_api_set_ip_flow_hash_reply_t *rmp;
3235 u32 flow_hash_config = 0;
3237 table_id = ntohl(mp->vrf_id);
3239 #define _(a,b) if (mp->a) flow_hash_config |= b;
3240 foreach_flow_hash_bit;
3243 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3245 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3249 static void vl_api_set_ip_flow_hash_t_handler
3250 (vl_api_set_ip_flow_hash_t *mp)
3252 if (mp->is_ipv6 == 0)
3253 set_ip4_flow_hash (mp);
3255 set_ip6_flow_hash (mp);
3258 static void vl_api_sw_interface_set_unnumbered_t_handler
3259 (vl_api_sw_interface_set_unnumbered_t *mp)
3261 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3263 vnet_sw_interface_t * si;
3264 vnet_main_t *vnm = vnet_get_main();
3265 u32 sw_if_index, unnumbered_sw_if_index;
3267 sw_if_index = ntohl(mp->sw_if_index);
3268 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3271 * The API message field names are backwards from
3272 * the underlying data structure names.
3273 * It's not worth changing them now.
3275 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3276 unnumbered_sw_if_index)) {
3277 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3281 /* Only check the "use loop0" field when setting the binding */
3283 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3284 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3288 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3291 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3292 si->unnumbered_sw_if_index = sw_if_index;
3294 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3295 si->unnumbered_sw_if_index = (u32)~0;
3299 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3302 static void vl_api_create_loopback_t_handler
3303 (vl_api_create_loopback_t *mp)
3305 vl_api_create_loopback_reply_t * rmp;
3309 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3311 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3313 rmp->sw_if_index = ntohl (sw_if_index);
3317 static void vl_api_delete_loopback_t_handler
3318 (vl_api_delete_loopback_t *mp)
3320 vl_api_delete_loopback_reply_t * rmp;
3324 sw_if_index = ntohl (mp->sw_if_index);
3325 rv = vnet_delete_loopback_interface (sw_if_index);
3327 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3330 static void vl_api_control_ping_t_handler
3331 (vl_api_control_ping_t *mp)
3333 vl_api_control_ping_reply_t * rmp;
3336 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3338 rmp->vpe_pid = ntohl (getpid());
3342 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3344 u8 **shmem_vecp = (u8 **)arg;
3347 api_main_t * am = &api_main;
3350 shmem_vec = *shmem_vecp;
3352 offset = vec_len (shmem_vec);
3354 pthread_mutex_lock (&am->vlib_rp->mutex);
3355 oldheap = svm_push_data_heap (am->vlib_rp);
3357 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3359 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3361 svm_pop_heap (oldheap);
3362 pthread_mutex_unlock (&am->vlib_rp->mutex);
3364 *shmem_vecp = shmem_vec;
3368 static void vl_api_cli_request_t_handler
3369 (vl_api_cli_request_t *mp)
3371 vl_api_cli_reply_t *rp;
3372 unix_shared_memory_queue_t *q;
3373 vlib_main_t * vm = vlib_get_main();
3374 api_main_t * am = &api_main;
3375 unformat_input_t input;
3379 q = vl_api_client_index_to_input_queue (mp->client_index);
3383 rp = vl_msg_api_alloc (sizeof (*rp));
3384 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3385 rp->context = mp->context;
3387 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3389 vlib_cli_input (vm, &input, shmem_cli_output,
3392 pthread_mutex_lock (&am->vlib_rp->mutex);
3393 oldheap = svm_push_data_heap (am->vlib_rp);
3395 vec_add1(shmem_vec, 0);
3397 svm_pop_heap (oldheap);
3398 pthread_mutex_unlock (&am->vlib_rp->mutex);
3400 rp->reply_in_shmem = (uword)shmem_vec;
3402 vl_msg_api_send_shmem (q, (u8 *)&rp);
3405 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3408 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3409 vnet_main_t *vnm = vnet_get_main();
3410 clib_error_t * error;
3415 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3417 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3420 clib_error_report(error);
3421 rv = VNET_API_ERROR_UNSPECIFIED;
3423 rv = vnm->api_errno;
3426 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3429 static void vl_api_sr_tunnel_add_del_t_handler
3430 (vl_api_sr_tunnel_add_del_t *mp)
3433 clib_warning ("unimplemented");
3435 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3437 vl_api_sr_tunnel_add_del_reply_t * rmp;
3438 ip6_address_t * segments = 0, * seg;
3439 ip6_address_t * tags = 0, *tag;
3440 ip6_address_t * this_address;
3443 if (mp->n_segments == 0) {
3448 memset (a, 0, sizeof (*a));
3449 a->src_address = (ip6_address_t *)&mp->src_address;
3450 a->dst_address = (ip6_address_t *)&mp->dst_address;
3451 a->dst_mask_width = mp->dst_mask_width;
3452 a->flags_net_byte_order = mp->flags_net_byte_order;
3453 a->is_del = (mp->is_add == 0);
3454 a->rx_table_id = ntohl(mp->outer_vrf_id);
3455 a->tx_table_id = ntohl(mp->inner_vrf_id);
3457 a->name = format(0, "%s", mp->name);
3458 if (!(vec_len(a->name)))
3461 a->policy_name = format(0, "%s", mp->policy_name);
3462 if (!(vec_len(a->policy_name)))
3465 /* Yank segments and tags out of the API message */
3466 this_address = (ip6_address_t *)mp->segs_and_tags;
3467 for (i = 0; i < mp->n_segments; i++) {
3468 vec_add2 (segments, seg, 1);
3469 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3472 for (i = 0; i < mp->n_tags; i++) {
3473 vec_add2 (tags, tag, 1);
3474 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3478 a->segments = segments;
3481 rv = ip6_sr_add_del_tunnel (a);
3485 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3489 static void vl_api_sr_policy_add_del_t_handler
3490 (vl_api_sr_policy_add_del_t *mp)
3493 clib_warning ("unimplemented");
3495 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3497 vl_api_sr_policy_add_del_reply_t * rmp;
3500 memset (a, 0, sizeof (*a));
3501 a->is_del = (mp->is_add == 0);
3503 a->name = format(0, "%s", mp->name);
3504 if (!(vec_len(a->name)))
3506 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3510 if (!(mp->tunnel_names[0]))
3512 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3516 // start deserializing tunnel_names
3517 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3518 u8 * deser_tun_names = mp->tunnel_names;
3519 deser_tun_names += 1; //moving along
3522 int tun_name_len = 0;
3524 for (i=0; i < num_tunnels; i++)
3526 tun_name_len= *deser_tun_names;
3527 deser_tun_names += 1;
3528 vec_resize (tun_name, tun_name_len);
3529 memcpy(tun_name, deser_tun_names, tun_name_len);
3530 vec_add1 (a->tunnel_names, tun_name);
3531 deser_tun_names += tun_name_len;
3535 rv = ip6_sr_add_del_policy (a);
3539 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3543 static void vl_api_sr_multicast_map_add_del_t_handler
3544 (vl_api_sr_multicast_map_add_del_t *mp)
3547 clib_warning ("unimplemented");
3549 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3551 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3553 memset (a, 0, sizeof (*a));
3554 a->is_del = (mp->is_add == 0);
3556 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3557 a->policy_name = format(0, "%s", mp->policy_name);
3559 if (a->multicast_address == 0)
3565 if (!(a->policy_name))
3571 #if DPDK > 0 /* Cannot call replicate without DPDK */
3572 rv = ip6_sr_add_del_multicastmap (a);
3574 clib_warning ("multicast replication without DPDK not implemented");
3575 rv = VNET_API_ERROR_UNIMPLEMENTED;
3580 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3584 #define foreach_classify_add_del_table_field \
3589 _(match_n_vectors) \
3590 _(next_table_index) \
3593 static void vl_api_classify_add_del_table_t_handler
3594 (vl_api_classify_add_del_table_t * mp)
3596 vl_api_classify_add_del_table_reply_t * rmp;
3597 vnet_classify_main_t * cm = &vnet_classify_main;
3598 vnet_classify_table_t * t;
3602 foreach_classify_add_del_table_field;
3605 #define _(a) a = ntohl(mp->a);
3606 foreach_classify_add_del_table_field;
3609 /* The underlying API fails silently, on purpose, so check here */
3610 if (mp->is_add == 0)
3611 if (pool_is_free_index (cm->tables, table_index)) {
3612 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3616 rv = vnet_classify_add_del_table
3617 (cm, mp->mask, nbuckets, memory_size,
3618 skip_n_vectors, match_n_vectors,
3619 next_table_index, miss_next_index,
3620 &table_index, mp->is_add);
3623 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3625 if (rv == 0 && mp->is_add) {
3626 t = pool_elt_at_index (cm->tables, table_index);
3627 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3628 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3629 rmp->new_table_index = ntohl(table_index);
3631 rmp->skip_n_vectors = ~0;
3632 rmp->match_n_vectors = ~0;
3633 rmp->new_table_index = ~0;
3638 static void vl_api_classify_add_del_session_t_handler
3639 (vl_api_classify_add_del_session_t * mp)
3641 vnet_classify_main_t * cm = &vnet_classify_main;
3642 vl_api_classify_add_del_session_reply_t * rmp;
3644 u32 table_index, hit_next_index, opaque_index;
3647 table_index = ntohl (mp->table_index);
3648 hit_next_index = ntohl (mp->hit_next_index);
3649 opaque_index = ntohl (mp->opaque_index);
3650 advance = ntohl (mp->advance);
3652 rv = vnet_classify_add_del_session
3653 (cm, table_index, mp->match, hit_next_index, opaque_index,
3654 advance, mp->is_add);
3656 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3659 static void vl_api_classify_set_interface_ip_table_t_handler
3660 (vl_api_classify_set_interface_ip_table_t * mp)
3662 vlib_main_t * vm = vlib_get_main();
3663 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3665 u32 table_index, sw_if_index;
3667 table_index = ntohl (mp->table_index);
3668 sw_if_index = ntohl (mp->sw_if_index);
3670 VALIDATE_SW_IF_INDEX(mp);
3673 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3675 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3677 BAD_SW_IF_INDEX_LABEL;
3679 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3682 static void vl_api_classify_set_interface_l2_tables_t_handler
3683 (vl_api_classify_set_interface_l2_tables_t * mp)
3685 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3687 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3690 ip4_table_index = ntohl(mp->ip4_table_index);
3691 ip6_table_index = ntohl(mp->ip6_table_index);
3692 other_table_index = ntohl(mp->other_table_index);
3693 sw_if_index = ntohl(mp->sw_if_index);
3695 VALIDATE_SW_IF_INDEX(mp);
3697 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3698 ip6_table_index, other_table_index);
3701 if (ip4_table_index != ~0 || ip6_table_index != ~0
3702 || other_table_index != ~0)
3707 vnet_l2_classify_enable_disable (sw_if_index, enable);
3710 BAD_SW_IF_INDEX_LABEL;
3712 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3716 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3719 vl_api_l2_fib_clear_table_reply_t * rmp;
3721 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3722 * that is not currently implemented. When that TODO is fixed
3723 * this call should be changed to pass 1 instead of 0.
3725 l2fib_clear_table (0);
3727 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3730 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3735 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3738 vl_api_l2_interface_efp_filter_reply_t * rmp;
3739 vnet_main_t *vnm = vnet_get_main();
3741 // enable/disable the feature
3742 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3743 rv = vnm->api_errno;
3745 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3749 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3752 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3753 vnet_main_t * vnm = vnet_get_main();
3754 vlib_main_t * vm = vlib_get_main();
3757 VALIDATE_SW_IF_INDEX(mp);
3759 vtr_op = ntohl(mp->vtr_op);
3761 /* The L2 code is unsuspicious */
3763 case L2_VTR_DISABLED:
3768 case L2_VTR_TRANSLATE_1_1:
3769 case L2_VTR_TRANSLATE_1_2:
3770 case L2_VTR_TRANSLATE_2_1:
3771 case L2_VTR_TRANSLATE_2_2:
3775 rv = VNET_API_ERROR_INVALID_VALUE;
3776 goto bad_sw_if_index;
3779 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3780 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3783 BAD_SW_IF_INDEX_LABEL;
3785 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3789 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3793 vl_api_create_vhost_user_if_reply_t * rmp;
3794 u32 sw_if_index = (u32)~0;
3796 vnet_main_t * vnm = vnet_get_main();
3797 vlib_main_t * vm = vlib_get_main();
3799 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3800 mp->is_server, &sw_if_index, (u64)~0,
3801 mp->renumber, ntohl(mp->custom_dev_instance),
3802 (mp->use_custom_mac)?mp->mac_address:NULL);
3804 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3806 rmp->sw_if_index = ntohl (sw_if_index);
3812 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3816 vl_api_modify_vhost_user_if_reply_t * rmp;
3817 u32 sw_if_index = ntohl(mp->sw_if_index);
3819 vnet_main_t * vnm = vnet_get_main();
3820 vlib_main_t * vm = vlib_get_main();
3822 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3823 mp->is_server, sw_if_index, (u64)~0,
3824 mp->renumber, ntohl(mp->custom_dev_instance));
3826 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3831 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3835 vpe_api_main_t * vam = &vpe_api_main;
3836 vl_api_delete_vhost_user_if_reply_t * rmp;
3837 u32 sw_if_index = ntohl(mp->sw_if_index);
3839 vnet_main_t * vnm = vnet_get_main();
3840 vlib_main_t * vm = vlib_get_main();
3842 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3844 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3846 unix_shared_memory_queue_t * q =
3847 vl_api_client_index_to_input_queue (mp->client_index);
3851 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3856 static void vl_api_sw_interface_vhost_user_details_t_handler (
3857 vl_api_sw_interface_vhost_user_details_t * mp)
3859 clib_warning ("BUG");
3863 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3864 unix_shared_memory_queue_t *q,
3865 vhost_user_intf_details_t * vui,
3868 vl_api_sw_interface_vhost_user_details_t * mp;
3870 mp = vl_msg_api_alloc (sizeof (*mp));
3871 memset (mp, 0, sizeof (*mp));
3872 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3873 mp->sw_if_index = ntohl(vui->sw_if_index);
3874 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3875 mp->features = clib_net_to_host_u64 (vui->features);
3876 mp->is_server = vui->is_server;
3877 mp->num_regions = ntohl(vui->num_regions);
3878 mp->sock_errno = ntohl(vui->sock_errno);
3879 mp->context = context;
3881 strncpy ((char *) mp->sock_filename,
3882 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3883 strncpy ((char *) mp->interface_name,
3884 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3886 vl_msg_api_send_shmem (q, (u8 *)&mp);
3891 vl_api_sw_interface_vhost_user_dump_t_handler (
3892 vl_api_sw_interface_vhost_user_dump_t *mp)
3896 vpe_api_main_t * am = &vpe_api_main;
3897 vnet_main_t * vnm = vnet_get_main();
3898 vlib_main_t * vm = vlib_get_main();
3899 vhost_user_intf_details_t *ifaces = NULL;
3900 vhost_user_intf_details_t *vuid = NULL;
3901 unix_shared_memory_queue_t * q;
3903 q = vl_api_client_index_to_input_queue (mp->client_index);
3907 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3911 vec_foreach (vuid, ifaces) {
3912 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3918 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3919 unix_shared_memory_queue_t *q,
3924 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3925 u8 * if_name = NULL;
3926 vnet_sw_interface_t * si = NULL;
3928 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3930 if_name = format(if_name, "%U",
3931 format_vnet_sw_interface_name, lm->vnet_main, si);
3933 mp = vl_msg_api_alloc (sizeof (*mp));
3934 memset (mp, 0, sizeof (*mp));
3935 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3936 strncpy((char *)mp->interface_name,
3937 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3938 mp->sw_if_index = ntohl(si->sw_if_index);
3939 mp->local_session_id = s->local_session_id;
3940 mp->remote_session_id = s->remote_session_id;
3941 mp->local_cookie[0] = s->local_cookie[0];
3942 mp->local_cookie[1] = s->local_cookie[1];
3943 mp->remote_cookie = s->remote_cookie;
3944 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3945 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3946 mp->l2_sublayer_present = s->l2_sublayer_present;
3947 mp->context = context;
3949 vl_msg_api_send_shmem (q, (u8 *)&mp);
3952 static void send_ip_address_details (vpe_api_main_t * am,
3953 unix_shared_memory_queue_t * q,
3959 vl_api_ip_address_details_t * mp;
3961 mp = vl_msg_api_alloc (sizeof (*mp));
3962 memset (mp, 0, sizeof (*mp));
3963 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3966 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3968 u32 * tp = (u32 *)mp->ip;
3969 *tp = ntohl(*(u32*)ip);
3971 mp->prefix_length = prefix_length;
3972 mp->context = context;
3974 vl_msg_api_send_shmem (q, (u8 *)&mp);
3978 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3980 vpe_api_main_t * am = &vpe_api_main;
3981 unix_shared_memory_queue_t * q;
3984 ip6_main_t * im6 = &ip6_main;
3985 ip4_main_t * im4 = &ip4_main;
3986 ip_lookup_main_t * lm6 = &im6->lookup_main;
3987 ip_lookup_main_t * lm4 = &im4->lookup_main;
3988 ip_interface_address_t * ia = 0;
3989 u32 sw_if_index = ~0;
3990 int rv __attribute__ ((unused)) = 0;
3992 VALIDATE_SW_IF_INDEX(mp);
3994 sw_if_index = ntohl(mp->sw_if_index);
3996 q = vl_api_client_index_to_input_queue (mp->client_index);
4002 foreach_ip_interface_address (lm6, ia, sw_if_index,
4003 1 /* honor unnumbered */,
4005 r6 = ip_interface_address_get_address (lm6, ia);
4006 u16 prefix_length = ia->address_length;
4007 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4010 foreach_ip_interface_address (lm4, ia, sw_if_index,
4011 1 /* honor unnumbered */,
4013 r4 = ip_interface_address_get_address (lm4, ia);
4014 u16 prefix_length = ia->address_length;
4015 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4018 BAD_SW_IF_INDEX_LABEL;
4021 static void send_ip_details (vpe_api_main_t * am,
4022 unix_shared_memory_queue_t *q,
4026 vl_api_ip_details_t * mp;
4028 mp = vl_msg_api_alloc (sizeof (*mp));
4029 memset (mp, 0, sizeof (*mp));
4030 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
4032 mp->sw_if_index = ntohl(sw_if_index);
4033 mp->context = context;
4035 vl_msg_api_send_shmem (q, (u8 *)&mp);
4039 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
4040 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
4042 vpe_api_main_t * am = &vpe_api_main;
4043 l2t_main_t * lm = &l2t_main;
4044 unix_shared_memory_queue_t * q;
4045 l2t_session_t *session;
4047 q = vl_api_client_index_to_input_queue (mp->client_index);
4051 pool_foreach (session, lm->sessions,
4053 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4058 static void send_sw_interface_tap_details (vpe_api_main_t * am,
4059 unix_shared_memory_queue_t *q,
4060 tapcli_interface_details_t *tap_if,
4063 vl_api_sw_interface_tap_details_t * mp;
4064 mp = vl_msg_api_alloc (sizeof (*mp));
4065 memset (mp, 0, sizeof (*mp));
4066 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4067 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4068 strncpy((char *)mp->dev_name,
4069 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4070 mp->context = context;
4072 vl_msg_api_send_shmem (q, (u8 *)&mp);
4076 vl_api_sw_interface_tap_dump_t_handler (
4077 vl_api_sw_interface_tap_dump_t *mp)
4080 vpe_api_main_t * am = &vpe_api_main;
4081 unix_shared_memory_queue_t * q;
4082 tapcli_interface_details_t *tapifs = NULL;
4083 tapcli_interface_details_t *tap_if = NULL;
4085 q = vl_api_client_index_to_input_queue (mp->client_index);
4089 rv = vnet_tap_dump_ifs(&tapifs);
4093 vec_foreach(tap_if, tapifs) {
4094 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4101 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4103 vpe_api_main_t * am = &vpe_api_main;
4104 vnet_main_t * vnm = vnet_get_main();
4105 vlib_main_t * vm = vlib_get_main();
4106 vnet_interface_main_t * im = &vnm->interface_main;
4107 unix_shared_memory_queue_t * q;
4108 vnet_sw_interface_t * si, * sorted_sis;
4109 u32 sw_if_index = ~0;
4111 q = vl_api_client_index_to_input_queue (mp->client_index);
4116 /* Gather interfaces. */
4117 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4118 _vec_len (sorted_sis) = 0;
4119 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4121 vec_foreach (si, sorted_sis) {
4122 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4123 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4126 sw_if_index = si->sw_if_index;
4127 send_ip_details(am, q, sw_if_index, mp->context);
4132 static void vl_api_l2_fib_table_entry_t_handler (
4133 vl_api_l2_fib_table_entry_t * mp)
4135 clib_warning ("BUG");
4138 static void send_l2fib_table_entry (vpe_api_main_t * am,
4139 unix_shared_memory_queue_t *q,
4140 l2fib_entry_key_t * l2fe_key,
4141 l2fib_entry_result_t * l2fe_res,
4144 vl_api_l2_fib_table_entry_t * mp;
4146 mp = vl_msg_api_alloc (sizeof (*mp));
4147 memset (mp, 0, sizeof (*mp));
4148 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4150 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4152 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4153 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4154 mp->static_mac = l2fe_res->fields.static_mac;
4155 mp->filter_mac = l2fe_res->fields.filter;
4156 mp->bvi_mac = l2fe_res->fields.bvi;
4157 mp->context = context;
4159 vl_msg_api_send_shmem (q, (u8 *)&mp);
4163 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4165 vpe_api_main_t * am = &vpe_api_main;
4166 bd_main_t * bdm = &bd_main;
4167 l2fib_entry_key_t *l2fe_key = NULL;
4168 l2fib_entry_result_t *l2fe_res = NULL;
4169 u32 ni, bd_id = ntohl (mp->bd_id);
4171 unix_shared_memory_queue_t * q;
4174 q = vl_api_client_index_to_input_queue (mp->client_index);
4178 /* see l2fib_table_dump: ~0 means "any" */
4182 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4189 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4191 vec_foreach_index (ni, l2fe_key) {
4192 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4193 vec_elt_at_index(l2fe_res, ni), mp->context);
4200 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4202 vl_api_show_version_reply_t *rmp;
4204 char * vpe_api_get_build_directory(void);
4205 char * vpe_api_get_version(void);
4206 char * vpe_api_get_build_date(void);
4208 unix_shared_memory_queue_t * q =
4209 vl_api_client_index_to_input_queue (mp->client_index);
4214 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4216 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4217 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4218 ARRAY_LEN(rmp->build_directory)-1);
4219 strncpy ((char *) rmp->version, vpe_api_get_version(),
4220 ARRAY_LEN(rmp->version)-1);
4221 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4222 ARRAY_LEN(rmp->build_date)-1);
4226 static void vl_api_get_node_index_t_handler
4227 (vl_api_get_node_index_t * mp)
4229 vlib_main_t * vm = vlib_get_main();
4230 vl_api_get_node_index_reply_t * rmp;
4233 u32 node_index = ~0;
4235 n = vlib_get_node_by_name (vm, mp->node_name);
4238 rv = VNET_API_ERROR_NO_SUCH_NODE;
4240 node_index = n->index;
4242 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4244 rmp->node_index = ntohl(node_index);
4248 static void vl_api_get_next_index_t_handler
4249 (vl_api_get_next_index_t * mp)
4251 vlib_main_t * vm = vlib_get_main();
4252 vl_api_get_next_index_reply_t * rmp;
4253 vlib_node_t * node, * next_node;
4255 u32 next_node_index = ~0, next_index = ~0;
4258 node = vlib_get_node_by_name (vm, mp->node_name);
4261 rv = VNET_API_ERROR_NO_SUCH_NODE;
4265 next_node = vlib_get_node_by_name (vm, mp->next_name);
4267 if (next_node == 0) {
4268 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4272 next_node_index = next_node->index;
4274 p = hash_get (node->next_slot_by_node, next_node_index);
4277 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4284 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4286 rmp->next_index = ntohl(next_index);
4290 static void vl_api_add_node_next_t_handler
4291 (vl_api_add_node_next_t * mp)
4293 vlib_main_t * vm = vlib_get_main();
4294 vl_api_add_node_next_reply_t * rmp;
4295 vlib_node_t * n, * next;
4297 u32 next_index = ~0;
4299 n = vlib_get_node_by_name (vm, mp->node_name);
4302 rv = VNET_API_ERROR_NO_SUCH_NODE;
4306 next = vlib_get_node_by_name (vm, mp->next_name);
4309 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4311 next_index = vlib_node_add_next (vm, n->index, next->index);
4314 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4316 rmp->next_index = ntohl(next_index);
4320 static void vl_api_l2tpv3_create_tunnel_t_handler
4321 (vl_api_l2tpv3_create_tunnel_t *mp)
4323 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4324 l2t_main_t *lm = &l2t_main;
4325 u32 sw_if_index = (u32)~0;
4328 if (mp->is_ipv6 != 1) {
4329 rv = VNET_API_ERROR_UNIMPLEMENTED;
4333 u32 encap_fib_index;
4335 if (mp->encap_vrf_id != ~0) {
4337 ip6_main_t *im = &ip6_main;
4338 if (!(p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id)))) {
4339 rv = VNET_API_ERROR_NO_SUCH_FIB;
4342 encap_fib_index = p[0];
4344 encap_fib_index = ~0;
4347 rv = create_l2tpv3_ipv6_tunnel (lm,
4348 (ip6_address_t *) mp->client_address,
4349 (ip6_address_t *) mp->our_address,
4350 ntohl(mp->local_session_id),
4351 ntohl(mp->remote_session_id),
4352 clib_net_to_host_u64(mp->local_cookie),
4353 clib_net_to_host_u64(mp->remote_cookie),
4354 mp->l2_sublayer_present,
4359 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4361 rmp->sw_if_index = ntohl (sw_if_index);
4365 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4366 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4368 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4369 l2t_main_t *lm = &l2t_main;
4372 VALIDATE_SW_IF_INDEX(mp);
4374 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4375 clib_net_to_host_u64(mp->new_local_cookie),
4376 clib_net_to_host_u64(mp->new_remote_cookie));
4378 BAD_SW_IF_INDEX_LABEL;
4380 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4383 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4384 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4387 vnet_main_t * vnm = vnet_get_main();
4388 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4390 VALIDATE_SW_IF_INDEX(mp);
4392 rv = l2tpv3_interface_enable_disable
4393 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4395 BAD_SW_IF_INDEX_LABEL;
4397 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4400 static void vl_api_l2tpv3_set_lookup_key_t_handler
4401 (vl_api_l2tpv3_set_lookup_key_t * mp)
4404 l2t_main_t *lm = &l2t_main;
4405 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4407 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4408 rv = VNET_API_ERROR_INVALID_VALUE;
4412 lm->lookup_type = mp->key;
4415 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4418 static void vl_api_vxlan_add_del_tunnel_t_handler
4419 (vl_api_vxlan_add_del_tunnel_t * mp)
4421 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4423 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4424 u32 encap_fib_index;
4426 ip4_main_t * im = &ip4_main;
4427 u32 sw_if_index = ~0;
4429 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4431 rv = VNET_API_ERROR_NO_SUCH_FIB;
4434 encap_fib_index = p[0];
4436 /* Check src & dst are different */
4437 if ((mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4438 (!mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4439 rv = VNET_API_ERROR_SAME_SRC_DST;
4442 memset (a, 0, sizeof (*a));
4444 a->is_add = mp->is_add;
4445 a->is_ip6 = mp->is_ipv6;
4447 /* ip addresses sent in network byte order */
4449 memcpy(&(a->src.ip6), mp->src_address, 16);
4450 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4452 memcpy(&(a->src.ip4), mp->src_address, 4);
4453 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4456 a->encap_fib_index = encap_fib_index;
4457 a->decap_next_index = ntohl(mp->decap_next_index);
4458 a->vni = ntohl(mp->vni);
4459 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4462 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4464 rmp->sw_if_index = ntohl (sw_if_index);
4468 static void send_vxlan_tunnel_details
4469 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4471 vl_api_vxlan_tunnel_details_t * rmp;
4472 ip4_main_t * im4 = &ip4_main;
4473 ip6_main_t * im6 = &ip6_main;
4474 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4476 rmp = vl_msg_api_alloc (sizeof (*rmp));
4477 memset (rmp, 0, sizeof (*rmp));
4478 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4480 memcpy(rmp->src_address, &(t->src.ip6), 16);
4481 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4482 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4484 memcpy(rmp->src_address, &(t->src.ip4), 4);
4485 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4486 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4488 rmp->vni = htonl(t->vni);
4489 rmp->decap_next_index = htonl(t->decap_next_index);
4490 rmp->sw_if_index = htonl(t->sw_if_index);
4491 rmp->is_ipv6 = is_ipv6;
4492 rmp->context = context;
4494 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4497 static void vl_api_vxlan_tunnel_dump_t_handler
4498 (vl_api_vxlan_tunnel_dump_t * mp)
4500 unix_shared_memory_queue_t * q;
4501 vxlan_main_t * vxm = &vxlan_main;
4505 q = vl_api_client_index_to_input_queue (mp->client_index);
4510 sw_if_index = ntohl(mp->sw_if_index);
4512 if (~0 == sw_if_index) {
4513 pool_foreach (t, vxm->tunnels,
4515 send_vxlan_tunnel_details(t, q, mp->context);
4518 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4519 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4522 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4523 send_vxlan_tunnel_details(t, q, mp->context);
4527 static void vl_api_gre_add_del_tunnel_t_handler
4528 (vl_api_gre_add_del_tunnel_t * mp)
4530 vl_api_gre_add_del_tunnel_reply_t * rmp;
4532 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4535 ip4_main_t * im = &ip4_main;
4536 u32 sw_if_index = ~0;
4538 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_table_id));
4540 rv = VNET_API_ERROR_NO_SUCH_FIB;
4543 outer_table_id = p[0];
4545 /* Check src & dst are different */
4546 if (memcmp(&mp->src_address, &mp->dst_address, 4) == 0) {
4547 rv = VNET_API_ERROR_SAME_SRC_DST;
4551 memset (a, 0, sizeof (*a));
4553 a->is_add = mp->is_add;
4555 /* ip addresses sent in network byte order */
4556 a->src.as_u32 = mp->src_address;
4557 a->dst.as_u32 = mp->dst_address;
4559 a->outer_table_id = outer_table_id;
4560 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4563 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4565 rmp->sw_if_index = ntohl (sw_if_index);
4569 static void send_gre_tunnel_details
4570 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4572 vl_api_gre_tunnel_details_t * rmp;
4573 ip4_main_t * im = &ip4_main;
4575 rmp = vl_msg_api_alloc (sizeof (*rmp));
4576 memset (rmp, 0, sizeof (*rmp));
4577 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4578 rmp->src_address = t->tunnel_src.data_u32;
4579 rmp->dst_address = t->tunnel_dst.data_u32;
4580 rmp->outer_table_id = htonl(im->fibs[t->outer_fib_index].table_id);
4581 rmp->sw_if_index = htonl(t->sw_if_index);
4582 rmp->context = context;
4584 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4587 static void vl_api_gre_tunnel_dump_t_handler
4588 (vl_api_gre_tunnel_dump_t * mp)
4590 unix_shared_memory_queue_t * q;
4591 gre_main_t * gm = &gre_main;
4595 q = vl_api_client_index_to_input_queue (mp->client_index);
4600 sw_if_index = ntohl(mp->sw_if_index);
4602 if (~0 == sw_if_index) {
4603 pool_foreach (t, gm->tunnels,
4605 send_gre_tunnel_details(t, q, mp->context);
4608 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4609 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4612 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4613 send_gre_tunnel_details(t, q, mp->context);
4618 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4620 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4622 vl_api_l2_patch_add_del_reply_t * rmp;
4623 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4627 VALIDATE_RX_SW_IF_INDEX(mp);
4628 VALIDATE_TX_SW_IF_INDEX(mp);
4630 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4631 ntohl(mp->tx_sw_if_index),
4632 (int)(mp->is_add != 0));
4634 BAD_RX_SW_IF_INDEX_LABEL;
4635 BAD_TX_SW_IF_INDEX_LABEL;
4637 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4641 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4642 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4644 vl_api_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4646 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4647 u32 encap_fib_index, decap_fib_index;
4650 ip4_main_t * im = &ip4_main;
4651 u32 sw_if_index = ~0;
4654 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4656 rv = VNET_API_ERROR_NO_SUCH_FIB;
4659 encap_fib_index = p[0];
4661 protocol = mp->protocol;
4663 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4664 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT) {
4665 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4667 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4670 decap_fib_index = p[0];
4672 decap_fib_index = ntohl(mp->decap_vrf_id);
4675 /* Check src & dst are different */
4676 if ((mp->is_ipv6 && memcmp(mp->local, mp->remote, 16) == 0) ||
4677 (!mp->is_ipv6 && memcmp(mp->local, mp->remote, 4) == 0)) {
4678 rv = VNET_API_ERROR_SAME_SRC_DST;
4681 memset (a, 0, sizeof (*a));
4683 a->is_add = mp->is_add;
4684 a->is_ip6 = mp->is_ipv6;
4685 /* ip addresses sent in network byte order */
4687 clib_memcpy(&(a->local.ip6), mp->local, 16);
4688 clib_memcpy(&(a->remote.ip6), mp->remote, 16);
4690 clib_memcpy(&(a->local.ip4), mp->local, 4);
4691 clib_memcpy(&(a->remote.ip4), mp->remote, 4);
4693 a->encap_fib_index = encap_fib_index;
4694 a->decap_fib_index = decap_fib_index;
4695 a->protocol = protocol;
4696 a->vni = ntohl(mp->vni);
4697 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4700 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4702 rmp->sw_if_index = ntohl (sw_if_index);
4706 static void send_vxlan_gpe_tunnel_details
4707 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4709 vl_api_vxlan_gpe_tunnel_details_t * rmp;
4710 ip4_main_t * im4 = &ip4_main;
4711 ip6_main_t * im6 = &ip6_main;
4712 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
4714 rmp = vl_msg_api_alloc (sizeof (*rmp));
4715 memset (rmp, 0, sizeof (*rmp));
4716 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_GPE_TUNNEL_DETAILS);
4718 memcpy(rmp->local, &(t->local.ip6), 16);
4719 memcpy(rmp->remote, &(t->remote.ip6), 16);
4720 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4721 rmp->decap_vrf_id = htonl(im6->fibs[t->decap_fib_index].table_id);
4723 memcpy(rmp->local, &(t->local.ip4), 4);
4724 memcpy(rmp->remote, &(t->remote.ip4), 4);
4725 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4726 rmp->decap_vrf_id = htonl(im4->fibs[t->decap_fib_index].table_id);
4728 rmp->vni = htonl(t->vni);
4729 rmp->protocol = t->protocol;
4730 rmp->sw_if_index = htonl(t->sw_if_index);
4731 rmp->is_ipv6 = is_ipv6;
4732 rmp->context = context;
4734 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4737 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
4738 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
4740 unix_shared_memory_queue_t * q;
4741 vxlan_gpe_main_t * vgm = &vxlan_gpe_main;
4742 vxlan_gpe_tunnel_t * t;
4745 q = vl_api_client_index_to_input_queue (mp->client_index);
4750 sw_if_index = ntohl(mp->sw_if_index);
4752 if (~0 == sw_if_index) {
4753 pool_foreach (t, vgm->tunnels,
4755 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4758 if ((sw_if_index >= vec_len(vgm->tunnel_index_by_sw_if_index)) ||
4759 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index])) {
4762 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
4763 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4768 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4770 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4772 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4774 u8 *locator_name = NULL;
4776 memset(a, 0, sizeof(a[0]));
4778 locator_name = format(0, "%s", mp->locator_set_name);
4780 a->name = locator_name;
4782 a->is_add = mp->is_add;
4785 rv = vnet_lisp_add_del_locator_set(a, &ls_index);
4787 vec_free(locator_name);
4789 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4793 vl_api_lisp_add_del_locator_t_handler(
4794 vl_api_lisp_add_del_locator_t *mp)
4796 vl_api_lisp_add_del_locator_reply_t *rmp;
4798 locator_t locator, *locators = NULL;
4799 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4801 u8 *locator_name = NULL;
4803 memset(&locator, 0, sizeof(locator));
4804 memset(a, 0, sizeof(a[0]));
4806 locator.sw_if_index = ntohl(mp->sw_if_index);
4807 locator.priority = mp->priority;
4808 locator.weight = mp->weight;
4810 vec_add1(locators, locator);
4812 locator_name = format(0, "%s", mp->locator_set_name);
4814 a->name = locator_name;
4815 a->locators = locators;
4816 a->is_add = mp->is_add;
4819 rv = vnet_lisp_add_del_locator(a, NULL, &ls_index);
4822 vec_free(locator_name);
4824 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4828 vl_api_lisp_add_del_local_eid_t_handler(
4829 vl_api_lisp_add_del_local_eid_t *mp)
4831 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4832 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4834 ip_prefix_t *prefp = NULL;
4835 ip_address_t *ip_eid = NULL;
4837 u8 * mac = gid_address_mac (&eid);
4839 u32 locator_set_index = ~0, map_index = ~0;
4840 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4842 memset (a, 0, sizeof (a[0]));
4843 memset (&eid, 0, sizeof (eid));
4845 prefp = &gid_address_ippref(&eid);
4846 ip_eid = &ip_prefix_addr(prefp);
4848 switch (mp->eid_type)
4851 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4852 ip_address_set(ip_eid, mp->eid, IP4);
4853 ip_prefix_len(prefp) = mp->prefix_len;
4856 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4857 ip_address_set(ip_eid, mp->eid, IP6);
4858 ip_prefix_len(prefp) = mp->prefix_len;
4860 case 2: /* l2 mac */
4861 gid_address_type (&eid) = GID_ADDR_MAC;
4862 clib_memcpy(mac, mp->eid, 6);
4865 rv = VNET_API_ERROR_INVALID_EID_TYPE;
4869 name = format(0, "%s", mp->locator_set_name);
4870 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4872 rv = VNET_API_ERROR_INVALID_VALUE;
4875 locator_set_index = p[0];
4877 /* XXX treat batch configuration */
4878 a->is_add = mp->is_add;
4879 gid_address_vni (&eid) = clib_net_to_host_u32 (mp->vni);
4880 gid_address_copy (&a->eid, &eid);
4881 a->locator_set_index = locator_set_index;
4883 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4887 gid_address_free (&a->eid);
4889 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4893 vl_api_lisp_eid_table_add_del_map_t_handler(
4894 vl_api_lisp_eid_table_add_del_map_t *mp)
4896 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
4898 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
4899 clib_net_to_host_u32 (mp->vrf), mp->is_add);
4900 REPLY_MACRO(VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)
4904 lisp_gpe_add_del_fwd_entry_set_address(
4905 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4906 ip_address_t *slocator,
4907 ip_address_t *dlocator,
4910 ip_address_t *ip_eid = NULL;
4911 ip_prefix_t *prefp = NULL;
4913 prefp = &gid_address_ippref(eid);
4914 ip_eid = &ip_prefix_addr(prefp);
4916 if (mp->eid_is_ipv6) {
4917 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4918 sizeof(ip_addr_v6(ip_eid)));
4919 ip_addr_version(ip_eid) = IP6;
4921 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4922 sizeof(ip_addr_v4(ip_eid)));
4923 ip_addr_version(ip_eid) = IP4;
4925 ip_prefix_len(prefp) = mp->eid_prefix_len;
4927 if (mp->address_is_ipv6) {
4928 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4929 sizeof(ip_addr_v6(slocator)));
4930 ip_addr_version(slocator) = IP6;
4931 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4932 sizeof(ip_addr_v6(dlocator)));
4933 ip_addr_version(dlocator) = IP6;
4935 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4936 sizeof(ip_addr_v4(slocator)));
4937 ip_addr_version(slocator) = IP4;
4938 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4939 sizeof(ip_addr_v4(dlocator)));
4940 ip_addr_version(dlocator) = IP4;
4945 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4946 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4948 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4950 ip_address_t slocator, dlocator;
4952 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4954 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4956 memset (&a, 0, sizeof(a));
4958 a.is_add = mp->is_add;
4960 a.slocator = slocator;
4961 a.dlocator = dlocator;
4962 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4964 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4968 vl_api_lisp_add_del_map_resolver_t_handler(
4969 vl_api_lisp_add_del_map_resolver_t *mp)
4971 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4973 ip_address_t *ip_addr = NULL;
4974 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4976 a->is_add = mp->is_add;
4977 ip_addr = &a->address;
4980 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4981 sizeof(ip_addr_v6(ip_addr)));
4982 ip_addr_version(ip_addr) = IP6;
4984 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4985 sizeof(ip_addr_v4(ip_addr)));
4986 ip_addr_version(ip_addr) = IP4;
4989 rv = vnet_lisp_add_del_map_resolver (a);
4991 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4995 vl_api_lisp_gpe_enable_disable_t_handler(
4996 vl_api_lisp_gpe_enable_disable_t *mp)
4998 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5000 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
5002 a->is_en = mp->is_en;
5003 vnet_lisp_gpe_enable_disable (a);
5005 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5009 vl_api_lisp_enable_disable_t_handler(
5010 vl_api_lisp_enable_disable_t *mp)
5012 vl_api_lisp_enable_disable_reply_t *rmp;
5015 vnet_lisp_enable_disable (mp->is_en);
5016 REPLY_MACRO(VL_API_LISP_ENABLE_DISABLE_REPLY);
5020 vl_api_lisp_gpe_add_del_iface_t_handler(
5021 vl_api_lisp_gpe_add_del_iface_t *mp)
5023 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5025 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
5027 a->is_add = mp->is_add;
5028 a->table_id = mp->table_id;
5030 rv = vnet_lisp_gpe_add_del_iface (a, 0);
5032 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5036 vl_api_lisp_pitr_set_locator_set_t_handler(
5037 vl_api_lisp_pitr_set_locator_set_t *mp)
5039 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5043 ls_name = format (0, "%s", mp->ls_name);
5044 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5047 REPLY_MACRO(VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5051 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5052 (vl_api_lisp_add_del_map_request_itr_rlocs_t *mp)
5054 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5056 u8 * locator_set_name = NULL;
5057 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, * a = &_a;
5059 locator_set_name = format (0, "%s", mp->locator_set_name);
5061 a->is_add = mp->is_add;
5062 a->locator_set_name = locator_set_name;
5064 rv = vnet_lisp_add_del_mreq_itr_rlocs(a);
5066 vec_free(locator_set_name);
5068 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5071 /** Used for transferring locators via VPP API */
5072 typedef CLIB_PACKED(struct
5074 u8 is_ip4; /**< is locator an IPv4 address */
5075 u8 priority; /**< locator priority */
5076 u8 weight; /**< locator weight */
5077 u8 addr[16]; /**< IPv4/IPv6 address */
5081 send_lisp_locator_set_details_set_address
5082 (vl_api_lisp_locator_set_details_t *rmp,
5083 gid_address_t *gid_address)
5085 ip_prefix_t *ip_addr;
5087 if (gid_address_type(gid_address) != GID_ADDR_IP_PREFIX) {
5091 ip_addr = &gid_address_ippref(gid_address);
5092 rmp->prefix_len = ip_prefix_len(ip_addr);
5093 rmp->is_ipv6 = ip_prefix_version(ip_addr);
5094 ip_address_copy_addr(rmp->ip_address, &ip_prefix_addr(ip_addr));
5098 vl_api_lisp_add_del_remote_mapping_t_handler (
5099 vl_api_lisp_add_del_remote_mapping_t *mp)
5102 locator_t rloc, * rlocs = 0;
5103 vl_api_lisp_add_del_remote_mapping_reply_t * rmp;
5105 gid_address_t _seid, * seid = &_seid;
5106 gid_address_t _deid, * deid = &_deid;
5107 ip_prefix_t * seid_pref = &gid_address_ippref(seid);
5108 ip_prefix_t * deid_pref = &gid_address_ippref(deid);
5110 /* TODO remove seid from API */
5111 memset (seid, 0, sizeof (seid[0]));
5112 memset (deid, 0, sizeof (deid[0]));
5113 ip_address_t * seid_addr = &ip_prefix_addr(seid_pref);
5114 ip_address_t * deid_addr = &ip_prefix_addr(deid_pref);
5115 ip_prefix_len(seid_pref) = mp->seid_len;
5116 ip_prefix_len(deid_pref) = mp->deid_len;
5117 u8 * seid_mac = gid_address_mac (seid);
5118 u8 * deid_mac = gid_address_mac (deid);
5119 gid_address_vni (seid) = ntohl (mp->vni);
5120 gid_address_vni (deid) = ntohl (mp->vni);
5122 switch (mp->eid_type)
5125 gid_address_type(seid) = GID_ADDR_IP_PREFIX;
5126 gid_address_type(deid) = GID_ADDR_IP_PREFIX;
5127 ip_address_set (seid_addr, mp->seid, IP4);
5128 ip_address_set (deid_addr, mp->deid, IP4);
5131 gid_address_type(seid) = GID_ADDR_IP_PREFIX;
5132 gid_address_type(deid) = GID_ADDR_IP_PREFIX;
5133 ip_address_set (seid_addr, mp->seid, IP6);
5134 ip_address_set (deid_addr, mp->deid, IP6);
5136 case 2: /* l2 mac */
5137 gid_address_type(seid) = GID_ADDR_MAC;
5138 gid_address_type(deid) = GID_ADDR_MAC;
5139 clib_memcpy (seid_mac, mp->seid, 6);
5140 clib_memcpy (deid_mac, mp->deid, 6);
5143 rv = VNET_API_ERROR_INVALID_EID_TYPE;
5147 for (i = 0; i < mp->rloc_num; i++) {
5148 rloc_t * r = &((rloc_t *) mp->rlocs)[i];
5149 memset(&rloc, 0, sizeof(rloc));
5150 ip_address_set(&gid_address_ip(&rloc.address), &r->addr,
5151 r->is_ip4 ? IP4 : IP6);
5152 gid_address_ippref_len(&rloc.address) = r->is_ip4 ? 32: 128;
5153 gid_address_type(&rloc.address) = GID_ADDR_IP_PREFIX;
5154 rloc.priority = r->priority;
5155 rloc.weight = r->weight;
5156 vec_add1 (rlocs, rloc);
5160 vnet_lisp_add_del_adjacency_args_t _a, * a = &_a;
5161 gid_address_copy(&a->deid, deid);
5163 rv = vnet_lisp_add_del_adjacency (a);
5165 /* NOTE: for now this works as a static remote mapping, i.e.,
5166 * not authoritative and ttl infinite. */
5167 rv = vnet_lisp_add_del_mapping (deid, rlocs, mp->action, 0, ~0,
5170 /* TODO remove once CSIT switched to lisp_add_del_adjacency */
5171 vnet_lisp_add_del_adjacency_args_t _a, * a = &_a;
5172 gid_address_copy(&a->seid, seid);
5173 gid_address_copy(&a->deid, deid);
5175 vnet_lisp_add_del_adjacency (a);
5179 vnet_lisp_clear_all_remote_adjacencies ();
5183 REPLY_MACRO(VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5187 vl_api_lisp_add_del_adjacency_t_handler (
5188 vl_api_lisp_add_del_adjacency_t *mp)
5190 vl_api_lisp_add_del_adjacency_reply_t * rmp;
5191 vnet_lisp_add_del_adjacency_args_t _a, * a = &_a;
5194 memset(a, 0, sizeof(a[0]));
5196 ip_prefix_t * seid_pref = &gid_address_ippref(&a->seid);
5197 ip_prefix_t * deid_pref = &gid_address_ippref(&a->deid);
5199 ip_address_t * seid_addr = &ip_prefix_addr(seid_pref);
5200 ip_address_t * deid_addr = &ip_prefix_addr(deid_pref);
5201 ip_prefix_len(seid_pref) = mp->seid_len;
5202 ip_prefix_len(deid_pref) = mp->deid_len;
5203 u8 * seid_mac = gid_address_mac (&a->seid);
5204 u8 * deid_mac = gid_address_mac (&a->deid);
5205 gid_address_vni(&a->seid) = ntohl (mp->vni);
5206 gid_address_vni(&a->deid) = ntohl (mp->vni);
5208 switch (mp->eid_type)
5211 gid_address_type(&a->seid) = GID_ADDR_IP_PREFIX;
5212 gid_address_type(&a->deid) = GID_ADDR_IP_PREFIX;
5213 ip_address_set (seid_addr, mp->seid, IP4);
5214 ip_address_set (deid_addr, mp->deid, IP4);
5217 gid_address_type(&a->seid) = GID_ADDR_IP_PREFIX;
5218 gid_address_type(&a->deid) = GID_ADDR_IP_PREFIX;
5219 ip_address_set (seid_addr, mp->seid, IP6);
5220 ip_address_set (deid_addr, mp->deid, IP6);
5222 case 2: /* l2 mac */
5223 gid_address_type(&a->seid) = GID_ADDR_MAC;
5224 gid_address_type(&a->deid) = GID_ADDR_MAC;
5225 clib_memcpy (seid_mac, mp->seid, 6);
5226 clib_memcpy (deid_mac, mp->deid, 6);
5229 rv = VNET_API_ERROR_INVALID_EID_TYPE;
5233 a->is_add = mp->is_add;
5234 rv = vnet_lisp_add_del_adjacency (a);
5237 REPLY_MACRO(VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5241 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
5242 locator_set_t *lsit,
5243 unix_shared_memory_queue_t *q,
5247 vl_api_lisp_locator_set_details_t *rmp;
5248 locator_t *loc = NULL;
5252 vec_foreach (locit, lsit->locator_indices) {
5253 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5254 rmp = vl_msg_api_alloc (sizeof (*rmp));
5255 memset (rmp, 0, sizeof (*rmp));
5256 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
5257 rmp->local = lsit->local;
5259 ASSERT(lsit->name != NULL);
5260 strncpy((char *) rmp->locator_set_name,
5261 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5262 rmp->sw_if_index = htonl(loc->sw_if_index);
5264 str = format(0, "remote-%d", index);
5265 strncpy((char *) rmp->locator_set_name, (char *) str,
5266 ARRAY_LEN(rmp->locator_set_name) - 1);
5267 send_lisp_locator_set_details_set_address(rmp, &loc->address);
5271 rmp->priority = loc->priority;
5272 rmp->weight = loc->weight;
5273 rmp->context = context;
5275 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5280 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
5282 unix_shared_memory_queue_t * q = NULL;
5283 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5284 locator_set_t * lsit = NULL;
5287 q = vl_api_client_index_to_input_queue (mp->client_index);
5293 pool_foreach (lsit, lcm->locator_set_pool,
5295 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
5300 send_lisp_local_eid_table_details (mapping_t *mapit,
5301 unix_shared_memory_queue_t *q,
5304 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
5305 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5306 locator_set_t *ls = NULL;
5307 gid_address_t *gid = NULL;
5309 ip_prefix_t *ip_prefix = NULL;
5312 ls = pool_elt_at_index (lcm->locator_set_pool,
5313 mapit->locator_set_index);
5315 ip_prefix = &gid_address_ippref(gid);
5316 mac = gid_address_mac(gid);
5318 rmp = vl_msg_api_alloc (sizeof (*rmp));
5319 memset (rmp, 0, sizeof (*rmp));
5320 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
5322 ASSERT(ls->name != NULL);
5323 strncpy((char *) rmp->locator_set_name,
5324 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5326 str = format(0, "remote-%d", mapit->locator_set_index);
5327 strncpy((char *) rmp->locator_set_name, (char *) str,
5328 ARRAY_LEN(rmp->locator_set_name) - 1);
5332 switch (gid_address_type (gid))
5334 case GID_ADDR_IP_PREFIX:
5335 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
5336 if (ip_prefix_version(ip_prefix) == IP4)
5338 rmp->eid_type = 0; /* ipv4 type */
5339 clib_memcpy(rmp->eid, &ip_prefix_v4(ip_prefix),
5340 sizeof(ip_prefix_v4(ip_prefix)));
5344 rmp->eid_type = 1; /* ipv6 type */
5345 clib_memcpy(rmp->eid, &ip_prefix_v6(ip_prefix),
5346 sizeof(ip_prefix_v6(ip_prefix)));
5350 rmp->eid_type = 2; /* l2 mac type */
5351 clib_memcpy(rmp->eid, mac, 6);
5356 rmp->context = context;
5357 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5358 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5362 vl_api_lisp_local_eid_table_dump_t_handler (
5363 vl_api_lisp_local_eid_table_dump_t *mp)
5366 unix_shared_memory_queue_t * q = NULL;
5367 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5368 mapping_t * mapit = NULL;
5369 gid_address_t _eid, * eid = &_eid;
5371 q = vl_api_client_index_to_input_queue (mp->client_index);
5377 memset (eid, 0, sizeof (*eid));
5378 gid_address_vni(eid) = ntohl(mp->vni);
5379 switch (mp->eid_type) {
5381 gid_address_type(eid) = GID_ADDR_IP_PREFIX;
5382 gid_address_ippref_len(eid) = mp->prefix_length;
5383 gid_address_ip_version(eid) = IP4;
5384 clib_memcpy (&gid_address_ippref(eid), mp->eid, 4);
5387 gid_address_type(eid) = GID_ADDR_IP_PREFIX;
5388 gid_address_ippref_len(eid) = mp->prefix_length;
5389 gid_address_ip_version(eid) = IP6;
5390 clib_memcpy (&gid_address_ippref(eid), mp->eid, 16);
5393 gid_address_type(eid) = GID_ADDR_MAC;
5394 clib_memcpy (gid_address_mac(eid), mp->eid, 6);
5397 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5401 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5402 send_lisp_local_eid_table_details(mapit, q, mp->context);
5404 pool_foreach (mapit, lcm->mapping_pool,
5406 send_lisp_local_eid_table_details(mapit, q, mp->context);
5412 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5413 unix_shared_memory_queue_t *q,
5416 vl_api_lisp_gpe_tunnel_details_t *rmp;
5417 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5419 rmp = vl_msg_api_alloc (sizeof (*rmp));
5420 memset (rmp, 0, sizeof (*rmp));
5421 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5423 rmp->tunnels = tunnel - lgm->tunnels;
5425 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5426 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5427 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5429 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5430 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5431 rmp->dcap_next = htonl(tunnel->decap_next_index);
5432 rmp->lisp_ver = tunnel->ver_res;
5433 rmp->next_protocol = tunnel->next_protocol;
5434 rmp->flags = tunnel->flags;
5435 rmp->ver_res = tunnel->ver_res;
5436 rmp->res = tunnel->res;
5437 rmp->iid = htonl(tunnel->vni);
5438 rmp->context = context;
5440 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5444 vl_api_lisp_gpe_tunnel_dump_t_handler (
5445 vl_api_lisp_gpe_tunnel_dump_t *mp)
5447 unix_shared_memory_queue_t * q = NULL;
5448 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5449 lisp_gpe_tunnel_t * tunnel = NULL;
5451 if (pool_elts(lgm->tunnels) == 0) {
5455 q = vl_api_client_index_to_input_queue (mp->client_index);
5460 pool_foreach(tunnel, lgm->tunnels,
5462 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5467 send_lisp_map_resolver_details (ip_address_t *ip,
5468 unix_shared_memory_queue_t *q,
5471 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5473 rmp = vl_msg_api_alloc (sizeof (*rmp));
5474 memset (rmp, 0, sizeof (*rmp));
5475 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5477 switch (ip_addr_version(ip)) {
5480 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5485 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5491 rmp->context = context;
5493 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5497 vl_api_lisp_map_resolver_dump_t_handler (
5498 vl_api_lisp_map_resolver_dump_t *mp)
5500 unix_shared_memory_queue_t * q = NULL;
5501 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5502 ip_address_t *ip = NULL;
5504 q = vl_api_client_index_to_input_queue (mp->client_index);
5509 vec_foreach(ip, lcm->map_resolvers) {
5510 send_lisp_map_resolver_details(ip, q, mp->context);
5516 send_eid_table_map_pair (hash_pair_t * p,
5517 unix_shared_memory_queue_t * q,
5520 vl_api_lisp_eid_table_map_details_t * rmp = NULL;
5522 rmp = vl_msg_api_alloc (sizeof (*rmp));
5523 memset (rmp, 0, sizeof (*rmp));
5524 rmp->_vl_msg_id = ntohs(VL_API_LISP_EID_TABLE_MAP_DETAILS);
5526 rmp->vni = clib_host_to_net_u32 (p->key);
5527 rmp->vrf = clib_host_to_net_u32 (p->value[0]);
5528 rmp->context = context;
5529 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5533 vl_api_lisp_eid_table_map_dump_t_handler (
5534 vl_api_lisp_eid_table_map_dump_t *mp)
5536 unix_shared_memory_queue_t * q = NULL;
5537 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5540 q = vl_api_client_index_to_input_queue (mp->client_index);
5544 hash_foreach_pair (p, lcm->table_id_by_vni, {
5545 send_eid_table_map_pair (p, q, mp->context);
5550 send_lisp_enable_disable_details (unix_shared_memory_queue_t *q,
5553 vl_api_lisp_enable_disable_status_details_t *rmp = NULL;
5555 rmp = vl_msg_api_alloc (sizeof (*rmp));
5556 memset (rmp, 0, sizeof (*rmp));
5557 rmp->_vl_msg_id = ntohs(VL_API_LISP_ENABLE_DISABLE_STATUS_DETAILS);
5559 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5560 rmp->feature_status = vnet_lisp_enable_disable_status ();
5561 rmp->context = context;
5563 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5567 vl_api_lisp_enable_disable_status_dump_t_handler
5568 (vl_api_lisp_enable_disable_status_dump_t *mp)
5570 unix_shared_memory_queue_t * q = NULL;
5572 q = vl_api_client_index_to_input_queue (mp->client_index);
5577 send_lisp_enable_disable_details(q, mp->context);
5581 vl_api_lisp_get_map_request_itr_rlocs_t_handler (
5582 vl_api_lisp_get_map_request_itr_rlocs_t *mp)
5584 unix_shared_memory_queue_t * q = NULL;
5585 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
5586 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5587 locator_set_t * loc_set = 0;
5591 q = vl_api_client_index_to_input_queue (mp->client_index);
5596 if (~0 == lcm->mreq_itr_rlocs) {
5597 tmp_str = format(0, " ");
5599 loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
5600 tmp_str = format(0, "%s", loc_set->name);
5603 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
5605 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5606 ARRAY_LEN(rmp->locator_set_name) - 1);
5613 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
5615 unix_shared_memory_queue_t * q = NULL;
5616 vl_api_show_lisp_pitr_reply_t * rmp = NULL;
5617 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5619 locator_set_t * ls = 0;
5623 q = vl_api_client_index_to_input_queue (mp->client_index);
5628 if (~0 == lcm->pitr_map_index) {
5629 tmp_str = format(0, "N/A");
5631 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
5632 if (~0 != m->locator_set_index) {
5633 ls = pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
5634 tmp_str = format(0, "%s", ls->name);
5636 tmp_str = format(0, "N/A");
5639 vec_add1(tmp_str, 0);
5641 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
5643 rmp->status = lcm->lisp_pitr;
5644 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5645 ARRAY_LEN(rmp->locator_set_name) - 1);
5650 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5652 vl_api_interface_name_renumber_reply_t * rmp;
5655 VALIDATE_SW_IF_INDEX(mp);
5657 rv = vnet_interface_name_renumber
5658 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5660 BAD_SW_IF_INDEX_LABEL;
5662 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5665 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5666 u32 sw_if_index, u32 address)
5668 vpe_api_main_t * am = &vpe_api_main;
5669 vlib_main_t * vm = am->vlib_main;
5670 vl_api_ip4_arp_event_t * event;
5671 static f64 arp_event_last_time;
5672 f64 now = vlib_time_now (vm);
5674 if (pool_is_free_index (am->arp_events, pool_index))
5677 event = pool_elt_at_index (am->arp_events, pool_index);
5678 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5679 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5680 } else { /* same mac */
5681 if ((sw_if_index == event->sw_if_index) &&
5683 /* for BD case, also check IP address with 10 sec timeout */
5684 ((address == event->address) &&
5685 ((now - arp_event_last_time) < 10.0))))
5689 arp_event_last_time = now;
5690 event->sw_if_index = sw_if_index;
5691 if (address) event->address = address;
5695 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5697 vpe_api_main_t * am = &vpe_api_main;
5699 if (pool_is_free_index (am->arp_events, pool_index))
5702 pool_put_index (am->arp_events, pool_index);
5707 vl_api_want_ip4_arp_events_t_handler
5708 (vl_api_want_ip4_arp_events_t * mp)
5710 vpe_api_main_t * am = &vpe_api_main;
5711 vnet_main_t * vnm = vnet_get_main();
5712 vl_api_want_ip4_arp_events_reply_t *rmp;
5713 vl_api_ip4_arp_event_t * event;
5716 if (mp->enable_disable) {
5717 pool_get (am->arp_events, event);
5718 memset (event, 0, sizeof (*event));
5720 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5721 event->client_index = mp->client_index;
5722 event->context = mp->context;
5723 event->address = mp->address;
5724 event->pid = mp->pid;
5726 rv = vnet_add_del_ip4_arp_change_event
5727 (vnm, arp_change_data_callback,
5729 &mp->address /* addr, in net byte order */,
5730 vpe_resolver_process_node.index,
5731 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5733 rv = vnet_add_del_ip4_arp_change_event
5734 (vnm, arp_change_delete_callback,
5736 &mp->address /* addr, in net byte order */,
5737 vpe_resolver_process_node.index,
5738 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5740 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5743 static void vl_api_input_acl_set_interface_t_handler
5744 (vl_api_input_acl_set_interface_t * mp)
5746 vlib_main_t *vm = vlib_get_main();
5747 vl_api_input_acl_set_interface_reply_t * rmp;
5749 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5751 ip4_table_index = ntohl(mp->ip4_table_index);
5752 ip6_table_index = ntohl(mp->ip6_table_index);
5753 l2_table_index = ntohl(mp->l2_table_index);
5754 sw_if_index = ntohl(mp->sw_if_index);
5756 VALIDATE_SW_IF_INDEX(mp);
5758 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5759 ip6_table_index, l2_table_index,
5762 BAD_SW_IF_INDEX_LABEL;
5764 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5767 static void vl_api_ipsec_spd_add_del_t_handler
5768 (vl_api_ipsec_spd_add_del_t * mp)
5771 clib_warning ("unimplemented");
5774 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5775 vl_api_ipsec_spd_add_del_reply_t * rmp;
5779 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5781 rv = VNET_API_ERROR_UNIMPLEMENTED;
5784 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5788 static void vl_api_ipsec_interface_add_del_spd_t_handler
5789 (vl_api_ipsec_interface_add_del_spd_t * mp)
5791 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5792 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5794 u32 sw_if_index __attribute__((unused));
5795 u32 spd_id __attribute__((unused));
5797 sw_if_index = ntohl(mp->sw_if_index);
5798 spd_id = ntohl(mp->spd_id);
5800 VALIDATE_SW_IF_INDEX(mp);
5803 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5805 rv = VNET_API_ERROR_UNIMPLEMENTED;
5808 BAD_SW_IF_INDEX_LABEL;
5810 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5813 static void vl_api_ipsec_spd_add_del_entry_t_handler
5814 (vl_api_ipsec_spd_add_del_entry_t * mp)
5816 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5817 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5823 memset(&p, 0, sizeof(p));
5825 p.id = ntohl(mp->spd_id);
5826 p.priority = ntohl(mp->priority);
5827 p.is_outbound = mp->is_outbound;
5828 p.is_ipv6 = mp->is_ipv6;
5830 if (mp->is_ipv6 || mp->is_ip_any) {
5831 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5832 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5833 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5834 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5836 clib_memcpy(&p.raddr.start.ip4.data, mp->remote_address_start, 4);
5837 clib_memcpy(&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
5838 clib_memcpy(&p.laddr.start.ip4.data, mp->local_address_start, 4);
5839 clib_memcpy(&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
5841 p.protocol = mp->protocol;
5842 p.rport.start = ntohs(mp->remote_port_start);
5843 p.rport.stop = ntohs(mp->remote_port_stop);
5844 p.lport.start = ntohs(mp->local_port_start);
5845 p.lport.stop = ntohs(mp->local_port_stop);
5846 /* policy action resolve unsupported */
5847 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5848 clib_warning("unsupported action: 'resolve'");
5849 rv = VNET_API_ERROR_UNIMPLEMENTED;
5852 p.policy = mp->policy;
5853 p.sa_id = ntohl(mp->sa_id);
5855 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5859 if (mp->is_ip_any) {
5861 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5864 rv = VNET_API_ERROR_UNIMPLEMENTED;
5869 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5872 static void vl_api_ipsec_sad_add_del_entry_t_handler
5873 (vl_api_ipsec_sad_add_del_entry_t * mp)
5875 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5876 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5881 memset(&sa, 0, sizeof(sa));
5883 sa.id = ntohl(mp->sad_id);
5884 sa.spi = ntohl(mp->spi);
5885 /* security protocol AH unsupported */
5886 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5887 clib_warning("unsupported security protocol 'AH'");
5888 rv = VNET_API_ERROR_UNIMPLEMENTED;
5891 sa.protocol = mp->protocol;
5892 /* check for unsupported crypto-alg */
5893 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5894 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5895 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5896 mp->crypto_algorithm);
5897 rv = VNET_API_ERROR_UNIMPLEMENTED;
5900 sa.crypto_alg = mp->crypto_algorithm;
5901 sa.crypto_key_len = mp->crypto_key_length;
5902 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5903 /* check for unsupported integ-alg */
5904 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5905 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5906 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5907 mp->integrity_algorithm);
5908 rv = VNET_API_ERROR_UNIMPLEMENTED;
5911 sa.integ_alg = mp->integrity_algorithm;
5912 sa.integ_key_len = mp->integrity_key_length;
5913 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5914 sa.use_esn = mp->use_extended_sequence_number;
5915 sa.is_tunnel = mp->is_tunnel;
5916 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5917 if (sa.is_tunnel_ip6) {
5918 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5919 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5921 clib_memcpy(&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
5922 clib_memcpy(&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
5925 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5927 rv = VNET_API_ERROR_UNIMPLEMENTED;
5932 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5936 vl_api_ikev2_profile_add_del_t_handler
5937 (vl_api_ikev2_profile_add_del_t * mp)
5939 vl_api_ikev2_profile_add_del_reply_t * rmp;
5943 vlib_main_t * vm = vlib_get_main();
5944 clib_error_t * error;
5945 u8 * tmp = format(0, "%s", mp->name);
5946 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5949 rv = VNET_API_ERROR_UNSPECIFIED;
5951 rv = VNET_API_ERROR_UNIMPLEMENTED;
5954 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5958 vl_api_ikev2_profile_set_auth_t_handler
5959 (vl_api_ikev2_profile_set_auth_t * mp)
5961 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5965 vlib_main_t * vm = vlib_get_main();
5966 clib_error_t * error;
5967 u8 * tmp = format(0, "%s", mp->name);
5968 u8 * data = vec_new (u8, mp->data_len);
5969 clib_memcpy(data, mp->data, mp->data_len);
5970 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5974 rv = VNET_API_ERROR_UNSPECIFIED;
5976 rv = VNET_API_ERROR_UNIMPLEMENTED;
5979 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5983 vl_api_ikev2_profile_set_id_t_handler
5984 (vl_api_ikev2_profile_set_id_t * mp)
5986 vl_api_ikev2_profile_add_del_reply_t * rmp;
5990 vlib_main_t * vm = vlib_get_main();
5991 clib_error_t * error;
5992 u8 * tmp = format(0, "%s", mp->name);
5993 u8 * data = vec_new (u8, mp->data_len);
5994 clib_memcpy(data, mp->data, mp->data_len);
5995 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
5999 rv = VNET_API_ERROR_UNSPECIFIED;
6001 rv = VNET_API_ERROR_UNIMPLEMENTED;
6004 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6008 vl_api_ikev2_profile_set_ts_t_handler
6009 (vl_api_ikev2_profile_set_ts_t * mp)
6011 vl_api_ikev2_profile_set_ts_reply_t * rmp;
6015 vlib_main_t * vm = vlib_get_main();
6016 clib_error_t * error;
6017 u8 * tmp = format(0, "%s", mp->name);
6018 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
6019 mp->end_port, (ip4_address_t) mp->start_addr,
6020 (ip4_address_t) mp->end_addr, mp->is_local);
6023 rv = VNET_API_ERROR_UNSPECIFIED;
6025 rv = VNET_API_ERROR_UNIMPLEMENTED;
6028 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6032 vl_api_ikev2_set_local_key_t_handler
6033 (vl_api_ikev2_set_local_key_t * mp)
6035 vl_api_ikev2_profile_set_ts_reply_t * rmp;
6039 vlib_main_t * vm = vlib_get_main();
6040 clib_error_t * error;
6042 error = ikev2_set_local_key(vm, mp->key_file);
6044 rv = VNET_API_ERROR_UNSPECIFIED;
6046 rv = VNET_API_ERROR_UNIMPLEMENTED;
6049 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6053 vl_api_map_add_domain_t_handler
6054 (vl_api_map_add_domain_t * mp)
6056 vl_api_map_add_domain_reply_t * rmp;
6059 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6060 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
6061 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
6062 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
6063 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
6065 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6067 rmp->index = ntohl(index);
6072 vl_api_map_del_domain_t_handler
6073 (vl_api_map_del_domain_t * mp)
6075 vl_api_map_del_domain_reply_t * rmp;
6078 rv = map_delete_domain(ntohl(mp->index));
6080 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
6084 vl_api_map_add_del_rule_t_handler
6085 (vl_api_map_add_del_rule_t * mp)
6087 vl_api_map_del_domain_reply_t * rmp;
6090 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
6092 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
6096 vl_api_map_domain_dump_t_handler
6097 (vl_api_map_domain_dump_t * mp)
6099 vl_api_map_domain_details_t * rmp;
6100 map_main_t *mm = &map_main;
6102 unix_shared_memory_queue_t * q;
6104 if (pool_elts (mm->domains) == 0)
6107 q = vl_api_client_index_to_input_queue (mp->client_index);
6112 pool_foreach(d, mm->domains, ({
6113 /* Make sure every field is initiated (or don't skip the memset()) */
6114 rmp = vl_msg_api_alloc (sizeof (*rmp));
6115 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6116 rmp->domain_index = htonl(d - mm->domains);
6117 rmp->ea_bits_len = d->ea_bits_len;
6118 rmp->psid_offset = d->psid_offset;
6119 rmp->psid_length = d->psid_length;
6120 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6121 rmp->ip4_prefix_len = d->ip4_prefix_len;
6122 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6123 rmp->ip6_prefix_len = d->ip6_prefix_len;
6124 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6125 rmp->ip6_src_len = d->ip6_src_len;
6126 rmp->mtu = htons(d->mtu);
6127 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6128 rmp->context = mp->context;
6130 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6135 vl_api_map_rule_dump_t_handler
6136 (vl_api_map_rule_dump_t * mp)
6138 unix_shared_memory_queue_t * q;
6141 vl_api_map_rule_details_t * rmp;
6142 map_main_t *mm = &map_main;
6143 u32 domain_index = ntohl(mp->domain_index);
6146 if (pool_elts (mm->domains) == 0)
6149 d = pool_elt_at_index(mm->domains, domain_index);
6150 if (!d || !d->rules) {
6154 q = vl_api_client_index_to_input_queue (mp->client_index);
6159 for (i = 0; i < (0x1 << d->psid_length); i++) {
6161 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
6164 rmp = vl_msg_api_alloc(sizeof(*rmp));
6165 memset(rmp, 0, sizeof(*rmp));
6166 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
6167 rmp->psid = htons(i);
6168 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
6169 rmp->context = mp->context;
6170 vl_msg_api_send_shmem(q, (u8 *)&rmp);
6175 vl_api_map_summary_stats_t_handler (
6176 vl_api_map_summary_stats_t *mp)
6178 vl_api_map_summary_stats_reply_t *rmp;
6179 vlib_combined_counter_main_t *cm;
6182 u64 total_pkts[VLIB_N_RX_TX];
6183 u64 total_bytes[VLIB_N_RX_TX];
6184 map_main_t *mm = &map_main;
6185 unix_shared_memory_queue_t *q =
6186 vl_api_client_index_to_input_queue(mp->client_index);
6191 rmp = vl_msg_api_alloc (sizeof (*rmp));
6192 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
6193 rmp->context = mp->context;
6196 memset (total_pkts, 0, sizeof (total_pkts));
6197 memset (total_bytes, 0, sizeof (total_bytes));
6199 map_domain_counter_lock (mm);
6200 vec_foreach(cm, mm->domain_counters) {
6201 which = cm - mm->domain_counters;
6203 for (i = 0; i < vec_len(cm->maxi); i++) {
6204 vlib_get_combined_counter (cm, i, &v);
6205 total_pkts[which] += v.packets;
6206 total_bytes[which] += v.bytes;
6210 map_domain_counter_unlock (mm);
6212 /* Note: in network byte order! */
6213 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
6214 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
6215 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
6216 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
6217 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
6218 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6219 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));
6220 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));
6222 vl_msg_api_send_shmem(q, (u8 *)&rmp);
6225 static void vl_api_ipsec_sa_set_key_t_handler
6226 (vl_api_ipsec_sa_set_key_t * mp)
6228 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
6229 vl_api_ipsec_sa_set_key_reply_t *rmp;
6233 sa.id = ntohl(mp->sa_id);
6234 sa.crypto_key_len = mp->crypto_key_length;
6235 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
6236 sa.integ_key_len = mp->integrity_key_length;
6237 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
6239 rv = ipsec_set_sa_key(vm, &sa);
6241 rv = VNET_API_ERROR_UNIMPLEMENTED;
6244 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
6247 static void vl_api_cop_interface_enable_disable_t_handler
6248 (vl_api_cop_interface_enable_disable_t * mp)
6250 vl_api_cop_interface_enable_disable_reply_t * rmp;
6252 u32 sw_if_index = ntohl(mp->sw_if_index);
6255 VALIDATE_SW_IF_INDEX(mp);
6257 enable_disable = (int) mp->enable_disable;
6259 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6261 BAD_SW_IF_INDEX_LABEL;
6263 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6266 static void vl_api_cop_whitelist_enable_disable_t_handler
6267 (vl_api_cop_whitelist_enable_disable_t * mp)
6269 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
6270 cop_whitelist_enable_disable_args_t _a, *a=&_a;
6271 u32 sw_if_index = ntohl(mp->sw_if_index);
6274 VALIDATE_SW_IF_INDEX(mp);
6276 a->sw_if_index = sw_if_index;
6279 a->default_cop = mp->default_cop;
6280 a->fib_id = ntohl(mp->fib_id);
6282 rv = cop_whitelist_enable_disable (a);
6284 BAD_SW_IF_INDEX_LABEL;
6286 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
6289 static void vl_api_get_node_graph_t_handler
6290 (vl_api_get_node_graph_t * mp)
6294 api_main_t * am = &api_main;
6295 vlib_main_t * vm = vlib_get_main();
6297 vl_api_get_node_graph_reply_t * rmp;
6299 pthread_mutex_lock (&am->vlib_rp->mutex);
6300 oldheap = svm_push_data_heap (am->vlib_rp);
6303 * Keep the number of memcpy ops to a minimum (e.g. 1).
6305 vec_validate (vector, 16384);
6306 vec_reset_length (vector);
6309 vector = vlib_node_serialize (&vm->node_main, vector,
6310 (u32)~0 /* all threads */,
6311 1 /* include nexts */,
6312 1 /* include stats */);
6314 svm_pop_heap (oldheap);
6315 pthread_mutex_unlock (&am->vlib_rp->mutex);
6317 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
6318 rmp->reply_in_shmem = (uword) vector);
6321 static void vl_api_trace_profile_add_t_handler
6322 (vl_api_trace_profile_add_t *mp)
6325 vl_api_trace_profile_add_reply_t * rmp;
6326 clib_error_t *error;
6328 /* Ignoring the profile id as currently a single profile
6330 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
6331 ntohl(mp->node_id), ntohl(mp->trace_app_data),
6332 mp->pow_enable, mp->trace_tsp,
6335 clib_error_report(error);
6336 rv = clib_error_get_code(error);
6339 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
6342 static void vl_api_trace_profile_apply_t_handler
6343 (vl_api_trace_profile_apply_t *mp)
6346 vl_api_trace_profile_apply_reply_t * rmp;
6348 if (mp->enable != 0) {
6349 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
6350 ntohl(mp->prefix_length),
6352 mp->trace_op == IOAM_HBYH_ADD,
6353 mp->trace_op == IOAM_HBYH_POP,
6354 mp->trace_op == IOAM_HBYH_MOD);
6356 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
6358 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
6361 static void vl_api_trace_profile_del_t_handler
6362 (vl_api_trace_profile_del_t *mp)
6365 vl_api_trace_profile_del_reply_t * rmp;
6366 clib_error_t *error;
6368 error = clear_ioam_rewrite_fn();
6370 clib_error_report(error);
6371 rv = clib_error_get_code(error);
6374 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
6378 vl_api_af_packet_create_t_handler
6379 (vl_api_af_packet_create_t *mp)
6381 vlib_main_t *vm = vlib_get_main();
6382 vl_api_af_packet_create_reply_t *rmp;
6384 u8 *host_if_name = NULL;
6387 host_if_name = format(0, "%s", mp->host_if_name);
6388 vec_add1 (host_if_name, 0);
6390 rv = af_packet_create_if(vm, host_if_name,
6391 mp->use_random_hw_addr ? 0 : mp->hw_addr, &sw_if_index);
6393 vec_free(host_if_name);
6395 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
6396 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index));
6400 vl_api_af_packet_delete_t_handler
6401 (vl_api_af_packet_delete_t *mp)
6403 vlib_main_t * vm = vlib_get_main();
6404 vl_api_af_packet_delete_reply_t *rmp;
6406 u8 *host_if_name = NULL;
6408 host_if_name = format(0, "%s", mp->host_if_name);
6409 vec_add1 (host_if_name, 0);
6411 rv = af_packet_delete_if(vm, host_if_name);
6413 vec_free(host_if_name);
6415 REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY);
6419 vl_api_policer_add_del_t_handler
6420 (vl_api_policer_add_del_t *mp)
6422 vlib_main_t * vm = vlib_get_main();
6423 vl_api_policer_add_del_reply_t *rmp;
6426 sse2_qos_pol_cfg_params_st cfg;
6427 clib_error_t * error;
6429 name = format(0, "%s", mp->name);
6431 memset (&cfg, 0, sizeof (cfg));
6433 cfg.rnd_type = mp->round_type;
6434 cfg.rate_type = mp->rate_type;
6435 cfg.rb.kbps.cir_kbps = mp->cir;
6436 cfg.rb.kbps.eir_kbps = mp->eir;
6437 cfg.rb.kbps.cb_bytes = mp->cb;
6438 cfg.rb.kbps.eb_bytes = mp->eb;
6439 cfg.conform_action.action_type = mp->conform_action_type;
6440 cfg.conform_action.dscp = mp->conform_dscp;
6441 cfg.exceed_action.action_type = mp->exceed_action_type;
6442 cfg.exceed_action.dscp = mp->exceed_dscp;
6443 cfg.violate_action.action_type = mp->violate_action_type;
6444 cfg.violate_action.dscp = mp->violate_dscp;
6446 error = policer_add_del(vm, name, &cfg, mp->is_add);
6449 rv = VNET_API_ERROR_UNSPECIFIED;
6451 REPLY_MACRO(VL_API_POLICER_ADD_DEL_REPLY);
6455 send_policer_details (u8 *name,
6456 sse2_qos_pol_cfg_params_st *config,
6457 policer_read_response_type_st *templ,
6458 unix_shared_memory_queue_t *q,
6461 vl_api_policer_details_t * mp;
6463 mp = vl_msg_api_alloc (sizeof (*mp));
6464 memset (mp, 0, sizeof (*mp));
6465 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
6466 mp->context = context;
6467 mp->cir = htonl(config->rb.kbps.cir_kbps);
6468 mp->eir = htonl(config->rb.kbps.eir_kbps);
6469 mp->cb = htonl(config->rb.kbps.cb_bytes);
6470 mp->eb = htonl(config->rb.kbps.eb_bytes);
6471 mp->rate_type = config->rate_type;
6472 mp->round_type = config->rnd_type;
6473 mp->type = config->rfc;
6474 mp->conform_action_type = config->conform_action.action_type;
6475 mp->conform_dscp = config->conform_action.dscp;
6476 mp->exceed_action_type = config->exceed_action.action_type;
6477 mp->exceed_dscp = config->exceed_action.dscp;
6478 mp->violate_action_type = config->violate_action.action_type;
6479 mp->violate_dscp = config->violate_action.dscp;
6480 mp->single_rate = templ->single_rate ? 1 : 0;
6481 mp->color_aware = templ->color_aware ? 1 : 0;
6482 mp->scale = htonl(templ->scale);
6483 mp->cir_tokens_per_period = htonl(templ->cir_tokens_per_period);
6484 mp->pir_tokens_per_period = htonl(templ->pir_tokens_per_period);
6485 mp->current_limit = htonl(templ->current_limit);
6486 mp->current_bucket = htonl(templ->current_bucket);
6487 mp->extended_limit = htonl(templ->extended_limit);
6488 mp->extended_bucket = htonl(templ->extended_bucket);
6489 mp->last_update_time = clib_host_to_net_u64(templ->last_update_time);
6491 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN(mp->name) - 1);
6493 vl_msg_api_send_shmem (q, (u8 *)&mp);
6497 vl_api_policer_dump_t_handler
6498 (vl_api_policer_dump_t *mp)
6500 unix_shared_memory_queue_t * q;
6501 vnet_policer_main_t * pm = &vnet_policer_main;
6505 u8 * match_name = 0;
6507 sse2_qos_pol_cfg_params_st *config;
6508 policer_read_response_type_st *templ;
6510 q = vl_api_client_index_to_input_queue (mp->client_index);
6514 if (mp->match_name_valid) {
6515 match_name = format(0, "%s%c", mp->match_name, 0);
6518 if (mp->match_name_valid) {
6519 p = hash_get_mem (pm->policer_config_by_name, match_name);
6522 config = pool_elt_at_index (pm->configs, pool_index);
6523 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6524 send_policer_details(match_name, config, templ, q, mp->context);
6527 hash_foreach_pair (hp, pm->policer_config_by_name,
6529 name = (u8 *) hp->key;
6530 pool_index = hp->value[0];
6531 config = pool_elt_at_index (pm->configs, pool_index);
6532 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6533 send_policer_details(name, config, templ, q, mp->context);
6539 vl_api_netmap_create_t_handler
6540 (vl_api_netmap_create_t *mp)
6542 vlib_main_t *vm = vlib_get_main();
6543 vl_api_netmap_create_reply_t *rmp;
6547 if_name = format(0, "%s", mp->netmap_if_name);
6548 vec_add1 (if_name, 0);
6550 rv = netmap_create_if(vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
6551 mp->is_pipe, mp->is_master, 0);
6555 REPLY_MACRO(VL_API_NETMAP_CREATE_REPLY);
6559 vl_api_netmap_delete_t_handler
6560 (vl_api_netmap_delete_t *mp)
6562 vlib_main_t * vm = vlib_get_main();
6563 vl_api_netmap_delete_reply_t *rmp;
6567 if_name = format(0, "%s", mp->netmap_if_name);
6568 vec_add1 (if_name, 0);
6570 rv = netmap_delete_if(vm, if_name);
6574 REPLY_MACRO(VL_API_NETMAP_DELETE_REPLY);
6577 static void vl_api_mpls_gre_tunnel_details_t_handler (
6578 vl_api_mpls_gre_tunnel_details_t * mp)
6580 clib_warning ("BUG");
6583 static void send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
6584 unix_shared_memory_queue_t *q,
6585 mpls_gre_tunnel_t * gt,
6589 vl_api_mpls_gre_tunnel_details_t * mp;
6591 mp = vl_msg_api_alloc (sizeof (*mp));
6592 memset (mp, 0, sizeof (*mp));
6593 mp->_vl_msg_id = ntohs(VL_API_MPLS_GRE_TUNNEL_DETAILS);
6594 mp->context = context;
6597 mp->tunnel_index = htonl(index);
6598 mp->tunnel_src = gt->tunnel_src.as_u32;
6599 mp->tunnel_dst = gt->tunnel_dst.as_u32;
6600 mp->intfc_address = gt->intfc_address.as_u32;
6601 mp->mask_width = htonl(gt->mask_width);
6602 mp->inner_fib_index = htonl(gt->inner_fib_index);
6603 mp->outer_fib_index = htonl(gt->outer_fib_index);
6604 mp->encap_index = htonl(gt->encap_index);
6605 mp->hw_if_index = htonl(gt->hw_if_index);
6606 mp->l2_only = htonl(gt->l2_only);
6609 mpls_main_t * mm = &mpls_main;
6614 e = pool_elt_at_index (mm->encaps, gt->encap_index);
6615 len = vec_len (e->labels);
6616 mp->nlabels = htonl(len);
6618 for (i = 0; i < len; i++) {
6619 mp->labels[i] = htonl(vnet_mpls_uc_get_label(
6620 clib_host_to_net_u32(e->labels[i].label_exp_s_ttl)));
6623 vl_msg_api_send_shmem (q, (u8 *)&mp);
6627 vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t *mp)
6629 vpe_api_main_t * am = &vpe_api_main;
6630 unix_shared_memory_queue_t * q;
6631 vlib_main_t * vm = &vlib_global_main;
6632 mpls_main_t * mm = &mpls_main;
6633 mpls_gre_tunnel_t * gt;
6634 u32 index = ntohl(mp->tunnel_index);
6636 q = vl_api_client_index_to_input_queue (mp->client_index);
6640 if (pool_elts (mm->gre_tunnels)) {
6641 if(mp->tunnel_index >= 0) {
6642 vlib_cli_output (vm, "MPLS-GRE tunnel %u", index);
6643 gt = pool_elt_at_index (mm->gre_tunnels, index);
6644 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels, mp->context);
6646 vlib_cli_output (vm, "MPLS-GRE tunnels");
6647 pool_foreach (gt, mm->gre_tunnels,
6649 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels, mp->context);
6653 vlib_cli_output (vm, "No MPLS-GRE tunnels");
6657 static void vl_api_mpls_eth_tunnel_details_t_handler (
6658 vl_api_mpls_eth_tunnel_details_t * mp)
6660 clib_warning ("BUG");
6663 static void send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
6664 unix_shared_memory_queue_t *q,
6665 mpls_eth_tunnel_t * et,
6669 vl_api_mpls_eth_tunnel_details_t * mp;
6671 mp = vl_msg_api_alloc (sizeof (*mp));
6672 memset (mp, 0, sizeof (*mp));
6673 mp->_vl_msg_id = ntohs(VL_API_MPLS_ETH_TUNNEL_DETAILS);
6674 mp->context = context;
6677 mp->tunnel_index = htonl(index);
6678 memcpy(mp->tunnel_dst_mac, et->tunnel_dst, 6);
6679 mp->intfc_address = et->intfc_address.as_u32;
6680 mp->tx_sw_if_index = htonl(et->tx_sw_if_index);
6681 mp->inner_fib_index = htonl(et->inner_fib_index);
6682 mp->mask_width = htonl(et->mask_width);
6683 mp->encap_index = htonl(et->encap_index);
6684 mp->hw_if_index = htonl(et->hw_if_index);
6685 mp->l2_only = htonl(et->l2_only);
6688 mpls_main_t * mm = &mpls_main;
6693 e = pool_elt_at_index (mm->encaps, et->encap_index);
6694 len = vec_len (e->labels);
6695 mp->nlabels = htonl(len);
6697 for (i = 0; i < len; i++) {
6698 mp->labels[i] = htonl(vnet_mpls_uc_get_label(
6699 clib_host_to_net_u32(e->labels[i].label_exp_s_ttl)));
6702 vl_msg_api_send_shmem (q, (u8 *)&mp);
6706 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t *mp)
6708 vpe_api_main_t * am = &vpe_api_main;
6709 unix_shared_memory_queue_t * q;
6710 vlib_main_t * vm = &vlib_global_main;
6711 mpls_main_t * mm = &mpls_main;
6712 mpls_eth_tunnel_t * et;
6713 u32 index = ntohl(mp->tunnel_index);
6715 q = vl_api_client_index_to_input_queue (mp->client_index);
6719 clib_warning("Received mpls_eth_tunnel_dump");
6720 clib_warning("Received tunnel index: %u from client %u", index, mp->client_index);
6722 if (pool_elts (mm->eth_tunnels)) {
6723 if(mp->tunnel_index >= 0) {
6724 vlib_cli_output (vm, "MPLS-Ethernet tunnel %u", index);
6725 et = pool_elt_at_index (mm->eth_tunnels, index);
6726 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels, mp->context);
6728 clib_warning("MPLS-Ethernet tunnels");
6729 pool_foreach (et, mm->eth_tunnels,
6731 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels, mp->context);
6735 clib_warning("No MPLS-Ethernet tunnels");
6739 static void vl_api_mpls_fib_encap_details_t_handler (
6740 vl_api_mpls_fib_encap_details_t * mp)
6742 clib_warning ("BUG");
6745 static void send_mpls_fib_encap_details (vpe_api_main_t * am,
6746 unix_shared_memory_queue_t *q,
6750 vl_api_mpls_fib_encap_details_t * mp;
6752 mp = vl_msg_api_alloc (sizeof (*mp));
6753 memset (mp, 0, sizeof (*mp));
6754 mp->_vl_msg_id = ntohs(VL_API_MPLS_FIB_ENCAP_DETAILS);
6755 mp->context = context;
6757 mp->fib_index = htonl(s->fib_index);
6758 mp->entry_index = htonl(s->entry_index);
6760 mp->s_bit = htonl(s->s_bit);
6762 mpls_main_t * mm = &mpls_main;
6767 e = pool_elt_at_index (mm->encaps, s->entry_index);
6768 len = vec_len (e->labels);
6769 mp->nlabels = htonl(len);
6771 for (i = 0; i < len; i++) {
6772 mp->labels[i] = htonl(vnet_mpls_uc_get_label(
6773 clib_host_to_net_u32(e->labels[i].label_exp_s_ttl)));
6776 vl_msg_api_send_shmem (q, (u8 *)&mp);
6780 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t *mp)
6782 vpe_api_main_t * am = &vpe_api_main;
6783 unix_shared_memory_queue_t * q;
6784 vlib_main_t * vm = &vlib_global_main;
6787 show_mpls_fib_t *records = 0;
6789 mpls_main_t * mm = &mpls_main;
6790 ip4_main_t * im = &ip4_main;
6793 q = vl_api_client_index_to_input_queue (mp->client_index);
6797 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
6799 vec_add2 (records, s, 1);
6800 s->fib_index = (u32)(key>>32);
6801 s->dest = (u32)(key & 0xFFFFFFFF);
6802 s->entry_index = (u32) value;
6805 if (0 == vec_len(records)) {
6806 vlib_cli_output(vm, "MPLS encap table empty");
6810 /* sort output by dst address within fib */
6811 vec_sort_with_function(records, mpls_dest_cmp);
6812 vec_sort_with_function(records, mpls_fib_index_cmp);
6813 vlib_cli_output(vm, "MPLS encap table");
6814 vlib_cli_output(vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
6815 vec_foreach (s, records)
6817 rx_fib = vec_elt_at_index(im->fibs, s->fib_index);
6818 vlib_cli_output(vm, "%=6d%=16U%=16U", rx_fib->table_id,
6819 format_ip4_address, &s->dest, format_mpls_encap_index, mm,
6821 send_mpls_fib_encap_details (am, q, s, mp->context);
6828 static void vl_api_mpls_fib_decap_details_t_handler (
6829 vl_api_mpls_fib_decap_details_t * mp)
6831 clib_warning ("BUG");
6834 static void send_mpls_fib_decap_details (vpe_api_main_t * am,
6835 unix_shared_memory_queue_t *q,
6842 vl_api_mpls_fib_decap_details_t * mp;
6844 mp = vl_msg_api_alloc (sizeof (*mp));
6845 memset (mp, 0, sizeof (*mp));
6846 mp->_vl_msg_id = ntohs(VL_API_MPLS_FIB_DECAP_DETAILS);
6847 mp->context = context;
6849 mp->fib_index = htonl(s->fib_index);
6850 mp->entry_index = htonl(s->entry_index);
6852 mp->s_bit = htonl(s->s_bit);
6853 mp->label = htonl(s->label);
6854 mp->rx_table_id = htonl(rx_table_id);
6855 mp->tx_table_id = htonl(tx_table_id);
6856 strncpy ((char *) mp->swif_tag,
6857 (char *) swif_tag, ARRAY_LEN(mp->swif_tag)-1);
6859 vl_msg_api_send_shmem (q, (u8 *)&mp);
6863 vl_api_mpls_fib_decap_dump_t_handler (vl_api_mpls_fib_decap_dump_t *mp)
6865 vpe_api_main_t * am = &vpe_api_main;
6866 unix_shared_memory_queue_t * q;
6867 vlib_main_t * vm = &vlib_global_main;
6870 show_mpls_fib_t *records = 0;
6872 mpls_main_t * mm = &mpls_main;
6873 ip4_main_t * im = &ip4_main;
6879 q = vl_api_client_index_to_input_queue (mp->client_index);
6883 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
6885 vec_add2 (records, s, 1);
6886 s->fib_index = (u32)(key>>32);
6887 s->entry_index = (u32) value;
6888 s->label = ((u32) key)>>12;
6889 s->s_bit = (key & (1<<8)) != 0;
6892 if (!vec_len(records)) {
6893 vlib_cli_output(vm, "MPLS decap table empty");
6897 vec_sort_with_function(records, mpls_label_cmp);
6898 vlib_cli_output(vm, "MPLS decap table");
6899 vlib_cli_output(vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
6901 vec_foreach (s, records)
6904 d = pool_elt_at_index(mm->decaps, s->entry_index);
6905 if (d->next_index == MPLS_INPUT_NEXT_IP4_INPUT) {
6906 tx_fib = vec_elt_at_index(im->fibs, d->tx_fib_index);
6907 tx_table_id = tx_fib->table_id;
6910 tx_table_id = d->tx_fib_index;
6913 rx_fib = vec_elt_at_index(im->fibs, s->fib_index);
6915 vlib_cli_output(vm, "%=10d%=10d%=5s%=6d%=6d", rx_fib->table_id,
6916 tx_table_id, swif_tag, s->label, s->s_bit);
6918 send_mpls_fib_decap_details (am, q, s, rx_fib->table_id,
6919 tx_table_id, swif_tag, mp->context);
6926 static void vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t *mp)
6928 unix_shared_memory_queue_t * q;
6930 q = vl_api_client_index_to_input_queue (mp->client_index);
6934 vnet_classify_main_t * cm = &vnet_classify_main;
6935 vnet_classify_table_t * t;
6936 u32 * table_ids = 0;
6939 pool_foreach (t, cm->tables,
6941 vec_add1 (table_ids, ntohl(t - cm->tables));
6943 count = vec_len(table_ids);
6945 vl_api_classify_table_ids_reply_t *rmp;
6946 rmp = vl_msg_api_alloc_as_if_client(sizeof (*rmp) + count);
6947 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
6948 rmp->context = mp->context;
6949 rmp->count = ntohl(count);
6950 clib_memcpy(rmp->ids, table_ids, count * sizeof(u32));
6953 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6955 vec_free (table_ids);
6958 static void vl_api_classify_table_by_interface_t_handler (vl_api_classify_table_by_interface_t *mp)
6960 vl_api_classify_table_by_interface_reply_t *rmp;
6963 u32 sw_if_index = ntohl(mp->sw_if_index);
6966 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
6969 VALIDATE_SW_IF_INDEX(mp);
6971 input_acl_main_t * am = &input_acl_main;
6976 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
6978 u32 * vec_tbl = am->classify_table_index_by_sw_if_index[type];
6979 if (vec_len(vec_tbl)) {
6980 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
6982 if (vec_elt(vec_tbl, if_idx) == ~0 || sw_if_index != if_idx) {
6985 acl[type] = vec_elt(vec_tbl, if_idx);
6990 BAD_SW_IF_INDEX_LABEL;
6992 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
6994 rmp->sw_if_index = ntohl(sw_if_index);
6995 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
6996 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
6997 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7002 static void vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t *mp)
7004 unix_shared_memory_queue_t * q;
7006 q = vl_api_client_index_to_input_queue (mp->client_index);
7010 vl_api_classify_table_info_reply_t *rmp = 0;
7012 vnet_classify_main_t * cm = &vnet_classify_main;
7013 u32 table_id = ntohl(mp->table_id);
7014 vnet_classify_table_t * t;
7016 pool_foreach (t, cm->tables,
7018 if (table_id == t - cm->tables) {
7019 rmp = vl_msg_api_alloc_as_if_client(sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7020 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7021 rmp->context = mp->context;
7022 rmp->table_id = ntohl(table_id);
7023 rmp->nbuckets = ntohl(t->nbuckets);
7024 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7025 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7026 rmp->active_sessions = ntohl(t->active_elements);
7027 rmp->next_table_index = ntohl(t->next_table_index);
7028 rmp->miss_next_index = ntohl(t->miss_next_index);
7029 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7030 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7037 rmp = vl_msg_api_alloc (sizeof (*rmp));
7038 rmp->_vl_msg_id = ntohs((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7039 rmp->context = mp->context;
7040 rmp->retval = ntohl(VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7043 vl_msg_api_send_shmem (q, (u8 *)&rmp);
7046 static void vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t * mp)
7048 clib_warning ("BUG");
7051 static void send_classify_session_details (unix_shared_memory_queue_t * q,
7054 vnet_classify_entry_t * e,
7057 vl_api_classify_session_details_t *rmp;
7059 rmp = vl_msg_api_alloc (sizeof (*rmp));
7060 memset (rmp, 0, sizeof (*rmp));
7061 rmp->_vl_msg_id = ntohs(VL_API_CLASSIFY_SESSION_DETAILS);
7062 rmp->context = context;
7063 rmp->table_id = ntohl(table_id);
7064 rmp->hit_next_index = ntohl(e->next_index);
7065 rmp->advance = ntohl(e->advance);
7066 rmp->opaque_index = ntohl(e->opaque_index);
7067 rmp->match_length = ntohl(match_length);
7068 clib_memcpy(rmp->match, e->key, match_length);
7070 vl_msg_api_send_shmem (q, (u8 *)&rmp);
7073 static void vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t *mp)
7075 vnet_classify_main_t * cm = &vnet_classify_main;
7076 unix_shared_memory_queue_t * q;
7078 u32 table_id = ntohl(mp->table_id);
7079 vnet_classify_table_t * t;
7081 q = vl_api_client_index_to_input_queue (mp->client_index);
7083 pool_foreach (t, cm->tables,
7085 if (table_id == t - cm->tables) {
7086 vnet_classify_bucket_t * b;
7087 vnet_classify_entry_t * v, * save_v;
7090 for (i = 0; i < t->nbuckets; i++)
7092 b = &t->buckets [i];
7096 save_v = vnet_classify_get_entry (t, b->offset);
7097 for (j = 0; j < (1<<b->log2_pages); j++)
7099 for (k = 0; k < t->entries_per_page; k++)
7101 v = vnet_classify_entry_at_index (t, save_v, j*t->entries_per_page + k);
7102 if (vnet_classify_entry_is_free (v))
7105 send_classify_session_details(q, table_id,
7106 t->match_n_vectors * sizeof (u32x4), v, mp->context);
7115 static void vl_api_ipfix_enable_t_handler (vl_api_ipfix_enable_t *mp)
7117 vlib_main_t *vm = vlib_get_main();
7118 flow_report_main_t * frm = &flow_report_main;
7119 vl_api_ipfix_enable_reply_t *rmp;
7120 ip4_address_t collector, src;
7121 u16 collector_port = UDP_DST_PORT_ipfix;
7123 u32 template_interval;
7128 memcpy(collector.data, mp->collector_address, sizeof(collector.data));
7129 collector_port = ntohs(mp->collector_port);
7130 if (collector_port == (u16)~0)
7131 collector_port = UDP_DST_PORT_ipfix;
7132 memcpy(src.data, mp->src_address, sizeof(src.data));
7133 fib_id = ntohl(mp->vrf_id);
7135 ip4_main_t * im = &ip4_main;
7136 uword * p = hash_get (im->fib_index_by_table_id, fib_id);
7138 rv = VNET_API_ERROR_NO_SUCH_FIB;
7143 path_mtu = ntohl(mp->path_mtu);
7145 path_mtu = 512; // RFC 7011 section 10.3.3.
7146 template_interval = ntohl(mp->template_interval);
7147 if (template_interval == ~0)
7148 template_interval = 20;
7150 if (collector.as_u32 == 0) {
7151 rv = VNET_API_ERROR_INVALID_VALUE;
7155 if (src.as_u32 == 0) {
7156 rv = VNET_API_ERROR_INVALID_VALUE;
7160 if (path_mtu > 1450 /* vpp does not support fragmentation */) {
7161 rv = VNET_API_ERROR_INVALID_VALUE;
7165 if (path_mtu < 68) {
7166 rv = VNET_API_ERROR_INVALID_VALUE;
7170 /* Reset report streams if we are reconfiguring IP addresses */
7171 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
7172 frm->src_address.as_u32 != src.as_u32 ||
7173 frm->collector_port != collector_port)
7174 vnet_flow_reports_reset(frm);
7176 frm->ipfix_collector.as_u32 = collector.as_u32;
7177 frm->collector_port = collector_port;
7178 frm->src_address.as_u32 = src.as_u32;
7179 frm->fib_index = fib_index;
7180 frm->path_mtu = path_mtu;
7181 frm->template_interval = template_interval;
7183 /* Turn on the flow reporting process */
7184 vlib_process_signal_event (vm, flow_report_process_node.index,
7188 REPLY_MACRO(VL_API_IPFIX_ENABLE_REPLY);
7191 static void vl_api_ipfix_dump_t_handler (vl_api_ipfix_dump_t *mp)
7193 flow_report_main_t * frm = &flow_report_main;
7194 unix_shared_memory_queue_t * q;
7195 vl_api_ipfix_details_t *rmp;
7197 q = vl_api_client_index_to_input_queue (mp->client_index);
7199 rmp = vl_msg_api_alloc (sizeof (*rmp));
7200 memset (rmp, 0, sizeof (*rmp));
7201 rmp->_vl_msg_id = ntohs(VL_API_IPFIX_DETAILS);
7202 rmp->context = mp->context;
7203 memcpy(rmp->collector_address, frm->ipfix_collector.data,
7204 sizeof(frm->ipfix_collector.data));
7205 rmp->collector_port = htons(frm->collector_port);
7206 memcpy(rmp->src_address, frm->src_address.data,
7207 sizeof(frm->src_address.data));
7208 rmp->fib_index = htonl(frm->fib_index);
7209 rmp->path_mtu = htonl(frm->path_mtu);
7210 rmp->template_interval = htonl(frm->template_interval);
7212 vl_msg_api_send_shmem (q, (u8 *)&rmp);
7215 #define BOUNCE_HANDLER(nn) \
7216 static void vl_api_##nn##_t_handler ( \
7217 vl_api_##nn##_t *mp) \
7219 vpe_client_registration_t *reg; \
7220 vpe_api_main_t * vam = &vpe_api_main; \
7221 unix_shared_memory_queue_t * q; \
7223 /* One registration only... */ \
7224 pool_foreach(reg, vam->nn##_registrations, \
7226 q = vl_api_client_index_to_input_queue (reg->client_index); \
7229 * If the queue is stuffed, turf the msg and complain \
7230 * It's unlikely that the intended recipient is \
7231 * alive; avoid deadlock at all costs. \
7233 if (q->cursize == q->maxsize) { \
7234 clib_warning ("ERROR: receiver queue full, drop msg"); \
7235 vl_msg_api_free (mp); \
7238 vl_msg_api_send_shmem (q, (u8 *)&mp); \
7242 vl_msg_api_free (mp); \
7247 * Add vpe's API message handlers to the table.
7248 * vlib has alread mapped shared memory and
7249 * added the client registration handlers.
7250 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
7253 static clib_error_t *
7254 vpe_api_hookup (vlib_main_t *vm)
7256 api_main_t * am = &api_main;
7259 vl_msg_api_set_handlers(VL_API_##N, #n, \
7260 vl_api_##n##_t_handler, \
7262 vl_api_##n##_t_endian, \
7263 vl_api_##n##_t_print, \
7264 sizeof(vl_api_##n##_t), 1);
7265 foreach_vpe_api_msg;
7269 * Manually register the sr tunnel add del msg, so we trace
7270 * enough bytes to capture a typical segment list
7272 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
7273 "sr_tunnel_add_del",
7274 vl_api_sr_tunnel_add_del_t_handler,
7276 vl_api_sr_tunnel_add_del_t_endian,
7277 vl_api_sr_tunnel_add_del_t_print,
7282 * Manually register the sr policy add del msg, so we trace
7283 * enough bytes to capture a typical tunnel name list
7285 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
7286 "sr_policy_add_del",
7287 vl_api_sr_policy_add_del_t_handler,
7289 vl_api_sr_policy_add_del_t_endian,
7290 vl_api_sr_policy_add_del_t_print,
7294 * Trace space for 8 MPLS encap labels, classifier mask+match
7296 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
7297 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
7298 += 5 * sizeof (u32x4);
7299 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
7300 += 5 * sizeof (u32x4);
7301 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
7302 += 16 * sizeof (u32);
7305 * Thread-safe API messages
7307 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
7308 am->is_mp_safe [VL_API_GET_NODE_GRAPH] = 1;
7313 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
7315 static clib_error_t *
7316 vpe_api_init (vlib_main_t *vm)
7318 vpe_api_main_t *am = &vpe_api_main;
7321 am->vnet_main = vnet_get_main();
7322 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
7323 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
7324 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
7325 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
7326 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
7327 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
7330 vl_set_memory_region_name ("/vpe-api");
7331 vl_enable_disable_memory_api (vm, 1 /* enable it */);
7336 VLIB_INIT_FUNCTION(vpe_api_init);
7339 static clib_error_t *
7340 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
7345 struct passwd _pw, *pw;
7346 struct group _grp, *grp;
7349 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7351 if (unformat (input, "prefix %s", &chroot_path))
7353 vec_add1 (chroot_path, 0);
7354 vl_set_memory_root_path ((char *)chroot_path);
7356 else if (unformat (input, "uid %d", &uid))
7357 vl_set_memory_uid (uid);
7358 else if (unformat (input, "gid %d", &gid))
7359 vl_set_memory_gid (gid);
7360 else if (unformat (input, "uid %s", &s))
7362 /* lookup the username */
7364 rv = getpwnam_r(s, &_pw, buf, sizeof(buf), &pw);
7367 e = clib_error_return_code(0, rv,
7368 CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
7369 "cannot fetch username %s", s);
7375 e = clib_error_return_fatal(0, "username %s does not exist", s);
7380 vl_set_memory_uid (pw->pw_uid);
7382 else if (unformat (input, "gid %s", &s))
7384 /* lookup the group name */
7386 rv = getgrnam_r(s, &_grp, buf, sizeof(buf), &grp);
7389 e = clib_error_return_code(0, rv,
7390 CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
7391 "cannot fetch group %s", s);
7397 e = clib_error_return_fatal(0, "group %s does not exist", s);
7402 vl_set_memory_gid (grp->gr_gid);
7405 return clib_error_return (0, "unknown input `%U'",
7406 format_unformat_error, input);
7410 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
7412 void * get_unformat_vnet_sw_interface (void)
7414 return (void *) &unformat_vnet_sw_interface;
7417 #undef vl_api_version
7418 #define vl_api_version(n,v) static u32 vpe_api_version = v;
7419 #include <vpp-api/vpe.api.h>
7420 #undef vl_api_version
7422 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
7424 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
7425 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
7426 clib_host_to_net_u32 (mp->api_versions[0]),
7433 static u8 * format_arp_event (u8 * s, va_list * args)
7435 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
7437 s = format (s, "pid %d: %U", event->pid,
7438 format_ip4_address, &event->address);
7442 static clib_error_t *
7443 show_ip4_arp_events_fn (vlib_main_t * vm,
7444 unformat_input_t * input,
7445 vlib_cli_command_t * cmd)
7447 vpe_api_main_t * am = &vpe_api_main;
7448 vl_api_ip4_arp_event_t * event;
7450 if (pool_elts (am->arp_events) == 0) {
7451 vlib_cli_output (vm, "No active arp event registrations");
7455 pool_foreach (event, am->arp_events,
7457 vlib_cli_output (vm, "%U", format_arp_event, event);
7463 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
7464 .path = "show arp event registrations",
7465 .function = show_ip4_arp_events_fn,
7466 .short_help = "Show arp event registrations",