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>
84 #undef __included_bihash_template_h__
85 #include <vnet/l2/l2_fib.h>
88 #include <vnet/ipsec/ipsec.h>
89 #include <vnet/ipsec/ikev2.h>
92 #include <vnet/devices/virtio/vhost-user.h>
95 #include <stats/stats.h>
98 #include <vnet/ethernet/ethernet.h>
99 #include <vnet/ethernet/arp_packet.h>
100 #include <vnet/interface.h>
102 #include <vnet/l2/l2_fib.h>
103 #include <vnet/l2/l2_bd.h>
104 #include <vpp-api/vpe_msg_enum.h>
106 #define f64_endian(a)
107 #define f64_print(a,b)
109 #define vl_typedefs /* define message structures */
110 #include <vpp-api/vpe_all_api_h.h>
113 #define vl_endianfun /* define message structures */
114 #include <vpp-api/vpe_all_api_h.h>
117 /* instantiate all the print functions we know about */
118 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
120 #include <vpp-api/vpe_all_api_h.h>
123 #define REPLY_MACRO(t) \
125 unix_shared_memory_queue_t * q; \
126 rv = vl_msg_api_pd_handler (mp, rv); \
127 q = vl_api_client_index_to_input_queue (mp->client_index); \
131 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
132 rmp->_vl_msg_id = ntohs((t)); \
133 rmp->context = mp->context; \
134 rmp->retval = ntohl(rv); \
136 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
139 #define REPLY_MACRO2(t, body) \
141 unix_shared_memory_queue_t * q; \
142 rv = vl_msg_api_pd_handler (mp, rv); \
143 q = vl_api_client_index_to_input_queue (mp->client_index); \
147 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
148 rmp->_vl_msg_id = ntohs((t)); \
149 rmp->context = mp->context; \
150 rmp->retval = ntohl(rv); \
151 do {body;} while (0); \
152 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
155 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
157 #define VALIDATE_SW_IF_INDEX(mp) \
158 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
159 vnet_main_t *__vnm = vnet_get_main(); \
160 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
162 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
163 goto bad_sw_if_index; \
167 #define BAD_SW_IF_INDEX_LABEL \
173 #define VALIDATE_RX_SW_IF_INDEX(mp) \
174 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
175 vnet_main_t *__vnm = vnet_get_main(); \
176 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
177 __rx_sw_if_index)) { \
178 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
179 goto bad_rx_sw_if_index; \
183 #define BAD_RX_SW_IF_INDEX_LABEL \
185 bad_rx_sw_if_index: \
189 #define VALIDATE_TX_SW_IF_INDEX(mp) \
190 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
191 vnet_main_t *__vnm = vnet_get_main(); \
192 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
193 __tx_sw_if_index)) { \
194 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
195 goto bad_tx_sw_if_index; \
199 #define BAD_TX_SW_IF_INDEX_LABEL \
201 bad_tx_sw_if_index: \
207 #define VALIDATE_SW_IF_INDEX(mp)
208 #define BAD_SW_IF_INDEX_LABEL
209 #define VALIDATE_RX_SW_IF_INDEX(mp)
210 #define BAD_RX_SW_IF_INDEX_LABEL
211 #define VALIDATE_TX_SW_IF_INDEX(mp)
212 #define BAD_TX_SW_IF_INDEX_LABEL
214 #endif /* CLIB_DEBUG > 0 */
216 #define foreach_vpe_api_msg \
217 _(WANT_INTERFACE_EVENTS, want_interface_events) \
218 _(WANT_OAM_EVENTS, want_oam_events) \
219 _(OAM_ADD_DEL, oam_add_del) \
220 _(SW_INTERFACE_DUMP, sw_interface_dump) \
221 _(SW_INTERFACE_DETAILS, sw_interface_details) \
222 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
223 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
224 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
225 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
226 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
227 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
228 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
229 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
230 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
231 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
232 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
233 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
234 _(L2FIB_ADD_DEL, l2fib_add_del) \
235 _(L2_FLAGS, l2_flags) \
236 _(BRIDGE_FLAGS, bridge_flags) \
237 _(TAP_CONNECT, tap_connect) \
238 _(TAP_MODIFY, tap_modify) \
239 _(TAP_DELETE, tap_delete) \
240 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
241 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
242 _(CREATE_SUBIF, create_subif) \
243 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
244 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
245 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
246 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
247 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
248 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
249 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
250 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
251 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
252 _(RESET_FIB, reset_fib) \
253 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
254 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
255 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
256 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
257 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
258 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
259 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
260 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
261 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
262 sw_interface_ip6_set_link_local_address) \
263 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
264 _(CREATE_LOOPBACK, create_loopback) \
265 _(CONTROL_PING, control_ping) \
266 _(CLI_REQUEST, cli_request) \
267 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
268 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
269 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
270 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
271 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
272 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
273 _(GET_NODE_INDEX, get_node_index) \
274 _(ADD_NODE_NEXT, add_node_next) \
275 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
276 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
277 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
278 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
279 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
280 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
281 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
282 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
283 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
284 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
285 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
286 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
287 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
288 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
289 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
290 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
291 _(IP_ADDRESS_DUMP, ip_address_dump) \
292 _(IP_DUMP, ip_dump) \
293 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
294 _(SHOW_VERSION, show_version) \
295 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
296 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
297 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
298 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
299 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
300 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
301 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
302 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
303 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
304 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
305 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
306 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
307 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
308 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
309 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
310 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
311 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
312 _(DELETE_LOOPBACK, delete_loopback) \
313 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
314 _(MAP_ADD_DOMAIN, map_add_domain) \
315 _(MAP_DEL_DOMAIN, map_del_domain) \
316 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
317 _(MAP_DOMAIN_DUMP, map_domain_dump) \
318 _(MAP_RULE_DUMP, map_rule_dump) \
319 _(MAP_SUMMARY_STATS, map_summary_stats) \
320 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
321 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
322 _(GET_NODE_GRAPH, get_node_graph) \
323 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
324 _(TRACE_PROFILE_ADD, trace_profile_add) \
325 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
326 _(TRACE_PROFILE_DEL, trace_profile_del) \
327 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
328 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
329 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
330 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
331 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
332 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
333 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
334 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
335 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
336 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
337 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
338 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
339 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
340 _(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump) \
341 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
342 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
343 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
344 _(LISP_ENABLE_DISABLE_STATUS_DUMP, \
345 lisp_enable_disable_status_dump) \
346 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
347 lisp_add_del_map_request_itr_rlocs) \
348 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
349 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
350 _(AF_PACKET_CREATE, af_packet_create) \
351 _(AF_PACKET_DELETE, af_packet_delete) \
352 _(POLICER_ADD_DEL, policer_add_del) \
353 _(POLICER_DUMP, policer_dump) \
354 _(NETMAP_CREATE, netmap_create) \
355 _(NETMAP_DELETE, netmap_delete) \
356 _(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump) \
357 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
358 _(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump) \
359 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
360 _(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
361 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
362 _(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump) \
363 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
364 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
365 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
366 _(CLASSIFY_TABLE_INFO,classify_table_info) \
367 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
368 _(CLASSIFY_SESSION_DETAILS,classify_session_details)
371 #define QUOTE(x) QUOTE_(x)
373 #define foreach_registration_hash \
374 _(interface_events) \
375 _(to_netconf_server) \
376 _(from_netconf_server) \
377 _(to_netconf_client) \
378 _(from_netconf_client) \
382 RESOLVE_IP4_ADD_DEL_ROUTE=1,
383 RESOLVE_IP6_ADD_DEL_ROUTE,
384 RESOLVE_MPLS_ETHERNET_ADD_DEL,
390 vl_api_ip_add_del_route_t r;
391 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
397 #define _(a) uword *a##_registration_hash; \
398 vpe_client_registration_t * a##_registrations;
399 foreach_registration_hash
402 /* notifications happen really early in the game */
403 u8 link_state_process_up;
405 /* ip4 pending route adds */
406 pending_route_t * pending_routes;
408 /* ip4 arp event registration pool */
409 vl_api_ip4_arp_event_t * arp_events;
412 vlib_main_t * vlib_main;
413 vnet_main_t * vnet_main;
416 static vlib_node_registration_t vpe_resolver_process_node;
417 static vpe_api_main_t vpe_api_main;
419 static void send_sw_interface_flags (vpe_api_main_t * am,
420 unix_shared_memory_queue_t *q,
421 vnet_sw_interface_t * swif);
422 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
423 unix_shared_memory_queue_t *q,
426 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
429 /* Clean up all registrations belonging to the indicated client */
430 int vl_api_memclnt_delete_callback (u32 client_index)
432 vpe_api_main_t * vam = &vpe_api_main;
433 vpe_client_registration_t *rp;
435 int stats_memclnt_delete_callback (u32 client_index);
437 stats_memclnt_delete_callback (client_index);
440 p = hash_get (vam->a##_registration_hash, client_index); \
442 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
443 pool_put (vam->a##_registrations, rp); \
444 hash_unset (vam->a##_registration_hash, client_index); \
446 foreach_registration_hash;
451 #define API_LINK_STATE_EVENT 1
452 #define API_ADMIN_UP_DOWN_EVENT 2
455 event_data_cmp (void * a1, void * a2)
460 return (word) e1[0] - (word) e2[0];
464 link_state_process (vlib_main_t * vm,
465 vlib_node_runtime_t * rt,
468 vpe_api_main_t * vam = &vpe_api_main;
469 vnet_main_t * vnm = vam->vnet_main;
470 vnet_sw_interface_t * swif;
471 uword * event_data = 0;
472 vpe_client_registration_t *reg;
474 u32 prev_sw_if_index;
475 unix_shared_memory_queue_t * q;
477 vam->link_state_process_up = 1;
480 vlib_process_wait_for_event (vm);
482 /* Unified list of changed link or admin state sw_if_indices */
483 vlib_process_get_events_with_type
484 (vm, &event_data, API_LINK_STATE_EVENT);
485 vlib_process_get_events_with_type
486 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
488 /* Sort, so we can eliminate duplicates */
489 vec_sort_with_function (event_data, event_data_cmp);
491 prev_sw_if_index = ~0;
493 for (i = 0; i < vec_len(event_data); i++) {
494 /* Only one message per swif */
495 if (prev_sw_if_index == event_data[i])
497 prev_sw_if_index = event_data[i];
499 pool_foreach(reg, vam->interface_events_registrations,
501 q = vl_api_client_index_to_input_queue (reg->client_index);
503 // sw_interface may be deleted already
504 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
507 swif = vnet_get_sw_interface (vnm, event_data[i]);
508 send_sw_interface_flags (vam, q, swif);
513 vec_reset_length (event_data);
519 static clib_error_t *
520 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
521 static clib_error_t *
522 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
524 VLIB_REGISTER_NODE (link_state_process_node,static) = {
525 .function = link_state_process,
526 .type = VLIB_NODE_TYPE_PROCESS,
527 .name = "vpe-link-state-process",
530 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
531 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
533 static clib_error_t *
534 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
536 vpe_api_main_t * vam = &vpe_api_main;
537 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
539 if (vam->link_state_process_up)
540 vlib_process_signal_event (vam->vlib_main,
541 link_state_process_node.index,
542 API_LINK_STATE_EVENT,
547 static clib_error_t *
548 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
550 vpe_api_main_t * vam = &vpe_api_main;
553 * Note: it's perfectly fair to set a subif admin up / admin down.
554 * Note the subtle distinction between this routine and the previous
557 if (vam->link_state_process_up)
558 vlib_process_signal_event (vam->vlib_main,
559 link_state_process_node.index,
560 API_ADMIN_UP_DOWN_EVENT,
565 #define pub_sub_handler(lca,UCA) \
566 static void vl_api_want_##lca##_t_handler ( \
567 vl_api_want_##lca##_t *mp) \
569 vpe_api_main_t *vam = &vpe_api_main; \
570 vpe_client_registration_t *rp; \
571 vl_api_want_##lca##_reply_t *rmp; \
575 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
577 if (mp->enable_disable) { \
578 clib_warning ("pid %d: already enabled...", mp->pid); \
579 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
582 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
583 pool_put (vam->lca##_registrations, rp); \
584 hash_unset (vam->lca##_registration_hash, \
589 if (mp->enable_disable == 0) { \
590 clib_warning ("pid %d: already disabled...", mp->pid); \
591 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
594 pool_get (vam->lca##_registrations, rp); \
595 rp->client_index = mp->client_index; \
596 rp->client_pid = mp->pid; \
597 hash_set (vam->lca##_registration_hash, rp->client_index, \
598 rp - vam->lca##_registrations); \
601 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
604 pub_sub_handler (interface_events,INTERFACE_EVENTS)
605 pub_sub_handler (oam_events,OAM_EVENTS)
607 #define RESOLUTION_EVENT 1
608 #define RESOLUTION_PENDING_EVENT 2
609 #define IP4_ARP_EVENT 3
611 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
612 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
613 static int mpls_ethernet_add_del_tunnel_2_t_handler
614 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
616 void handle_ip4_arp_event (u32 pool_index)
618 vpe_api_main_t * vam = &vpe_api_main;
619 vnet_main_t * vnm = vam->vnet_main;
620 vlib_main_t * vm = vam->vlib_main;
621 vl_api_ip4_arp_event_t * event;
622 vl_api_ip4_arp_event_t * mp;
623 unix_shared_memory_queue_t * q;
625 /* Client can cancel, die, etc. */
626 if (pool_is_free_index (vam->arp_events, pool_index))
629 event = pool_elt_at_index (vam->arp_events, pool_index);
631 q = vl_api_client_index_to_input_queue (event->client_index);
633 (void) vnet_add_del_ip4_arp_change_event
634 (vnm, arp_change_delete_callback,
635 event->pid, &event->address,
636 vpe_resolver_process_node.index, IP4_ARP_EVENT,
637 ~0 /* pool index, notused */, 0 /* is_add */);
641 if (q->cursize < q->maxsize) {
642 mp = vl_msg_api_alloc (sizeof (*mp));
643 clib_memcpy (mp, event, sizeof (*mp));
644 vl_msg_api_send_shmem (q, (u8 *)&mp);
646 static f64 last_time;
648 * Throttle syslog msgs.
649 * It's pretty tempting to just revoke the registration...
651 if (vlib_time_now (vm) > last_time + 10.0) {
652 clib_warning ("arp event for %U to pid %d: queue stuffed!",
653 format_ip4_address, &event->address, event->pid);
654 last_time = vlib_time_now(vm);
660 resolver_process (vlib_main_t * vm,
661 vlib_node_runtime_t * rt,
665 uword *event_data = 0;
667 vpe_api_main_t * vam = &vpe_api_main;
668 pending_route_t * pr;
669 vl_api_ip_add_del_route_t * adr;
670 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
671 u32 * resolution_failures = 0;
676 vlib_process_wait_for_event_or_clock (vm, timeout);
678 event_type = vlib_process_get_events (vm, &event_data);
680 switch (event_type) {
681 case RESOLUTION_PENDING_EVENT:
685 case RESOLUTION_EVENT:
686 for (i = 0; i < vec_len(event_data); i++) {
688 * Resolution events can occur long after the
689 * original request has timed out. $$$ add a cancel
692 if (pool_is_free_index (vam->pending_routes, event_data[i]))
695 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
699 switch (pr->resolve_type) {
700 case RESOLVE_IP4_ADD_DEL_ROUTE:
701 rv = ip4_add_del_route_t_handler (adr);
702 clib_warning ("resolver: add %U/%d via %U %s",
704 (ip4_address_t *)&(adr->dst_address),
705 adr->dst_address_length,
707 (ip4_address_t *)&(adr->next_hop_address),
708 (rv >= 0) ? "succeeded" : "failed");
711 case RESOLVE_IP6_ADD_DEL_ROUTE:
712 rv = ip6_add_del_route_t_handler (adr);
713 clib_warning ("resolver: add %U/%d via %U %s",
715 (ip6_address_t *)&(adr->dst_address),
716 adr->dst_address_length,
718 (ip6_address_t *)&(adr->next_hop_address),
719 (rv >= 0) ? "succeeded" : "failed");
722 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
723 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
724 clib_warning ("resolver: add mpls-o-e via %U %s",
726 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
727 (rv >= 0) ? "succeeded" : "failed");
731 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
733 pool_put (vam->pending_routes, pr);
738 for (i = 0; i < vec_len(event_data); i++)
739 handle_ip4_arp_event (event_data[i]);
742 case ~0: /* timeout, retry pending resolutions */
743 pool_foreach (pr, vam->pending_routes,
749 /* May fail, e.g. due to interface down */
750 switch (pr->resolve_type) {
751 case RESOLVE_IP4_ADD_DEL_ROUTE:
752 e = ip4_probe_neighbor
753 (vm, (ip4_address_t *)&(adr->next_hop_address),
754 ntohl(adr->next_hop_sw_if_index));
757 case RESOLVE_IP6_ADD_DEL_ROUTE:
758 e = ip6_probe_neighbor
759 (vm, (ip6_address_t *)&(adr->next_hop_address),
760 ntohl(adr->next_hop_sw_if_index));
763 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
765 e = ip4_probe_neighbor
767 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
768 pme->resolve_opaque);
772 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
776 clib_error_report (e);
778 adr->resolve_attempts = 1;
780 pme->resolve_attempts = 1;
784 adr->resolve_attempts -= 1;
785 if (adr->resolve_attempts == 0)
786 vec_add1 (resolution_failures,
787 pr - vam->pending_routes);
789 pme->resolve_attempts -= 1;
790 if (pme->resolve_attempts == 0)
791 vec_add1 (resolution_failures,
792 pr - vam->pending_routes);
796 for (i = 0; i < vec_len (resolution_failures); i++) {
797 pr = pool_elt_at_index (vam->pending_routes,
798 resolution_failures[i]);
802 switch (pr->resolve_type) {
803 case RESOLVE_IP4_ADD_DEL_ROUTE:
804 clib_warning ("resolver: add %U/%d via %U retry failure",
806 (ip4_address_t *)&(adr->dst_address),
807 adr->dst_address_length,
809 (ip4_address_t *)&(adr->next_hop_address));
812 case RESOLVE_IP6_ADD_DEL_ROUTE:
813 clib_warning ("resolver: add %U/%d via %U retry failure",
815 (ip6_address_t *)&(adr->dst_address),
816 adr->dst_address_length,
818 (ip6_address_t *)&(adr->next_hop_address));
821 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
822 clib_warning ("resolver: add mpls-o-e via %U retry failure",
824 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
828 clib_warning ("BUG");
830 pool_put(vam->pending_routes, pr);
832 vec_reset_length (resolution_failures);
835 if (pool_elts (vam->pending_routes) == 0)
837 vec_reset_length (event_data);
839 return 0; /* or not */
842 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
843 .function = resolver_process,
844 .type = VLIB_NODE_TYPE_PROCESS,
845 .name = "vpe-route-resolver-process",
848 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
850 ip4_main_t * im = &ip4_main;
851 ip_lookup_main_t * lm = &im->lookup_main;
852 vnet_classify_main_t * cm = &vnet_classify_main;
853 stats_main_t * sm = &stats_main;
854 ip4_add_del_route_args_t a;
855 ip4_address_t next_hop_address;
857 vpe_api_main_t * vam = &vpe_api_main;
858 vnet_main_t * vnm = vam->vnet_main;
859 vlib_main_t * vm = vlib_get_main();
860 pending_route_t * pr;
861 vl_api_ip_add_del_route_t * adr;
867 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
869 if (mp->create_vrf_if_needed) {
871 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
873 fib_index = f->index;
875 /* No such VRF, and we weren't asked to create one */
876 return VNET_API_ERROR_NO_SUCH_FIB;
882 if (~0 != mp->next_hop_sw_if_index &&
883 pool_is_free_index (vnm->interface_main.sw_interfaces,
884 ntohl(mp->next_hop_sw_if_index)))
885 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
887 clib_memcpy (next_hop_address.data, mp->next_hop_address,
888 sizeof (next_hop_address.data));
890 /* Arp for the next_hop if necessary */
891 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index) {
893 ip_adjacency_t * adj;
895 lookup_result = ip4_fib_lookup_with_table
896 (im, fib_index, &next_hop_address, 1 /* disable default route */);
898 adj = ip_get_adjacency (lm, lookup_result);
900 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
901 pool_get (vam->pending_routes, pr);
902 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
904 clib_memcpy (adr, mp, sizeof (*adr));
905 /* recursion block, "just in case" */
906 adr->resolve_if_needed = 0;
907 adr->resolve_attempts = ntohl(mp->resolve_attempts);
908 vnet_register_ip4_arp_resolution_event
909 (vnm, &next_hop_address, vpe_resolver_process_node.index,
910 RESOLUTION_EVENT, pr - vam->pending_routes);
912 vlib_process_signal_event
913 (vm, vpe_resolver_process_node.index,
914 RESOLUTION_PENDING_EVENT, 0 /* data */);
916 /* The interface may be down, etc. */
917 e = ip4_probe_neighbor
918 (vm, (ip4_address_t *)&(mp->next_hop_address),
919 ntohl(mp->next_hop_sw_if_index));
922 clib_error_report(e);
924 return VNET_API_ERROR_IN_PROGRESS;
928 if (mp->is_multipath) {
931 dslock (sm, 1 /* release hint */, 10 /* tag */);
934 flags = IP4_ROUTE_FLAG_ADD;
936 flags = IP4_ROUTE_FLAG_DEL;
939 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
941 ip4_add_del_route_next_hop (im, flags,
942 (ip4_address_t *) mp->dst_address,
943 (u32) mp->dst_address_length,
944 (ip4_address_t *) mp->next_hop_address,
945 ntohl(mp->next_hop_sw_if_index),
946 (u32) mp->next_hop_weight,
953 memset (&a, 0, sizeof (a));
954 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
956 a.dst_address_length = mp->dst_address_length;
958 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
959 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
960 a.table_index_or_table_id = fib_index;
965 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
967 dslock (sm, 1 /* release hint */, 2 /* tag */);
971 ai = lm->drop_adj_index;
972 else if (mp->is_local)
973 ai = lm->local_adj_index;
974 else if (mp->is_classify) {
975 if (pool_is_free_index (cm->tables, ntohl(mp->classify_table_index))) {
977 return VNET_API_ERROR_NO_SUCH_TABLE;
979 adj = ip_add_adjacency (lm,
984 adj->lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
985 adj->classify.table_index = ntohl(mp->classify_table_index);
987 else if (mp->lookup_in_vrf) {
988 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
990 adj = ip_add_adjacency (lm,
994 adj->explicit_fib_index = p[0];
998 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1002 ai = ip4_route_get_next_hop_adj (im,
1005 ntohl(mp->next_hop_sw_if_index),
1008 if (ai == lm->miss_adj_index) {
1010 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1013 ip_adjacency_t * adj;
1014 int disable_default_route = 1;
1016 /* Trying to delete the default route? */
1017 if (a.dst_address.as_u32 == 0 &&
1018 a.dst_address_length == 0)
1019 disable_default_route = 0;
1021 ai = ip4_fib_lookup_with_table
1022 (im, fib_index, &a.dst_address, disable_default_route);
1023 if (ai == lm->miss_adj_index) {
1025 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1028 adj = ip_get_adjacency (lm, ai);
1029 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1031 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1036 ip4_add_del_route (im, &a);
1042 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1044 ip6_main_t * im = &ip6_main;
1045 ip_lookup_main_t * lm = &im->lookup_main;
1046 vnet_main_t * vnm = vnet_get_main();
1047 vlib_main_t * vm = vlib_get_main();
1048 vpe_api_main_t * vam = &vpe_api_main;
1049 stats_main_t * sm = &stats_main;
1050 ip6_add_del_route_args_t a;
1051 ip6_address_t next_hop_address;
1052 pending_route_t * pr;
1053 vl_api_ip_add_del_route_t * adr;
1058 ip_adjacency_t *adj = 0;
1061 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1064 if (mp->create_vrf_if_needed) {
1066 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1068 fib_index = f->index;
1070 /* No such VRF, and we weren't asked to create one */
1071 return VNET_API_ERROR_NO_SUCH_FIB;
1077 if (~0 != mp->next_hop_sw_if_index &&
1078 pool_is_free_index (vnm->interface_main.sw_interfaces,
1079 ntohl(mp->next_hop_sw_if_index)))
1080 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1082 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1083 sizeof (next_hop_address.as_u8));
1085 /* Arp for the next_hop if necessary */
1086 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index) {
1088 ip_adjacency_t * adj;
1090 lookup_result = ip6_fib_lookup_with_table
1091 (im, fib_index, &next_hop_address);
1093 adj = ip_get_adjacency (lm, lookup_result);
1095 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1096 pool_get (vam->pending_routes, pr);
1098 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1099 clib_memcpy (adr, mp, sizeof (*adr));
1100 /* recursion block, "just in case" */
1101 adr->resolve_if_needed = 0;
1102 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1103 vnet_register_ip6_neighbor_resolution_event
1104 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1105 RESOLUTION_EVENT, pr - vam->pending_routes);
1107 vlib_process_signal_event
1108 (vm, vpe_resolver_process_node.index,
1109 RESOLUTION_PENDING_EVENT, 0 /* data */);
1111 /* The interface may be down, etc. */
1112 e = ip6_probe_neighbor
1113 (vm, (ip6_address_t *)&(mp->next_hop_address),
1114 ntohl(mp->next_hop_sw_if_index));
1117 clib_error_report(e);
1119 return VNET_API_ERROR_IN_PROGRESS;
1123 if (mp->is_multipath) {
1126 dslock (sm, 1 /* release hint */, 11 /* tag */);
1129 flags = IP6_ROUTE_FLAG_ADD;
1131 flags = IP6_ROUTE_FLAG_DEL;
1134 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1136 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1137 (u32) mp->dst_address_length,
1138 (ip6_address_t *)mp->next_hop_address,
1139 ntohl(mp->next_hop_sw_if_index),
1140 (u32) mp->next_hop_weight,
1147 memset (&a, 0, sizeof (a));
1148 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1150 a.dst_address_length = mp->dst_address_length;
1152 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1153 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1154 a.table_index_or_table_id = fib_index;
1159 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1161 dslock (sm, 1 /* release hint */, 3 /* tag */);
1165 ai = lm->drop_adj_index;
1166 else if (mp->is_local)
1167 ai = lm->local_adj_index;
1168 else if (mp->lookup_in_vrf) {
1169 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1171 adj = ip_add_adjacency (lm,
1175 adj->explicit_fib_index = p[0];
1179 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1183 ai = ip6_route_get_next_hop_adj (im,
1186 ntohl(mp->next_hop_sw_if_index),
1188 if (ai == lm->miss_adj_index) {
1190 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1193 ip_adjacency_t * adj;
1195 ai = ip6_fib_lookup_with_table
1196 (im, fib_index, &a.dst_address);
1197 if (ai == lm->miss_adj_index) {
1199 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1201 adj = ip_get_adjacency (lm, ai);
1202 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1204 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1209 ip6_add_del_route (im, &a);
1215 void vl_api_ip_add_del_route_t_handler (
1216 vl_api_ip_add_del_route_t *mp)
1218 vl_api_ip_add_del_route_reply_t * rmp;
1220 vnet_main_t * vnm = vnet_get_main();
1225 rv = ip6_add_del_route_t_handler (mp);
1227 rv = ip4_add_del_route_t_handler (mp);
1229 rv = (rv == 0) ? vnm->api_errno : rv;
1231 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1234 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1235 u32 sw_if_index, u8 *next_hop_addr)
1237 vl_api_ip_add_del_route_t mp;
1240 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1243 * Configure default IP route:
1244 * - ip route add 0.0.0.0/1 via <GW IP>
1245 * - ip route add 128.0.0.0/1 via <GW IP>
1247 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1249 mp.resolve_attempts = ~0;
1250 mp.resolve_if_needed = 1;
1252 mp.is_ipv6 = is_ipv6;
1253 mp.next_hop_weight = 1;
1255 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1258 rv = ip6_add_del_route_t_handler (&mp);
1261 mp.dst_address_length = 1;
1263 mp.dst_address[0] = 0;
1264 rv = ip4_add_del_route_t_handler (&mp);
1266 mp.dst_address[0] = 128;
1267 rv |= ip4_add_del_route_t_handler (&mp);
1271 clib_error_return (0, "failed to config default IP route");
1276 vl_api_sw_interface_add_del_address_t_handler
1277 (vl_api_sw_interface_add_del_address_t *mp)
1279 vlib_main_t *vm = vlib_get_main();
1280 vl_api_sw_interface_add_del_address_reply_t * rmp;
1284 VALIDATE_SW_IF_INDEX(mp);
1286 is_del = mp->is_add == 0;
1289 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1290 else if (mp->is_ipv6)
1291 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1292 (void *)mp->address,
1293 mp->address_length, is_del);
1295 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1296 (void *) mp->address,
1297 mp->address_length, is_del);
1299 BAD_SW_IF_INDEX_LABEL;
1301 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1305 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1308 u32 table_id = ntohl(mp->vrf_id);
1309 u32 sw_if_index = ntohl(mp->sw_if_index);
1310 vl_api_sw_interface_set_table_reply_t * rmp;
1311 stats_main_t * sm = &stats_main;
1313 VALIDATE_SW_IF_INDEX(mp);
1315 dslock (sm, 1 /* release hint */, 4 /* tag */);
1318 ip6_main_t * im = &ip6_main;
1320 find_ip6_fib_by_table_index_or_id (im, table_id,
1321 IP6_ROUTE_FLAG_TABLE_ID);
1323 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1324 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1326 rv = VNET_API_ERROR_NO_SUCH_FIB;
1329 ip4_main_t * im = &ip4_main;
1330 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1331 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1333 /* Truthfully this can't fail */
1335 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1336 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1338 rv = VNET_API_ERROR_NO_SUCH_FIB;
1343 BAD_SW_IF_INDEX_LABEL;
1345 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1349 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1351 vlib_main_t *vm = vlib_get_main();
1352 ip4_main_t * im4 = &ip4_main;
1353 ip6_main_t * im6 = &ip6_main;
1354 vl_api_sw_interface_set_vpath_reply_t * rmp;
1357 u32 sw_if_index = ntohl(mp->sw_if_index);
1358 ip4_main_t *ip4m = &ip4_main;
1359 ip6_main_t *ip6m = &ip6_main;
1360 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1361 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1362 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1363 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1364 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1365 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1367 VALIDATE_SW_IF_INDEX(mp);
1369 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1371 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1372 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1374 im4->ip4_unicast_rx_feature_vpath,
1376 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1377 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1378 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1380 im4->ip4_multicast_rx_feature_vpath,
1382 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1383 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1384 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1386 im6->ip6_unicast_rx_feature_vpath,
1388 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1389 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1390 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1392 im6->ip6_multicast_rx_feature_vpath,
1394 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1396 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1397 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1399 im4->ip4_unicast_rx_feature_vpath,
1401 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1402 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1403 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1405 im4->ip4_multicast_rx_feature_vpath,
1407 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1408 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1409 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1411 im6->ip6_unicast_rx_feature_vpath,
1413 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1414 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1415 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1417 im6->ip6_multicast_rx_feature_vpath,
1419 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1422 BAD_SW_IF_INDEX_LABEL;
1424 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1428 vl_api_sw_interface_set_l2_xconnect_t_handler (
1429 vl_api_sw_interface_set_l2_xconnect_t *mp)
1431 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1433 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1434 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1435 vlib_main_t *vm = vlib_get_main();
1436 vnet_main_t *vnm = vnet_get_main();
1438 VALIDATE_RX_SW_IF_INDEX(mp);
1441 VALIDATE_TX_SW_IF_INDEX(mp);
1442 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1443 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1445 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1448 BAD_RX_SW_IF_INDEX_LABEL;
1449 BAD_TX_SW_IF_INDEX_LABEL;
1451 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1455 vl_api_sw_interface_set_l2_bridge_t_handler (
1456 vl_api_sw_interface_set_l2_bridge_t *mp)
1458 bd_main_t * bdm = &bd_main;
1459 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1461 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1462 u32 bd_id = ntohl(mp->bd_id);
1466 vlib_main_t *vm = vlib_get_main();
1467 vnet_main_t *vnm = vnet_get_main();
1469 VALIDATE_RX_SW_IF_INDEX(mp);
1471 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1474 //VALIDATE_TX_SW_IF_INDEX(mp);
1475 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1476 rx_sw_if_index, bd_index, bvi, shg, 0);
1478 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1481 BAD_RX_SW_IF_INDEX_LABEL;
1483 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1487 vl_api_bridge_domain_add_del_t_handler (
1488 vl_api_bridge_domain_add_del_t *mp)
1490 vlib_main_t * vm = vlib_get_main ();
1491 bd_main_t * bdm = &bd_main;
1492 vl_api_bridge_domain_add_del_reply_t * rmp;
1494 u32 enable_flags = 0, disable_flags = 0;
1495 u32 bd_id = ntohl(mp->bd_id);
1499 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1502 enable_flags |= L2_FLOOD;
1504 disable_flags |= L2_FLOOD;
1507 enable_flags |= L2_UU_FLOOD;
1509 disable_flags |= L2_UU_FLOOD;
1512 enable_flags |= L2_FWD;
1514 disable_flags |= L2_FWD;
1517 enable_flags |= L2_ARP_TERM;
1519 disable_flags |= L2_ARP_TERM;
1522 enable_flags |= L2_LEARN;
1524 disable_flags |= L2_LEARN;
1527 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1530 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1533 rv = bd_delete_bd_index(bdm, bd_id);
1535 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1538 static void vl_api_bridge_domain_details_t_handler (
1539 vl_api_bridge_domain_details_t * mp)
1541 clib_warning ("BUG");
1544 static void vl_api_bridge_domain_sw_if_details_t_handler (
1545 vl_api_bridge_domain_sw_if_details_t * mp)
1547 clib_warning ("BUG");
1550 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1551 l2_bridge_domain_t * bd_config,
1555 vl_api_bridge_domain_details_t * mp;
1557 mp = vl_msg_api_alloc (sizeof (*mp));
1558 memset (mp, 0, sizeof (*mp));
1559 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1560 mp->bd_id = ntohl (bd_config->bd_id);
1561 mp->flood = bd_feature_flood (bd_config);
1562 mp->uu_flood = bd_feature_uu_flood (bd_config);
1563 mp->forward = bd_feature_forward (bd_config);
1564 mp->learn = bd_feature_learn (bd_config);
1565 mp->arp_term = bd_feature_arp_term (bd_config);
1566 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1567 mp->n_sw_ifs = ntohl (n_sw_ifs);
1568 mp->context = context;
1570 vl_msg_api_send_shmem (q, (u8 *)&mp);
1573 static void send_bd_sw_if_details (l2input_main_t * l2im,
1574 unix_shared_memory_queue_t *q,
1575 l2_flood_member_t * member, u32 bd_id,
1578 vl_api_bridge_domain_sw_if_details_t * mp;
1579 l2_input_config_t * input_cfg;
1581 mp = vl_msg_api_alloc (sizeof (*mp));
1582 memset (mp, 0, sizeof (*mp));
1583 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1584 mp->bd_id = ntohl (bd_id);
1585 mp->sw_if_index = ntohl (member->sw_if_index);
1586 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1587 mp->shg = input_cfg->shg;
1588 mp->context = context;
1590 vl_msg_api_send_shmem (q, (u8 *)&mp);
1593 static void vl_api_bridge_domain_dump_t_handler (
1594 vl_api_bridge_domain_dump_t *mp)
1596 bd_main_t * bdm = &bd_main;
1597 l2input_main_t * l2im = &l2input_main;
1598 unix_shared_memory_queue_t * q;
1599 l2_bridge_domain_t * bd_config;
1600 u32 bd_id, bd_index;
1603 q = vl_api_client_index_to_input_queue (mp->client_index);
1608 bd_id = ntohl(mp->bd_id);
1610 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1611 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1612 for (; bd_index < end; bd_index++) {
1613 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1614 /* skip dummy bd_id 0 */
1615 if (bd_config && (bd_config->bd_id > 0)) {
1617 l2_flood_member_t * m;
1619 n_sw_ifs = vec_len (bd_config->members);
1620 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1622 vec_foreach (m, bd_config->members) {
1623 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1630 vl_api_l2fib_add_del_t_handler (
1631 vl_api_l2fib_add_del_t *mp)
1633 bd_main_t * bdm = &bd_main;
1634 l2input_main_t * l2im = &l2input_main;
1635 vl_api_l2fib_add_del_reply_t * rmp;
1638 u32 sw_if_index = ntohl(mp->sw_if_index);
1639 u32 bd_id = ntohl(mp->bd_id);
1648 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1650 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1651 goto bad_sw_if_index;
1656 VALIDATE_SW_IF_INDEX(mp);
1657 if (vec_len(l2im->configs) <= sw_if_index) {
1658 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1659 goto bad_sw_if_index;
1661 l2_input_config_t * config;
1662 config = vec_elt_at_index(l2im->configs, sw_if_index);
1663 if (config->bridge == 0) {
1664 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1665 goto bad_sw_if_index;
1668 static_mac = mp->static_mac ? 1 : 0;
1669 filter_mac = mp->filter_mac ? 1 : 0;
1670 bvi_mac = mp->bvi_mac ? 1 : 0;
1671 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1674 l2fib_del_entry(mac, bd_index);
1677 BAD_SW_IF_INDEX_LABEL;
1679 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1683 vl_api_l2_flags_t_handler (
1684 vl_api_l2_flags_t *mp)
1686 vl_api_l2_flags_reply_t * rmp;
1688 u32 sw_if_index = ntohl(mp->sw_if_index);
1689 u32 flags = ntohl(mp->feature_bitmap);
1692 VALIDATE_SW_IF_INDEX(mp);
1695 if (flags & L2INPUT_FEAT_ ## a) \
1696 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1697 foreach_l2input_feat;
1700 BAD_SW_IF_INDEX_LABEL;
1702 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1706 vl_api_bridge_flags_t_handler (
1707 vl_api_bridge_flags_t *mp)
1709 vlib_main_t *vm = vlib_get_main();
1710 bd_main_t * bdm = &bd_main;
1711 vl_api_bridge_flags_reply_t * rmp;
1713 u32 bd_id = ntohl(mp->bd_id);
1715 u32 flags = ntohl(mp->feature_bitmap);
1718 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1720 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1726 bd_set_flags(vm, bd_index, flags, mp->is_set);
1729 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1730 rmp->resulting_feature_bitmap = ntohl(flags));
1734 vl_api_bd_ip_mac_add_del_t_handler (
1735 vl_api_bd_ip_mac_add_del_t *mp)
1737 bd_main_t * bdm = &bd_main;
1738 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1740 u32 bd_id = ntohl(mp->bd_id);
1744 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1746 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1751 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1752 mp->mac_address, mp->is_ipv6, mp->is_add))
1753 rv = VNET_API_ERROR_UNSPECIFIED;
1756 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1760 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1763 vl_api_tap_connect_reply_t * rmp;
1764 unix_shared_memory_queue_t * q;
1765 u32 sw_if_index = (u32)~0;
1767 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1768 mp->use_random_mac ? 0 : mp->mac_address,
1769 &sw_if_index, mp->renumber,
1770 ntohl(mp->custom_dev_instance));
1772 q = vl_api_client_index_to_input_queue (mp->client_index);
1776 rmp = vl_msg_api_alloc (sizeof (*rmp));
1777 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1778 rmp->context = mp->context;
1779 rmp->retval = ntohl(rv);
1780 rmp->sw_if_index = ntohl(sw_if_index);
1782 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1786 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1789 vl_api_tap_modify_reply_t * rmp;
1790 unix_shared_memory_queue_t * q;
1791 u32 sw_if_index = (u32)~0;
1793 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1794 mp->use_random_mac ? 0 : mp->mac_address,
1795 &sw_if_index, mp->renumber,
1796 ntohl(mp->custom_dev_instance));
1798 q = vl_api_client_index_to_input_queue (mp->client_index);
1802 rmp = vl_msg_api_alloc (sizeof (*rmp));
1803 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1804 rmp->context = mp->context;
1805 rmp->retval = ntohl(rv);
1806 rmp->sw_if_index = ntohl(sw_if_index);
1808 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1812 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1815 vpe_api_main_t * vam = &vpe_api_main;
1816 vl_api_tap_delete_reply_t * rmp;
1817 unix_shared_memory_queue_t * q;
1818 u32 sw_if_index = ntohl(mp->sw_if_index);
1820 rv = vnet_tap_delete (vm, sw_if_index);
1822 q = vl_api_client_index_to_input_queue (mp->client_index);
1826 rmp = vl_msg_api_alloc (sizeof (*rmp));
1827 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1828 rmp->context = mp->context;
1829 rmp->retval = ntohl(rv);
1831 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1834 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1838 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1840 vl_api_create_vlan_subif_reply_t * rmp;
1841 vnet_main_t * vnm = vnet_get_main();
1842 u32 hw_if_index, sw_if_index = (u32)~0;
1843 vnet_hw_interface_t * hi;
1846 vnet_sw_interface_t template;
1848 vnet_interface_main_t * im = &vnm->interface_main;
1849 u64 sup_and_sub_key;
1851 unix_shared_memory_queue_t * q;
1852 clib_error_t * error;
1854 VALIDATE_SW_IF_INDEX(mp);
1856 hw_if_index = ntohl(mp->sw_if_index);
1857 hi = vnet_get_hw_interface (vnm, hw_if_index);
1859 id = ntohl(mp->vlan_id);
1860 if (id == 0 || id > 4095) {
1861 rv = VNET_API_ERROR_INVALID_VLAN;
1865 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1867 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1869 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1873 kp = clib_mem_alloc (sizeof (*kp));
1874 *kp = sup_and_sub_key;
1876 memset (&template, 0, sizeof (template));
1877 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1878 template.sup_sw_if_index = hi->sw_if_index;
1879 template.sub.id = id;
1880 template.sub.eth.raw_flags = 0;
1881 template.sub.eth.flags.one_tag = 1;
1882 template.sub.eth.outer_vlan_id = id;
1883 template.sub.eth.flags.exact_match = 1;
1885 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1887 clib_error_report(error);
1888 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1891 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1892 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1894 BAD_SW_IF_INDEX_LABEL;
1897 q = vl_api_client_index_to_input_queue (mp->client_index);
1901 rmp = vl_msg_api_alloc (sizeof (*rmp));
1902 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1903 rmp->context = mp->context;
1904 rmp->retval = ntohl(rv);
1905 rmp->sw_if_index = ntohl(sw_if_index);
1906 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1910 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1912 vl_api_create_subif_reply_t * rmp;
1913 vnet_main_t * vnm = vnet_get_main();
1914 u32 sw_if_index = ~0;
1917 vnet_sw_interface_t *si;
1918 vnet_hw_interface_t *hi;
1919 vnet_sw_interface_t template;
1921 vnet_interface_main_t * im = &vnm->interface_main;
1922 u64 sup_and_sub_key;
1924 clib_error_t * error;
1926 VALIDATE_SW_IF_INDEX(mp);
1928 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1929 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1931 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1932 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1936 sw_if_index = si->sw_if_index;
1937 sub_id = ntohl(mp->sub_id);
1939 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1941 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1944 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1945 sw_if_index, sub_id);
1946 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1950 kp = clib_mem_alloc (sizeof (*kp));
1951 *kp = sup_and_sub_key;
1953 memset (&template, 0, sizeof (template));
1954 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1955 template.sup_sw_if_index = sw_if_index;
1956 template.sub.id = sub_id;
1957 template.sub.eth.flags.no_tags = mp->no_tags;
1958 template.sub.eth.flags.one_tag = mp->one_tag;
1959 template.sub.eth.flags.two_tags = mp->two_tags;
1960 template.sub.eth.flags.dot1ad = mp->dot1ad;
1961 template.sub.eth.flags.exact_match = mp->exact_match;
1962 template.sub.eth.flags.default_sub = mp->default_sub;
1963 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1964 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1965 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1966 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1968 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1970 clib_error_report (error);
1971 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1975 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1976 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1978 BAD_SW_IF_INDEX_LABEL;
1982 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1984 rmp->sw_if_index = ntohl(sw_if_index);
1989 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1991 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1993 stats_main_t * sm = &stats_main;
1994 u32 tunnel_sw_if_index = ~0;
1996 dslock (sm, 1 /* release hint */, 5 /* tag */);
1998 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1999 (ip4_address_t *)(mp->dst_address),
2000 (ip4_address_t *)(mp->intfc_address),
2001 (u32)(mp->intfc_address_length),
2002 ntohl(mp->inner_vrf_id),
2003 ntohl(mp->outer_vrf_id),
2004 &tunnel_sw_if_index,
2009 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
2011 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2016 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2017 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
2019 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2021 stats_main_t * sm = &stats_main;
2022 u32 tunnel_sw_if_index;
2024 dslock (sm, 1 /* release hint */, 5 /* tag */);
2026 rv = vnet_mpls_ethernet_add_del_tunnel
2027 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
2028 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
2029 ntohl(mp->tx_sw_if_index),
2030 &tunnel_sw_if_index,
2036 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2038 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2043 * This piece of misery brought to you because the control-plane
2044 * can't figure out the tx interface + dst-mac address all by itself
2046 static int mpls_ethernet_add_del_tunnel_2_t_handler
2047 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2049 pending_route_t * pr;
2050 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2051 vnet_main_t * vnm = vnet_get_main();
2052 vlib_main_t * vm = vlib_get_main();
2053 stats_main_t * sm = &stats_main;
2054 vpe_api_main_t * vam = &vpe_api_main;
2055 u32 inner_fib_index, outer_fib_index;
2056 ip4_main_t * im = &ip4_main;
2057 ip_lookup_main_t * lm = &im->lookup_main;
2058 ip_adjacency_t * adj = 0;
2061 u8 * dst_mac_address;
2065 u32 tunnel_sw_if_index;
2067 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2069 return VNET_API_ERROR_NO_SUCH_FIB;
2071 outer_fib_index = p[0];
2074 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2076 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2078 inner_fib_index = p[0];
2080 if (inner_fib_index == outer_fib_index)
2081 return VNET_API_ERROR_INVALID_VALUE;
2083 lookup_result = ip4_fib_lookup_with_table
2084 (im, outer_fib_index,
2085 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2086 1 /* disable default route */);
2088 adj = ip_get_adjacency (lm, lookup_result);
2089 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2091 if (mp->is_add && mp->resolve_if_needed) {
2092 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2093 pool_get (vam->pending_routes, pr);
2094 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2096 clib_memcpy (pme, mp, sizeof (*pme));
2097 /* recursion block, "just in case" */
2098 pme->resolve_if_needed = 0;
2099 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2100 pme->resolve_opaque = tx_sw_if_index;
2101 vnet_register_ip4_arp_resolution_event
2103 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2104 vpe_resolver_process_node.index,
2105 RESOLUTION_EVENT, pr - vam->pending_routes);
2107 vlib_process_signal_event
2108 (vm, vpe_resolver_process_node.index,
2109 RESOLUTION_PENDING_EVENT, 0 /* data */);
2111 /* The interface may be down, etc. */
2112 e = ip4_probe_neighbor
2113 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2117 clib_error_report(e);
2119 return VNET_API_ERROR_IN_PROGRESS;
2123 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2124 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2127 vnet_rewrite_get_data_internal
2128 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2130 dslock (sm, 1 /* release hint */, 10 /* tag */);
2132 rv = vnet_mpls_ethernet_add_del_tunnel
2133 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2134 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2135 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2143 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2144 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2146 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2149 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2151 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2156 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2158 vl_api_mpls_add_del_encap_reply_t * rmp;
2160 static u32 * labels;
2163 vec_reset_length (labels);
2165 for (i = 0; i < mp->nlabels; i++)
2166 vec_add1 (labels, ntohl(mp->labels[i]));
2169 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2170 ntohl(mp->vrf_id), labels,
2171 ~0 /* policy_tunnel_index */,
2172 0 /* no_dst_hash */,
2176 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2180 vl_api_mpls_add_del_decap_t_handler
2181 (vl_api_mpls_add_del_decap_t *mp)
2183 vl_api_mpls_add_del_decap_reply_t * rmp;
2186 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2187 ntohl(mp->label), ntohl(mp->next_index),
2188 mp->s_bit, mp->is_add);
2190 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2194 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2196 vl_api_proxy_arp_add_del_reply_t * rmp;
2199 ip4_main_t * im = &ip4_main;
2200 stats_main_t * sm = &stats_main;
2201 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2202 ip4_address_t *hi_addr,
2203 u32 fib_index, int is_del);
2206 dslock (sm, 1 /* release hint */, 6 /* tag */);
2208 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2211 rv = VNET_API_ERROR_NO_SUCH_FIB;
2217 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2218 (ip4_address_t *)mp->hi_address,
2219 fib_index, mp->is_add == 0);
2223 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2227 vl_api_proxy_arp_intfc_enable_disable_t_handler
2228 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2231 vnet_main_t * vnm = vnet_get_main();
2232 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2233 vnet_sw_interface_t * si;
2236 VALIDATE_SW_IF_INDEX(mp);
2238 sw_if_index = ntohl(mp->sw_if_index);
2240 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2242 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2246 si = vnet_get_sw_interface (vnm, sw_if_index);
2250 if (mp->enable_disable)
2251 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2253 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2255 BAD_SW_IF_INDEX_LABEL;
2258 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2262 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2264 vl_api_ip_neighbor_add_del_reply_t * rmp;
2265 vnet_main_t * vnm = vnet_get_main();
2268 stats_main_t * sm = &stats_main;
2270 VALIDATE_SW_IF_INDEX(mp);
2272 dslock (sm, 1 /* release hint */, 7 /* tag */);
2276 rv = vnet_set_ip6_ethernet_neighbor
2277 (vm, ntohl(mp->sw_if_index),
2278 (ip6_address_t *)(mp->dst_address),
2279 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2281 rv = vnet_unset_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));
2286 ip4_main_t * im = &ip4_main;
2287 ip_lookup_main_t * lm = &im->lookup_main;
2288 ethernet_arp_ip4_over_ethernet_address_t a;
2290 ip_adjacency_t *nh_adj;
2292 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2294 rv = VNET_API_ERROR_NO_SUCH_FIB;
2300 * Unfortunately, folks have a penchant for
2301 * adding interface addresses to the ARP cache, and
2302 * wondering why the forwarder eventually ASSERTs...
2304 ai = ip4_fib_lookup_with_table
2305 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2306 1 /* disable default route */);
2309 nh_adj = ip_get_adjacency (lm, ai);
2310 /* Never allow manipulation of a local adj! */
2311 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2312 clib_warning("%U matches local adj",
2314 (ip4_address_t *)(mp->dst_address));
2315 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2320 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2321 clib_memcpy (&a.ip4, mp->dst_address, 4);
2324 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2325 fib_index, &a, mp->is_static);
2327 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2331 BAD_SW_IF_INDEX_LABEL;
2334 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2338 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2341 vpe_main_t *rm = &vpe_main;
2342 ip4_main_t *im4 = &ip4_main;
2343 ip6_main_t *im6 = &ip6_main;
2344 ip_lookup_main_t * lm;
2349 u32 adj_index, sw_if_index;
2350 vl_api_is_address_reachable_t *rmp;
2351 ip_adjacency_t * adj;
2352 unix_shared_memory_queue_t *q;
2354 q = vl_api_client_index_to_input_queue (mp->client_index);
2356 increment_missing_api_client_counter (rm->vlib_main);
2360 rmp = vl_msg_api_alloc (sizeof (*rmp));
2361 clib_memcpy (rmp, mp, sizeof (*rmp));
2363 sw_if_index = mp->next_hop_sw_if_index;
2364 clib_memcpy (&addr, mp->address, sizeof (addr));
2366 lm = &im6->lookup_main;
2368 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2370 lm = &im4->lookup_main;
2372 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2374 if (adj_index == ~0) {
2378 adj = ip_get_adjacency (lm, adj_index);
2380 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2381 && adj->rewrite_header.sw_if_index == sw_if_index) {
2384 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2385 && adj->rewrite_header.sw_if_index == sw_if_index) {
2387 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2389 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2390 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2398 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2402 static void vl_api_sw_interface_details_t_handler (
2403 vl_api_sw_interface_details_t * mp)
2405 clib_warning ("BUG");
2408 static void vl_api_sw_interface_set_flags_t_handler (
2409 vl_api_sw_interface_set_flags_t * mp)
2411 vl_api_sw_interface_set_flags_reply_t *rmp;
2412 vnet_main_t * vnm = vnet_get_main();
2414 clib_error_t * error;
2417 VALIDATE_SW_IF_INDEX(mp);
2419 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2421 error = vnet_sw_interface_set_flags (vnm,
2422 ntohl(mp->sw_if_index),
2426 clib_error_report (error);
2429 BAD_SW_IF_INDEX_LABEL;
2430 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2433 static void vl_api_sw_interface_clear_stats_t_handler (
2434 vl_api_sw_interface_clear_stats_t * mp)
2436 vl_api_sw_interface_clear_stats_reply_t *rmp;
2438 vnet_main_t * vnm = vnet_get_main();
2439 vnet_interface_main_t * im = &vnm->interface_main;
2440 vlib_simple_counter_main_t * sm;
2441 vlib_combined_counter_main_t * cm;
2442 static vnet_main_t ** my_vnet_mains;
2443 int i, j, n_counters;
2447 vec_reset_length (my_vnet_mains);
2449 for (i = 0; i < vec_len (vnet_mains); i++)
2452 vec_add1 (my_vnet_mains, vnet_mains[i]);
2455 if (vec_len (vnet_mains) == 0)
2456 vec_add1 (my_vnet_mains, vnm);
2458 n_counters = vec_len (im->combined_sw_if_counters);
2460 for (j = 0; j < n_counters; j++)
2462 for (i = 0; i < vec_len(my_vnet_mains); i++)
2464 im = &my_vnet_mains[i]->interface_main;
2465 cm = im->combined_sw_if_counters + j;
2466 if (mp->sw_if_index == (u32)~0)
2467 vlib_clear_combined_counters (cm);
2469 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2473 n_counters = vec_len (im->sw_if_counters);
2475 for (j = 0; j < n_counters; j++)
2477 for (i = 0; i < vec_len(my_vnet_mains); i++)
2479 im = &my_vnet_mains[i]->interface_main;
2480 sm = im->sw_if_counters + j;
2481 if (mp->sw_if_index == (u32)~0)
2482 vlib_clear_simple_counters (sm);
2484 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2488 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2491 static void send_sw_interface_details (vpe_api_main_t * am,
2492 unix_shared_memory_queue_t *q,
2493 vnet_sw_interface_t * swif,
2494 u8 * interface_name,
2497 vl_api_sw_interface_details_t * mp;
2498 vnet_hw_interface_t * hi;
2500 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2502 mp = vl_msg_api_alloc (sizeof (*mp));
2503 memset (mp, 0, sizeof (*mp));
2504 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2505 mp->sw_if_index = ntohl(swif->sw_if_index);
2506 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2507 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2509 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2511 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2512 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2513 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2514 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2515 mp->link_mtu = ntohs(hi->max_packet_bytes);
2516 mp->context = context;
2518 strncpy ((char *) mp->interface_name,
2519 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2521 /* Send the L2 address for ethernet physical intfcs */
2522 if (swif->sup_sw_if_index == swif->sw_if_index
2523 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2524 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2525 ethernet_interface_t *ei;
2527 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2528 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2529 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2530 mp->l2_address_length = ntohl(sizeof (ei->address));
2531 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2532 vnet_sub_interface_t *sub = &swif->sub;
2533 mp->sub_id = ntohl(sub->id);
2534 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2535 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2536 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2537 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2538 mp->sub_exact_match = sub->eth.flags.exact_match;
2539 mp->sub_default = sub->eth.flags.default_sub;
2540 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2541 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2543 /* vlan tag rewrite data */
2544 u32 vtr_op = L2_VTR_DISABLED;
2545 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2547 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2548 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2549 // error - default to disabled
2550 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2551 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2554 mp->vtr_op = ntohl(vtr_op);
2555 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2556 mp->vtr_tag1 = ntohl(vtr_tag1);
2557 mp->vtr_tag2 = ntohl(vtr_tag2);
2561 vl_msg_api_send_shmem (q, (u8 *)&mp);
2564 static void send_sw_interface_flags (vpe_api_main_t * am,
2565 unix_shared_memory_queue_t *q,
2566 vnet_sw_interface_t * swif)
2568 vl_api_sw_interface_set_flags_t *mp;
2569 vnet_main_t * vnm = am->vnet_main;
2571 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2573 mp = vl_msg_api_alloc (sizeof (*mp));
2574 memset (mp, 0, sizeof (*mp));
2575 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2576 mp->sw_if_index = ntohl(swif->sw_if_index);
2578 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2580 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2582 vl_msg_api_send_shmem (q, (u8 *)&mp);
2585 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2586 unix_shared_memory_queue_t *q,
2588 __attribute__((unused));
2590 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2591 unix_shared_memory_queue_t *q,
2594 vl_api_sw_interface_set_flags_t *mp;
2596 mp = vl_msg_api_alloc (sizeof (*mp));
2597 memset (mp, 0, sizeof (*mp));
2598 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2599 mp->sw_if_index = ntohl(sw_if_index);
2601 mp->admin_up_down = 0;
2602 mp->link_up_down = 0;
2604 vl_msg_api_send_shmem (q, (u8 *)&mp);
2607 static void vl_api_sw_interface_dump_t_handler (
2608 vl_api_sw_interface_dump_t *mp)
2610 vpe_api_main_t * am = &vpe_api_main;
2611 vnet_sw_interface_t * swif;
2612 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2613 u8 * filter_string = 0, * name_string = 0;
2614 unix_shared_memory_queue_t * q;
2615 char * strcasestr (char *, char *); /* lnx hdr file botch */
2617 q = vl_api_client_index_to_input_queue (mp->client_index);
2622 if (mp->name_filter_valid) {
2623 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2624 filter_string = format (0, "%s%c", mp->name_filter, 0);
2627 pool_foreach (swif, im->sw_interfaces,
2629 name_string = format (name_string, "%U%c",
2630 format_vnet_sw_interface_name,
2631 am->vnet_main, swif, 0);
2633 if (mp->name_filter_valid == 0 ||
2634 strcasestr((char *) name_string, (char *) filter_string)) {
2636 send_sw_interface_details (am, q, swif, name_string, mp->context);
2638 _vec_len (name_string) = 0;
2641 vec_free (name_string);
2642 vec_free (filter_string);
2645 void send_oam_event (oam_target_t * t)
2647 vpe_api_main_t * vam = &vpe_api_main;
2648 unix_shared_memory_queue_t * q;
2649 vpe_client_registration_t *reg;
2650 vl_api_oam_event_t * mp;
2652 pool_foreach(reg, vam->oam_events_registrations,
2654 q = vl_api_client_index_to_input_queue (reg->client_index);
2656 mp = vl_msg_api_alloc (sizeof (*mp));
2657 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2658 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2659 mp->state = t->state;
2660 vl_msg_api_send_shmem (q, (u8 *)&mp);
2666 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2668 vl_api_oam_add_del_reply_t * rmp;
2671 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2672 (ip4_address_t *)mp->dst_address,
2676 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2680 vl_api_vnet_get_summary_stats_t_handler (
2681 vl_api_vnet_get_summary_stats_t *mp)
2683 stats_main_t * sm = &stats_main;
2684 vnet_interface_main_t * im = sm->interface_main;
2685 vl_api_vnet_summary_stats_reply_t *rmp;
2686 vlib_combined_counter_main_t * cm;
2689 u64 total_pkts[VLIB_N_RX_TX];
2690 u64 total_bytes[VLIB_N_RX_TX];
2692 unix_shared_memory_queue_t * q =
2693 vl_api_client_index_to_input_queue (mp->client_index);
2698 rmp = vl_msg_api_alloc (sizeof (*rmp));
2699 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2700 rmp->context = mp->context;
2703 memset (total_pkts, 0, sizeof (total_pkts));
2704 memset (total_bytes, 0, sizeof (total_bytes));
2706 vnet_interface_counter_lock (im);
2708 vec_foreach (cm, im->combined_sw_if_counters) {
2709 which = cm - im->combined_sw_if_counters;
2711 for (i = 0; i < vec_len (cm->maxi); i++) {
2712 vlib_get_combined_counter (cm, i, &v);
2713 total_pkts[which] += v.packets;
2714 total_bytes[which] += v.bytes;
2717 vnet_interface_counter_unlock (im);
2719 /* Note: in HOST byte order! */
2720 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2721 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2722 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2723 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2724 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2726 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2729 typedef CLIB_PACKED (struct {
2730 ip4_address_t address;
2732 u32 address_length : 6;
2737 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2739 vnet_main_t * vnm = vnet_get_main();
2740 vnet_interface_main_t * im = &vnm->interface_main;
2741 ip4_main_t * im4 = &ip4_main;
2742 static ip4_route_t * routes;
2743 static u32 * sw_if_indices_to_shut;
2744 stats_main_t * sm = &stats_main;
2749 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2750 u32 target_fib_id = ntohl(mp->vrf_id);
2752 dslock (sm, 1 /* release hint */, 8 /* tag */);
2754 vec_foreach (fib, im4->fibs) {
2755 vnet_sw_interface_t * si;
2757 if (fib->table_id != target_fib_id)
2760 /* remove any mpls/gre tunnels in this fib */
2761 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2763 /* remove any mpls encap/decap labels */
2764 mpls_fib_reset_labels (fib->table_id);
2766 /* remove any proxy arps in this fib */
2767 vnet_proxy_arp_fib_reset (fib->table_id);
2769 /* Set the flow hash for this fib to the default */
2770 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2772 vec_reset_length (sw_if_indices_to_shut);
2774 /* Shut down interfaces in this FIB / clean out intfc routes */
2775 pool_foreach (si, im->sw_interfaces,
2777 u32 sw_if_index = si->sw_if_index;
2779 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2780 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2782 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2785 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2786 sw_if_index = sw_if_indices_to_shut[i];
2787 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2789 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2790 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2791 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2794 vec_reset_length (routes);
2796 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2797 uword * hash = fib->adj_index_by_dst_address[i];
2801 x.address_length = i;
2803 hash_foreach_pair (p, hash,
2805 x.address.data_u32 = p->key;
2806 vec_add1 (routes, x);
2810 vec_foreach (r, routes) {
2811 ip4_add_del_route_args_t a;
2813 memset (&a, 0, sizeof (a));
2814 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2815 a.table_index_or_table_id = fib - im4->fibs;
2816 a.dst_address = r->address;
2817 a.dst_address_length = r->address_length;
2820 ip4_add_del_route (im4, &a);
2821 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2822 IP4_ROUTE_FLAG_FIB_INDEX);
2826 } /* vec_foreach (fib) */
2833 ip6_address_t address;
2840 ip6_route_t ** routep;
2841 } add_routes_in_fib_arg_t;
2843 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2845 add_routes_in_fib_arg_t * ap = arg;
2847 if (kvp->key[2]>>32 == ap->fib_index)
2849 ip6_address_t *addr;
2851 addr = (ip6_address_t *) kvp;
2852 vec_add2 (*ap->routep, r, 1);
2853 r->address = addr[0];
2854 r->address_length = kvp->key[2] & 0xFF;
2855 r->index = kvp->value;
2859 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2861 vnet_main_t * vnm = vnet_get_main();
2862 vnet_interface_main_t * im = &vnm->interface_main;
2863 ip6_main_t * im6 = &ip6_main;
2864 stats_main_t * sm = &stats_main;
2865 static ip6_route_t * routes;
2866 static u32 * sw_if_indices_to_shut;
2871 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2872 u32 target_fib_id = ntohl(mp->vrf_id);
2873 add_routes_in_fib_arg_t _a, *a=&_a;
2874 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2876 dslock (sm, 1 /* release hint */, 9 /* tag */);
2878 vec_foreach (fib, im6->fibs) {
2879 vnet_sw_interface_t * si;
2881 if (fib->table_id != target_fib_id)
2884 vec_reset_length (sw_if_indices_to_shut);
2886 /* Shut down interfaces in this FIB / clean out intfc routes */
2887 pool_foreach (si, im->sw_interfaces,
2889 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2891 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2894 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2895 sw_if_index = sw_if_indices_to_shut[i];
2896 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2898 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2899 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2900 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2903 vec_reset_length (routes);
2905 a->fib_index = fib - im6->fibs;
2906 a->routep = &routes;
2908 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2910 vec_foreach (r, routes) {
2911 ip6_add_del_route_args_t a;
2913 memset (&a, 0, sizeof (a));
2914 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2915 a.table_index_or_table_id = fib - im6->fibs;
2916 a.dst_address = r->address;
2917 a.dst_address_length = r->address_length;
2920 ip6_add_del_route (im6, &a);
2921 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2922 IP6_ROUTE_FLAG_FIB_INDEX);
2925 /* Reinstall the neighbor / router discovery routes */
2926 vnet_ip6_fib_init (im6, fib - im6->fibs);
2928 } /* vec_foreach (fib) */
2934 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2937 vl_api_reset_fib_reply_t * rmp;
2940 rv = ip6_reset_fib_t_handler (mp);
2942 rv = ip4_reset_fib_t_handler (mp);
2944 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2949 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2951 vl_api_dhcp_proxy_config_reply_t * rmp;
2954 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2955 (ip4_address_t *)(&mp->dhcp_src_address),
2956 (u32) ntohl(mp->vrf_id),
2957 (int) mp->insert_circuit_id,
2958 (int) (mp->is_add == 0));
2960 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2965 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2967 vl_api_dhcp_proxy_config_reply_t * rmp;
2970 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2971 (ip6_address_t *)(&mp->dhcp_src_address),
2972 (u32) ntohl(mp->vrf_id),
2973 (int) mp->insert_circuit_id,
2974 (int) (mp->is_add == 0));
2976 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2980 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2982 vl_api_dhcp_proxy_config_reply_t * rmp;
2985 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2986 (ip4_address_t *)(&mp->dhcp_src_address),
2987 (u32) ntohl(mp->rx_vrf_id),
2988 (u32) ntohl(mp->server_vrf_id),
2989 (int) mp->insert_circuit_id,
2990 (int) (mp->is_add == 0));
2992 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2997 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2999 vl_api_dhcp_proxy_config_reply_t * rmp;
3003 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
3004 (ip6_address_t *)(&mp->dhcp_src_address),
3005 (u32) ntohl(mp->rx_vrf_id),
3006 (u32) ntohl(mp->server_vrf_id),
3007 (int) mp->insert_circuit_id,
3008 (int) (mp->is_add == 0));
3010 rv = VNET_API_ERROR_UNIMPLEMENTED;
3013 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3018 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
3020 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3023 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
3026 (int)mp->is_add == 0);
3028 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
3031 (int)mp->is_add == 0);
3033 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
3037 static void vl_api_dhcp_proxy_config_t_handler
3038 (vl_api_dhcp_proxy_config_t *mp)
3040 if (mp->is_ipv6 == 0)
3041 dhcpv4_proxy_config (mp);
3043 dhcpv6_proxy_config (mp);
3046 static void vl_api_dhcp_proxy_config_2_t_handler
3047 (vl_api_dhcp_proxy_config_2_t *mp)
3049 if (mp->is_ipv6 == 0)
3050 dhcpv4_proxy_config_2 (mp);
3052 dhcpv6_proxy_config_2 (mp);
3055 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3056 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3058 unix_shared_memory_queue_t * q;
3059 vl_api_dhcp_compl_event_t * mp;
3061 q = vl_api_client_index_to_input_queue (client_index);
3065 mp = vl_msg_api_alloc (sizeof (*mp));
3066 mp->client_index = client_index;
3068 mp->is_ipv6 = is_ipv6;
3069 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3070 mp->hostname[vec_len(hostname) + 1] = '\n';
3071 clib_memcpy (&mp->host_address[0], host_address, 16);
3072 clib_memcpy (&mp->router_address[0], router_address, 16);
3073 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3075 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3077 vl_msg_api_send_shmem (q, (u8 *)&mp);
3080 static void vl_api_dhcp_client_config_t_handler
3081 (vl_api_dhcp_client_config_t *mp)
3083 vlib_main_t *vm = vlib_get_main();
3084 vl_api_dhcp_client_config_reply_t * rmp;
3087 VALIDATE_SW_IF_INDEX(mp);
3089 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3090 mp->hostname, mp->is_add, mp->client_index,
3091 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3094 BAD_SW_IF_INDEX_LABEL;
3096 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3100 vl_api_sw_interface_ip6nd_ra_config_t_handler
3101 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3103 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3105 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease, default_router;
3107 is_no = mp->is_no == 1;
3108 suppress = mp->suppress == 1;
3109 managed = mp->managed == 1;
3110 other = mp->other == 1;
3111 ll_option = mp->ll_option == 1;
3112 send_unicast = mp->send_unicast == 1;
3113 cease = mp->cease == 1;
3114 default_router = mp->default_router == 1;
3116 VALIDATE_SW_IF_INDEX(mp);
3118 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3119 suppress, managed, other,
3120 ll_option, send_unicast, cease,
3121 default_router, ntohl (mp->lifetime),
3122 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3123 ntohl(mp->max_interval), ntohl( mp->min_interval),
3126 BAD_SW_IF_INDEX_LABEL;
3128 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3132 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3133 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3135 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3137 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3139 VALIDATE_SW_IF_INDEX(mp);
3141 is_no = mp->is_no == 1;
3142 use_default = mp->use_default == 1;
3143 no_advertise = mp->no_advertise == 1;
3144 off_link = mp->off_link == 1;
3145 no_autoconfig = mp->no_autoconfig == 1;
3146 no_onlink = mp->no_onlink == 1;
3148 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3149 (ip6_address_t *)mp->address, mp->address_length,
3150 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3151 no_advertise, off_link, no_autoconfig, no_onlink,
3154 BAD_SW_IF_INDEX_LABEL;
3155 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3159 vl_api_sw_interface_ip6_enable_disable_t_handler
3160 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3162 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3163 vnet_main_t * vnm = vnet_get_main();
3165 clib_error_t * error;
3169 VALIDATE_SW_IF_INDEX(mp);
3171 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3172 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3175 clib_error_report(error);
3176 rv = VNET_API_ERROR_UNSPECIFIED;
3178 rv = vnm->api_errno;
3181 BAD_SW_IF_INDEX_LABEL;
3183 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3187 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3188 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3190 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3192 clib_error_t * error;
3193 vnet_main_t * vnm = vnet_get_main();
3197 VALIDATE_SW_IF_INDEX(mp);
3199 error = set_ip6_link_local_address(vm,
3200 ntohl(mp->sw_if_index),
3201 (ip6_address_t *)mp->address,
3202 mp->address_length);
3204 clib_error_report(error);
3205 rv = VNET_API_ERROR_UNSPECIFIED;
3207 rv = vnm->api_errno;
3210 BAD_SW_IF_INDEX_LABEL;
3212 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3215 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3217 vl_api_set_ip_flow_hash_reply_t *rmp;
3218 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3220 clib_warning ("unimplemented...");
3222 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3225 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3227 vl_api_set_ip_flow_hash_reply_t *rmp;
3230 u32 flow_hash_config = 0;
3232 table_id = ntohl(mp->vrf_id);
3234 #define _(a,b) if (mp->a) flow_hash_config |= b;
3235 foreach_flow_hash_bit;
3238 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3240 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3244 static void vl_api_set_ip_flow_hash_t_handler
3245 (vl_api_set_ip_flow_hash_t *mp)
3247 if (mp->is_ipv6 == 0)
3248 set_ip4_flow_hash (mp);
3250 set_ip6_flow_hash (mp);
3253 static void vl_api_sw_interface_set_unnumbered_t_handler
3254 (vl_api_sw_interface_set_unnumbered_t *mp)
3256 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3258 vnet_sw_interface_t * si;
3259 vnet_main_t *vnm = vnet_get_main();
3260 u32 sw_if_index, unnumbered_sw_if_index;
3262 sw_if_index = ntohl(mp->sw_if_index);
3263 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3266 * The API message field names are backwards from
3267 * the underlying data structure names.
3268 * It's not worth changing them now.
3270 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3271 unnumbered_sw_if_index)) {
3272 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3276 /* Only check the "use loop0" field when setting the binding */
3278 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3279 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3283 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3286 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3287 si->unnumbered_sw_if_index = sw_if_index;
3289 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3290 si->unnumbered_sw_if_index = (u32)~0;
3294 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3297 static void vl_api_create_loopback_t_handler
3298 (vl_api_create_loopback_t *mp)
3300 vl_api_create_loopback_reply_t * rmp;
3304 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3306 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3308 rmp->sw_if_index = ntohl (sw_if_index);
3312 static void vl_api_delete_loopback_t_handler
3313 (vl_api_delete_loopback_t *mp)
3315 vl_api_delete_loopback_reply_t * rmp;
3319 sw_if_index = ntohl (mp->sw_if_index);
3320 rv = vnet_delete_loopback_interface (sw_if_index);
3322 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3325 static void vl_api_control_ping_t_handler
3326 (vl_api_control_ping_t *mp)
3328 vl_api_control_ping_reply_t * rmp;
3331 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3333 rmp->vpe_pid = ntohl (getpid());
3337 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3339 u8 **shmem_vecp = (u8 **)arg;
3342 api_main_t * am = &api_main;
3345 shmem_vec = *shmem_vecp;
3347 offset = vec_len (shmem_vec);
3349 pthread_mutex_lock (&am->vlib_rp->mutex);
3350 oldheap = svm_push_data_heap (am->vlib_rp);
3352 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3354 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3356 svm_pop_heap (oldheap);
3357 pthread_mutex_unlock (&am->vlib_rp->mutex);
3359 *shmem_vecp = shmem_vec;
3363 static void vl_api_cli_request_t_handler
3364 (vl_api_cli_request_t *mp)
3366 vl_api_cli_reply_t *rp;
3367 unix_shared_memory_queue_t *q;
3368 vlib_main_t * vm = vlib_get_main();
3369 api_main_t * am = &api_main;
3370 unformat_input_t input;
3374 q = vl_api_client_index_to_input_queue (mp->client_index);
3378 rp = vl_msg_api_alloc (sizeof (*rp));
3379 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3380 rp->context = mp->context;
3382 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3384 vlib_cli_input (vm, &input, shmem_cli_output,
3387 pthread_mutex_lock (&am->vlib_rp->mutex);
3388 oldheap = svm_push_data_heap (am->vlib_rp);
3390 vec_add1(shmem_vec, 0);
3392 svm_pop_heap (oldheap);
3393 pthread_mutex_unlock (&am->vlib_rp->mutex);
3395 rp->reply_in_shmem = (uword)shmem_vec;
3397 vl_msg_api_send_shmem (q, (u8 *)&rp);
3400 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3403 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3404 vnet_main_t *vnm = vnet_get_main();
3405 clib_error_t * error;
3410 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3412 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3415 clib_error_report(error);
3416 rv = VNET_API_ERROR_UNSPECIFIED;
3418 rv = vnm->api_errno;
3421 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3424 static void vl_api_sr_tunnel_add_del_t_handler
3425 (vl_api_sr_tunnel_add_del_t *mp)
3428 clib_warning ("unimplemented");
3430 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3432 vl_api_sr_tunnel_add_del_reply_t * rmp;
3433 ip6_address_t * segments = 0, * seg;
3434 ip6_address_t * tags = 0, *tag;
3435 ip6_address_t * this_address;
3438 if (mp->n_segments == 0) {
3443 memset (a, 0, sizeof (*a));
3444 a->src_address = (ip6_address_t *)&mp->src_address;
3445 a->dst_address = (ip6_address_t *)&mp->dst_address;
3446 a->dst_mask_width = mp->dst_mask_width;
3447 a->flags_net_byte_order = mp->flags_net_byte_order;
3448 a->is_del = (mp->is_add == 0);
3449 a->rx_table_id = ntohl(mp->outer_vrf_id);
3450 a->tx_table_id = ntohl(mp->inner_vrf_id);
3452 a->name = format(0, "%s", mp->name);
3453 if (!(vec_len(a->name)))
3456 a->policy_name = format(0, "%s", mp->policy_name);
3457 if (!(vec_len(a->policy_name)))
3460 /* Yank segments and tags out of the API message */
3461 this_address = (ip6_address_t *)mp->segs_and_tags;
3462 for (i = 0; i < mp->n_segments; i++) {
3463 vec_add2 (segments, seg, 1);
3464 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3467 for (i = 0; i < mp->n_tags; i++) {
3468 vec_add2 (tags, tag, 1);
3469 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3473 a->segments = segments;
3476 rv = ip6_sr_add_del_tunnel (a);
3480 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3484 static void vl_api_sr_policy_add_del_t_handler
3485 (vl_api_sr_policy_add_del_t *mp)
3488 clib_warning ("unimplemented");
3490 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3492 vl_api_sr_policy_add_del_reply_t * rmp;
3495 memset (a, 0, sizeof (*a));
3496 a->is_del = (mp->is_add == 0);
3498 a->name = format(0, "%s", mp->name);
3499 if (!(vec_len(a->name)))
3501 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3505 if (!(mp->tunnel_names[0]))
3507 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3511 // start deserializing tunnel_names
3512 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3513 u8 * deser_tun_names = mp->tunnel_names;
3514 deser_tun_names += 1; //moving along
3517 int tun_name_len = 0;
3519 for (i=0; i < num_tunnels; i++)
3521 tun_name_len= *deser_tun_names;
3522 deser_tun_names += 1;
3523 vec_resize (tun_name, tun_name_len);
3524 memcpy(tun_name, deser_tun_names, tun_name_len);
3525 vec_add1 (a->tunnel_names, tun_name);
3526 deser_tun_names += tun_name_len;
3530 rv = ip6_sr_add_del_policy (a);
3534 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3538 static void vl_api_sr_multicast_map_add_del_t_handler
3539 (vl_api_sr_multicast_map_add_del_t *mp)
3542 clib_warning ("unimplemented");
3544 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3546 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3548 memset (a, 0, sizeof (*a));
3549 a->is_del = (mp->is_add == 0);
3551 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3552 a->policy_name = format(0, "%s", mp->policy_name);
3554 if (a->multicast_address == 0)
3560 if (!(a->policy_name))
3566 #if DPDK > 0 /* Cannot call replicate without DPDK */
3567 rv = ip6_sr_add_del_multicastmap (a);
3569 clib_warning ("multicast replication without DPDK not implemented");
3570 rv = VNET_API_ERROR_UNIMPLEMENTED;
3575 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3579 #define foreach_classify_add_del_table_field \
3584 _(match_n_vectors) \
3585 _(next_table_index) \
3588 static void vl_api_classify_add_del_table_t_handler
3589 (vl_api_classify_add_del_table_t * mp)
3591 vl_api_classify_add_del_table_reply_t * rmp;
3592 vnet_classify_main_t * cm = &vnet_classify_main;
3593 vnet_classify_table_t * t;
3597 foreach_classify_add_del_table_field;
3600 #define _(a) a = ntohl(mp->a);
3601 foreach_classify_add_del_table_field;
3604 /* The underlying API fails silently, on purpose, so check here */
3605 if (mp->is_add == 0)
3606 if (pool_is_free_index (cm->tables, table_index)) {
3607 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3611 rv = vnet_classify_add_del_table
3612 (cm, mp->mask, nbuckets, memory_size,
3613 skip_n_vectors, match_n_vectors,
3614 next_table_index, miss_next_index,
3615 &table_index, mp->is_add);
3618 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3620 if (rv == 0 && mp->is_add) {
3621 t = pool_elt_at_index (cm->tables, table_index);
3622 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3623 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3624 rmp->new_table_index = ntohl(table_index);
3626 rmp->skip_n_vectors = ~0;
3627 rmp->match_n_vectors = ~0;
3628 rmp->new_table_index = ~0;
3633 static void vl_api_classify_add_del_session_t_handler
3634 (vl_api_classify_add_del_session_t * mp)
3636 vnet_classify_main_t * cm = &vnet_classify_main;
3637 vl_api_classify_add_del_session_reply_t * rmp;
3639 u32 table_index, hit_next_index, opaque_index;
3642 table_index = ntohl (mp->table_index);
3643 hit_next_index = ntohl (mp->hit_next_index);
3644 opaque_index = ntohl (mp->opaque_index);
3645 advance = ntohl (mp->advance);
3647 rv = vnet_classify_add_del_session
3648 (cm, table_index, mp->match, hit_next_index, opaque_index,
3649 advance, mp->is_add);
3651 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3654 static void vl_api_classify_set_interface_ip_table_t_handler
3655 (vl_api_classify_set_interface_ip_table_t * mp)
3657 vlib_main_t * vm = vlib_get_main();
3658 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3660 u32 table_index, sw_if_index;
3662 table_index = ntohl (mp->table_index);
3663 sw_if_index = ntohl (mp->sw_if_index);
3665 VALIDATE_SW_IF_INDEX(mp);
3668 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3670 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3672 BAD_SW_IF_INDEX_LABEL;
3674 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3677 static void vl_api_classify_set_interface_l2_tables_t_handler
3678 (vl_api_classify_set_interface_l2_tables_t * mp)
3680 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3682 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3685 ip4_table_index = ntohl(mp->ip4_table_index);
3686 ip6_table_index = ntohl(mp->ip6_table_index);
3687 other_table_index = ntohl(mp->other_table_index);
3688 sw_if_index = ntohl(mp->sw_if_index);
3690 VALIDATE_SW_IF_INDEX(mp);
3692 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3693 ip6_table_index, other_table_index);
3696 if (ip4_table_index != ~0 || ip6_table_index != ~0
3697 || other_table_index != ~0)
3702 vnet_l2_classify_enable_disable (sw_if_index, enable);
3705 BAD_SW_IF_INDEX_LABEL;
3707 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3711 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3714 vl_api_l2_fib_clear_table_reply_t * rmp;
3716 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3717 * that is not currently implemented. When that TODO is fixed
3718 * this call should be changed to pass 1 instead of 0.
3720 l2fib_clear_table (0);
3722 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3725 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3730 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3733 vl_api_l2_interface_efp_filter_reply_t * rmp;
3734 vnet_main_t *vnm = vnet_get_main();
3736 // enable/disable the feature
3737 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3738 rv = vnm->api_errno;
3740 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3744 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3747 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3748 vnet_main_t * vnm = vnet_get_main();
3749 vlib_main_t * vm = vlib_get_main();
3752 VALIDATE_SW_IF_INDEX(mp);
3754 vtr_op = ntohl(mp->vtr_op);
3756 /* The L2 code is unsuspicious */
3758 case L2_VTR_DISABLED:
3763 case L2_VTR_TRANSLATE_1_1:
3764 case L2_VTR_TRANSLATE_1_2:
3765 case L2_VTR_TRANSLATE_2_1:
3766 case L2_VTR_TRANSLATE_2_2:
3770 rv = VNET_API_ERROR_INVALID_VALUE;
3771 goto bad_sw_if_index;
3774 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3775 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3778 BAD_SW_IF_INDEX_LABEL;
3780 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3784 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3788 vl_api_create_vhost_user_if_reply_t * rmp;
3789 u32 sw_if_index = (u32)~0;
3791 vnet_main_t * vnm = vnet_get_main();
3792 vlib_main_t * vm = vlib_get_main();
3794 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3795 mp->is_server, &sw_if_index, (u64)~0,
3796 mp->renumber, ntohl(mp->custom_dev_instance),
3797 (mp->use_custom_mac)?mp->mac_address:NULL);
3799 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3801 rmp->sw_if_index = ntohl (sw_if_index);
3807 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3811 vl_api_modify_vhost_user_if_reply_t * rmp;
3812 u32 sw_if_index = ntohl(mp->sw_if_index);
3814 vnet_main_t * vnm = vnet_get_main();
3815 vlib_main_t * vm = vlib_get_main();
3817 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3818 mp->is_server, sw_if_index, (u64)~0,
3819 mp->renumber, ntohl(mp->custom_dev_instance));
3821 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3826 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3830 vpe_api_main_t * vam = &vpe_api_main;
3831 vl_api_delete_vhost_user_if_reply_t * rmp;
3832 u32 sw_if_index = ntohl(mp->sw_if_index);
3834 vnet_main_t * vnm = vnet_get_main();
3835 vlib_main_t * vm = vlib_get_main();
3837 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3839 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3841 unix_shared_memory_queue_t * q =
3842 vl_api_client_index_to_input_queue (mp->client_index);
3846 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3851 static void vl_api_sw_interface_vhost_user_details_t_handler (
3852 vl_api_sw_interface_vhost_user_details_t * mp)
3854 clib_warning ("BUG");
3858 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3859 unix_shared_memory_queue_t *q,
3860 vhost_user_intf_details_t * vui,
3863 vl_api_sw_interface_vhost_user_details_t * mp;
3865 mp = vl_msg_api_alloc (sizeof (*mp));
3866 memset (mp, 0, sizeof (*mp));
3867 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3868 mp->sw_if_index = ntohl(vui->sw_if_index);
3869 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3870 mp->features = clib_net_to_host_u64 (vui->features);
3871 mp->is_server = vui->is_server;
3872 mp->num_regions = ntohl(vui->num_regions);
3873 mp->sock_errno = ntohl(vui->sock_errno);
3874 mp->context = context;
3876 strncpy ((char *) mp->sock_filename,
3877 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3878 strncpy ((char *) mp->interface_name,
3879 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3881 vl_msg_api_send_shmem (q, (u8 *)&mp);
3886 vl_api_sw_interface_vhost_user_dump_t_handler (
3887 vl_api_sw_interface_vhost_user_dump_t *mp)
3891 vpe_api_main_t * am = &vpe_api_main;
3892 vnet_main_t * vnm = vnet_get_main();
3893 vlib_main_t * vm = vlib_get_main();
3894 vhost_user_intf_details_t *ifaces = NULL;
3895 vhost_user_intf_details_t *vuid = NULL;
3896 unix_shared_memory_queue_t * q;
3898 q = vl_api_client_index_to_input_queue (mp->client_index);
3902 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3906 vec_foreach (vuid, ifaces) {
3907 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3913 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3914 unix_shared_memory_queue_t *q,
3919 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3920 u8 * if_name = NULL;
3921 vnet_sw_interface_t * si = NULL;
3923 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3925 if_name = format(if_name, "%U",
3926 format_vnet_sw_interface_name, lm->vnet_main, si);
3928 mp = vl_msg_api_alloc (sizeof (*mp));
3929 memset (mp, 0, sizeof (*mp));
3930 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3931 strncpy((char *)mp->interface_name,
3932 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3933 mp->sw_if_index = ntohl(si->sw_if_index);
3934 mp->local_session_id = s->local_session_id;
3935 mp->remote_session_id = s->remote_session_id;
3936 mp->local_cookie[0] = s->local_cookie[0];
3937 mp->local_cookie[1] = s->local_cookie[1];
3938 mp->remote_cookie = s->remote_cookie;
3939 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3940 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3941 mp->l2_sublayer_present = s->l2_sublayer_present;
3942 mp->context = context;
3944 vl_msg_api_send_shmem (q, (u8 *)&mp);
3947 static void send_ip_address_details (vpe_api_main_t * am,
3948 unix_shared_memory_queue_t * q,
3954 vl_api_ip_address_details_t * mp;
3956 mp = vl_msg_api_alloc (sizeof (*mp));
3957 memset (mp, 0, sizeof (*mp));
3958 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3961 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3963 u32 * tp = (u32 *)mp->ip;
3964 *tp = ntohl(*(u32*)ip);
3966 mp->prefix_length = prefix_length;
3967 mp->context = context;
3969 vl_msg_api_send_shmem (q, (u8 *)&mp);
3973 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3975 vpe_api_main_t * am = &vpe_api_main;
3976 unix_shared_memory_queue_t * q;
3979 ip6_main_t * im6 = &ip6_main;
3980 ip4_main_t * im4 = &ip4_main;
3981 ip_lookup_main_t * lm6 = &im6->lookup_main;
3982 ip_lookup_main_t * lm4 = &im4->lookup_main;
3983 ip_interface_address_t * ia = 0;
3984 u32 sw_if_index = ~0;
3985 int rv __attribute__ ((unused)) = 0;
3987 VALIDATE_SW_IF_INDEX(mp);
3989 sw_if_index = ntohl(mp->sw_if_index);
3991 q = vl_api_client_index_to_input_queue (mp->client_index);
3997 foreach_ip_interface_address (lm6, ia, sw_if_index,
3998 1 /* honor unnumbered */,
4000 r6 = ip_interface_address_get_address (lm6, ia);
4001 u16 prefix_length = ia->address_length;
4002 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4005 foreach_ip_interface_address (lm4, ia, sw_if_index,
4006 1 /* honor unnumbered */,
4008 r4 = ip_interface_address_get_address (lm4, ia);
4009 u16 prefix_length = ia->address_length;
4010 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4013 BAD_SW_IF_INDEX_LABEL;
4016 static void send_ip_details (vpe_api_main_t * am,
4017 unix_shared_memory_queue_t *q,
4021 vl_api_ip_details_t * mp;
4023 mp = vl_msg_api_alloc (sizeof (*mp));
4024 memset (mp, 0, sizeof (*mp));
4025 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
4027 mp->sw_if_index = ntohl(sw_if_index);
4028 mp->context = context;
4030 vl_msg_api_send_shmem (q, (u8 *)&mp);
4034 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
4035 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
4037 vpe_api_main_t * am = &vpe_api_main;
4038 l2t_main_t * lm = &l2t_main;
4039 unix_shared_memory_queue_t * q;
4040 l2t_session_t *session;
4042 q = vl_api_client_index_to_input_queue (mp->client_index);
4046 pool_foreach (session, lm->sessions,
4048 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4053 static void send_sw_interface_tap_details (vpe_api_main_t * am,
4054 unix_shared_memory_queue_t *q,
4055 tapcli_interface_details_t *tap_if,
4058 vl_api_sw_interface_tap_details_t * mp;
4059 mp = vl_msg_api_alloc (sizeof (*mp));
4060 memset (mp, 0, sizeof (*mp));
4061 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4062 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4063 strncpy((char *)mp->dev_name,
4064 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4065 mp->context = context;
4067 vl_msg_api_send_shmem (q, (u8 *)&mp);
4071 vl_api_sw_interface_tap_dump_t_handler (
4072 vl_api_sw_interface_tap_dump_t *mp)
4075 vpe_api_main_t * am = &vpe_api_main;
4076 unix_shared_memory_queue_t * q;
4077 tapcli_interface_details_t *tapifs = NULL;
4078 tapcli_interface_details_t *tap_if = NULL;
4080 q = vl_api_client_index_to_input_queue (mp->client_index);
4084 rv = vnet_tap_dump_ifs(&tapifs);
4088 vec_foreach(tap_if, tapifs) {
4089 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4096 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4098 vpe_api_main_t * am = &vpe_api_main;
4099 vnet_main_t * vnm = vnet_get_main();
4100 vlib_main_t * vm = vlib_get_main();
4101 vnet_interface_main_t * im = &vnm->interface_main;
4102 unix_shared_memory_queue_t * q;
4103 vnet_sw_interface_t * si, * sorted_sis;
4104 u32 sw_if_index = ~0;
4106 q = vl_api_client_index_to_input_queue (mp->client_index);
4111 /* Gather interfaces. */
4112 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4113 _vec_len (sorted_sis) = 0;
4114 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4116 vec_foreach (si, sorted_sis) {
4117 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4118 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4121 sw_if_index = si->sw_if_index;
4122 send_ip_details(am, q, sw_if_index, mp->context);
4127 static void vl_api_l2_fib_table_entry_t_handler (
4128 vl_api_l2_fib_table_entry_t * mp)
4130 clib_warning ("BUG");
4133 static void send_l2fib_table_entry (vpe_api_main_t * am,
4134 unix_shared_memory_queue_t *q,
4135 l2fib_entry_key_t * l2fe_key,
4136 l2fib_entry_result_t * l2fe_res,
4139 vl_api_l2_fib_table_entry_t * mp;
4141 mp = vl_msg_api_alloc (sizeof (*mp));
4142 memset (mp, 0, sizeof (*mp));
4143 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4145 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4147 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4148 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4149 mp->static_mac = l2fe_res->fields.static_mac;
4150 mp->filter_mac = l2fe_res->fields.filter;
4151 mp->bvi_mac = l2fe_res->fields.bvi;
4152 mp->context = context;
4154 vl_msg_api_send_shmem (q, (u8 *)&mp);
4158 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4160 vpe_api_main_t * am = &vpe_api_main;
4161 bd_main_t * bdm = &bd_main;
4162 l2fib_entry_key_t *l2fe_key = NULL;
4163 l2fib_entry_result_t *l2fe_res = NULL;
4164 u32 ni, bd_id = ntohl (mp->bd_id);
4166 unix_shared_memory_queue_t * q;
4169 q = vl_api_client_index_to_input_queue (mp->client_index);
4173 /* see l2fib_table_dump: ~0 means "any" */
4177 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4184 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4186 vec_foreach_index (ni, l2fe_key) {
4187 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4188 vec_elt_at_index(l2fe_res, ni), mp->context);
4195 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4197 vl_api_show_version_reply_t *rmp;
4199 char * vpe_api_get_build_directory(void);
4200 char * vpe_api_get_version(void);
4201 char * vpe_api_get_build_date(void);
4203 unix_shared_memory_queue_t * q =
4204 vl_api_client_index_to_input_queue (mp->client_index);
4209 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4211 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4212 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4213 ARRAY_LEN(rmp->build_directory)-1);
4214 strncpy ((char *) rmp->version, vpe_api_get_version(),
4215 ARRAY_LEN(rmp->version)-1);
4216 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4217 ARRAY_LEN(rmp->build_date)-1);
4221 static void vl_api_get_node_index_t_handler
4222 (vl_api_get_node_index_t * mp)
4224 vlib_main_t * vm = vlib_get_main();
4225 vl_api_get_node_index_reply_t * rmp;
4228 u32 node_index = ~0;
4230 n = vlib_get_node_by_name (vm, mp->node_name);
4233 rv = VNET_API_ERROR_NO_SUCH_NODE;
4235 node_index = n->index;
4237 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4239 rmp->node_index = ntohl(node_index);
4243 static void vl_api_add_node_next_t_handler
4244 (vl_api_add_node_next_t * mp)
4246 vlib_main_t * vm = vlib_get_main();
4247 vl_api_add_node_next_reply_t * rmp;
4248 vlib_node_t * n, * next;
4250 u32 next_index = ~0;
4252 n = vlib_get_node_by_name (vm, mp->node_name);
4255 rv = VNET_API_ERROR_NO_SUCH_NODE;
4259 next = vlib_get_node_by_name (vm, mp->next_name);
4262 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4264 next_index = vlib_node_add_next (vm, n->index, next->index);
4267 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4269 rmp->next_index = ntohl(next_index);
4273 static void vl_api_l2tpv3_create_tunnel_t_handler
4274 (vl_api_l2tpv3_create_tunnel_t *mp)
4276 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4277 l2t_main_t *lm = &l2t_main;
4278 u32 sw_if_index = (u32)~0;
4281 if (mp->is_ipv6 != 1) {
4282 rv = VNET_API_ERROR_UNIMPLEMENTED;
4286 rv = create_l2tpv3_ipv6_tunnel (lm,
4287 (ip6_address_t *) mp->client_address,
4288 (ip6_address_t *) mp->our_address,
4289 ntohl(mp->local_session_id),
4290 ntohl(mp->remote_session_id),
4291 clib_net_to_host_u64(mp->local_cookie),
4292 clib_net_to_host_u64(mp->remote_cookie),
4293 mp->l2_sublayer_present,
4297 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4299 rmp->sw_if_index = ntohl (sw_if_index);
4303 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4304 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4306 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4307 l2t_main_t *lm = &l2t_main;
4310 VALIDATE_SW_IF_INDEX(mp);
4312 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4313 clib_net_to_host_u64(mp->new_local_cookie),
4314 clib_net_to_host_u64(mp->new_remote_cookie));
4316 BAD_SW_IF_INDEX_LABEL;
4318 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4321 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4322 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4325 vnet_main_t * vnm = vnet_get_main();
4326 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4328 VALIDATE_SW_IF_INDEX(mp);
4330 rv = l2tpv3_interface_enable_disable
4331 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4333 BAD_SW_IF_INDEX_LABEL;
4335 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4338 static void vl_api_l2tpv3_set_lookup_key_t_handler
4339 (vl_api_l2tpv3_set_lookup_key_t * mp)
4342 l2t_main_t *lm = &l2t_main;
4343 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4345 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4346 rv = VNET_API_ERROR_INVALID_VALUE;
4350 lm->lookup_type = mp->key;
4353 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4356 static void vl_api_vxlan_add_del_tunnel_t_handler
4357 (vl_api_vxlan_add_del_tunnel_t * mp)
4359 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4361 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4362 u32 encap_fib_index;
4364 ip4_main_t * im = &ip4_main;
4365 u32 sw_if_index = ~0;
4367 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4369 rv = VNET_API_ERROR_NO_SUCH_FIB;
4372 encap_fib_index = p[0];
4374 /* Check src & dst are different */
4375 if ((mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4376 (!mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4377 rv = VNET_API_ERROR_SAME_SRC_DST;
4380 memset (a, 0, sizeof (*a));
4382 a->is_add = mp->is_add;
4383 a->is_ip6 = mp->is_ipv6;
4385 /* ip addresses sent in network byte order */
4387 memcpy(&(a->src.ip6), mp->src_address, 16);
4388 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4390 memcpy(&(a->src.ip4), mp->src_address, 4);
4391 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4394 a->encap_fib_index = encap_fib_index;
4395 a->decap_next_index = ntohl(mp->decap_next_index);
4396 a->vni = ntohl(mp->vni);
4397 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4400 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4402 rmp->sw_if_index = ntohl (sw_if_index);
4406 static void send_vxlan_tunnel_details
4407 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4409 vl_api_vxlan_tunnel_details_t * rmp;
4410 ip4_main_t * im4 = &ip4_main;
4411 ip6_main_t * im6 = &ip6_main;
4412 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4414 rmp = vl_msg_api_alloc (sizeof (*rmp));
4415 memset (rmp, 0, sizeof (*rmp));
4416 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4418 memcpy(rmp->src_address, &(t->src.ip6), 16);
4419 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4420 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4422 memcpy(rmp->src_address, &(t->src.ip4), 4);
4423 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4424 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4426 rmp->vni = htonl(t->vni);
4427 rmp->decap_next_index = htonl(t->decap_next_index);
4428 rmp->sw_if_index = htonl(t->sw_if_index);
4429 rmp->is_ipv6 = is_ipv6;
4430 rmp->context = context;
4432 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4435 static void vl_api_vxlan_tunnel_dump_t_handler
4436 (vl_api_vxlan_tunnel_dump_t * mp)
4438 unix_shared_memory_queue_t * q;
4439 vxlan_main_t * vxm = &vxlan_main;
4443 q = vl_api_client_index_to_input_queue (mp->client_index);
4448 sw_if_index = ntohl(mp->sw_if_index);
4450 if (~0 == sw_if_index) {
4451 pool_foreach (t, vxm->tunnels,
4453 send_vxlan_tunnel_details(t, q, mp->context);
4456 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4457 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4460 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4461 send_vxlan_tunnel_details(t, q, mp->context);
4465 static void vl_api_gre_add_del_tunnel_t_handler
4466 (vl_api_gre_add_del_tunnel_t * mp)
4468 vl_api_gre_add_del_tunnel_reply_t * rmp;
4470 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4473 ip4_main_t * im = &ip4_main;
4474 u32 sw_if_index = ~0;
4476 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_table_id));
4478 rv = VNET_API_ERROR_NO_SUCH_FIB;
4481 outer_table_id = p[0];
4483 /* Check src & dst are different */
4484 if (memcmp(&mp->src_address, &mp->dst_address, 4) == 0) {
4485 rv = VNET_API_ERROR_SAME_SRC_DST;
4489 memset (a, 0, sizeof (*a));
4491 a->is_add = mp->is_add;
4493 /* ip addresses sent in network byte order */
4494 a->src.as_u32 = mp->src_address;
4495 a->dst.as_u32 = mp->dst_address;
4497 a->outer_table_id = outer_table_id;
4498 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4501 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4503 rmp->sw_if_index = ntohl (sw_if_index);
4507 static void send_gre_tunnel_details
4508 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4510 vl_api_gre_tunnel_details_t * rmp;
4511 ip4_main_t * im = &ip4_main;
4513 rmp = vl_msg_api_alloc (sizeof (*rmp));
4514 memset (rmp, 0, sizeof (*rmp));
4515 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4516 rmp->src_address = t->tunnel_src.data_u32;
4517 rmp->dst_address = t->tunnel_dst.data_u32;
4518 rmp->outer_table_id = htonl(im->fibs[t->outer_fib_index].table_id);
4519 rmp->sw_if_index = htonl(t->sw_if_index);
4520 rmp->context = context;
4522 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4525 static void vl_api_gre_tunnel_dump_t_handler
4526 (vl_api_gre_tunnel_dump_t * mp)
4528 unix_shared_memory_queue_t * q;
4529 gre_main_t * gm = &gre_main;
4533 q = vl_api_client_index_to_input_queue (mp->client_index);
4538 sw_if_index = ntohl(mp->sw_if_index);
4540 if (~0 == sw_if_index) {
4541 pool_foreach (t, gm->tunnels,
4543 send_gre_tunnel_details(t, q, mp->context);
4546 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4547 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4550 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4551 send_gre_tunnel_details(t, q, mp->context);
4556 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4558 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4560 vl_api_l2_patch_add_del_reply_t * rmp;
4561 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4565 VALIDATE_RX_SW_IF_INDEX(mp);
4566 VALIDATE_TX_SW_IF_INDEX(mp);
4568 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4569 ntohl(mp->tx_sw_if_index),
4570 (int)(mp->is_add != 0));
4572 BAD_RX_SW_IF_INDEX_LABEL;
4573 BAD_TX_SW_IF_INDEX_LABEL;
4575 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4579 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4580 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4582 vl_api_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4584 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4585 u32 encap_fib_index, decap_fib_index;
4588 ip4_main_t * im = &ip4_main;
4589 u32 sw_if_index = ~0;
4592 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4594 rv = VNET_API_ERROR_NO_SUCH_FIB;
4597 encap_fib_index = p[0];
4599 protocol = mp->protocol;
4601 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4602 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT) {
4603 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4605 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4608 decap_fib_index = p[0];
4610 decap_fib_index = ntohl(mp->decap_vrf_id);
4613 /* Check src & dst are different */
4614 if ((mp->is_ipv6 && memcmp(mp->local, mp->remote, 16) == 0) ||
4615 (!mp->is_ipv6 && memcmp(mp->local, mp->remote, 4) == 0)) {
4616 rv = VNET_API_ERROR_SAME_SRC_DST;
4619 memset (a, 0, sizeof (*a));
4621 a->is_add = mp->is_add;
4622 a->is_ip6 = mp->is_ipv6;
4623 /* ip addresses sent in network byte order */
4625 clib_memcpy(&(a->local.ip6), mp->local, 16);
4626 clib_memcpy(&(a->remote.ip6), mp->remote, 16);
4628 clib_memcpy(&(a->local.ip4), mp->local, 4);
4629 clib_memcpy(&(a->remote.ip4), mp->remote, 4);
4631 a->encap_fib_index = encap_fib_index;
4632 a->decap_fib_index = decap_fib_index;
4633 a->protocol = protocol;
4634 a->vni = ntohl(mp->vni);
4635 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4638 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4640 rmp->sw_if_index = ntohl (sw_if_index);
4644 static void send_vxlan_gpe_tunnel_details
4645 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4647 vl_api_vxlan_gpe_tunnel_details_t * rmp;
4648 ip4_main_t * im4 = &ip4_main;
4649 ip6_main_t * im6 = &ip6_main;
4650 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
4652 rmp = vl_msg_api_alloc (sizeof (*rmp));
4653 memset (rmp, 0, sizeof (*rmp));
4654 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_GPE_TUNNEL_DETAILS);
4656 memcpy(rmp->local, &(t->local.ip6), 16);
4657 memcpy(rmp->remote, &(t->remote.ip6), 16);
4658 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4659 rmp->decap_vrf_id = htonl(im6->fibs[t->decap_fib_index].table_id);
4661 memcpy(rmp->local, &(t->local.ip4), 4);
4662 memcpy(rmp->remote, &(t->remote.ip4), 4);
4663 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4664 rmp->decap_vrf_id = htonl(im4->fibs[t->decap_fib_index].table_id);
4666 rmp->vni = htonl(t->vni);
4667 rmp->protocol = t->protocol;
4668 rmp->sw_if_index = htonl(t->sw_if_index);
4669 rmp->is_ipv6 = is_ipv6;
4670 rmp->context = context;
4672 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4675 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
4676 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
4678 unix_shared_memory_queue_t * q;
4679 vxlan_gpe_main_t * vgm = &vxlan_gpe_main;
4680 vxlan_gpe_tunnel_t * t;
4683 q = vl_api_client_index_to_input_queue (mp->client_index);
4688 sw_if_index = ntohl(mp->sw_if_index);
4690 if (~0 == sw_if_index) {
4691 pool_foreach (t, vgm->tunnels,
4693 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4696 if ((sw_if_index >= vec_len(vgm->tunnel_index_by_sw_if_index)) ||
4697 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index])) {
4700 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
4701 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4706 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4708 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4710 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4712 u8 *locator_name = NULL;
4714 memset(a, 0, sizeof(a[0]));
4716 locator_name = format(0, "%s", mp->locator_set_name);
4718 a->name = locator_name;
4720 a->is_add = mp->is_add;
4723 rv = vnet_lisp_add_del_locator_set(a, &ls_index);
4725 vec_free(locator_name);
4727 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4731 vl_api_lisp_add_del_locator_t_handler(
4732 vl_api_lisp_add_del_locator_t *mp)
4734 vl_api_lisp_add_del_locator_reply_t *rmp;
4736 locator_t locator, *locators = NULL;
4737 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4739 u8 *locator_name = NULL;
4741 memset(&locator, 0, sizeof(locator));
4742 memset(a, 0, sizeof(a[0]));
4744 locator.sw_if_index = ntohl(mp->sw_if_index);
4745 locator.priority = mp->priority;
4746 locator.weight = mp->weight;
4748 vec_add1(locators, locator);
4750 locator_name = format(0, "%s", mp->locator_set_name);
4752 a->name = locator_name;
4753 a->locators = locators;
4754 a->is_add = mp->is_add;
4757 rv = vnet_lisp_add_del_locator(a, NULL, &ls_index);
4760 vec_free(locator_name);
4762 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4766 vl_api_lisp_add_del_local_eid_t_handler(
4767 vl_api_lisp_add_del_local_eid_t *mp)
4769 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4770 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4772 ip_prefix_t *prefp = NULL;
4773 ip_address_t *ip_eid = NULL;
4775 u8 * mac = gid_address_mac (&eid);
4777 u32 locator_set_index = ~0, map_index = ~0;
4778 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4780 memset (a, 0, sizeof (a[0]));
4781 memset (&eid, 0, sizeof (eid));
4783 prefp = &gid_address_ippref(&eid);
4784 ip_eid = &ip_prefix_addr(prefp);
4786 switch (mp->eid_type)
4789 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4790 ip_address_set(ip_eid, mp->eid, IP4);
4791 ip_prefix_len(prefp) = mp->prefix_len;
4794 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4795 ip_address_set(ip_eid, mp->eid, IP6);
4796 ip_prefix_len(prefp) = mp->prefix_len;
4798 case 2: /* l2 mac */
4799 gid_address_type (&eid) = GID_ADDR_MAC;
4800 clib_memcpy(mac, mp->eid, 6);
4803 rv = VNET_API_ERROR_INVALID_EID_TYPE;
4807 name = format(0, "%s", mp->locator_set_name);
4808 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4810 rv = VNET_API_ERROR_INVALID_VALUE;
4813 locator_set_index = p[0];
4815 /* XXX treat batch configuration */
4816 a->is_add = mp->is_add;
4817 gid_address_vni (&eid) = clib_net_to_host_u32 (mp->vni);
4818 gid_address_copy (&a->eid, &eid);
4819 a->locator_set_index = locator_set_index;
4821 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4825 gid_address_free (&a->eid);
4827 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4831 vl_api_lisp_eid_table_add_del_map_t_handler(
4832 vl_api_lisp_eid_table_add_del_map_t *mp)
4834 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
4836 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
4837 clib_net_to_host_u32 (mp->vrf), mp->is_add);
4838 REPLY_MACRO(VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)
4842 lisp_gpe_add_del_fwd_entry_set_address(
4843 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4844 ip_address_t *slocator,
4845 ip_address_t *dlocator,
4848 ip_address_t *ip_eid = NULL;
4849 ip_prefix_t *prefp = NULL;
4851 prefp = &gid_address_ippref(eid);
4852 ip_eid = &ip_prefix_addr(prefp);
4854 if (mp->eid_is_ipv6) {
4855 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4856 sizeof(ip_addr_v6(ip_eid)));
4857 ip_addr_version(ip_eid) = IP6;
4859 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4860 sizeof(ip_addr_v4(ip_eid)));
4861 ip_addr_version(ip_eid) = IP4;
4863 ip_prefix_len(prefp) = mp->eid_prefix_len;
4865 if (mp->address_is_ipv6) {
4866 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4867 sizeof(ip_addr_v6(slocator)));
4868 ip_addr_version(slocator) = IP6;
4869 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4870 sizeof(ip_addr_v6(dlocator)));
4871 ip_addr_version(dlocator) = IP6;
4873 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4874 sizeof(ip_addr_v4(slocator)));
4875 ip_addr_version(slocator) = IP4;
4876 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4877 sizeof(ip_addr_v4(dlocator)));
4878 ip_addr_version(dlocator) = IP4;
4883 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4884 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4886 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4888 ip_address_t slocator, dlocator;
4890 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4892 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4894 memset (&a, 0, sizeof(a));
4896 a.is_add = mp->is_add;
4898 a.slocator = slocator;
4899 a.dlocator = dlocator;
4900 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4902 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4906 vl_api_lisp_add_del_map_resolver_t_handler(
4907 vl_api_lisp_add_del_map_resolver_t *mp)
4909 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4911 ip_address_t *ip_addr = NULL;
4912 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4914 a->is_add = mp->is_add;
4915 ip_addr = &a->address;
4918 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4919 sizeof(ip_addr_v6(ip_addr)));
4920 ip_addr_version(ip_addr) = IP6;
4922 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4923 sizeof(ip_addr_v4(ip_addr)));
4924 ip_addr_version(ip_addr) = IP4;
4927 rv = vnet_lisp_add_del_map_resolver (a);
4929 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4933 vl_api_lisp_gpe_enable_disable_t_handler(
4934 vl_api_lisp_gpe_enable_disable_t *mp)
4936 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4938 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
4940 a->is_en = mp->is_en;
4941 vnet_lisp_gpe_enable_disable (a);
4943 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4947 vl_api_lisp_enable_disable_t_handler(
4948 vl_api_lisp_enable_disable_t *mp)
4950 vl_api_lisp_enable_disable_reply_t *rmp;
4953 vnet_lisp_enable_disable (mp->is_en);
4954 REPLY_MACRO(VL_API_LISP_ENABLE_DISABLE_REPLY);
4958 vl_api_lisp_gpe_add_del_iface_t_handler(
4959 vl_api_lisp_gpe_add_del_iface_t *mp)
4961 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4963 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4965 a->is_add = mp->is_add;
4966 a->table_id = mp->table_id;
4968 rv = vnet_lisp_gpe_add_del_iface (a, 0);
4970 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4974 vl_api_lisp_pitr_set_locator_set_t_handler(
4975 vl_api_lisp_pitr_set_locator_set_t *mp)
4977 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
4981 ls_name = format (0, "%s", mp->ls_name);
4982 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
4985 REPLY_MACRO(VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
4989 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
4990 (vl_api_lisp_add_del_map_request_itr_rlocs_t *mp)
4992 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
4994 u8 * locator_set_name = NULL;
4995 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, * a = &_a;
4997 locator_set_name = format (0, "%s", mp->locator_set_name);
4999 a->is_add = mp->is_add;
5000 a->locator_set_name = locator_set_name;
5002 rv = vnet_lisp_add_del_mreq_itr_rlocs(a);
5004 vec_free(locator_set_name);
5006 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5009 /** Used for transferring locators via VPP API */
5010 typedef CLIB_PACKED(struct
5012 u8 is_ip4; /**< is locator an IPv4 address */
5013 u8 addr[16]; /**< IPv4/IPv6 address */
5017 send_lisp_locator_set_details_set_address
5018 (vl_api_lisp_locator_set_details_t *rmp,
5019 gid_address_t *gid_address)
5021 ip_prefix_t *ip_addr;
5023 if (gid_address_type(gid_address) != GID_ADDR_IP_PREFIX) {
5027 ip_addr = &gid_address_ippref(gid_address);
5028 rmp->prefix_len = ip_prefix_len(ip_addr);
5029 rmp->is_ipv6 = ip_prefix_version(ip_addr);
5030 ip_address_copy_addr(rmp->ip_address, &ip_prefix_addr(ip_addr));
5034 vl_api_lisp_add_del_remote_mapping_t_handler (
5035 vl_api_lisp_add_del_remote_mapping_t *mp)
5038 locator_t rloc, * rlocs = 0;
5039 vl_api_lisp_add_del_remote_mapping_reply_t * rmp;
5041 gid_address_t _seid, * seid = &_seid;
5042 gid_address_t _deid, * deid = &_deid;
5043 ip_prefix_t * seid_pref = &gid_address_ippref(seid);
5044 ip_prefix_t * deid_pref = &gid_address_ippref(deid);
5046 /* TODO remove seid from API */
5047 memset (seid, 0, sizeof (seid[0]));
5048 memset (deid, 0, sizeof (deid[0]));
5049 ip_address_t * seid_addr = &ip_prefix_addr(seid_pref);
5050 ip_address_t * deid_addr = &ip_prefix_addr(deid_pref);
5051 ip_prefix_len(seid_pref) = mp->seid_len;
5052 ip_prefix_len(deid_pref) = mp->deid_len;
5053 u8 * seid_mac = gid_address_mac (seid);
5054 u8 * deid_mac = gid_address_mac (deid);
5055 gid_address_vni (seid) = ntohl (mp->vni);
5056 gid_address_vni (deid) = ntohl (mp->vni);
5058 switch (mp->eid_type)
5061 gid_address_type(seid) = GID_ADDR_IP_PREFIX;
5062 gid_address_type(deid) = GID_ADDR_IP_PREFIX;
5063 ip_address_set (seid_addr, mp->seid, IP4);
5064 ip_address_set (deid_addr, mp->deid, IP4);
5067 gid_address_type(seid) = GID_ADDR_IP_PREFIX;
5068 gid_address_type(deid) = GID_ADDR_IP_PREFIX;
5069 ip_address_set (seid_addr, mp->seid, IP6);
5070 ip_address_set (deid_addr, mp->deid, IP6);
5072 case 2: /* l2 mac */
5073 gid_address_type(seid) = GID_ADDR_MAC;
5074 gid_address_type(deid) = GID_ADDR_MAC;
5075 clib_memcpy (seid_mac, mp->seid, 6);
5076 clib_memcpy (deid_mac, mp->deid, 6);
5079 rv = VNET_API_ERROR_INVALID_EID_TYPE;
5083 for (i = 0; i < mp->rloc_num; i++) {
5084 rloc_t * r = &((rloc_t *) mp->rlocs)[i];
5085 memset(&rloc, 0, sizeof(rloc));
5086 ip_address_set(&gid_address_ip(&rloc.address), &r->addr,
5087 r->is_ip4 ? IP4 : IP6);
5088 gid_address_ippref_len(&rloc.address) = r->is_ip4 ? 32: 128;
5089 gid_address_type(&rloc.address) = GID_ADDR_IP_PREFIX;
5090 /* TODO fix API to pass priority and weight */
5093 vec_add1 (rlocs, rloc);
5096 /* TODO Uncomment once https://gerrit.fd.io/r/#/c/1802 is merged and CSIT
5097 * is switched to lisp_add_del_adjacency */
5098 // if (!mp->is_add) {
5099 // vnet_lisp_add_del_adjacency_args_t _a, * a = &_a;
5100 // gid_address_copy(&a->deid, deid);
5102 // rv = vnet_lisp_add_del_adjacency (a);
5104 // /* NOTE: for now this works as a static remote mapping, i.e.,
5105 // * not authoritative and ttl infinite. */
5106 // rv = vnet_lisp_add_del_mapping (deid, rlocs, mp->action, 0, ~0,
5110 /* TODO: remove once the above is merged */
5111 vnet_lisp_add_del_adjacency_args_t _a, * a = &_a;
5112 a->is_add = mp->is_add;
5113 a->authoritative = 0;
5114 a->action = mp->action;
5115 a->locators = rlocs;
5116 gid_address_copy(&a->seid, seid);
5117 gid_address_copy(&a->deid, deid);
5118 rv = vnet_lisp_add_del_adjacency (a);
5121 vnet_lisp_clear_all_remote_adjacencies ();
5125 REPLY_MACRO(VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5129 vl_api_lisp_add_del_adjacency_t_handler (
5130 vl_api_lisp_add_del_adjacency_t *mp)
5134 vl_api_lisp_add_del_adjacency_reply_t * rmp;
5135 vnet_lisp_add_del_adjacency_args_t _a, * a = &_a;
5138 memset(a, 0, sizeof(a[0]));
5140 ip_prefix_t * seid_pref = &gid_address_ippref(&a->seid);
5141 ip_prefix_t * deid_pref = &gid_address_ippref(&a->deid);
5143 ip_address_t * seid_addr = &ip_prefix_addr(seid_pref);
5144 ip_address_t * deid_addr = &ip_prefix_addr(deid_pref);
5145 ip_prefix_len(seid_pref) = mp->seid_len;
5146 ip_prefix_len(deid_pref) = mp->deid_len;
5147 u8 * seid_mac = gid_address_mac (&a->seid);
5148 u8 * deid_mac = gid_address_mac (&a->deid);
5149 gid_address_vni(&a->seid) = ntohl (mp->vni);
5150 gid_address_vni(&a->deid) = ntohl (mp->vni);
5152 switch (mp->eid_type)
5155 gid_address_type(&a->seid) = GID_ADDR_IP_PREFIX;
5156 gid_address_type(&a->deid) = GID_ADDR_IP_PREFIX;
5157 ip_address_set (seid_addr, mp->seid, IP4);
5158 ip_address_set (deid_addr, mp->deid, IP4);
5161 gid_address_type(&a->seid) = GID_ADDR_IP_PREFIX;
5162 gid_address_type(&a->deid) = GID_ADDR_IP_PREFIX;
5163 ip_address_set (seid_addr, mp->seid, IP6);
5164 ip_address_set (deid_addr, mp->deid, IP6);
5166 case 2: /* l2 mac */
5167 gid_address_type(&a->seid) = GID_ADDR_MAC;
5168 gid_address_type(&a->deid) = GID_ADDR_MAC;
5169 clib_memcpy (seid_mac, mp->seid, 6);
5170 clib_memcpy (deid_mac, mp->deid, 6);
5173 rv = VNET_API_ERROR_INVALID_EID_TYPE;
5177 for (i = 0; i < mp->rloc_num; i++) {
5178 rloc_t * r = &((rloc_t *) mp->rlocs)[i];
5179 memset(&rloc, 0, sizeof(rloc));
5180 ip_address_set(&gid_address_ip(&rloc.address), &r->addr,
5181 r->is_ip4 ? IP4 : IP6);
5182 gid_address_ippref_len(&rloc.address) = r->is_ip4 ? 32: 128;
5183 gid_address_type(&rloc.address) = GID_ADDR_IP_PREFIX;
5184 /* TODO fix API to pass priority and weight */
5187 vec_add1 (a->locators, rloc);
5190 a->action = mp->action;
5191 a->is_add = mp->is_add;
5193 /* NOTE: the remote mapping is static, i.e., not authoritative and
5194 * ttl is infinite. */
5195 a->authoritative = 0;
5198 rv = vnet_lisp_add_del_adjacency (a);
5200 vec_free (a->locators);
5202 REPLY_MACRO(VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5206 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
5207 locator_set_t *lsit,
5208 unix_shared_memory_queue_t *q,
5212 vl_api_lisp_locator_set_details_t *rmp;
5213 locator_t *loc = NULL;
5217 vec_foreach (locit, lsit->locator_indices) {
5218 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5219 rmp = vl_msg_api_alloc (sizeof (*rmp));
5220 memset (rmp, 0, sizeof (*rmp));
5221 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
5222 rmp->local = lsit->local;
5224 ASSERT(lsit->name != NULL);
5225 strncpy((char *) rmp->locator_set_name,
5226 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5227 rmp->sw_if_index = htonl(loc->sw_if_index);
5229 str = format(0, "remote-%d", index);
5230 strncpy((char *) rmp->locator_set_name, (char *) str,
5231 ARRAY_LEN(rmp->locator_set_name) - 1);
5232 send_lisp_locator_set_details_set_address(rmp, &loc->address);
5236 rmp->priority = loc->priority;
5237 rmp->weight = loc->weight;
5238 rmp->context = context;
5240 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5245 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
5247 unix_shared_memory_queue_t * q = NULL;
5248 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5249 locator_set_t * lsit = NULL;
5252 q = vl_api_client_index_to_input_queue (mp->client_index);
5258 pool_foreach (lsit, lcm->locator_set_pool,
5260 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
5265 send_lisp_local_eid_table_details (mapping_t *mapit,
5266 unix_shared_memory_queue_t *q,
5269 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
5270 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5271 locator_set_t *ls = NULL;
5272 gid_address_t *gid = NULL;
5274 ip_prefix_t *ip_prefix = NULL;
5277 ls = pool_elt_at_index (lcm->locator_set_pool,
5278 mapit->locator_set_index);
5280 ip_prefix = &gid_address_ippref(gid);
5281 mac = gid_address_mac(gid);
5283 rmp = vl_msg_api_alloc (sizeof (*rmp));
5284 memset (rmp, 0, sizeof (*rmp));
5285 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
5287 ASSERT(ls->name != NULL);
5288 strncpy((char *) rmp->locator_set_name,
5289 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5291 str = format(0, "remote-%d", mapit->locator_set_index);
5292 strncpy((char *) rmp->locator_set_name, (char *) str,
5293 ARRAY_LEN(rmp->locator_set_name) - 1);
5297 switch (gid_address_type (gid))
5299 case GID_ADDR_IP_PREFIX:
5300 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
5301 if (ip_prefix_version(ip_prefix) == IP4)
5303 rmp->eid_type = 0; /* ipv4 type */
5304 clib_memcpy(rmp->eid, &ip_prefix_v4(ip_prefix),
5305 sizeof(ip_prefix_v4(ip_prefix)));
5309 rmp->eid_type = 1; /* ipv6 type */
5310 clib_memcpy(rmp->eid, &ip_prefix_v6(ip_prefix),
5311 sizeof(ip_prefix_v6(ip_prefix)));
5315 rmp->eid_type = 2; /* l2 mac type */
5316 clib_memcpy(rmp->eid, mac, 6);
5321 rmp->context = context;
5322 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5323 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5327 vl_api_lisp_local_eid_table_dump_t_handler (
5328 vl_api_lisp_local_eid_table_dump_t *mp)
5331 unix_shared_memory_queue_t * q = NULL;
5332 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5333 mapping_t * mapit = NULL;
5334 gid_address_t _eid, * eid = &_eid;
5336 q = vl_api_client_index_to_input_queue (mp->client_index);
5342 memset (eid, 0, sizeof (*eid));
5343 gid_address_vni(eid) = ntohl(mp->vni);
5344 switch (mp->eid_type) {
5346 gid_address_type(eid) = GID_ADDR_IP_PREFIX;
5347 gid_address_ippref_len(eid) = mp->prefix_length;
5348 gid_address_ip_version(eid) = IP4;
5349 clib_memcpy (&gid_address_ippref(eid), mp->eid, 4);
5352 gid_address_type(eid) = GID_ADDR_IP_PREFIX;
5353 gid_address_ippref_len(eid) = mp->prefix_length;
5354 gid_address_ip_version(eid) = IP6;
5355 clib_memcpy (&gid_address_ippref(eid), mp->eid, 16);
5358 gid_address_type(eid) = GID_ADDR_MAC;
5359 clib_memcpy (gid_address_mac(eid), mp->eid, 6);
5362 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5366 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5367 send_lisp_local_eid_table_details(mapit, q, mp->context);
5369 pool_foreach (mapit, lcm->mapping_pool,
5371 send_lisp_local_eid_table_details(mapit, q, mp->context);
5377 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5378 unix_shared_memory_queue_t *q,
5381 vl_api_lisp_gpe_tunnel_details_t *rmp;
5382 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5384 rmp = vl_msg_api_alloc (sizeof (*rmp));
5385 memset (rmp, 0, sizeof (*rmp));
5386 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5388 rmp->tunnels = tunnel - lgm->tunnels;
5390 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5391 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5392 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5394 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5395 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5396 rmp->dcap_next = htonl(tunnel->decap_next_index);
5397 rmp->lisp_ver = tunnel->ver_res;
5398 rmp->next_protocol = tunnel->next_protocol;
5399 rmp->flags = tunnel->flags;
5400 rmp->ver_res = tunnel->ver_res;
5401 rmp->res = tunnel->res;
5402 rmp->iid = htonl(tunnel->vni);
5403 rmp->context = context;
5405 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5409 vl_api_lisp_gpe_tunnel_dump_t_handler (
5410 vl_api_lisp_gpe_tunnel_dump_t *mp)
5412 unix_shared_memory_queue_t * q = NULL;
5413 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5414 lisp_gpe_tunnel_t * tunnel = NULL;
5416 if (pool_elts(lgm->tunnels) == 0) {
5420 q = vl_api_client_index_to_input_queue (mp->client_index);
5425 pool_foreach(tunnel, lgm->tunnels,
5427 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5432 send_lisp_map_resolver_details (ip_address_t *ip,
5433 unix_shared_memory_queue_t *q,
5436 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5438 rmp = vl_msg_api_alloc (sizeof (*rmp));
5439 memset (rmp, 0, sizeof (*rmp));
5440 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5442 switch (ip_addr_version(ip)) {
5445 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5450 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5456 rmp->context = context;
5458 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5462 vl_api_lisp_map_resolver_dump_t_handler (
5463 vl_api_lisp_map_resolver_dump_t *mp)
5465 unix_shared_memory_queue_t * q = NULL;
5466 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5467 ip_address_t *ip = NULL;
5469 q = vl_api_client_index_to_input_queue (mp->client_index);
5474 vec_foreach(ip, lcm->map_resolvers) {
5475 send_lisp_map_resolver_details(ip, q, mp->context);
5481 vl_api_lisp_eid_table_map_dump_t_handler (
5482 vl_api_lisp_eid_table_map_dump_t *mp)
5484 unix_shared_memory_queue_t * q = NULL;
5485 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5488 q = vl_api_client_index_to_input_queue (mp->client_index);
5492 hash_foreach_pair (p, lcm->table_id_by_vni, {
5493 vl_api_lisp_eid_table_map_details_t * rmp = NULL;
5494 memset (rmp, 0, sizeof (*rmp));
5495 rmp->_vl_msg_id = ntohs(VL_API_LISP_EID_TABLE_MAP_DETAILS);
5497 rmp->vrf = p->value[0];
5498 rmp->context = mp->context;
5503 send_lisp_enable_disable_details (unix_shared_memory_queue_t *q,
5506 vl_api_lisp_enable_disable_status_details_t *rmp = NULL;
5508 rmp = vl_msg_api_alloc (sizeof (*rmp));
5509 memset (rmp, 0, sizeof (*rmp));
5510 rmp->_vl_msg_id = ntohs(VL_API_LISP_ENABLE_DISABLE_STATUS_DETAILS);
5512 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5513 rmp->feature_status = vnet_lisp_enable_disable_status ();
5514 rmp->context = context;
5516 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5520 vl_api_lisp_enable_disable_status_dump_t_handler
5521 (vl_api_lisp_enable_disable_status_dump_t *mp)
5523 unix_shared_memory_queue_t * q = NULL;
5525 q = vl_api_client_index_to_input_queue (mp->client_index);
5530 send_lisp_enable_disable_details(q, mp->context);
5534 vl_api_lisp_get_map_request_itr_rlocs_t_handler (
5535 vl_api_lisp_get_map_request_itr_rlocs_t *mp)
5537 unix_shared_memory_queue_t * q = NULL;
5538 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
5539 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5540 locator_set_t * loc_set = 0;
5544 q = vl_api_client_index_to_input_queue (mp->client_index);
5549 if (~0 == lcm->mreq_itr_rlocs) {
5550 tmp_str = format(0, " ");
5552 loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
5553 tmp_str = format(0, "%s", loc_set->name);
5556 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
5558 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5559 ARRAY_LEN(rmp->locator_set_name) - 1);
5566 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5568 vl_api_interface_name_renumber_reply_t * rmp;
5571 VALIDATE_SW_IF_INDEX(mp);
5573 rv = vnet_interface_name_renumber
5574 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5576 BAD_SW_IF_INDEX_LABEL;
5578 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5581 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5582 u32 sw_if_index, u32 address)
5584 vpe_api_main_t * am = &vpe_api_main;
5585 vlib_main_t * vm = am->vlib_main;
5586 vl_api_ip4_arp_event_t * event;
5587 static f64 arp_event_last_time;
5588 f64 now = vlib_time_now (vm);
5590 if (pool_is_free_index (am->arp_events, pool_index))
5593 event = pool_elt_at_index (am->arp_events, pool_index);
5594 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5595 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5596 } else { /* same mac */
5597 if ((sw_if_index == event->sw_if_index) &&
5599 /* for BD case, also check IP address with 10 sec timeout */
5600 ((address == event->address) &&
5601 ((now - arp_event_last_time) < 10.0))))
5605 arp_event_last_time = now;
5606 event->sw_if_index = sw_if_index;
5607 if (address) event->address = address;
5611 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5613 vpe_api_main_t * am = &vpe_api_main;
5615 if (pool_is_free_index (am->arp_events, pool_index))
5618 pool_put_index (am->arp_events, pool_index);
5623 vl_api_want_ip4_arp_events_t_handler
5624 (vl_api_want_ip4_arp_events_t * mp)
5626 vpe_api_main_t * am = &vpe_api_main;
5627 vnet_main_t * vnm = vnet_get_main();
5628 vl_api_want_ip4_arp_events_reply_t *rmp;
5629 vl_api_ip4_arp_event_t * event;
5632 if (mp->enable_disable) {
5633 pool_get (am->arp_events, event);
5634 memset (event, 0, sizeof (*event));
5636 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5637 event->client_index = mp->client_index;
5638 event->context = mp->context;
5639 event->address = mp->address;
5640 event->pid = mp->pid;
5642 rv = vnet_add_del_ip4_arp_change_event
5643 (vnm, arp_change_data_callback,
5645 &mp->address /* addr, in net byte order */,
5646 vpe_resolver_process_node.index,
5647 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5649 rv = vnet_add_del_ip4_arp_change_event
5650 (vnm, arp_change_delete_callback,
5652 &mp->address /* addr, in net byte order */,
5653 vpe_resolver_process_node.index,
5654 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5656 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5659 static void vl_api_input_acl_set_interface_t_handler
5660 (vl_api_input_acl_set_interface_t * mp)
5662 vlib_main_t *vm = vlib_get_main();
5663 vl_api_input_acl_set_interface_reply_t * rmp;
5665 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5667 ip4_table_index = ntohl(mp->ip4_table_index);
5668 ip6_table_index = ntohl(mp->ip6_table_index);
5669 l2_table_index = ntohl(mp->l2_table_index);
5670 sw_if_index = ntohl(mp->sw_if_index);
5672 VALIDATE_SW_IF_INDEX(mp);
5674 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5675 ip6_table_index, l2_table_index,
5678 BAD_SW_IF_INDEX_LABEL;
5680 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5683 static void vl_api_ipsec_spd_add_del_t_handler
5684 (vl_api_ipsec_spd_add_del_t * mp)
5687 clib_warning ("unimplemented");
5690 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5691 vl_api_ipsec_spd_add_del_reply_t * rmp;
5695 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5697 rv = VNET_API_ERROR_UNIMPLEMENTED;
5700 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5704 static void vl_api_ipsec_interface_add_del_spd_t_handler
5705 (vl_api_ipsec_interface_add_del_spd_t * mp)
5707 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5708 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5710 u32 sw_if_index __attribute__((unused));
5711 u32 spd_id __attribute__((unused));
5713 sw_if_index = ntohl(mp->sw_if_index);
5714 spd_id = ntohl(mp->spd_id);
5716 VALIDATE_SW_IF_INDEX(mp);
5719 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5721 rv = VNET_API_ERROR_UNIMPLEMENTED;
5724 BAD_SW_IF_INDEX_LABEL;
5726 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5729 static void vl_api_ipsec_spd_add_del_entry_t_handler
5730 (vl_api_ipsec_spd_add_del_entry_t * mp)
5732 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5733 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5739 memset(&p, 0, sizeof(p));
5741 p.id = ntohl(mp->spd_id);
5742 p.priority = ntohl(mp->priority);
5743 p.is_outbound = mp->is_outbound;
5744 p.is_ipv6 = mp->is_ipv6;
5747 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5748 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5749 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5750 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5752 clib_memcpy(&p.raddr.start.ip4.data, mp->remote_address_start, 4);
5753 clib_memcpy(&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
5754 clib_memcpy(&p.laddr.start.ip4.data, mp->local_address_start, 4);
5755 clib_memcpy(&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
5757 p.protocol = mp->protocol;
5758 p.rport.start = ntohs(mp->remote_port_start);
5759 p.rport.stop = ntohs(mp->remote_port_stop);
5760 p.lport.start = ntohs(mp->local_port_start);
5761 p.lport.stop = ntohs(mp->local_port_stop);
5762 /* policy action resolve unsupported */
5763 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5764 clib_warning("unsupported action: 'resolve'");
5765 rv = VNET_API_ERROR_UNIMPLEMENTED;
5768 p.policy = mp->policy;
5769 p.sa_id = ntohl(mp->sa_id);
5771 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5775 if (mp->is_ip_any) {
5777 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5780 rv = VNET_API_ERROR_UNIMPLEMENTED;
5785 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5788 static void vl_api_ipsec_sad_add_del_entry_t_handler
5789 (vl_api_ipsec_sad_add_del_entry_t * mp)
5791 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5792 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5797 memset(&sa, 0, sizeof(sa));
5799 sa.id = ntohl(mp->sad_id);
5800 sa.spi = ntohl(mp->spi);
5801 /* security protocol AH unsupported */
5802 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5803 clib_warning("unsupported security protocol 'AH'");
5804 rv = VNET_API_ERROR_UNIMPLEMENTED;
5807 sa.protocol = mp->protocol;
5808 /* check for unsupported crypto-alg */
5809 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5810 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5811 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5812 mp->crypto_algorithm);
5813 rv = VNET_API_ERROR_UNIMPLEMENTED;
5816 sa.crypto_alg = mp->crypto_algorithm;
5817 sa.crypto_key_len = mp->crypto_key_length;
5818 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5819 /* check for unsupported integ-alg */
5820 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5821 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5822 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5823 mp->integrity_algorithm);
5824 rv = VNET_API_ERROR_UNIMPLEMENTED;
5827 sa.integ_alg = mp->integrity_algorithm;
5828 sa.integ_key_len = mp->integrity_key_length;
5829 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5830 sa.use_esn = mp->use_extended_sequence_number;
5831 sa.is_tunnel = mp->is_tunnel;
5832 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5833 if (sa.is_tunnel_ip6) {
5834 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5835 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5837 clib_memcpy(&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
5838 clib_memcpy(&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
5841 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5843 rv = VNET_API_ERROR_UNIMPLEMENTED;
5848 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5852 vl_api_ikev2_profile_add_del_t_handler
5853 (vl_api_ikev2_profile_add_del_t * mp)
5855 vl_api_ikev2_profile_add_del_reply_t * rmp;
5859 vlib_main_t * vm = vlib_get_main();
5860 clib_error_t * error;
5861 u8 * tmp = format(0, "%s", mp->name);
5862 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5865 rv = VNET_API_ERROR_UNSPECIFIED;
5867 rv = VNET_API_ERROR_UNIMPLEMENTED;
5870 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5874 vl_api_ikev2_profile_set_auth_t_handler
5875 (vl_api_ikev2_profile_set_auth_t * mp)
5877 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5881 vlib_main_t * vm = vlib_get_main();
5882 clib_error_t * error;
5883 u8 * tmp = format(0, "%s", mp->name);
5884 u8 * data = vec_new (u8, mp->data_len);
5885 clib_memcpy(data, mp->data, mp->data_len);
5886 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5890 rv = VNET_API_ERROR_UNSPECIFIED;
5892 rv = VNET_API_ERROR_UNIMPLEMENTED;
5895 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5899 vl_api_ikev2_profile_set_id_t_handler
5900 (vl_api_ikev2_profile_set_id_t * mp)
5902 vl_api_ikev2_profile_add_del_reply_t * rmp;
5906 vlib_main_t * vm = vlib_get_main();
5907 clib_error_t * error;
5908 u8 * tmp = format(0, "%s", mp->name);
5909 u8 * data = vec_new (u8, mp->data_len);
5910 clib_memcpy(data, mp->data, mp->data_len);
5911 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
5915 rv = VNET_API_ERROR_UNSPECIFIED;
5917 rv = VNET_API_ERROR_UNIMPLEMENTED;
5920 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5924 vl_api_ikev2_profile_set_ts_t_handler
5925 (vl_api_ikev2_profile_set_ts_t * mp)
5927 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5931 vlib_main_t * vm = vlib_get_main();
5932 clib_error_t * error;
5933 u8 * tmp = format(0, "%s", mp->name);
5934 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
5935 mp->end_port, (ip4_address_t) mp->start_addr,
5936 (ip4_address_t) mp->end_addr, mp->is_local);
5939 rv = VNET_API_ERROR_UNSPECIFIED;
5941 rv = VNET_API_ERROR_UNIMPLEMENTED;
5944 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5948 vl_api_ikev2_set_local_key_t_handler
5949 (vl_api_ikev2_set_local_key_t * mp)
5951 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5955 vlib_main_t * vm = vlib_get_main();
5956 clib_error_t * error;
5958 error = ikev2_set_local_key(vm, mp->key_file);
5960 rv = VNET_API_ERROR_UNSPECIFIED;
5962 rv = VNET_API_ERROR_UNIMPLEMENTED;
5965 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5969 vl_api_map_add_domain_t_handler
5970 (vl_api_map_add_domain_t * mp)
5972 vl_api_map_add_domain_reply_t * rmp;
5975 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
5976 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
5977 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
5978 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
5979 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
5981 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
5983 rmp->index = ntohl(index);
5988 vl_api_map_del_domain_t_handler
5989 (vl_api_map_del_domain_t * mp)
5991 vl_api_map_del_domain_reply_t * rmp;
5994 rv = map_delete_domain(ntohl(mp->index));
5996 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
6000 vl_api_map_add_del_rule_t_handler
6001 (vl_api_map_add_del_rule_t * mp)
6003 vl_api_map_del_domain_reply_t * rmp;
6006 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
6008 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
6012 vl_api_map_domain_dump_t_handler
6013 (vl_api_map_domain_dump_t * mp)
6015 vl_api_map_domain_details_t * rmp;
6016 map_main_t *mm = &map_main;
6018 unix_shared_memory_queue_t * q;
6020 if (pool_elts (mm->domains) == 0)
6023 q = vl_api_client_index_to_input_queue (mp->client_index);
6028 pool_foreach(d, mm->domains, ({
6029 /* Make sure every field is initiated (or don't skip the memset()) */
6030 rmp = vl_msg_api_alloc (sizeof (*rmp));
6031 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6032 rmp->domain_index = htonl(d - mm->domains);
6033 rmp->ea_bits_len = d->ea_bits_len;
6034 rmp->psid_offset = d->psid_offset;
6035 rmp->psid_length = d->psid_length;
6036 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6037 rmp->ip4_prefix_len = d->ip4_prefix_len;
6038 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6039 rmp->ip6_prefix_len = d->ip6_prefix_len;
6040 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6041 rmp->ip6_src_len = d->ip6_src_len;
6042 rmp->mtu = htons(d->mtu);
6043 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6044 rmp->context = mp->context;
6046 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6051 vl_api_map_rule_dump_t_handler
6052 (vl_api_map_rule_dump_t * mp)
6054 unix_shared_memory_queue_t * q;
6057 vl_api_map_rule_details_t * rmp;
6058 map_main_t *mm = &map_main;
6059 u32 domain_index = ntohl(mp->domain_index);
6062 if (pool_elts (mm->domains) == 0)
6065 d = pool_elt_at_index(mm->domains, domain_index);
6066 if (!d || !d->rules) {
6070 q = vl_api_client_index_to_input_queue (mp->client_index);
6075 for (i = 0; i < (0x1 << d->psid_length); i++) {
6077 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
6080 rmp = vl_msg_api_alloc(sizeof(*rmp));
6081 memset(rmp, 0, sizeof(*rmp));
6082 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
6083 rmp->psid = htons(i);
6084 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
6085 rmp->context = mp->context;
6086 vl_msg_api_send_shmem(q, (u8 *)&rmp);
6091 vl_api_map_summary_stats_t_handler (
6092 vl_api_map_summary_stats_t *mp)
6094 vl_api_map_summary_stats_reply_t *rmp;
6095 vlib_combined_counter_main_t *cm;
6098 u64 total_pkts[VLIB_N_RX_TX];
6099 u64 total_bytes[VLIB_N_RX_TX];
6100 map_main_t *mm = &map_main;
6101 unix_shared_memory_queue_t *q =
6102 vl_api_client_index_to_input_queue(mp->client_index);
6107 rmp = vl_msg_api_alloc (sizeof (*rmp));
6108 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
6109 rmp->context = mp->context;
6112 memset (total_pkts, 0, sizeof (total_pkts));
6113 memset (total_bytes, 0, sizeof (total_bytes));
6115 map_domain_counter_lock (mm);
6116 vec_foreach(cm, mm->domain_counters) {
6117 which = cm - mm->domain_counters;
6119 for (i = 0; i < vec_len(cm->maxi); i++) {
6120 vlib_get_combined_counter (cm, i, &v);
6121 total_pkts[which] += v.packets;
6122 total_bytes[which] += v.bytes;
6126 map_domain_counter_unlock (mm);
6128 /* Note: in network byte order! */
6129 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
6130 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
6131 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
6132 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
6133 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
6134 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6135 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));
6136 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));
6138 vl_msg_api_send_shmem(q, (u8 *)&rmp);
6141 static void vl_api_ipsec_sa_set_key_t_handler
6142 (vl_api_ipsec_sa_set_key_t * mp)
6144 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
6145 vl_api_ipsec_sa_set_key_reply_t *rmp;
6149 sa.id = ntohl(mp->sa_id);
6150 sa.crypto_key_len = mp->crypto_key_length;
6151 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
6152 sa.integ_key_len = mp->integrity_key_length;
6153 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
6155 rv = ipsec_set_sa_key(vm, &sa);
6157 rv = VNET_API_ERROR_UNIMPLEMENTED;
6160 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
6163 static void vl_api_cop_interface_enable_disable_t_handler
6164 (vl_api_cop_interface_enable_disable_t * mp)
6166 vl_api_cop_interface_enable_disable_reply_t * rmp;
6168 u32 sw_if_index = ntohl(mp->sw_if_index);
6171 VALIDATE_SW_IF_INDEX(mp);
6173 enable_disable = (int) mp->enable_disable;
6175 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6177 BAD_SW_IF_INDEX_LABEL;
6179 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6182 static void vl_api_cop_whitelist_enable_disable_t_handler
6183 (vl_api_cop_whitelist_enable_disable_t * mp)
6185 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
6186 cop_whitelist_enable_disable_args_t _a, *a=&_a;
6187 u32 sw_if_index = ntohl(mp->sw_if_index);
6190 VALIDATE_SW_IF_INDEX(mp);
6192 a->sw_if_index = sw_if_index;
6195 a->default_cop = mp->default_cop;
6196 a->fib_id = ntohl(mp->fib_id);
6198 rv = cop_whitelist_enable_disable (a);
6200 BAD_SW_IF_INDEX_LABEL;
6202 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
6205 static void vl_api_get_node_graph_t_handler
6206 (vl_api_get_node_graph_t * mp)
6210 api_main_t * am = &api_main;
6211 vlib_main_t * vm = vlib_get_main();
6213 vl_api_get_node_graph_reply_t * rmp;
6215 pthread_mutex_lock (&am->vlib_rp->mutex);
6216 oldheap = svm_push_data_heap (am->vlib_rp);
6219 * Keep the number of memcpy ops to a minimum (e.g. 1).
6221 vec_validate (vector, 16384);
6222 vec_reset_length (vector);
6225 vector = vlib_node_serialize (&vm->node_main, vector,
6226 (u32)~0 /* all threads */,
6227 1 /* include nexts */,
6228 1 /* include stats */);
6230 svm_pop_heap (oldheap);
6231 pthread_mutex_unlock (&am->vlib_rp->mutex);
6233 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
6234 rmp->reply_in_shmem = (uword) vector);
6237 static void vl_api_trace_profile_add_t_handler
6238 (vl_api_trace_profile_add_t *mp)
6241 vl_api_trace_profile_add_reply_t * rmp;
6242 clib_error_t *error;
6244 /* Ignoring the profile id as currently a single profile
6246 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
6247 ntohl(mp->node_id), ntohl(mp->trace_app_data),
6248 mp->pow_enable, mp->trace_tsp,
6251 clib_error_report(error);
6252 rv = clib_error_get_code(error);
6255 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
6258 static void vl_api_trace_profile_apply_t_handler
6259 (vl_api_trace_profile_apply_t *mp)
6262 vl_api_trace_profile_apply_reply_t * rmp;
6264 if (mp->enable != 0) {
6265 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
6266 ntohl(mp->prefix_length),
6268 mp->trace_op == IOAM_HBYH_ADD,
6269 mp->trace_op == IOAM_HBYH_POP,
6270 mp->trace_op == IOAM_HBYH_MOD);
6272 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
6274 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
6277 static void vl_api_trace_profile_del_t_handler
6278 (vl_api_trace_profile_del_t *mp)
6281 vl_api_trace_profile_del_reply_t * rmp;
6282 clib_error_t *error;
6284 error = clear_ioam_rewrite_fn();
6286 clib_error_report(error);
6287 rv = clib_error_get_code(error);
6290 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
6294 vl_api_af_packet_create_t_handler
6295 (vl_api_af_packet_create_t *mp)
6297 vlib_main_t *vm = vlib_get_main();
6298 vl_api_af_packet_create_reply_t *rmp;
6300 u8 *host_if_name = NULL;
6303 host_if_name = format(0, "%s", mp->host_if_name);
6304 vec_add1 (host_if_name, 0);
6306 rv = af_packet_create_if(vm, host_if_name,
6307 mp->use_random_hw_addr ? 0 : mp->hw_addr, &sw_if_index);
6309 vec_free(host_if_name);
6311 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
6312 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index));
6316 vl_api_af_packet_delete_t_handler
6317 (vl_api_af_packet_delete_t *mp)
6319 vlib_main_t * vm = vlib_get_main();
6320 vl_api_af_packet_delete_reply_t *rmp;
6322 u8 *host_if_name = NULL;
6324 host_if_name = format(0, "%s", mp->host_if_name);
6325 vec_add1 (host_if_name, 0);
6327 rv = af_packet_delete_if(vm, host_if_name);
6329 vec_free(host_if_name);
6331 REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY);
6335 vl_api_policer_add_del_t_handler
6336 (vl_api_policer_add_del_t *mp)
6338 vlib_main_t * vm = vlib_get_main();
6339 vl_api_policer_add_del_reply_t *rmp;
6342 sse2_qos_pol_cfg_params_st cfg;
6343 clib_error_t * error;
6345 name = format(0, "%s", mp->name);
6347 memset (&cfg, 0, sizeof (cfg));
6349 cfg.rnd_type = mp->round_type;
6350 cfg.rate_type = mp->rate_type;
6351 cfg.rb.kbps.cir_kbps = mp->cir;
6352 cfg.rb.kbps.eir_kbps = mp->eir;
6353 cfg.rb.kbps.cb_bytes = mp->cb;
6354 cfg.rb.kbps.eb_bytes = mp->eb;
6356 error = policer_add_del(vm, name, &cfg, mp->is_add);
6359 rv = VNET_API_ERROR_UNSPECIFIED;
6361 REPLY_MACRO(VL_API_POLICER_ADD_DEL_REPLY);
6365 send_policer_details (u8 *name,
6366 sse2_qos_pol_cfg_params_st *config,
6367 policer_read_response_type_st *templ,
6368 unix_shared_memory_queue_t *q,
6371 vl_api_policer_details_t * mp;
6373 mp = vl_msg_api_alloc (sizeof (*mp));
6374 memset (mp, 0, sizeof (*mp));
6375 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
6376 mp->context = context;
6377 mp->cir = htonl(config->rb.kbps.cir_kbps);
6378 mp->eir = htonl(config->rb.kbps.eir_kbps);
6379 mp->cb = htonl(config->rb.kbps.cb_bytes);
6380 mp->eb = htonl(config->rb.kbps.eb_bytes);
6381 mp->rate_type = config->rate_type;
6382 mp->round_type = config->rnd_type;
6383 mp->type = config->rfc;
6384 mp->single_rate = templ->single_rate ? 1 : 0;
6385 mp->color_aware = templ->color_aware ? 1 : 0;
6386 mp->scale = htonl(templ->scale);
6387 mp->cir_tokens_per_period = htonl(templ->cir_tokens_per_period);
6388 mp->pir_tokens_per_period = htonl(templ->pir_tokens_per_period);
6389 mp->current_limit = htonl(templ->current_limit);
6390 mp->current_bucket = htonl(templ->current_bucket);
6391 mp->extended_limit = htonl(templ->extended_limit);
6392 mp->extended_bucket = htonl(templ->extended_bucket);
6393 mp->last_update_time = clib_host_to_net_u64(templ->last_update_time);
6395 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN(mp->name) - 1);
6397 vl_msg_api_send_shmem (q, (u8 *)&mp);
6401 vl_api_policer_dump_t_handler
6402 (vl_api_policer_dump_t *mp)
6404 unix_shared_memory_queue_t * q;
6405 vnet_policer_main_t * pm = &vnet_policer_main;
6409 u8 * match_name = 0;
6411 sse2_qos_pol_cfg_params_st *config;
6412 policer_read_response_type_st *templ;
6414 q = vl_api_client_index_to_input_queue (mp->client_index);
6418 if (mp->match_name_valid) {
6419 match_name = format(0, "%s%c", mp->match_name, 0);
6422 if (mp->match_name_valid) {
6423 p = hash_get_mem (pm->policer_config_by_name, match_name);
6426 config = pool_elt_at_index (pm->configs, pool_index);
6427 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6428 send_policer_details(match_name, config, templ, q, mp->context);
6431 hash_foreach_pair (hp, pm->policer_config_by_name,
6433 name = (u8 *) hp->key;
6434 pool_index = hp->value[0];
6435 config = pool_elt_at_index (pm->configs, pool_index);
6436 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6437 send_policer_details(name, config, templ, q, mp->context);
6443 vl_api_netmap_create_t_handler
6444 (vl_api_netmap_create_t *mp)
6446 vlib_main_t *vm = vlib_get_main();
6447 vl_api_netmap_create_reply_t *rmp;
6451 if_name = format(0, "%s", mp->netmap_if_name);
6452 vec_add1 (if_name, 0);
6454 rv = netmap_create_if(vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
6455 mp->is_pipe, mp->is_master, 0);
6459 REPLY_MACRO(VL_API_NETMAP_CREATE_REPLY);
6463 vl_api_netmap_delete_t_handler
6464 (vl_api_netmap_delete_t *mp)
6466 vlib_main_t * vm = vlib_get_main();
6467 vl_api_netmap_delete_reply_t *rmp;
6471 if_name = format(0, "%s", mp->netmap_if_name);
6472 vec_add1 (if_name, 0);
6474 rv = netmap_delete_if(vm, if_name);
6478 REPLY_MACRO(VL_API_NETMAP_DELETE_REPLY);
6481 static void vl_api_mpls_gre_tunnel_details_t_handler (
6482 vl_api_mpls_gre_tunnel_details_t * mp)
6484 clib_warning ("BUG");
6487 static void send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
6488 unix_shared_memory_queue_t *q,
6489 mpls_gre_tunnel_t * gt,
6493 vl_api_mpls_gre_tunnel_details_t * mp;
6495 mp = vl_msg_api_alloc (sizeof (*mp));
6496 memset (mp, 0, sizeof (*mp));
6497 mp->_vl_msg_id = ntohs(VL_API_MPLS_GRE_TUNNEL_DETAILS);
6498 mp->context = context;
6501 mp->tunnel_index = htonl(index);
6502 mp->tunnel_src = gt->tunnel_src.as_u32;
6503 mp->tunnel_dst = gt->tunnel_dst.as_u32;
6504 mp->intfc_address = gt->intfc_address.as_u32;
6505 mp->mask_width = htonl(gt->mask_width);
6506 mp->inner_fib_index = htonl(gt->inner_fib_index);
6507 mp->outer_fib_index = htonl(gt->outer_fib_index);
6508 mp->encap_index = htonl(gt->encap_index);
6509 mp->hw_if_index = htonl(gt->hw_if_index);
6510 mp->l2_only = htonl(gt->l2_only);
6513 mpls_main_t * mm = &mpls_main;
6518 e = pool_elt_at_index (mm->encaps, gt->encap_index);
6519 len = vec_len (e->labels);
6520 mp->nlabels = htonl(len);
6522 for (i = 0; i < len; i++) {
6523 mp->labels[i] = htonl(vnet_mpls_uc_get_label(
6524 clib_host_to_net_u32(e->labels[i].label_exp_s_ttl)));
6527 vl_msg_api_send_shmem (q, (u8 *)&mp);
6531 vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t *mp)
6533 vpe_api_main_t * am = &vpe_api_main;
6534 unix_shared_memory_queue_t * q;
6535 vlib_main_t * vm = &vlib_global_main;
6536 mpls_main_t * mm = &mpls_main;
6537 mpls_gre_tunnel_t * gt;
6538 u32 index = ntohl(mp->tunnel_index);
6540 q = vl_api_client_index_to_input_queue (mp->client_index);
6544 if (pool_elts (mm->gre_tunnels)) {
6545 if(mp->tunnel_index >= 0) {
6546 vlib_cli_output (vm, "MPLS-GRE tunnel %u", index);
6547 gt = pool_elt_at_index (mm->gre_tunnels, index);
6548 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels, mp->context);
6550 vlib_cli_output (vm, "MPLS-GRE tunnels");
6551 pool_foreach (gt, mm->gre_tunnels,
6553 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels, mp->context);
6557 vlib_cli_output (vm, "No MPLS-GRE tunnels");
6561 static void vl_api_mpls_eth_tunnel_details_t_handler (
6562 vl_api_mpls_eth_tunnel_details_t * mp)
6564 clib_warning ("BUG");
6567 static void send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
6568 unix_shared_memory_queue_t *q,
6569 mpls_eth_tunnel_t * et,
6573 vl_api_mpls_eth_tunnel_details_t * mp;
6575 mp = vl_msg_api_alloc (sizeof (*mp));
6576 memset (mp, 0, sizeof (*mp));
6577 mp->_vl_msg_id = ntohs(VL_API_MPLS_ETH_TUNNEL_DETAILS);
6578 mp->context = context;
6581 mp->tunnel_index = htonl(index);
6582 memcpy(mp->tunnel_dst_mac, et->tunnel_dst, 6);
6583 mp->intfc_address = et->intfc_address.as_u32;
6584 mp->tx_sw_if_index = htonl(et->tx_sw_if_index);
6585 mp->inner_fib_index = htonl(et->inner_fib_index);
6586 mp->mask_width = htonl(et->mask_width);
6587 mp->encap_index = htonl(et->encap_index);
6588 mp->hw_if_index = htonl(et->hw_if_index);
6589 mp->l2_only = htonl(et->l2_only);
6592 mpls_main_t * mm = &mpls_main;
6597 e = pool_elt_at_index (mm->encaps, et->encap_index);
6598 len = vec_len (e->labels);
6599 mp->nlabels = htonl(len);
6601 for (i = 0; i < len; i++) {
6602 mp->labels[i] = htonl(vnet_mpls_uc_get_label(
6603 clib_host_to_net_u32(e->labels[i].label_exp_s_ttl)));
6606 vl_msg_api_send_shmem (q, (u8 *)&mp);
6610 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t *mp)
6612 vpe_api_main_t * am = &vpe_api_main;
6613 unix_shared_memory_queue_t * q;
6614 vlib_main_t * vm = &vlib_global_main;
6615 mpls_main_t * mm = &mpls_main;
6616 mpls_eth_tunnel_t * et;
6617 u32 index = ntohl(mp->tunnel_index);
6619 q = vl_api_client_index_to_input_queue (mp->client_index);
6623 clib_warning("Received mpls_eth_tunnel_dump");
6624 clib_warning("Received tunnel index: %u from client %u", index, mp->client_index);
6626 if (pool_elts (mm->eth_tunnels)) {
6627 if(mp->tunnel_index >= 0) {
6628 vlib_cli_output (vm, "MPLS-Ethernet tunnel %u", index);
6629 et = pool_elt_at_index (mm->eth_tunnels, index);
6630 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels, mp->context);
6632 clib_warning("MPLS-Ethernet tunnels");
6633 pool_foreach (et, mm->eth_tunnels,
6635 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels, mp->context);
6639 clib_warning("No MPLS-Ethernet tunnels");
6643 static void vl_api_mpls_fib_encap_details_t_handler (
6644 vl_api_mpls_fib_encap_details_t * mp)
6646 clib_warning ("BUG");
6649 static void send_mpls_fib_encap_details (vpe_api_main_t * am,
6650 unix_shared_memory_queue_t *q,
6654 vl_api_mpls_fib_encap_details_t * mp;
6656 mp = vl_msg_api_alloc (sizeof (*mp));
6657 memset (mp, 0, sizeof (*mp));
6658 mp->_vl_msg_id = ntohs(VL_API_MPLS_FIB_ENCAP_DETAILS);
6659 mp->context = context;
6661 mp->fib_index = htonl(s->fib_index);
6662 mp->entry_index = htonl(s->entry_index);
6664 mp->s_bit = htonl(s->s_bit);
6666 mpls_main_t * mm = &mpls_main;
6671 e = pool_elt_at_index (mm->encaps, s->entry_index);
6672 len = vec_len (e->labels);
6673 mp->nlabels = htonl(len);
6675 for (i = 0; i < len; i++) {
6676 mp->labels[i] = htonl(vnet_mpls_uc_get_label(
6677 clib_host_to_net_u32(e->labels[i].label_exp_s_ttl)));
6680 vl_msg_api_send_shmem (q, (u8 *)&mp);
6684 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t *mp)
6686 vpe_api_main_t * am = &vpe_api_main;
6687 unix_shared_memory_queue_t * q;
6688 vlib_main_t * vm = &vlib_global_main;
6691 show_mpls_fib_t *records = 0;
6693 mpls_main_t * mm = &mpls_main;
6694 ip4_main_t * im = &ip4_main;
6697 q = vl_api_client_index_to_input_queue (mp->client_index);
6701 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
6703 vec_add2 (records, s, 1);
6704 s->fib_index = (u32)(key>>32);
6705 s->dest = (u32)(key & 0xFFFFFFFF);
6706 s->entry_index = (u32) value;
6709 if (0 == vec_len(records)) {
6710 vlib_cli_output(vm, "MPLS encap table empty");
6714 /* sort output by dst address within fib */
6715 vec_sort_with_function(records, mpls_dest_cmp);
6716 vec_sort_with_function(records, mpls_fib_index_cmp);
6717 vlib_cli_output(vm, "MPLS encap table");
6718 vlib_cli_output(vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
6719 vec_foreach (s, records)
6721 rx_fib = vec_elt_at_index(im->fibs, s->fib_index);
6722 vlib_cli_output(vm, "%=6d%=16U%=16U", rx_fib->table_id,
6723 format_ip4_address, &s->dest, format_mpls_encap_index, mm,
6725 send_mpls_fib_encap_details (am, q, s, mp->context);
6732 static void vl_api_mpls_fib_decap_details_t_handler (
6733 vl_api_mpls_fib_decap_details_t * mp)
6735 clib_warning ("BUG");
6738 static void send_mpls_fib_decap_details (vpe_api_main_t * am,
6739 unix_shared_memory_queue_t *q,
6746 vl_api_mpls_fib_decap_details_t * mp;
6748 mp = vl_msg_api_alloc (sizeof (*mp));
6749 memset (mp, 0, sizeof (*mp));
6750 mp->_vl_msg_id = ntohs(VL_API_MPLS_FIB_DECAP_DETAILS);
6751 mp->context = context;
6753 mp->fib_index = htonl(s->fib_index);
6754 mp->entry_index = htonl(s->entry_index);
6756 mp->s_bit = htonl(s->s_bit);
6757 mp->label = htonl(s->label);
6758 mp->rx_table_id = htonl(rx_table_id);
6759 mp->tx_table_id = htonl(tx_table_id);
6760 strncpy ((char *) mp->swif_tag,
6761 (char *) swif_tag, ARRAY_LEN(mp->swif_tag)-1);
6763 vl_msg_api_send_shmem (q, (u8 *)&mp);
6767 vl_api_mpls_fib_decap_dump_t_handler (vl_api_mpls_fib_decap_dump_t *mp)
6769 vpe_api_main_t * am = &vpe_api_main;
6770 unix_shared_memory_queue_t * q;
6771 vlib_main_t * vm = &vlib_global_main;
6774 show_mpls_fib_t *records = 0;
6776 mpls_main_t * mm = &mpls_main;
6777 ip4_main_t * im = &ip4_main;
6783 q = vl_api_client_index_to_input_queue (mp->client_index);
6787 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
6789 vec_add2 (records, s, 1);
6790 s->fib_index = (u32)(key>>32);
6791 s->entry_index = (u32) value;
6792 s->label = ((u32) key)>>12;
6793 s->s_bit = (key & (1<<8)) != 0;
6796 if (!vec_len(records)) {
6797 vlib_cli_output(vm, "MPLS decap table empty");
6801 vec_sort_with_function(records, mpls_label_cmp);
6802 vlib_cli_output(vm, "MPLS decap table");
6803 vlib_cli_output(vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
6805 vec_foreach (s, records)
6808 d = pool_elt_at_index(mm->decaps, s->entry_index);
6809 if (d->next_index == MPLS_INPUT_NEXT_IP4_INPUT) {
6810 tx_fib = vec_elt_at_index(im->fibs, d->tx_fib_index);
6811 tx_table_id = tx_fib->table_id;
6814 tx_table_id = d->tx_fib_index;
6817 rx_fib = vec_elt_at_index(im->fibs, s->fib_index);
6819 vlib_cli_output(vm, "%=10d%=10d%=5s%=6d%=6d", rx_fib->table_id,
6820 tx_table_id, swif_tag, s->label, s->s_bit);
6822 send_mpls_fib_decap_details (am, q, s, rx_fib->table_id,
6823 tx_table_id, swif_tag, mp->context);
6830 static void vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t *mp)
6832 unix_shared_memory_queue_t * q;
6834 q = vl_api_client_index_to_input_queue (mp->client_index);
6838 vnet_classify_main_t * cm = &vnet_classify_main;
6839 vnet_classify_table_t * t;
6840 u32 * table_ids = 0;
6843 pool_foreach (t, cm->tables,
6845 vec_add1 (table_ids, ntohl(t - cm->tables));
6847 count = vec_len(table_ids);
6849 vl_api_classify_table_ids_reply_t *rmp;
6850 rmp = vl_msg_api_alloc_as_if_client(sizeof (*rmp) + count);
6851 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
6852 rmp->context = mp->context;
6853 rmp->count = ntohl(count);
6854 clib_memcpy(rmp->ids, table_ids, count * sizeof(u32));
6857 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6859 vec_free (table_ids);
6862 static void vl_api_classify_table_by_interface_t_handler (vl_api_classify_table_by_interface_t *mp)
6864 vl_api_classify_table_by_interface_reply_t *rmp;
6867 u32 sw_if_index = ntohl(mp->sw_if_index);
6870 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
6873 VALIDATE_SW_IF_INDEX(mp);
6875 input_acl_main_t * am = &input_acl_main;
6880 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
6882 u32 * vec_tbl = am->classify_table_index_by_sw_if_index[type];
6883 if (vec_len(vec_tbl)) {
6884 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
6886 if (vec_elt(vec_tbl, if_idx) == ~0 || sw_if_index != if_idx) {
6889 acl[type] = vec_elt(vec_tbl, if_idx);
6894 BAD_SW_IF_INDEX_LABEL;
6896 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
6898 rmp->sw_if_index = ntohl(sw_if_index);
6899 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
6900 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
6901 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
6906 static void vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t *mp)
6908 unix_shared_memory_queue_t * q;
6910 q = vl_api_client_index_to_input_queue (mp->client_index);
6914 vl_api_classify_table_info_reply_t *rmp = 0;
6916 vnet_classify_main_t * cm = &vnet_classify_main;
6917 u32 table_id = ntohl(mp->table_id);
6918 vnet_classify_table_t * t;
6920 pool_foreach (t, cm->tables,
6922 if (table_id == t - cm->tables) {
6923 rmp = vl_msg_api_alloc_as_if_client(sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
6924 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
6925 rmp->context = mp->context;
6926 rmp->table_id = ntohl(table_id);
6927 rmp->nbuckets = ntohl(t->nbuckets);
6928 rmp->match_n_vectors = ntohl(t->match_n_vectors);
6929 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
6930 rmp->active_sessions = ntohl(t->active_elements);
6931 rmp->next_table_index = ntohl(t->next_table_index);
6932 rmp->miss_next_index = ntohl(t->miss_next_index);
6933 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
6934 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
6941 rmp = vl_msg_api_alloc (sizeof (*rmp));
6942 rmp->_vl_msg_id = ntohs((VL_API_CLASSIFY_TABLE_INFO_REPLY));
6943 rmp->context = mp->context;
6944 rmp->retval = ntohl(VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
6947 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6950 static void vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t * mp)
6952 clib_warning ("BUG");
6955 static void send_classify_session_details (unix_shared_memory_queue_t * q,
6958 vnet_classify_entry_t * e,
6961 vl_api_classify_session_details_t *rmp;
6963 rmp = vl_msg_api_alloc (sizeof (*rmp));
6964 memset (rmp, 0, sizeof (*rmp));
6965 rmp->_vl_msg_id = ntohs(VL_API_CLASSIFY_SESSION_DETAILS);
6966 rmp->context = context;
6967 rmp->table_id = ntohl(table_id);
6968 rmp->hit_next_index = ntohl(e->next_index);
6969 rmp->advance = ntohl(e->advance);
6970 rmp->opaque_index = ntohl(e->opaque_index);
6971 rmp->match_length = ntohl(match_length);
6972 clib_memcpy(rmp->match, e->key, match_length);
6974 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6977 static void vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t *mp)
6979 vnet_classify_main_t * cm = &vnet_classify_main;
6980 unix_shared_memory_queue_t * q;
6982 u32 table_id = ntohl(mp->table_id);
6983 vnet_classify_table_t * t;
6985 q = vl_api_client_index_to_input_queue (mp->client_index);
6987 pool_foreach (t, cm->tables,
6989 if (table_id == t - cm->tables) {
6990 vnet_classify_bucket_t * b;
6991 vnet_classify_entry_t * v, * save_v;
6994 for (i = 0; i < t->nbuckets; i++)
6996 b = &t->buckets [i];
7000 save_v = vnet_classify_get_entry (t, b->offset);
7001 for (j = 0; j < (1<<b->log2_pages); j++)
7003 for (k = 0; k < t->entries_per_page; k++)
7005 v = vnet_classify_entry_at_index (t, save_v, j*t->entries_per_page + k);
7006 if (vnet_classify_entry_is_free (v))
7009 send_classify_session_details(q, table_id,
7010 t->match_n_vectors * sizeof (u32x4), v, mp->context);
7019 #define BOUNCE_HANDLER(nn) \
7020 static void vl_api_##nn##_t_handler ( \
7021 vl_api_##nn##_t *mp) \
7023 vpe_client_registration_t *reg; \
7024 vpe_api_main_t * vam = &vpe_api_main; \
7025 unix_shared_memory_queue_t * q; \
7027 /* One registration only... */ \
7028 pool_foreach(reg, vam->nn##_registrations, \
7030 q = vl_api_client_index_to_input_queue (reg->client_index); \
7033 * If the queue is stuffed, turf the msg and complain \
7034 * It's unlikely that the intended recipient is \
7035 * alive; avoid deadlock at all costs. \
7037 if (q->cursize == q->maxsize) { \
7038 clib_warning ("ERROR: receiver queue full, drop msg"); \
7039 vl_msg_api_free (mp); \
7042 vl_msg_api_send_shmem (q, (u8 *)&mp); \
7046 vl_msg_api_free (mp); \
7051 * Add vpe's API message handlers to the table.
7052 * vlib has alread mapped shared memory and
7053 * added the client registration handlers.
7054 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
7057 static clib_error_t *
7058 vpe_api_hookup (vlib_main_t *vm)
7060 api_main_t * am = &api_main;
7063 vl_msg_api_set_handlers(VL_API_##N, #n, \
7064 vl_api_##n##_t_handler, \
7066 vl_api_##n##_t_endian, \
7067 vl_api_##n##_t_print, \
7068 sizeof(vl_api_##n##_t), 1);
7069 foreach_vpe_api_msg;
7073 * Manually register the sr tunnel add del msg, so we trace
7074 * enough bytes to capture a typical segment list
7076 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
7077 "sr_tunnel_add_del",
7078 vl_api_sr_tunnel_add_del_t_handler,
7080 vl_api_sr_tunnel_add_del_t_endian,
7081 vl_api_sr_tunnel_add_del_t_print,
7086 * Manually register the sr policy add del msg, so we trace
7087 * enough bytes to capture a typical tunnel name list
7089 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
7090 "sr_policy_add_del",
7091 vl_api_sr_policy_add_del_t_handler,
7093 vl_api_sr_policy_add_del_t_endian,
7094 vl_api_sr_policy_add_del_t_print,
7098 * Trace space for 8 MPLS encap labels, classifier mask+match
7100 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
7101 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
7102 += 5 * sizeof (u32x4);
7103 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
7104 += 5 * sizeof (u32x4);
7105 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
7106 += 16 * sizeof (u32);
7109 * Thread-safe API messages
7111 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
7112 am->is_mp_safe [VL_API_GET_NODE_GRAPH] = 1;
7117 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
7119 static clib_error_t *
7120 vpe_api_init (vlib_main_t *vm)
7122 vpe_api_main_t *am = &vpe_api_main;
7125 am->vnet_main = vnet_get_main();
7126 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
7127 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
7128 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
7129 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
7130 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
7131 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
7134 vl_set_memory_region_name ("/vpe-api");
7135 vl_enable_disable_memory_api (vm, 1 /* enable it */);
7140 VLIB_INIT_FUNCTION(vpe_api_init);
7143 static clib_error_t *
7144 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
7149 struct passwd _pw, *pw;
7150 struct group _grp, *grp;
7153 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7155 if (unformat (input, "prefix %s", &chroot_path))
7157 vec_add1 (chroot_path, 0);
7158 vl_set_memory_root_path ((char *)chroot_path);
7160 else if (unformat (input, "uid %d", &uid))
7161 vl_set_memory_uid (uid);
7162 else if (unformat (input, "gid %d", &gid))
7163 vl_set_memory_gid (gid);
7164 else if (unformat (input, "uid %s", &s))
7166 /* lookup the username */
7168 rv = getpwnam_r(s, &_pw, buf, sizeof(buf), &pw);
7171 e = clib_error_return_code(0, rv,
7172 CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
7173 "cannot fetch username %s", s);
7179 e = clib_error_return_fatal(0, "username %s does not exist", s);
7184 vl_set_memory_uid (pw->pw_uid);
7186 else if (unformat (input, "gid %s", &s))
7188 /* lookup the group name */
7190 rv = getgrnam_r(s, &_grp, buf, sizeof(buf), &grp);
7193 e = clib_error_return_code(0, rv,
7194 CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
7195 "cannot fetch group %s", s);
7201 e = clib_error_return_fatal(0, "group %s does not exist", s);
7206 vl_set_memory_gid (grp->gr_gid);
7209 return clib_error_return (0, "unknown input `%U'",
7210 format_unformat_error, input);
7214 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
7216 void * get_unformat_vnet_sw_interface (void)
7218 return (void *) &unformat_vnet_sw_interface;
7221 #undef vl_api_version
7222 #define vl_api_version(n,v) static u32 vpe_api_version = v;
7223 #include <vpp-api/vpe.api.h>
7224 #undef vl_api_version
7226 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
7228 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
7229 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
7230 clib_host_to_net_u32 (mp->api_versions[0]),
7237 static u8 * format_arp_event (u8 * s, va_list * args)
7239 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
7241 s = format (s, "pid %d: %U", event->pid,
7242 format_ip4_address, &event->address);
7246 static clib_error_t *
7247 show_ip4_arp_events_fn (vlib_main_t * vm,
7248 unformat_input_t * input,
7249 vlib_cli_command_t * cmd)
7251 vpe_api_main_t * am = &vpe_api_main;
7252 vl_api_ip4_arp_event_t * event;
7254 if (pool_elts (am->arp_events) == 0) {
7255 vlib_cli_output (vm, "No active arp event registrations");
7259 pool_foreach (event, am->arp_events,
7261 vlib_cli_output (vm, "%U", format_arp_event, event);
7267 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
7268 .path = "show arp event registrations",
7269 .function = show_ip4_arp_events_fn,
7270 .short_help = "Show arp event registrations",