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 <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 <api/vpe_all_api_h.h>
113 #define vl_endianfun /* define message structures */
114 #include <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 <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_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
337 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
338 _(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump) \
339 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
340 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
341 _(LISP_ENABLE_DISABLE_STATUS_DUMP, \
342 lisp_enable_disable_status_dump) \
343 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
344 lisp_add_del_map_request_itr_rlocs) \
345 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
346 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
347 _(AF_PACKET_CREATE, af_packet_create) \
348 _(AF_PACKET_DELETE, af_packet_delete) \
349 _(POLICER_ADD_DEL, policer_add_del) \
350 _(POLICER_DUMP, policer_dump) \
351 _(NETMAP_CREATE, netmap_create) \
352 _(NETMAP_DELETE, netmap_delete)
355 #define QUOTE(x) QUOTE_(x)
357 #define foreach_registration_hash \
358 _(interface_events) \
359 _(to_netconf_server) \
360 _(from_netconf_server) \
361 _(to_netconf_client) \
362 _(from_netconf_client) \
366 RESOLVE_IP4_ADD_DEL_ROUTE=1,
367 RESOLVE_IP6_ADD_DEL_ROUTE,
368 RESOLVE_MPLS_ETHERNET_ADD_DEL,
374 vl_api_ip_add_del_route_t r;
375 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
381 #define _(a) uword *a##_registration_hash; \
382 vpe_client_registration_t * a##_registrations;
383 foreach_registration_hash
386 /* notifications happen really early in the game */
387 u8 link_state_process_up;
389 /* ip4 pending route adds */
390 pending_route_t * pending_routes;
392 /* ip4 arp event registration pool */
393 vl_api_ip4_arp_event_t * arp_events;
396 vlib_main_t * vlib_main;
397 vnet_main_t * vnet_main;
400 static vlib_node_registration_t vpe_resolver_process_node;
401 static vpe_api_main_t vpe_api_main;
403 static void send_sw_interface_flags (vpe_api_main_t * am,
404 unix_shared_memory_queue_t *q,
405 vnet_sw_interface_t * swif);
406 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
407 unix_shared_memory_queue_t *q,
410 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
413 /* Clean up all registrations belonging to the indicated client */
414 int vl_api_memclnt_delete_callback (u32 client_index)
416 vpe_api_main_t * vam = &vpe_api_main;
417 vpe_client_registration_t *rp;
419 int stats_memclnt_delete_callback (u32 client_index);
421 stats_memclnt_delete_callback (client_index);
424 p = hash_get (vam->a##_registration_hash, client_index); \
426 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
427 pool_put (vam->a##_registrations, rp); \
428 hash_unset (vam->a##_registration_hash, client_index); \
430 foreach_registration_hash;
435 #define API_LINK_STATE_EVENT 1
436 #define API_ADMIN_UP_DOWN_EVENT 2
439 event_data_cmp (void * a1, void * a2)
444 return (word) e1[0] - (word) e2[0];
448 link_state_process (vlib_main_t * vm,
449 vlib_node_runtime_t * rt,
452 vpe_api_main_t * vam = &vpe_api_main;
453 vnet_main_t * vnm = vam->vnet_main;
454 vnet_sw_interface_t * swif;
455 uword * event_data = 0;
456 vpe_client_registration_t *reg;
458 u32 prev_sw_if_index;
459 unix_shared_memory_queue_t * q;
461 vam->link_state_process_up = 1;
464 vlib_process_wait_for_event (vm);
466 /* Unified list of changed link or admin state sw_if_indices */
467 vlib_process_get_events_with_type
468 (vm, &event_data, API_LINK_STATE_EVENT);
469 vlib_process_get_events_with_type
470 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
472 /* Sort, so we can eliminate duplicates */
473 vec_sort_with_function (event_data, event_data_cmp);
475 prev_sw_if_index = ~0;
477 for (i = 0; i < vec_len(event_data); i++) {
478 /* Only one message per swif */
479 if (prev_sw_if_index == event_data[i])
481 prev_sw_if_index = event_data[i];
483 pool_foreach(reg, vam->interface_events_registrations,
485 q = vl_api_client_index_to_input_queue (reg->client_index);
487 // sw_interface may be deleted already
488 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
491 swif = vnet_get_sw_interface (vnm, event_data[i]);
492 send_sw_interface_flags (vam, q, swif);
497 vec_reset_length (event_data);
503 static clib_error_t *
504 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
505 static clib_error_t *
506 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
508 VLIB_REGISTER_NODE (link_state_process_node,static) = {
509 .function = link_state_process,
510 .type = VLIB_NODE_TYPE_PROCESS,
511 .name = "vpe-link-state-process",
514 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
515 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
517 static clib_error_t *
518 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
520 vpe_api_main_t * vam = &vpe_api_main;
521 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
523 if (vam->link_state_process_up)
524 vlib_process_signal_event (vam->vlib_main,
525 link_state_process_node.index,
526 API_LINK_STATE_EVENT,
531 static clib_error_t *
532 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
534 vpe_api_main_t * vam = &vpe_api_main;
537 * Note: it's perfectly fair to set a subif admin up / admin down.
538 * Note the subtle distinction between this routine and the previous
541 if (vam->link_state_process_up)
542 vlib_process_signal_event (vam->vlib_main,
543 link_state_process_node.index,
544 API_ADMIN_UP_DOWN_EVENT,
549 #define pub_sub_handler(lca,UCA) \
550 static void vl_api_want_##lca##_t_handler ( \
551 vl_api_want_##lca##_t *mp) \
553 vpe_api_main_t *vam = &vpe_api_main; \
554 vpe_client_registration_t *rp; \
555 vl_api_want_##lca##_reply_t *rmp; \
559 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
561 if (mp->enable_disable) { \
562 clib_warning ("pid %d: already enabled...", mp->pid); \
563 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
566 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
567 pool_put (vam->lca##_registrations, rp); \
568 hash_unset (vam->lca##_registration_hash, \
573 if (mp->enable_disable == 0) { \
574 clib_warning ("pid %d: already disabled...", mp->pid); \
575 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
578 pool_get (vam->lca##_registrations, rp); \
579 rp->client_index = mp->client_index; \
580 rp->client_pid = mp->pid; \
581 hash_set (vam->lca##_registration_hash, rp->client_index, \
582 rp - vam->lca##_registrations); \
585 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
588 pub_sub_handler (interface_events,INTERFACE_EVENTS)
589 pub_sub_handler (oam_events,OAM_EVENTS)
591 #define RESOLUTION_EVENT 1
592 #define RESOLUTION_PENDING_EVENT 2
593 #define IP4_ARP_EVENT 3
595 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
596 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
597 static int mpls_ethernet_add_del_tunnel_2_t_handler
598 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
600 void handle_ip4_arp_event (u32 pool_index)
602 vpe_api_main_t * vam = &vpe_api_main;
603 vnet_main_t * vnm = vam->vnet_main;
604 vlib_main_t * vm = vam->vlib_main;
605 vl_api_ip4_arp_event_t * event;
606 vl_api_ip4_arp_event_t * mp;
607 unix_shared_memory_queue_t * q;
609 /* Client can cancel, die, etc. */
610 if (pool_is_free_index (vam->arp_events, pool_index))
613 event = pool_elt_at_index (vam->arp_events, pool_index);
615 q = vl_api_client_index_to_input_queue (event->client_index);
617 (void) vnet_add_del_ip4_arp_change_event
618 (vnm, arp_change_delete_callback,
619 event->pid, &event->address,
620 vpe_resolver_process_node.index, IP4_ARP_EVENT,
621 ~0 /* pool index, notused */, 0 /* is_add */);
625 if (q->cursize < q->maxsize) {
626 mp = vl_msg_api_alloc (sizeof (*mp));
627 clib_memcpy (mp, event, sizeof (*mp));
628 vl_msg_api_send_shmem (q, (u8 *)&mp);
630 static f64 last_time;
632 * Throttle syslog msgs.
633 * It's pretty tempting to just revoke the registration...
635 if (vlib_time_now (vm) > last_time + 10.0) {
636 clib_warning ("arp event for %U to pid %d: queue stuffed!",
637 format_ip4_address, &event->address, event->pid);
638 last_time = vlib_time_now(vm);
644 resolver_process (vlib_main_t * vm,
645 vlib_node_runtime_t * rt,
649 uword *event_data = 0;
651 vpe_api_main_t * vam = &vpe_api_main;
652 pending_route_t * pr;
653 vl_api_ip_add_del_route_t * adr;
654 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
655 u32 * resolution_failures = 0;
660 vlib_process_wait_for_event_or_clock (vm, timeout);
662 event_type = vlib_process_get_events (vm, &event_data);
664 switch (event_type) {
665 case RESOLUTION_PENDING_EVENT:
669 case RESOLUTION_EVENT:
670 for (i = 0; i < vec_len(event_data); i++) {
672 * Resolution events can occur long after the
673 * original request has timed out. $$$ add a cancel
676 if (pool_is_free_index (vam->pending_routes, event_data[i]))
679 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
683 switch (pr->resolve_type) {
684 case RESOLVE_IP4_ADD_DEL_ROUTE:
685 rv = ip4_add_del_route_t_handler (adr);
686 clib_warning ("resolver: add %U/%d via %U %s",
688 (ip4_address_t *)&(adr->dst_address),
689 adr->dst_address_length,
691 (ip4_address_t *)&(adr->next_hop_address),
692 (rv >= 0) ? "succeeded" : "failed");
695 case RESOLVE_IP6_ADD_DEL_ROUTE:
696 rv = ip6_add_del_route_t_handler (adr);
697 clib_warning ("resolver: add %U/%d via %U %s",
699 (ip6_address_t *)&(adr->dst_address),
700 adr->dst_address_length,
702 (ip6_address_t *)&(adr->next_hop_address),
703 (rv >= 0) ? "succeeded" : "failed");
706 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
707 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
708 clib_warning ("resolver: add mpls-o-e via %U %s",
710 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
711 (rv >= 0) ? "succeeded" : "failed");
715 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
717 pool_put (vam->pending_routes, pr);
722 for (i = 0; i < vec_len(event_data); i++)
723 handle_ip4_arp_event (event_data[i]);
726 case ~0: /* timeout, retry pending resolutions */
727 pool_foreach (pr, vam->pending_routes,
733 /* May fail, e.g. due to interface down */
734 switch (pr->resolve_type) {
735 case RESOLVE_IP4_ADD_DEL_ROUTE:
736 e = ip4_probe_neighbor
737 (vm, (ip4_address_t *)&(adr->next_hop_address),
738 ntohl(adr->next_hop_sw_if_index));
741 case RESOLVE_IP6_ADD_DEL_ROUTE:
742 e = ip6_probe_neighbor
743 (vm, (ip6_address_t *)&(adr->next_hop_address),
744 ntohl(adr->next_hop_sw_if_index));
747 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
749 e = ip4_probe_neighbor
751 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
752 pme->resolve_opaque);
756 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
760 clib_error_report (e);
762 adr->resolve_attempts = 1;
764 pme->resolve_attempts = 1;
768 adr->resolve_attempts -= 1;
769 if (adr->resolve_attempts == 0)
770 vec_add1 (resolution_failures,
771 pr - vam->pending_routes);
773 pme->resolve_attempts -= 1;
774 if (pme->resolve_attempts == 0)
775 vec_add1 (resolution_failures,
776 pr - vam->pending_routes);
780 for (i = 0; i < vec_len (resolution_failures); i++) {
781 pr = pool_elt_at_index (vam->pending_routes,
782 resolution_failures[i]);
786 switch (pr->resolve_type) {
787 case RESOLVE_IP4_ADD_DEL_ROUTE:
788 clib_warning ("resolver: add %U/%d via %U retry failure",
790 (ip4_address_t *)&(adr->dst_address),
791 adr->dst_address_length,
793 (ip4_address_t *)&(adr->next_hop_address));
796 case RESOLVE_IP6_ADD_DEL_ROUTE:
797 clib_warning ("resolver: add %U/%d via %U retry failure",
799 (ip6_address_t *)&(adr->dst_address),
800 adr->dst_address_length,
802 (ip6_address_t *)&(adr->next_hop_address));
805 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
806 clib_warning ("resolver: add mpls-o-e via %U retry failure",
808 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
812 clib_warning ("BUG");
814 pool_put(vam->pending_routes, pr);
816 vec_reset_length (resolution_failures);
819 if (pool_elts (vam->pending_routes) == 0)
821 vec_reset_length (event_data);
823 return 0; /* or not */
826 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
827 .function = resolver_process,
828 .type = VLIB_NODE_TYPE_PROCESS,
829 .name = "vpe-route-resolver-process",
832 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
834 ip4_main_t * im = &ip4_main;
835 ip_lookup_main_t * lm = &im->lookup_main;
836 vnet_classify_main_t * cm = &vnet_classify_main;
837 stats_main_t * sm = &stats_main;
838 ip4_add_del_route_args_t a;
839 ip4_address_t next_hop_address;
841 vpe_api_main_t * vam = &vpe_api_main;
842 vnet_main_t * vnm = vam->vnet_main;
843 vlib_main_t * vm = vlib_get_main();
844 pending_route_t * pr;
845 vl_api_ip_add_del_route_t * adr;
849 ip_adjacency_t *nh_adj, *add_adj = 0;
851 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
853 if (mp->create_vrf_if_needed) {
855 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
857 fib_index = f->index;
859 /* No such VRF, and we weren't asked to create one */
860 return VNET_API_ERROR_NO_SUCH_FIB;
866 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
867 ntohl(mp->next_hop_sw_if_index)))
868 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
870 clib_memcpy (next_hop_address.data, mp->next_hop_address,
871 sizeof (next_hop_address.data));
873 /* Arp for the next_hop if necessary */
874 if (mp->is_add && mp->resolve_if_needed) {
876 ip_adjacency_t * adj;
878 lookup_result = ip4_fib_lookup_with_table
879 (im, fib_index, &next_hop_address, 1 /* disable default route */);
881 adj = ip_get_adjacency (lm, lookup_result);
883 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
884 pool_get (vam->pending_routes, pr);
885 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
887 clib_memcpy (adr, mp, sizeof (*adr));
888 /* recursion block, "just in case" */
889 adr->resolve_if_needed = 0;
890 adr->resolve_attempts = ntohl(mp->resolve_attempts);
891 vnet_register_ip4_arp_resolution_event
892 (vnm, &next_hop_address, vpe_resolver_process_node.index,
893 RESOLUTION_EVENT, pr - vam->pending_routes);
895 vlib_process_signal_event
896 (vm, vpe_resolver_process_node.index,
897 RESOLUTION_PENDING_EVENT, 0 /* data */);
899 /* The interface may be down, etc. */
900 e = ip4_probe_neighbor
901 (vm, (ip4_address_t *)&(mp->next_hop_address),
902 ntohl(mp->next_hop_sw_if_index));
905 clib_error_report(e);
907 return VNET_API_ERROR_IN_PROGRESS;
911 if (mp->is_multipath) {
914 dslock (sm, 1 /* release hint */, 10 /* tag */);
917 flags = IP4_ROUTE_FLAG_ADD;
919 flags = IP4_ROUTE_FLAG_DEL;
922 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
924 ip4_add_del_route_next_hop (im, flags,
925 (ip4_address_t *) mp->dst_address,
926 (u32) mp->dst_address_length,
927 (ip4_address_t *) mp->next_hop_address,
928 ntohl(mp->next_hop_sw_if_index),
929 (u32) mp->next_hop_weight,
936 memset (&a, 0, sizeof (a));
937 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
939 a.dst_address_length = mp->dst_address_length;
941 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
942 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
943 a.table_index_or_table_id = fib_index;
948 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
950 dslock (sm, 1 /* release hint */, 2 /* tag */);
954 ai = lm->drop_adj_index;
955 else if (mp->is_local)
956 ai = lm->local_adj_index;
957 else if (mp->is_classify) {
959 memset(&cadj, 0, sizeof(cadj));
960 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
961 cadj.classify.table_index = ntohl(mp->classify_table_index);
962 if (pool_is_free_index (cm->tables, cadj.classify.table_index)) {
964 return VNET_API_ERROR_NO_SUCH_TABLE;
966 vec_add1 (add_adj, cadj);
970 ai = ip4_fib_lookup_with_table
971 (im, fib_index, &next_hop_address,
972 1 /* disable default route */);
973 if (ai == lm->miss_adj_index) {
975 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
979 nh_adj = ip_get_adjacency (lm, ai);
980 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_ARP &&
981 nh_adj->arp.next_hop.ip4.as_u32 == 0) {
982 /* the next-hop resovles via a glean adj. create and use
983 * a ARP adj for the next-hop */
984 a.adj_index = vnet_arp_glean_add(fib_index, &next_hop_address);
987 ip4_add_del_route (im, &a);
991 vec_add1 (add_adj, nh_adj[0]);
992 if (mp->lookup_in_vrf) {
993 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
995 add_adj[0].explicit_fib_index = p[0];
999 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1003 ip_adjacency_t * adj;
1004 int disable_default_route = 1;
1006 /* Trying to delete the default route? */
1007 if (a.dst_address.as_u32 == 0 &&
1008 a.dst_address_length == 0)
1009 disable_default_route = 0;
1011 ai = ip4_fib_lookup_with_table
1012 (im, fib_index, &a.dst_address, disable_default_route);
1013 if (ai == lm->miss_adj_index) {
1015 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1018 adj = ip_get_adjacency (lm, ai);
1019 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1021 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1027 a.add_adj = add_adj;
1028 a.n_add_adj = vec_len(add_adj);
1029 ip4_add_del_route (im, &a);
1038 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1040 ip6_main_t * im = &ip6_main;
1041 ip_lookup_main_t * lm = &im->lookup_main;
1042 vnet_main_t * vnm = vnet_get_main();
1043 vlib_main_t * vm = vlib_get_main();
1044 vpe_api_main_t * vam = &vpe_api_main;
1045 stats_main_t * sm = &stats_main;
1046 ip6_add_del_route_args_t a;
1047 ip6_address_t next_hop_address;
1048 pending_route_t * pr;
1049 vl_api_ip_add_del_route_t * adr;
1054 ip_adjacency_t * nh_adj, * add_adj = 0;
1057 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1060 if (mp->create_vrf_if_needed) {
1062 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1064 fib_index = f->index;
1066 /* No such VRF, and we weren't asked to create one */
1067 return VNET_API_ERROR_NO_SUCH_FIB;
1073 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1074 ntohl(mp->next_hop_sw_if_index)))
1075 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1077 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1078 sizeof (next_hop_address.as_u8));
1080 /* Arp for the next_hop if necessary */
1081 if (mp->is_add && mp->resolve_if_needed) {
1083 ip_adjacency_t * adj;
1085 lookup_result = ip6_fib_lookup_with_table
1086 (im, fib_index, &next_hop_address);
1088 adj = ip_get_adjacency (lm, lookup_result);
1090 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1091 pool_get (vam->pending_routes, pr);
1093 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1094 clib_memcpy (adr, mp, sizeof (*adr));
1095 /* recursion block, "just in case" */
1096 adr->resolve_if_needed = 0;
1097 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1098 vnet_register_ip6_neighbor_resolution_event
1099 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1100 RESOLUTION_EVENT, pr - vam->pending_routes);
1102 vlib_process_signal_event
1103 (vm, vpe_resolver_process_node.index,
1104 RESOLUTION_PENDING_EVENT, 0 /* data */);
1106 /* The interface may be down, etc. */
1107 e = ip6_probe_neighbor
1108 (vm, (ip6_address_t *)&(mp->next_hop_address),
1109 ntohl(mp->next_hop_sw_if_index));
1112 clib_error_report(e);
1114 return VNET_API_ERROR_IN_PROGRESS;
1118 if (mp->is_multipath) {
1121 dslock (sm, 1 /* release hint */, 11 /* tag */);
1124 flags = IP6_ROUTE_FLAG_ADD;
1126 flags = IP6_ROUTE_FLAG_DEL;
1129 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1131 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1132 (u32) mp->dst_address_length,
1133 (ip6_address_t *)mp->next_hop_address,
1134 ntohl(mp->next_hop_sw_if_index),
1135 (u32) mp->next_hop_weight,
1142 memset (&a, 0, sizeof (a));
1143 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1145 a.dst_address_length = mp->dst_address_length;
1147 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1148 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1149 a.table_index_or_table_id = fib_index;
1154 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1156 dslock (sm, 1 /* release hint */, 3 /* tag */);
1160 ai = lm->drop_adj_index;
1161 else if (mp->is_local)
1162 ai = lm->local_adj_index;
1164 ai = ip6_fib_lookup_with_table
1165 (im, fib_index, &next_hop_address);
1166 if (ai == lm->miss_adj_index) {
1168 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1172 nh_adj = ip_get_adjacency (lm, ai);
1173 vec_add1 (add_adj, nh_adj[0]);
1174 if (mp->lookup_in_vrf) {
1175 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1177 add_adj[0].explicit_fib_index = p[0];
1181 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1185 ip_adjacency_t * adj;
1187 ai = ip6_fib_lookup_with_table
1188 (im, fib_index, &a.dst_address);
1189 if (ai == lm->miss_adj_index) {
1191 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1193 adj = ip_get_adjacency (lm, ai);
1194 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1196 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1201 a.add_adj = add_adj;
1202 a.n_add_adj = vec_len(add_adj);
1203 ip6_add_del_route (im, &a);
1211 void vl_api_ip_add_del_route_t_handler (
1212 vl_api_ip_add_del_route_t *mp)
1214 vl_api_ip_add_del_route_reply_t * rmp;
1216 vnet_main_t * vnm = vnet_get_main();
1221 rv = ip6_add_del_route_t_handler (mp);
1223 rv = ip4_add_del_route_t_handler (mp);
1225 rv = (rv == 0) ? vnm->api_errno : rv;
1227 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1230 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1231 u32 sw_if_index, u8 *next_hop_addr)
1233 vl_api_ip_add_del_route_t mp;
1236 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1239 * Configure default IP route:
1240 * - ip route add 0.0.0.0/1 via <GW IP>
1241 * - ip route add 128.0.0.0/1 via <GW IP>
1243 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1245 mp.resolve_attempts = ~0;
1246 mp.resolve_if_needed = 1;
1248 mp.is_ipv6 = is_ipv6;
1249 mp.next_hop_weight = 1;
1251 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1254 rv = ip6_add_del_route_t_handler (&mp);
1257 mp.dst_address_length = 1;
1259 mp.dst_address[0] = 0;
1260 rv = ip4_add_del_route_t_handler (&mp);
1262 mp.dst_address[0] = 128;
1263 rv |= ip4_add_del_route_t_handler (&mp);
1267 clib_error_return (0, "failed to config default IP route");
1272 vl_api_sw_interface_add_del_address_t_handler
1273 (vl_api_sw_interface_add_del_address_t *mp)
1275 vlib_main_t *vm = vlib_get_main();
1276 vl_api_sw_interface_add_del_address_reply_t * rmp;
1280 VALIDATE_SW_IF_INDEX(mp);
1282 is_del = mp->is_add == 0;
1285 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1286 else if (mp->is_ipv6)
1287 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1288 (void *)mp->address,
1289 mp->address_length, is_del);
1291 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1292 (void *) mp->address,
1293 mp->address_length, is_del);
1295 BAD_SW_IF_INDEX_LABEL;
1297 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1301 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1304 u32 table_id = ntohl(mp->vrf_id);
1305 u32 sw_if_index = ntohl(mp->sw_if_index);
1306 vl_api_sw_interface_set_table_reply_t * rmp;
1307 stats_main_t * sm = &stats_main;
1309 VALIDATE_SW_IF_INDEX(mp);
1311 dslock (sm, 1 /* release hint */, 4 /* tag */);
1314 ip6_main_t * im = &ip6_main;
1316 find_ip6_fib_by_table_index_or_id (im, table_id,
1317 IP6_ROUTE_FLAG_TABLE_ID);
1319 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1320 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1322 rv = VNET_API_ERROR_NO_SUCH_FIB;
1325 ip4_main_t * im = &ip4_main;
1326 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1327 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1329 /* Truthfully this can't fail */
1331 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1332 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1334 rv = VNET_API_ERROR_NO_SUCH_FIB;
1339 BAD_SW_IF_INDEX_LABEL;
1341 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1345 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1347 vlib_main_t *vm = vlib_get_main();
1348 vl_api_sw_interface_set_vpath_reply_t * rmp;
1351 u32 sw_if_index = ntohl(mp->sw_if_index);
1352 ip4_main_t *ip4m = &ip4_main;
1353 ip6_main_t *ip6m = &ip6_main;
1354 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1355 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1356 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1357 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1358 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1359 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1361 VALIDATE_SW_IF_INDEX(mp);
1363 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1365 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1366 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1367 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1368 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1369 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1370 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1371 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1372 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1373 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1374 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1375 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1376 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1377 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1378 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1379 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1380 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1382 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1383 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1384 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1385 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1386 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1387 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1388 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1389 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1390 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1391 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1392 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1393 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1394 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1395 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1396 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1397 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1400 BAD_SW_IF_INDEX_LABEL;
1402 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1406 vl_api_sw_interface_set_l2_xconnect_t_handler (
1407 vl_api_sw_interface_set_l2_xconnect_t *mp)
1409 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1411 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1412 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1413 vlib_main_t *vm = vlib_get_main();
1414 vnet_main_t *vnm = vnet_get_main();
1416 VALIDATE_RX_SW_IF_INDEX(mp);
1419 VALIDATE_TX_SW_IF_INDEX(mp);
1420 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1421 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1423 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1426 BAD_RX_SW_IF_INDEX_LABEL;
1427 BAD_TX_SW_IF_INDEX_LABEL;
1429 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1433 vl_api_sw_interface_set_l2_bridge_t_handler (
1434 vl_api_sw_interface_set_l2_bridge_t *mp)
1436 bd_main_t * bdm = &bd_main;
1437 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1439 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1440 u32 bd_id = ntohl(mp->bd_id);
1444 vlib_main_t *vm = vlib_get_main();
1445 vnet_main_t *vnm = vnet_get_main();
1447 VALIDATE_RX_SW_IF_INDEX(mp);
1449 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1452 //VALIDATE_TX_SW_IF_INDEX(mp);
1453 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1454 rx_sw_if_index, bd_index, bvi, shg, 0);
1456 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1459 BAD_RX_SW_IF_INDEX_LABEL;
1461 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1465 vl_api_bridge_domain_add_del_t_handler (
1466 vl_api_bridge_domain_add_del_t *mp)
1468 vlib_main_t * vm = vlib_get_main ();
1469 bd_main_t * bdm = &bd_main;
1470 vl_api_bridge_domain_add_del_reply_t * rmp;
1472 u32 enable_flags = 0, disable_flags = 0;
1473 u32 bd_id = ntohl(mp->bd_id);
1477 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1480 enable_flags |= L2_FLOOD;
1482 disable_flags |= L2_FLOOD;
1485 enable_flags |= L2_UU_FLOOD;
1487 disable_flags |= L2_UU_FLOOD;
1490 enable_flags |= L2_FWD;
1492 disable_flags |= L2_FWD;
1495 enable_flags |= L2_ARP_TERM;
1497 disable_flags |= L2_ARP_TERM;
1500 enable_flags |= L2_LEARN;
1502 disable_flags |= L2_LEARN;
1505 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1508 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1511 rv = bd_delete_bd_index(bdm, bd_id);
1513 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1516 static void vl_api_bridge_domain_details_t_handler (
1517 vl_api_bridge_domain_details_t * mp)
1519 clib_warning ("BUG");
1522 static void vl_api_bridge_domain_sw_if_details_t_handler (
1523 vl_api_bridge_domain_sw_if_details_t * mp)
1525 clib_warning ("BUG");
1528 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1529 l2_bridge_domain_t * bd_config,
1533 vl_api_bridge_domain_details_t * mp;
1535 mp = vl_msg_api_alloc (sizeof (*mp));
1536 memset (mp, 0, sizeof (*mp));
1537 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1538 mp->bd_id = ntohl (bd_config->bd_id);
1539 mp->flood = bd_feature_flood (bd_config);
1540 mp->uu_flood = bd_feature_uu_flood (bd_config);
1541 mp->forward = bd_feature_forward (bd_config);
1542 mp->learn = bd_feature_learn (bd_config);
1543 mp->arp_term = bd_feature_arp_term (bd_config);
1544 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1545 mp->n_sw_ifs = ntohl (n_sw_ifs);
1546 mp->context = context;
1548 vl_msg_api_send_shmem (q, (u8 *)&mp);
1551 static void send_bd_sw_if_details (l2input_main_t * l2im,
1552 unix_shared_memory_queue_t *q,
1553 l2_flood_member_t * member, u32 bd_id,
1556 vl_api_bridge_domain_sw_if_details_t * mp;
1557 l2_input_config_t * input_cfg;
1559 mp = vl_msg_api_alloc (sizeof (*mp));
1560 memset (mp, 0, sizeof (*mp));
1561 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1562 mp->bd_id = ntohl (bd_id);
1563 mp->sw_if_index = ntohl (member->sw_if_index);
1564 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1565 mp->shg = input_cfg->shg;
1566 mp->context = context;
1568 vl_msg_api_send_shmem (q, (u8 *)&mp);
1571 static void vl_api_bridge_domain_dump_t_handler (
1572 vl_api_bridge_domain_dump_t *mp)
1574 bd_main_t * bdm = &bd_main;
1575 l2input_main_t * l2im = &l2input_main;
1576 unix_shared_memory_queue_t * q;
1577 l2_bridge_domain_t * bd_config;
1578 u32 bd_id, bd_index;
1581 q = vl_api_client_index_to_input_queue (mp->client_index);
1586 bd_id = ntohl(mp->bd_id);
1588 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1589 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1590 for (; bd_index < end; bd_index++) {
1591 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1592 /* skip dummy bd_id 0 */
1593 if (bd_config && (bd_config->bd_id > 0)) {
1595 l2_flood_member_t * m;
1597 n_sw_ifs = vec_len (bd_config->members);
1598 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1600 vec_foreach (m, bd_config->members) {
1601 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1608 vl_api_l2fib_add_del_t_handler (
1609 vl_api_l2fib_add_del_t *mp)
1611 bd_main_t * bdm = &bd_main;
1612 l2input_main_t * l2im = &l2input_main;
1613 vl_api_l2fib_add_del_reply_t * rmp;
1616 u32 sw_if_index = ntohl(mp->sw_if_index);
1617 u32 bd_id = ntohl(mp->bd_id);
1625 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1627 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1628 goto bad_sw_if_index;
1633 VALIDATE_SW_IF_INDEX(mp);
1634 if (vec_len(l2im->configs) <= sw_if_index) {
1635 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1636 goto bad_sw_if_index;
1638 l2_input_config_t * config;
1639 config = vec_elt_at_index(l2im->configs, sw_if_index);
1640 if (config->bridge == 0) {
1641 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1642 goto bad_sw_if_index;
1645 static_mac = mp->static_mac ? 1 : 0;
1646 filter_mac = mp->filter_mac ? 1 : 0;
1647 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1650 l2fib_del_entry(mac, bd_index);
1653 BAD_SW_IF_INDEX_LABEL;
1655 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1659 vl_api_l2_flags_t_handler (
1660 vl_api_l2_flags_t *mp)
1662 vl_api_l2_flags_reply_t * rmp;
1664 u32 sw_if_index = ntohl(mp->sw_if_index);
1665 u32 flags = ntohl(mp->feature_bitmap);
1668 VALIDATE_SW_IF_INDEX(mp);
1671 if (flags & L2INPUT_FEAT_ ## a) \
1672 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1673 foreach_l2input_feat;
1676 BAD_SW_IF_INDEX_LABEL;
1678 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1682 vl_api_bridge_flags_t_handler (
1683 vl_api_bridge_flags_t *mp)
1685 vlib_main_t *vm = vlib_get_main();
1686 bd_main_t * bdm = &bd_main;
1687 vl_api_bridge_flags_reply_t * rmp;
1689 u32 bd_id = ntohl(mp->bd_id);
1691 u32 flags = ntohl(mp->feature_bitmap);
1694 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1696 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1702 bd_set_flags(vm, bd_index, flags, mp->is_set);
1705 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1706 rmp->resulting_feature_bitmap = ntohl(flags));
1710 vl_api_bd_ip_mac_add_del_t_handler (
1711 vl_api_bd_ip_mac_add_del_t *mp)
1713 bd_main_t * bdm = &bd_main;
1714 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1716 u32 bd_id = ntohl(mp->bd_id);
1720 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1722 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1727 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1728 mp->mac_address, mp->is_ipv6, mp->is_add))
1729 rv = VNET_API_ERROR_UNSPECIFIED;
1732 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1736 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1739 vl_api_tap_connect_reply_t * rmp;
1740 unix_shared_memory_queue_t * q;
1741 u32 sw_if_index = (u32)~0;
1743 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1744 mp->use_random_mac ? 0 : mp->mac_address,
1745 &sw_if_index, mp->renumber,
1746 ntohl(mp->custom_dev_instance));
1748 q = vl_api_client_index_to_input_queue (mp->client_index);
1752 rmp = vl_msg_api_alloc (sizeof (*rmp));
1753 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1754 rmp->context = mp->context;
1755 rmp->retval = ntohl(rv);
1756 rmp->sw_if_index = ntohl(sw_if_index);
1758 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1762 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1765 vl_api_tap_modify_reply_t * rmp;
1766 unix_shared_memory_queue_t * q;
1767 u32 sw_if_index = (u32)~0;
1769 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1770 mp->use_random_mac ? 0 : mp->mac_address,
1771 &sw_if_index, mp->renumber,
1772 ntohl(mp->custom_dev_instance));
1774 q = vl_api_client_index_to_input_queue (mp->client_index);
1778 rmp = vl_msg_api_alloc (sizeof (*rmp));
1779 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1780 rmp->context = mp->context;
1781 rmp->retval = ntohl(rv);
1782 rmp->sw_if_index = ntohl(sw_if_index);
1784 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1788 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1791 vpe_api_main_t * vam = &vpe_api_main;
1792 vl_api_tap_delete_reply_t * rmp;
1793 unix_shared_memory_queue_t * q;
1794 u32 sw_if_index = ntohl(mp->sw_if_index);
1796 rv = vnet_tap_delete (vm, sw_if_index);
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_DELETE_REPLY);
1804 rmp->context = mp->context;
1805 rmp->retval = ntohl(rv);
1807 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1810 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1814 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1816 vl_api_create_vlan_subif_reply_t * rmp;
1817 vnet_main_t * vnm = vnet_get_main();
1818 u32 hw_if_index, sw_if_index = (u32)~0;
1819 vnet_hw_interface_t * hi;
1822 vnet_sw_interface_t template;
1824 vnet_interface_main_t * im = &vnm->interface_main;
1825 u64 sup_and_sub_key;
1827 unix_shared_memory_queue_t * q;
1828 clib_error_t * error;
1830 VALIDATE_SW_IF_INDEX(mp);
1832 hw_if_index = ntohl(mp->sw_if_index);
1833 hi = vnet_get_hw_interface (vnm, hw_if_index);
1835 id = ntohl(mp->vlan_id);
1836 if (id == 0 || id > 4095) {
1837 rv = VNET_API_ERROR_INVALID_VLAN;
1841 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1843 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1845 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1849 kp = clib_mem_alloc (sizeof (*kp));
1850 *kp = sup_and_sub_key;
1852 memset (&template, 0, sizeof (template));
1853 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1854 template.sup_sw_if_index = hi->sw_if_index;
1855 template.sub.id = id;
1856 template.sub.eth.raw_flags = 0;
1857 template.sub.eth.flags.one_tag = 1;
1858 template.sub.eth.outer_vlan_id = id;
1859 template.sub.eth.flags.exact_match = 1;
1861 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1863 clib_error_report(error);
1864 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1867 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1868 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1870 BAD_SW_IF_INDEX_LABEL;
1873 q = vl_api_client_index_to_input_queue (mp->client_index);
1877 rmp = vl_msg_api_alloc (sizeof (*rmp));
1878 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1879 rmp->context = mp->context;
1880 rmp->retval = ntohl(rv);
1881 rmp->sw_if_index = ntohl(sw_if_index);
1882 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1886 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1888 vl_api_create_subif_reply_t * rmp;
1889 vnet_main_t * vnm = vnet_get_main();
1890 u32 sw_if_index = ~0;
1893 vnet_sw_interface_t *si;
1894 vnet_hw_interface_t *hi;
1895 vnet_sw_interface_t template;
1897 vnet_interface_main_t * im = &vnm->interface_main;
1898 u64 sup_and_sub_key;
1900 clib_error_t * error;
1902 VALIDATE_SW_IF_INDEX(mp);
1904 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1905 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1907 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1908 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1912 sw_if_index = si->sw_if_index;
1913 sub_id = ntohl(mp->sub_id);
1915 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1917 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1920 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1921 sw_if_index, sub_id);
1922 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1926 kp = clib_mem_alloc (sizeof (*kp));
1927 *kp = sup_and_sub_key;
1929 memset (&template, 0, sizeof (template));
1930 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1931 template.sup_sw_if_index = sw_if_index;
1932 template.sub.id = sub_id;
1933 template.sub.eth.flags.no_tags = mp->no_tags;
1934 template.sub.eth.flags.one_tag = mp->one_tag;
1935 template.sub.eth.flags.two_tags = mp->two_tags;
1936 template.sub.eth.flags.dot1ad = mp->dot1ad;
1937 template.sub.eth.flags.exact_match = mp->exact_match;
1938 template.sub.eth.flags.default_sub = mp->default_sub;
1939 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1940 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1941 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1942 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1944 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1946 clib_error_report (error);
1947 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1951 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1952 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1954 BAD_SW_IF_INDEX_LABEL;
1958 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1960 rmp->sw_if_index = ntohl(sw_if_index);
1965 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1967 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1969 stats_main_t * sm = &stats_main;
1970 u32 tunnel_sw_if_index = ~0;
1972 dslock (sm, 1 /* release hint */, 5 /* tag */);
1974 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1975 (ip4_address_t *)(mp->dst_address),
1976 (ip4_address_t *)(mp->intfc_address),
1977 (u32)(mp->intfc_address_length),
1978 ntohl(mp->inner_vrf_id),
1979 ntohl(mp->outer_vrf_id),
1980 &tunnel_sw_if_index,
1985 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1987 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1992 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1993 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1995 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1997 stats_main_t * sm = &stats_main;
1998 u32 tunnel_sw_if_index;
2000 dslock (sm, 1 /* release hint */, 5 /* tag */);
2002 rv = vnet_mpls_ethernet_add_del_tunnel
2003 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
2004 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
2005 ntohl(mp->tx_sw_if_index),
2006 &tunnel_sw_if_index,
2012 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2014 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2019 * This piece of misery brought to you because the control-plane
2020 * can't figure out the tx interface + dst-mac address all by itself
2022 static int mpls_ethernet_add_del_tunnel_2_t_handler
2023 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2025 pending_route_t * pr;
2026 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2027 vnet_main_t * vnm = vnet_get_main();
2028 vlib_main_t * vm = vlib_get_main();
2029 stats_main_t * sm = &stats_main;
2030 vpe_api_main_t * vam = &vpe_api_main;
2031 u32 inner_fib_index, outer_fib_index;
2032 ip4_main_t * im = &ip4_main;
2033 ip_lookup_main_t * lm = &im->lookup_main;
2034 ip_adjacency_t * adj = 0;
2037 u8 * dst_mac_address;
2041 u32 tunnel_sw_if_index;
2043 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2045 return VNET_API_ERROR_NO_SUCH_FIB;
2047 outer_fib_index = p[0];
2050 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2052 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2054 inner_fib_index = p[0];
2056 if (inner_fib_index == outer_fib_index)
2057 return VNET_API_ERROR_INVALID_VALUE;
2059 lookup_result = ip4_fib_lookup_with_table
2060 (im, outer_fib_index,
2061 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2062 1 /* disable default route */);
2064 adj = ip_get_adjacency (lm, lookup_result);
2065 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2067 if (mp->is_add && mp->resolve_if_needed) {
2068 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2069 pool_get (vam->pending_routes, pr);
2070 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2072 clib_memcpy (pme, mp, sizeof (*pme));
2073 /* recursion block, "just in case" */
2074 pme->resolve_if_needed = 0;
2075 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2076 pme->resolve_opaque = tx_sw_if_index;
2077 vnet_register_ip4_arp_resolution_event
2079 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2080 vpe_resolver_process_node.index,
2081 RESOLUTION_EVENT, pr - vam->pending_routes);
2083 vlib_process_signal_event
2084 (vm, vpe_resolver_process_node.index,
2085 RESOLUTION_PENDING_EVENT, 0 /* data */);
2087 /* The interface may be down, etc. */
2088 e = ip4_probe_neighbor
2089 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2093 clib_error_report(e);
2095 return VNET_API_ERROR_IN_PROGRESS;
2099 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2100 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2103 vnet_rewrite_get_data_internal
2104 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2106 dslock (sm, 1 /* release hint */, 10 /* tag */);
2108 rv = vnet_mpls_ethernet_add_del_tunnel
2109 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2110 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2111 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2119 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2120 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2122 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2125 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2127 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2132 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2134 vl_api_mpls_add_del_encap_reply_t * rmp;
2136 static u32 * labels;
2139 vec_reset_length (labels);
2141 for (i = 0; i < mp->nlabels; i++)
2142 vec_add1 (labels, ntohl(mp->labels[i]));
2145 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2146 ntohl(mp->vrf_id), labels,
2147 ~0 /* policy_tunnel_index */,
2148 0 /* no_dst_hash */,
2152 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2156 vl_api_mpls_add_del_decap_t_handler
2157 (vl_api_mpls_add_del_decap_t *mp)
2159 vl_api_mpls_add_del_decap_reply_t * rmp;
2162 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2163 ntohl(mp->label), ntohl(mp->next_index),
2164 mp->s_bit, mp->is_add);
2166 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2170 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2172 vl_api_proxy_arp_add_del_reply_t * rmp;
2175 ip4_main_t * im = &ip4_main;
2176 stats_main_t * sm = &stats_main;
2177 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2178 ip4_address_t *hi_addr,
2179 u32 fib_index, int is_del);
2182 dslock (sm, 1 /* release hint */, 6 /* tag */);
2184 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2187 rv = VNET_API_ERROR_NO_SUCH_FIB;
2193 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2194 (ip4_address_t *)mp->hi_address,
2195 fib_index, mp->is_add == 0);
2199 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2203 vl_api_proxy_arp_intfc_enable_disable_t_handler
2204 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2207 vnet_main_t * vnm = vnet_get_main();
2208 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2209 vnet_sw_interface_t * si;
2212 VALIDATE_SW_IF_INDEX(mp);
2214 sw_if_index = ntohl(mp->sw_if_index);
2216 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2218 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2222 si = vnet_get_sw_interface (vnm, sw_if_index);
2226 if (mp->enable_disable)
2227 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2229 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2231 BAD_SW_IF_INDEX_LABEL;
2234 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2238 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2240 vl_api_ip_neighbor_add_del_reply_t * rmp;
2241 vnet_main_t * vnm = vnet_get_main();
2244 stats_main_t * sm = &stats_main;
2246 VALIDATE_SW_IF_INDEX(mp);
2248 dslock (sm, 1 /* release hint */, 7 /* tag */);
2252 rv = vnet_set_ip6_ethernet_neighbor
2253 (vm, ntohl(mp->sw_if_index),
2254 (ip6_address_t *)(mp->dst_address),
2255 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2257 rv = vnet_unset_ip6_ethernet_neighbor
2258 (vm, ntohl(mp->sw_if_index),
2259 (ip6_address_t *)(mp->dst_address),
2260 mp->mac_address, sizeof(mp->mac_address));
2262 ip4_main_t * im = &ip4_main;
2263 ip_lookup_main_t * lm = &im->lookup_main;
2264 ethernet_arp_ip4_over_ethernet_address_t a;
2266 ip_adjacency_t *nh_adj;
2268 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2270 rv = VNET_API_ERROR_NO_SUCH_FIB;
2276 * Unfortunately, folks have a penchant for
2277 * adding interface addresses to the ARP cache, and
2278 * wondering why the forwarder eventually ASSERTs...
2280 ai = ip4_fib_lookup_with_table
2281 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2282 1 /* disable default route */);
2285 nh_adj = ip_get_adjacency (lm, ai);
2286 /* Never allow manipulation of a local adj! */
2287 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2288 clib_warning("%U matches local adj",
2290 (ip4_address_t *)(mp->dst_address));
2291 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2296 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2297 clib_memcpy (&a.ip4, mp->dst_address, 4);
2300 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2301 fib_index, &a, mp->is_static);
2303 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2307 BAD_SW_IF_INDEX_LABEL;
2310 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2314 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2317 vpe_main_t *rm = &vpe_main;
2318 ip4_main_t *im4 = &ip4_main;
2319 ip6_main_t *im6 = &ip6_main;
2320 ip_lookup_main_t * lm;
2325 u32 adj_index, sw_if_index;
2326 vl_api_is_address_reachable_t *rmp;
2327 ip_adjacency_t * adj;
2328 unix_shared_memory_queue_t *q;
2330 q = vl_api_client_index_to_input_queue (mp->client_index);
2332 increment_missing_api_client_counter (rm->vlib_main);
2336 rmp = vl_msg_api_alloc (sizeof (*rmp));
2337 clib_memcpy (rmp, mp, sizeof (*rmp));
2339 sw_if_index = mp->next_hop_sw_if_index;
2340 clib_memcpy (&addr, mp->address, sizeof (addr));
2342 lm = &im6->lookup_main;
2344 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2346 lm = &im4->lookup_main;
2348 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2350 if (adj_index == ~0) {
2354 adj = ip_get_adjacency (lm, adj_index);
2356 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2357 && adj->rewrite_header.sw_if_index == sw_if_index) {
2360 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2361 && adj->rewrite_header.sw_if_index == sw_if_index) {
2363 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2365 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2366 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2374 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2378 static void vl_api_sw_interface_details_t_handler (
2379 vl_api_sw_interface_details_t * mp)
2381 clib_warning ("BUG");
2384 static void vl_api_sw_interface_set_flags_t_handler (
2385 vl_api_sw_interface_set_flags_t * mp)
2387 vl_api_sw_interface_set_flags_reply_t *rmp;
2388 vnet_main_t * vnm = vnet_get_main();
2390 clib_error_t * error;
2393 VALIDATE_SW_IF_INDEX(mp);
2395 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2397 error = vnet_sw_interface_set_flags (vnm,
2398 ntohl(mp->sw_if_index),
2402 clib_error_report (error);
2405 BAD_SW_IF_INDEX_LABEL;
2406 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2409 static void vl_api_sw_interface_clear_stats_t_handler (
2410 vl_api_sw_interface_clear_stats_t * mp)
2412 vl_api_sw_interface_clear_stats_reply_t *rmp;
2414 vnet_main_t * vnm = vnet_get_main();
2415 vnet_interface_main_t * im = &vnm->interface_main;
2416 vlib_simple_counter_main_t * sm;
2417 vlib_combined_counter_main_t * cm;
2418 static vnet_main_t ** my_vnet_mains;
2419 int i, j, n_counters;
2423 vec_reset_length (my_vnet_mains);
2425 for (i = 0; i < vec_len (vnet_mains); i++)
2428 vec_add1 (my_vnet_mains, vnet_mains[i]);
2431 if (vec_len (vnet_mains) == 0)
2432 vec_add1 (my_vnet_mains, vnm);
2434 n_counters = vec_len (im->combined_sw_if_counters);
2436 for (j = 0; j < n_counters; j++)
2438 for (i = 0; i < vec_len(my_vnet_mains); i++)
2440 im = &my_vnet_mains[i]->interface_main;
2441 cm = im->combined_sw_if_counters + j;
2442 if (mp->sw_if_index == (u32)~0)
2443 vlib_clear_combined_counters (cm);
2445 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2449 n_counters = vec_len (im->sw_if_counters);
2451 for (j = 0; j < n_counters; j++)
2453 for (i = 0; i < vec_len(my_vnet_mains); i++)
2455 im = &my_vnet_mains[i]->interface_main;
2456 sm = im->sw_if_counters + j;
2457 if (mp->sw_if_index == (u32)~0)
2458 vlib_clear_simple_counters (sm);
2460 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2464 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2467 static void send_sw_interface_details (vpe_api_main_t * am,
2468 unix_shared_memory_queue_t *q,
2469 vnet_sw_interface_t * swif,
2470 u8 * interface_name,
2473 vl_api_sw_interface_details_t * mp;
2474 vnet_hw_interface_t * hi;
2476 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2478 mp = vl_msg_api_alloc (sizeof (*mp));
2479 memset (mp, 0, sizeof (*mp));
2480 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2481 mp->sw_if_index = ntohl(swif->sw_if_index);
2482 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2483 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2485 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2487 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2488 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2489 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2490 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2491 mp->link_mtu = ntohs(hi->max_packet_bytes);
2492 mp->context = context;
2494 strncpy ((char *) mp->interface_name,
2495 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2497 /* Send the L2 address for ethernet physical intfcs */
2498 if (swif->sup_sw_if_index == swif->sw_if_index
2499 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2500 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2501 ethernet_interface_t *ei;
2503 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2504 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2505 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2506 mp->l2_address_length = ntohl(sizeof (ei->address));
2507 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2508 vnet_sub_interface_t *sub = &swif->sub;
2509 mp->sub_id = ntohl(sub->id);
2510 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2511 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2512 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2513 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2514 mp->sub_exact_match = sub->eth.flags.exact_match;
2515 mp->sub_default = sub->eth.flags.default_sub;
2516 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2517 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2519 /* vlan tag rewrite data */
2520 u32 vtr_op = L2_VTR_DISABLED;
2521 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2523 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2524 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2525 // error - default to disabled
2526 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2527 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2530 mp->vtr_op = ntohl(vtr_op);
2531 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2532 mp->vtr_tag1 = ntohl(vtr_tag1);
2533 mp->vtr_tag2 = ntohl(vtr_tag2);
2537 vl_msg_api_send_shmem (q, (u8 *)&mp);
2540 static void send_sw_interface_flags (vpe_api_main_t * am,
2541 unix_shared_memory_queue_t *q,
2542 vnet_sw_interface_t * swif)
2544 vl_api_sw_interface_set_flags_t *mp;
2545 vnet_main_t * vnm = am->vnet_main;
2547 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2549 mp = vl_msg_api_alloc (sizeof (*mp));
2550 memset (mp, 0, sizeof (*mp));
2551 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2552 mp->sw_if_index = ntohl(swif->sw_if_index);
2554 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2556 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2558 vl_msg_api_send_shmem (q, (u8 *)&mp);
2561 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2562 unix_shared_memory_queue_t *q,
2564 __attribute__((unused));
2566 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2567 unix_shared_memory_queue_t *q,
2570 vl_api_sw_interface_set_flags_t *mp;
2572 mp = vl_msg_api_alloc (sizeof (*mp));
2573 memset (mp, 0, sizeof (*mp));
2574 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2575 mp->sw_if_index = ntohl(sw_if_index);
2577 mp->admin_up_down = 0;
2578 mp->link_up_down = 0;
2580 vl_msg_api_send_shmem (q, (u8 *)&mp);
2583 static void vl_api_sw_interface_dump_t_handler (
2584 vl_api_sw_interface_dump_t *mp)
2586 vpe_api_main_t * am = &vpe_api_main;
2587 vnet_sw_interface_t * swif;
2588 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2589 u8 * filter_string = 0, * name_string = 0;
2590 unix_shared_memory_queue_t * q;
2591 char * strcasestr (char *, char *); /* lnx hdr file botch */
2593 q = vl_api_client_index_to_input_queue (mp->client_index);
2598 if (mp->name_filter_valid) {
2599 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2600 filter_string = format (0, "%s%c", mp->name_filter, 0);
2603 pool_foreach (swif, im->sw_interfaces,
2605 name_string = format (name_string, "%U%c",
2606 format_vnet_sw_interface_name,
2607 am->vnet_main, swif, 0);
2609 if (mp->name_filter_valid == 0 ||
2610 strcasestr((char *) name_string, (char *) filter_string)) {
2612 send_sw_interface_details (am, q, swif, name_string, mp->context);
2614 _vec_len (name_string) = 0;
2617 vec_free (name_string);
2618 vec_free (filter_string);
2621 void send_oam_event (oam_target_t * t)
2623 vpe_api_main_t * vam = &vpe_api_main;
2624 unix_shared_memory_queue_t * q;
2625 vpe_client_registration_t *reg;
2626 vl_api_oam_event_t * mp;
2628 pool_foreach(reg, vam->oam_events_registrations,
2630 q = vl_api_client_index_to_input_queue (reg->client_index);
2632 mp = vl_msg_api_alloc (sizeof (*mp));
2633 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2634 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2635 mp->state = t->state;
2636 vl_msg_api_send_shmem (q, (u8 *)&mp);
2642 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2644 vl_api_oam_add_del_reply_t * rmp;
2647 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2648 (ip4_address_t *)mp->dst_address,
2652 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2656 vl_api_vnet_get_summary_stats_t_handler (
2657 vl_api_vnet_get_summary_stats_t *mp)
2659 stats_main_t * sm = &stats_main;
2660 vnet_interface_main_t * im = sm->interface_main;
2661 vl_api_vnet_summary_stats_reply_t *rmp;
2662 vlib_combined_counter_main_t * cm;
2665 u64 total_pkts[VLIB_N_RX_TX];
2666 u64 total_bytes[VLIB_N_RX_TX];
2668 unix_shared_memory_queue_t * q =
2669 vl_api_client_index_to_input_queue (mp->client_index);
2674 rmp = vl_msg_api_alloc (sizeof (*rmp));
2675 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2676 rmp->context = mp->context;
2679 memset (total_pkts, 0, sizeof (total_pkts));
2680 memset (total_bytes, 0, sizeof (total_bytes));
2682 vnet_interface_counter_lock (im);
2684 vec_foreach (cm, im->combined_sw_if_counters) {
2685 which = cm - im->combined_sw_if_counters;
2687 for (i = 0; i < vec_len (cm->maxi); i++) {
2688 vlib_get_combined_counter (cm, i, &v);
2689 total_pkts[which] += v.packets;
2690 total_bytes[which] += v.bytes;
2693 vnet_interface_counter_unlock (im);
2695 /* Note: in HOST byte order! */
2696 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2697 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2698 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2699 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2700 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2702 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2705 typedef CLIB_PACKED (struct {
2706 ip4_address_t address;
2708 u32 address_length : 6;
2713 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2715 vnet_main_t * vnm = vnet_get_main();
2716 vnet_interface_main_t * im = &vnm->interface_main;
2717 ip4_main_t * im4 = &ip4_main;
2718 static ip4_route_t * routes;
2719 static u32 * sw_if_indices_to_shut;
2720 stats_main_t * sm = &stats_main;
2725 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2726 u32 target_fib_id = ntohl(mp->vrf_id);
2728 dslock (sm, 1 /* release hint */, 8 /* tag */);
2730 vec_foreach (fib, im4->fibs) {
2731 vnet_sw_interface_t * si;
2733 if (fib->table_id != target_fib_id)
2736 /* remove any mpls/gre tunnels in this fib */
2737 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2739 /* remove any mpls encap/decap labels */
2740 mpls_fib_reset_labels (fib->table_id);
2742 /* remove any proxy arps in this fib */
2743 vnet_proxy_arp_fib_reset (fib->table_id);
2745 /* Set the flow hash for this fib to the default */
2746 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2748 vec_reset_length (sw_if_indices_to_shut);
2750 /* Shut down interfaces in this FIB / clean out intfc routes */
2751 pool_foreach (si, im->sw_interfaces,
2753 u32 sw_if_index = si->sw_if_index;
2755 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2756 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2758 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2761 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2762 sw_if_index = sw_if_indices_to_shut[i];
2763 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2765 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2766 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2767 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2770 vec_reset_length (routes);
2772 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2773 uword * hash = fib->adj_index_by_dst_address[i];
2777 x.address_length = i;
2779 hash_foreach_pair (p, hash,
2781 x.address.data_u32 = p->key;
2782 vec_add1 (routes, x);
2786 vec_foreach (r, routes) {
2787 ip4_add_del_route_args_t a;
2789 memset (&a, 0, sizeof (a));
2790 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2791 a.table_index_or_table_id = fib - im4->fibs;
2792 a.dst_address = r->address;
2793 a.dst_address_length = r->address_length;
2796 ip4_add_del_route (im4, &a);
2797 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2798 IP4_ROUTE_FLAG_FIB_INDEX);
2802 } /* vec_foreach (fib) */
2809 ip6_address_t address;
2816 ip6_route_t ** routep;
2817 } add_routes_in_fib_arg_t;
2819 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2821 add_routes_in_fib_arg_t * ap = arg;
2823 if (kvp->key[2]>>32 == ap->fib_index)
2825 ip6_address_t *addr;
2827 addr = (ip6_address_t *) kvp;
2828 vec_add2 (*ap->routep, r, 1);
2829 r->address = addr[0];
2830 r->address_length = kvp->key[2] & 0xFF;
2831 r->index = kvp->value;
2835 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2837 vnet_main_t * vnm = vnet_get_main();
2838 vnet_interface_main_t * im = &vnm->interface_main;
2839 ip6_main_t * im6 = &ip6_main;
2840 stats_main_t * sm = &stats_main;
2841 static ip6_route_t * routes;
2842 static u32 * sw_if_indices_to_shut;
2847 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2848 u32 target_fib_id = ntohl(mp->vrf_id);
2849 add_routes_in_fib_arg_t _a, *a=&_a;
2850 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2852 dslock (sm, 1 /* release hint */, 9 /* tag */);
2854 vec_foreach (fib, im6->fibs) {
2855 vnet_sw_interface_t * si;
2857 if (fib->table_id != target_fib_id)
2860 vec_reset_length (sw_if_indices_to_shut);
2862 /* Shut down interfaces in this FIB / clean out intfc routes */
2863 pool_foreach (si, im->sw_interfaces,
2865 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2867 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2870 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2871 sw_if_index = sw_if_indices_to_shut[i];
2872 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2874 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2875 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2876 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2879 vec_reset_length (routes);
2881 a->fib_index = fib - im6->fibs;
2882 a->routep = &routes;
2884 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2886 vec_foreach (r, routes) {
2887 ip6_add_del_route_args_t a;
2889 memset (&a, 0, sizeof (a));
2890 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2891 a.table_index_or_table_id = fib - im6->fibs;
2892 a.dst_address = r->address;
2893 a.dst_address_length = r->address_length;
2896 ip6_add_del_route (im6, &a);
2897 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2898 IP6_ROUTE_FLAG_FIB_INDEX);
2901 /* Reinstall the neighbor / router discovery routes */
2902 vnet_ip6_fib_init (im6, fib - im6->fibs);
2904 } /* vec_foreach (fib) */
2910 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2913 vl_api_reset_fib_reply_t * rmp;
2916 rv = ip6_reset_fib_t_handler (mp);
2918 rv = ip4_reset_fib_t_handler (mp);
2920 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2925 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2927 vl_api_dhcp_proxy_config_reply_t * rmp;
2930 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2931 (ip4_address_t *)(&mp->dhcp_src_address),
2932 (u32) ntohl(mp->vrf_id),
2933 (int) mp->insert_circuit_id,
2934 (int) (mp->is_add == 0));
2936 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2941 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2943 vl_api_dhcp_proxy_config_reply_t * rmp;
2946 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2947 (ip6_address_t *)(&mp->dhcp_src_address),
2948 (u32) ntohl(mp->vrf_id),
2949 (int) mp->insert_circuit_id,
2950 (int) (mp->is_add == 0));
2952 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2956 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2958 vl_api_dhcp_proxy_config_reply_t * rmp;
2961 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2962 (ip4_address_t *)(&mp->dhcp_src_address),
2963 (u32) ntohl(mp->rx_vrf_id),
2964 (u32) ntohl(mp->server_vrf_id),
2965 (int) mp->insert_circuit_id,
2966 (int) (mp->is_add == 0));
2968 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2973 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2975 vl_api_dhcp_proxy_config_reply_t * rmp;
2979 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2980 (ip6_address_t *)(&mp->dhcp_src_address),
2981 (u32) ntohl(mp->rx_vrf_id),
2982 (u32) ntohl(mp->server_vrf_id),
2983 (int) mp->insert_circuit_id,
2984 (int) (mp->is_add == 0));
2986 rv = VNET_API_ERROR_UNIMPLEMENTED;
2989 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2994 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2996 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2999 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
3002 (int)mp->is_add == 0);
3004 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
3007 (int)mp->is_add == 0);
3009 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
3013 static void vl_api_dhcp_proxy_config_t_handler
3014 (vl_api_dhcp_proxy_config_t *mp)
3016 if (mp->is_ipv6 == 0)
3017 dhcpv4_proxy_config (mp);
3019 dhcpv6_proxy_config (mp);
3022 static void vl_api_dhcp_proxy_config_2_t_handler
3023 (vl_api_dhcp_proxy_config_2_t *mp)
3025 if (mp->is_ipv6 == 0)
3026 dhcpv4_proxy_config_2 (mp);
3028 dhcpv6_proxy_config_2 (mp);
3031 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3032 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3034 unix_shared_memory_queue_t * q;
3035 vl_api_dhcp_compl_event_t * mp;
3037 q = vl_api_client_index_to_input_queue (client_index);
3041 mp = vl_msg_api_alloc (sizeof (*mp));
3042 mp->client_index = client_index;
3044 mp->is_ipv6 = is_ipv6;
3045 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3046 mp->hostname[vec_len(hostname) + 1] = '\n';
3047 clib_memcpy (&mp->host_address[0], host_address, 16);
3048 clib_memcpy (&mp->router_address[0], router_address, 16);
3049 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3051 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3053 vl_msg_api_send_shmem (q, (u8 *)&mp);
3056 static void vl_api_dhcp_client_config_t_handler
3057 (vl_api_dhcp_client_config_t *mp)
3059 vlib_main_t *vm = vlib_get_main();
3060 vl_api_dhcp_client_config_reply_t * rmp;
3063 VALIDATE_SW_IF_INDEX(mp);
3065 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3066 mp->hostname, mp->is_add, mp->client_index,
3067 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3070 BAD_SW_IF_INDEX_LABEL;
3072 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3076 vl_api_sw_interface_ip6nd_ra_config_t_handler
3077 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3079 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3081 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3083 is_no = mp->is_no == 1;
3084 surpress = mp->surpress == 1;
3085 managed = mp->managed == 1;
3086 other = mp->other == 1;
3087 ll_option = mp->ll_option == 1;
3088 send_unicast = mp->send_unicast == 1;
3089 cease = mp->cease == 1;
3090 default_router = mp->default_router == 1;
3092 VALIDATE_SW_IF_INDEX(mp);
3094 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3095 surpress, managed, other,
3096 ll_option, send_unicast, cease,
3097 default_router, ntohl (mp->lifetime),
3098 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3099 ntohl(mp->max_interval), ntohl( mp->min_interval),
3102 BAD_SW_IF_INDEX_LABEL;
3104 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3108 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3109 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3111 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3113 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3115 VALIDATE_SW_IF_INDEX(mp);
3117 is_no = mp->is_no == 1;
3118 use_default = mp->use_default == 1;
3119 no_advertise = mp->no_advertise == 1;
3120 off_link = mp->off_link == 1;
3121 no_autoconfig = mp->no_autoconfig == 1;
3122 no_onlink = mp->no_onlink == 1;
3124 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3125 (ip6_address_t *)mp->address, mp->address_length,
3126 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3127 no_advertise, off_link, no_autoconfig, no_onlink,
3130 BAD_SW_IF_INDEX_LABEL;
3131 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3135 vl_api_sw_interface_ip6_enable_disable_t_handler
3136 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3138 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3139 vnet_main_t * vnm = vnet_get_main();
3141 clib_error_t * error;
3145 VALIDATE_SW_IF_INDEX(mp);
3147 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3148 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3151 clib_error_report(error);
3152 rv = VNET_API_ERROR_UNSPECIFIED;
3154 rv = vnm->api_errno;
3157 BAD_SW_IF_INDEX_LABEL;
3159 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3163 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3164 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3166 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3168 clib_error_t * error;
3169 vnet_main_t * vnm = vnet_get_main();
3173 VALIDATE_SW_IF_INDEX(mp);
3175 error = set_ip6_link_local_address(vm,
3176 ntohl(mp->sw_if_index),
3177 (ip6_address_t *)mp->address,
3178 mp->address_length);
3180 clib_error_report(error);
3181 rv = VNET_API_ERROR_UNSPECIFIED;
3183 rv = vnm->api_errno;
3186 BAD_SW_IF_INDEX_LABEL;
3188 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3191 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3193 vl_api_set_ip_flow_hash_reply_t *rmp;
3194 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3196 clib_warning ("unimplemented...");
3198 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3201 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3203 vl_api_set_ip_flow_hash_reply_t *rmp;
3206 u32 flow_hash_config = 0;
3208 table_id = ntohl(mp->vrf_id);
3210 #define _(a,b) if (mp->a) flow_hash_config |= b;
3211 foreach_flow_hash_bit;
3214 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3216 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3220 static void vl_api_set_ip_flow_hash_t_handler
3221 (vl_api_set_ip_flow_hash_t *mp)
3223 if (mp->is_ipv6 == 0)
3224 set_ip4_flow_hash (mp);
3226 set_ip6_flow_hash (mp);
3229 static void vl_api_sw_interface_set_unnumbered_t_handler
3230 (vl_api_sw_interface_set_unnumbered_t *mp)
3232 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3234 vnet_sw_interface_t * si;
3235 vnet_main_t *vnm = vnet_get_main();
3236 u32 sw_if_index, unnumbered_sw_if_index;
3238 sw_if_index = ntohl(mp->sw_if_index);
3239 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3242 * The API message field names are backwards from
3243 * the underlying data structure names.
3244 * It's not worth changing them now.
3246 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3247 unnumbered_sw_if_index)) {
3248 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3252 /* Only check the "use loop0" field when setting the binding */
3254 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3255 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3259 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3262 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3263 si->unnumbered_sw_if_index = sw_if_index;
3265 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3266 si->unnumbered_sw_if_index = (u32)~0;
3270 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3273 static void vl_api_create_loopback_t_handler
3274 (vl_api_create_loopback_t *mp)
3276 vl_api_create_loopback_reply_t * rmp;
3280 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3282 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3284 rmp->sw_if_index = ntohl (sw_if_index);
3288 static void vl_api_delete_loopback_t_handler
3289 (vl_api_delete_loopback_t *mp)
3291 vl_api_delete_loopback_reply_t * rmp;
3295 sw_if_index = ntohl (mp->sw_if_index);
3296 rv = vnet_delete_loopback_interface (sw_if_index);
3298 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3301 static void vl_api_control_ping_t_handler
3302 (vl_api_control_ping_t *mp)
3304 vl_api_control_ping_reply_t * rmp;
3307 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3309 rmp->vpe_pid = ntohl (getpid());
3313 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3315 u8 **shmem_vecp = (u8 **)arg;
3318 api_main_t * am = &api_main;
3321 shmem_vec = *shmem_vecp;
3323 offset = vec_len (shmem_vec);
3325 pthread_mutex_lock (&am->vlib_rp->mutex);
3326 oldheap = svm_push_data_heap (am->vlib_rp);
3328 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3330 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3332 svm_pop_heap (oldheap);
3333 pthread_mutex_unlock (&am->vlib_rp->mutex);
3335 *shmem_vecp = shmem_vec;
3339 static void vl_api_cli_request_t_handler
3340 (vl_api_cli_request_t *mp)
3342 vl_api_cli_reply_t *rp;
3343 unix_shared_memory_queue_t *q;
3344 vlib_main_t * vm = vlib_get_main();
3345 api_main_t * am = &api_main;
3346 unformat_input_t input;
3350 q = vl_api_client_index_to_input_queue (mp->client_index);
3354 rp = vl_msg_api_alloc (sizeof (*rp));
3355 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3356 rp->context = mp->context;
3358 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3360 vlib_cli_input (vm, &input, shmem_cli_output,
3363 pthread_mutex_lock (&am->vlib_rp->mutex);
3364 oldheap = svm_push_data_heap (am->vlib_rp);
3366 vec_add1(shmem_vec, 0);
3368 svm_pop_heap (oldheap);
3369 pthread_mutex_unlock (&am->vlib_rp->mutex);
3371 rp->reply_in_shmem = (uword)shmem_vec;
3373 vl_msg_api_send_shmem (q, (u8 *)&rp);
3376 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3379 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3380 vnet_main_t *vnm = vnet_get_main();
3381 clib_error_t * error;
3386 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3388 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3391 clib_error_report(error);
3392 rv = VNET_API_ERROR_UNSPECIFIED;
3394 rv = vnm->api_errno;
3397 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3400 static void vl_api_sr_tunnel_add_del_t_handler
3401 (vl_api_sr_tunnel_add_del_t *mp)
3404 clib_warning ("unimplemented");
3406 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3408 vl_api_sr_tunnel_add_del_reply_t * rmp;
3409 ip6_address_t * segments = 0, * seg;
3410 ip6_address_t * tags = 0, *tag;
3411 ip6_address_t * this_address;
3414 if (mp->n_segments == 0) {
3419 memset (a, 0, sizeof (*a));
3420 a->src_address = (ip6_address_t *)&mp->src_address;
3421 a->dst_address = (ip6_address_t *)&mp->dst_address;
3422 a->dst_mask_width = mp->dst_mask_width;
3423 a->flags_net_byte_order = mp->flags_net_byte_order;
3424 a->is_del = (mp->is_add == 0);
3425 a->rx_table_id = ntohl(mp->outer_vrf_id);
3426 a->tx_table_id = ntohl(mp->inner_vrf_id);
3428 a->name = format(0, "%s", mp->name);
3429 if (!(vec_len(a->name)))
3432 a->policy_name = format(0, "%s", mp->policy_name);
3433 if (!(vec_len(a->policy_name)))
3436 /* Yank segments and tags out of the API message */
3437 this_address = (ip6_address_t *)mp->segs_and_tags;
3438 for (i = 0; i < mp->n_segments; i++) {
3439 vec_add2 (segments, seg, 1);
3440 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3443 for (i = 0; i < mp->n_tags; i++) {
3444 vec_add2 (tags, tag, 1);
3445 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3449 a->segments = segments;
3452 rv = ip6_sr_add_del_tunnel (a);
3456 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3460 static void vl_api_sr_policy_add_del_t_handler
3461 (vl_api_sr_policy_add_del_t *mp)
3464 clib_warning ("unimplemented");
3466 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3468 vl_api_sr_policy_add_del_reply_t * rmp;
3471 memset (a, 0, sizeof (*a));
3472 a->is_del = (mp->is_add == 0);
3474 a->name = format(0, "%s", mp->name);
3475 if (!(vec_len(a->name)))
3477 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3481 if (!(mp->tunnel_names[0]))
3483 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3487 // start deserializing tunnel_names
3488 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3489 u8 * deser_tun_names = mp->tunnel_names;
3490 deser_tun_names += 1; //moving along
3493 int tun_name_len = 0;
3495 for (i=0; i < num_tunnels; i++)
3497 tun_name_len= *deser_tun_names;
3498 deser_tun_names += 1;
3499 vec_resize (tun_name, tun_name_len);
3500 memcpy(tun_name, deser_tun_names, tun_name_len);
3501 vec_add1 (a->tunnel_names, tun_name);
3502 deser_tun_names += tun_name_len;
3506 rv = ip6_sr_add_del_policy (a);
3510 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3514 static void vl_api_sr_multicast_map_add_del_t_handler
3515 (vl_api_sr_multicast_map_add_del_t *mp)
3518 clib_warning ("unimplemented");
3520 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3522 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3524 memset (a, 0, sizeof (*a));
3525 a->is_del = (mp->is_add == 0);
3527 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3528 a->policy_name = format(0, "%s", mp->policy_name);
3530 if (a->multicast_address == 0)
3536 if (!(a->policy_name))
3542 #if DPDK > 0 /* Cannot call replicate without DPDK */
3543 rv = ip6_sr_add_del_multicastmap (a);
3545 clib_warning ("multicast replication without DPDK not implemented");
3546 rv = VNET_API_ERROR_UNIMPLEMENTED;
3551 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3555 #define foreach_classify_add_del_table_field \
3560 _(match_n_vectors) \
3561 _(next_table_index) \
3564 static void vl_api_classify_add_del_table_t_handler
3565 (vl_api_classify_add_del_table_t * mp)
3567 vl_api_classify_add_del_table_reply_t * rmp;
3568 vnet_classify_main_t * cm = &vnet_classify_main;
3569 vnet_classify_table_t * t;
3573 foreach_classify_add_del_table_field;
3576 #define _(a) a = ntohl(mp->a);
3577 foreach_classify_add_del_table_field;
3580 /* The underlying API fails silently, on purpose, so check here */
3581 if (mp->is_add == 0)
3582 if (pool_is_free_index (cm->tables, table_index)) {
3583 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3587 rv = vnet_classify_add_del_table
3588 (cm, mp->mask, nbuckets, memory_size,
3589 skip_n_vectors, match_n_vectors,
3590 next_table_index, miss_next_index,
3591 &table_index, mp->is_add);
3594 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3596 if (rv == 0 && mp->is_add) {
3597 t = pool_elt_at_index (cm->tables, table_index);
3598 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3599 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3600 rmp->new_table_index = ntohl(table_index);
3602 rmp->skip_n_vectors = ~0;
3603 rmp->match_n_vectors = ~0;
3604 rmp->new_table_index = ~0;
3609 static void vl_api_classify_add_del_session_t_handler
3610 (vl_api_classify_add_del_session_t * mp)
3612 vnet_classify_main_t * cm = &vnet_classify_main;
3613 vl_api_classify_add_del_session_reply_t * rmp;
3615 u32 table_index, hit_next_index, opaque_index;
3618 table_index = ntohl (mp->table_index);
3619 hit_next_index = ntohl (mp->hit_next_index);
3620 opaque_index = ntohl (mp->opaque_index);
3621 advance = ntohl (mp->advance);
3623 rv = vnet_classify_add_del_session
3624 (cm, table_index, mp->match, hit_next_index, opaque_index,
3625 advance, mp->is_add);
3627 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3630 static void vl_api_classify_set_interface_ip_table_t_handler
3631 (vl_api_classify_set_interface_ip_table_t * mp)
3633 vlib_main_t * vm = vlib_get_main();
3634 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3636 u32 table_index, sw_if_index;
3638 table_index = ntohl (mp->table_index);
3639 sw_if_index = ntohl (mp->sw_if_index);
3641 VALIDATE_SW_IF_INDEX(mp);
3644 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3646 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3648 BAD_SW_IF_INDEX_LABEL;
3650 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3653 static void vl_api_classify_set_interface_l2_tables_t_handler
3654 (vl_api_classify_set_interface_l2_tables_t * mp)
3656 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3658 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3661 ip4_table_index = ntohl(mp->ip4_table_index);
3662 ip6_table_index = ntohl(mp->ip6_table_index);
3663 other_table_index = ntohl(mp->other_table_index);
3664 sw_if_index = ntohl(mp->sw_if_index);
3666 VALIDATE_SW_IF_INDEX(mp);
3668 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3669 ip6_table_index, other_table_index);
3672 if (ip4_table_index != ~0 || ip6_table_index != ~0
3673 || other_table_index != ~0)
3678 vnet_l2_classify_enable_disable (sw_if_index, enable);
3681 BAD_SW_IF_INDEX_LABEL;
3683 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3687 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3690 vl_api_l2_fib_clear_table_reply_t * rmp;
3692 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3693 * that is not currently implemented. When that TODO is fixed
3694 * this call should be changed to pass 1 instead of 0.
3696 l2fib_clear_table (0);
3698 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3701 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3706 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3709 vl_api_l2_interface_efp_filter_reply_t * rmp;
3710 vnet_main_t *vnm = vnet_get_main();
3712 // enable/disable the feature
3713 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3714 rv = vnm->api_errno;
3716 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3720 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3723 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3724 vnet_main_t * vnm = vnet_get_main();
3725 vlib_main_t * vm = vlib_get_main();
3728 VALIDATE_SW_IF_INDEX(mp);
3730 vtr_op = ntohl(mp->vtr_op);
3732 /* The L2 code is unsuspicious */
3734 case L2_VTR_DISABLED:
3739 case L2_VTR_TRANSLATE_1_1:
3740 case L2_VTR_TRANSLATE_1_2:
3741 case L2_VTR_TRANSLATE_2_1:
3742 case L2_VTR_TRANSLATE_2_2:
3746 rv = VNET_API_ERROR_INVALID_VALUE;
3747 goto bad_sw_if_index;
3750 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3751 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3754 BAD_SW_IF_INDEX_LABEL;
3756 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3760 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3764 vl_api_create_vhost_user_if_reply_t * rmp;
3765 u32 sw_if_index = (u32)~0;
3767 vnet_main_t * vnm = vnet_get_main();
3768 vlib_main_t * vm = vlib_get_main();
3770 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3771 mp->is_server, &sw_if_index, (u64)~0,
3772 mp->renumber, ntohl(mp->custom_dev_instance),
3773 (mp->use_custom_mac)?mp->mac_address:NULL);
3775 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3777 rmp->sw_if_index = ntohl (sw_if_index);
3783 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3787 vl_api_modify_vhost_user_if_reply_t * rmp;
3788 u32 sw_if_index = ntohl(mp->sw_if_index);
3790 vnet_main_t * vnm = vnet_get_main();
3791 vlib_main_t * vm = vlib_get_main();
3793 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3794 mp->is_server, sw_if_index, (u64)~0,
3795 mp->renumber, ntohl(mp->custom_dev_instance));
3797 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3802 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3806 vpe_api_main_t * vam = &vpe_api_main;
3807 vl_api_delete_vhost_user_if_reply_t * rmp;
3808 u32 sw_if_index = ntohl(mp->sw_if_index);
3810 vnet_main_t * vnm = vnet_get_main();
3811 vlib_main_t * vm = vlib_get_main();
3813 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3815 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3817 unix_shared_memory_queue_t * q =
3818 vl_api_client_index_to_input_queue (mp->client_index);
3822 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3827 static void vl_api_sw_interface_vhost_user_details_t_handler (
3828 vl_api_sw_interface_vhost_user_details_t * mp)
3830 clib_warning ("BUG");
3834 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3835 unix_shared_memory_queue_t *q,
3836 vhost_user_intf_details_t * vui,
3839 vl_api_sw_interface_vhost_user_details_t * mp;
3841 mp = vl_msg_api_alloc (sizeof (*mp));
3842 memset (mp, 0, sizeof (*mp));
3843 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3844 mp->sw_if_index = ntohl(vui->sw_if_index);
3845 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3846 mp->features = clib_net_to_host_u64 (vui->features);
3847 mp->is_server = vui->is_server;
3848 mp->num_regions = ntohl(vui->num_regions);
3849 mp->sock_errno = ntohl(vui->sock_errno);
3850 mp->context = context;
3852 strncpy ((char *) mp->sock_filename,
3853 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3854 strncpy ((char *) mp->interface_name,
3855 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3857 vl_msg_api_send_shmem (q, (u8 *)&mp);
3862 vl_api_sw_interface_vhost_user_dump_t_handler (
3863 vl_api_sw_interface_vhost_user_dump_t *mp)
3867 vpe_api_main_t * am = &vpe_api_main;
3868 vnet_main_t * vnm = vnet_get_main();
3869 vlib_main_t * vm = vlib_get_main();
3870 vhost_user_intf_details_t *ifaces = NULL;
3871 vhost_user_intf_details_t *vuid = NULL;
3872 unix_shared_memory_queue_t * q;
3874 q = vl_api_client_index_to_input_queue (mp->client_index);
3878 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3882 vec_foreach (vuid, ifaces) {
3883 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3889 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3890 unix_shared_memory_queue_t *q,
3895 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3896 u8 * if_name = NULL;
3897 vnet_sw_interface_t * si = NULL;
3899 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3901 if_name = format(if_name, "%U",
3902 format_vnet_sw_interface_name, lm->vnet_main, si);
3904 mp = vl_msg_api_alloc (sizeof (*mp));
3905 memset (mp, 0, sizeof (*mp));
3906 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3907 strncpy((char *)mp->interface_name,
3908 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3909 mp->sw_if_index = ntohl(si->sw_if_index);
3910 mp->local_session_id = s->local_session_id;
3911 mp->remote_session_id = s->remote_session_id;
3912 mp->local_cookie[0] = s->local_cookie[0];
3913 mp->local_cookie[1] = s->local_cookie[1];
3914 mp->remote_cookie = s->remote_cookie;
3915 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3916 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3917 mp->l2_sublayer_present = s->l2_sublayer_present;
3918 mp->context = context;
3920 vl_msg_api_send_shmem (q, (u8 *)&mp);
3923 static void send_ip_address_details (vpe_api_main_t * am,
3924 unix_shared_memory_queue_t * q,
3930 vl_api_ip_address_details_t * mp;
3932 mp = vl_msg_api_alloc (sizeof (*mp));
3933 memset (mp, 0, sizeof (*mp));
3934 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3937 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3939 u32 * tp = (u32 *)mp->ip;
3940 *tp = ntohl(*(u32*)ip);
3942 mp->prefix_length = prefix_length;
3943 mp->context = context;
3945 vl_msg_api_send_shmem (q, (u8 *)&mp);
3949 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3951 vpe_api_main_t * am = &vpe_api_main;
3952 unix_shared_memory_queue_t * q;
3955 ip6_main_t * im6 = &ip6_main;
3956 ip4_main_t * im4 = &ip4_main;
3957 ip_lookup_main_t * lm6 = &im6->lookup_main;
3958 ip_lookup_main_t * lm4 = &im4->lookup_main;
3959 ip_interface_address_t * ia = 0;
3960 u32 sw_if_index = ~0;
3961 int rv __attribute__ ((unused)) = 0;
3963 VALIDATE_SW_IF_INDEX(mp);
3965 sw_if_index = ntohl(mp->sw_if_index);
3967 q = vl_api_client_index_to_input_queue (mp->client_index);
3973 foreach_ip_interface_address (lm6, ia, sw_if_index,
3974 1 /* honor unnumbered */,
3976 r6 = ip_interface_address_get_address (lm6, ia);
3977 u16 prefix_length = ia->address_length;
3978 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
3981 foreach_ip_interface_address (lm4, ia, sw_if_index,
3982 1 /* honor unnumbered */,
3984 r4 = ip_interface_address_get_address (lm4, ia);
3985 u16 prefix_length = ia->address_length;
3986 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
3989 BAD_SW_IF_INDEX_LABEL;
3992 static void send_ip_details (vpe_api_main_t * am,
3993 unix_shared_memory_queue_t *q,
3997 vl_api_ip_details_t * mp;
3999 mp = vl_msg_api_alloc (sizeof (*mp));
4000 memset (mp, 0, sizeof (*mp));
4001 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
4003 mp->sw_if_index = ntohl(sw_if_index);
4004 mp->context = context;
4006 vl_msg_api_send_shmem (q, (u8 *)&mp);
4010 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
4011 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
4013 vpe_api_main_t * am = &vpe_api_main;
4014 l2t_main_t * lm = &l2t_main;
4015 unix_shared_memory_queue_t * q;
4016 l2t_session_t *session;
4018 q = vl_api_client_index_to_input_queue (mp->client_index);
4022 pool_foreach (session, lm->sessions,
4024 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4029 static void send_sw_interface_tap_details (vpe_api_main_t * am,
4030 unix_shared_memory_queue_t *q,
4031 tapcli_interface_details_t *tap_if,
4034 vl_api_sw_interface_tap_details_t * mp;
4035 mp = vl_msg_api_alloc (sizeof (*mp));
4036 memset (mp, 0, sizeof (*mp));
4037 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4038 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4039 strncpy((char *)mp->dev_name,
4040 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4041 mp->context = context;
4043 vl_msg_api_send_shmem (q, (u8 *)&mp);
4047 vl_api_sw_interface_tap_dump_t_handler (
4048 vl_api_sw_interface_tap_dump_t *mp)
4051 vpe_api_main_t * am = &vpe_api_main;
4052 unix_shared_memory_queue_t * q;
4053 tapcli_interface_details_t *tapifs = NULL;
4054 tapcli_interface_details_t *tap_if = NULL;
4056 q = vl_api_client_index_to_input_queue (mp->client_index);
4060 rv = vnet_tap_dump_ifs(&tapifs);
4064 vec_foreach(tap_if, tapifs) {
4065 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4072 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4074 vpe_api_main_t * am = &vpe_api_main;
4075 vnet_main_t * vnm = vnet_get_main();
4076 vlib_main_t * vm = vlib_get_main();
4077 vnet_interface_main_t * im = &vnm->interface_main;
4078 unix_shared_memory_queue_t * q;
4079 vnet_sw_interface_t * si, * sorted_sis;
4080 u32 sw_if_index = ~0;
4082 q = vl_api_client_index_to_input_queue (mp->client_index);
4087 /* Gather interfaces. */
4088 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4089 _vec_len (sorted_sis) = 0;
4090 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4092 vec_foreach (si, sorted_sis) {
4093 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4094 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4097 sw_if_index = si->sw_if_index;
4098 send_ip_details(am, q, sw_if_index, mp->context);
4103 static void vl_api_l2_fib_table_entry_t_handler (
4104 vl_api_l2_fib_table_entry_t * mp)
4106 clib_warning ("BUG");
4109 static void send_l2fib_table_entry (vpe_api_main_t * am,
4110 unix_shared_memory_queue_t *q,
4111 l2fib_entry_key_t * l2fe_key,
4112 l2fib_entry_result_t * l2fe_res,
4115 vl_api_l2_fib_table_entry_t * mp;
4117 mp = vl_msg_api_alloc (sizeof (*mp));
4118 memset (mp, 0, sizeof (*mp));
4119 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4121 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4123 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4124 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4125 mp->static_mac = l2fe_res->fields.static_mac;
4126 mp->filter_mac = l2fe_res->fields.filter;
4127 mp->bvi_mac = l2fe_res->fields.bvi;
4128 mp->context = context;
4130 vl_msg_api_send_shmem (q, (u8 *)&mp);
4134 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4136 vpe_api_main_t * am = &vpe_api_main;
4137 bd_main_t * bdm = &bd_main;
4138 l2fib_entry_key_t *l2fe_key = NULL;
4139 l2fib_entry_result_t *l2fe_res = NULL;
4140 u32 ni, bd_id = ntohl (mp->bd_id);
4142 unix_shared_memory_queue_t * q;
4145 q = vl_api_client_index_to_input_queue (mp->client_index);
4149 /* see l2fib_table_dump: ~0 means "any" */
4153 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4160 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4162 vec_foreach_index (ni, l2fe_key) {
4163 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4164 vec_elt_at_index(l2fe_res, ni), mp->context);
4171 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4173 vl_api_show_version_reply_t *rmp;
4175 char * vpe_api_get_build_directory(void);
4176 char * vpe_api_get_version(void);
4177 char * vpe_api_get_build_date(void);
4179 unix_shared_memory_queue_t * q =
4180 vl_api_client_index_to_input_queue (mp->client_index);
4185 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4187 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4188 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4189 ARRAY_LEN(rmp->build_directory)-1);
4190 strncpy ((char *) rmp->version, vpe_api_get_version(),
4191 ARRAY_LEN(rmp->version)-1);
4192 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4193 ARRAY_LEN(rmp->build_date)-1);
4197 static void vl_api_get_node_index_t_handler
4198 (vl_api_get_node_index_t * mp)
4200 vlib_main_t * vm = vlib_get_main();
4201 vl_api_get_node_index_reply_t * rmp;
4204 u32 node_index = ~0;
4206 n = vlib_get_node_by_name (vm, mp->node_name);
4209 rv = VNET_API_ERROR_NO_SUCH_NODE;
4211 node_index = n->index;
4213 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4215 rmp->node_index = ntohl(node_index);
4219 static void vl_api_add_node_next_t_handler
4220 (vl_api_add_node_next_t * mp)
4222 vlib_main_t * vm = vlib_get_main();
4223 vl_api_add_node_next_reply_t * rmp;
4224 vlib_node_t * n, * next;
4226 u32 next_index = ~0;
4228 n = vlib_get_node_by_name (vm, mp->node_name);
4231 rv = VNET_API_ERROR_NO_SUCH_NODE;
4235 next = vlib_get_node_by_name (vm, mp->next_name);
4238 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4240 next_index = vlib_node_add_next (vm, n->index, next->index);
4243 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4245 rmp->next_index = ntohl(next_index);
4249 static void vl_api_l2tpv3_create_tunnel_t_handler
4250 (vl_api_l2tpv3_create_tunnel_t *mp)
4252 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4253 l2t_main_t *lm = &l2t_main;
4254 u32 sw_if_index = (u32)~0;
4257 if (mp->is_ipv6 != 1) {
4258 rv = VNET_API_ERROR_UNIMPLEMENTED;
4262 rv = create_l2tpv3_ipv6_tunnel (lm,
4263 (ip6_address_t *) mp->client_address,
4264 (ip6_address_t *) mp->our_address,
4265 ntohl(mp->local_session_id),
4266 ntohl(mp->remote_session_id),
4267 clib_net_to_host_u64(mp->local_cookie),
4268 clib_net_to_host_u64(mp->remote_cookie),
4269 mp->l2_sublayer_present,
4273 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4275 rmp->sw_if_index = ntohl (sw_if_index);
4279 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4280 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4282 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4283 l2t_main_t *lm = &l2t_main;
4286 VALIDATE_SW_IF_INDEX(mp);
4288 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4289 clib_net_to_host_u64(mp->new_local_cookie),
4290 clib_net_to_host_u64(mp->new_remote_cookie));
4292 BAD_SW_IF_INDEX_LABEL;
4294 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4297 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4298 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4301 vnet_main_t * vnm = vnet_get_main();
4302 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4304 VALIDATE_SW_IF_INDEX(mp);
4306 rv = l2tpv3_interface_enable_disable
4307 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4309 BAD_SW_IF_INDEX_LABEL;
4311 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4314 static void vl_api_l2tpv3_set_lookup_key_t_handler
4315 (vl_api_l2tpv3_set_lookup_key_t * mp)
4318 l2t_main_t *lm = &l2t_main;
4319 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4321 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4322 rv = VNET_API_ERROR_INVALID_VALUE;
4326 lm->lookup_type = mp->key;
4329 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4332 static void vl_api_vxlan_add_del_tunnel_t_handler
4333 (vl_api_vxlan_add_del_tunnel_t * mp)
4335 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4337 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4338 u32 encap_fib_index;
4340 ip4_main_t * im = &ip4_main;
4341 u32 sw_if_index = ~0;
4343 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4345 rv = VNET_API_ERROR_NO_SUCH_FIB;
4348 encap_fib_index = p[0];
4350 /* Check src & dst are different */
4351 if ((mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4352 (!mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4353 rv = VNET_API_ERROR_SAME_SRC_DST;
4356 memset (a, 0, sizeof (*a));
4358 a->is_add = mp->is_add;
4359 a->is_ip6 = mp->is_ipv6;
4361 /* ip addresses sent in network byte order */
4363 memcpy(&(a->src.ip6), mp->src_address, 16);
4364 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4366 memcpy(&(a->src.ip4), mp->src_address, 4);
4367 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4370 a->encap_fib_index = encap_fib_index;
4371 a->decap_next_index = ntohl(mp->decap_next_index);
4372 a->vni = ntohl(mp->vni);
4373 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4376 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4378 rmp->sw_if_index = ntohl (sw_if_index);
4382 static void send_vxlan_tunnel_details
4383 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4385 vl_api_vxlan_tunnel_details_t * rmp;
4386 ip4_main_t * im4 = &ip4_main;
4387 ip6_main_t * im6 = &ip6_main;
4388 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4390 rmp = vl_msg_api_alloc (sizeof (*rmp));
4391 memset (rmp, 0, sizeof (*rmp));
4392 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4394 memcpy(rmp->src_address, &(t->src.ip6), 16);
4395 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4396 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4398 memcpy(rmp->src_address, &(t->src.ip4), 4);
4399 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4400 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4402 rmp->vni = htonl(t->vni);
4403 rmp->decap_next_index = htonl(t->decap_next_index);
4404 rmp->sw_if_index = htonl(t->sw_if_index);
4405 rmp->is_ipv6 = is_ipv6;
4406 rmp->context = context;
4408 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4411 static void vl_api_vxlan_tunnel_dump_t_handler
4412 (vl_api_vxlan_tunnel_dump_t * mp)
4414 unix_shared_memory_queue_t * q;
4415 vxlan_main_t * vxm = &vxlan_main;
4419 q = vl_api_client_index_to_input_queue (mp->client_index);
4424 sw_if_index = ntohl(mp->sw_if_index);
4426 if (~0 == sw_if_index) {
4427 pool_foreach (t, vxm->tunnels,
4429 send_vxlan_tunnel_details(t, q, mp->context);
4432 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4433 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4436 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4437 send_vxlan_tunnel_details(t, q, mp->context);
4441 static void vl_api_gre_add_del_tunnel_t_handler
4442 (vl_api_gre_add_del_tunnel_t * mp)
4444 vl_api_gre_add_del_tunnel_reply_t * rmp;
4446 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4449 ip4_main_t * im = &ip4_main;
4450 u32 sw_if_index = ~0;
4452 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_table_id));
4454 rv = VNET_API_ERROR_NO_SUCH_FIB;
4457 outer_table_id = p[0];
4459 /* Check src & dst are different */
4460 if (memcmp(&mp->src_address, &mp->dst_address, 4) == 0) {
4461 rv = VNET_API_ERROR_SAME_SRC_DST;
4465 memset (a, 0, sizeof (*a));
4467 a->is_add = mp->is_add;
4469 /* ip addresses sent in network byte order */
4470 a->src.as_u32 = mp->src_address;
4471 a->dst.as_u32 = mp->dst_address;
4473 a->outer_table_id = outer_table_id;
4474 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4477 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4479 rmp->sw_if_index = ntohl (sw_if_index);
4483 static void send_gre_tunnel_details
4484 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4486 vl_api_gre_tunnel_details_t * rmp;
4487 ip4_main_t * im = &ip4_main;
4489 rmp = vl_msg_api_alloc (sizeof (*rmp));
4490 memset (rmp, 0, sizeof (*rmp));
4491 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4492 rmp->src_address = t->tunnel_src.data_u32;
4493 rmp->dst_address = t->tunnel_dst.data_u32;
4494 rmp->outer_table_id = htonl(im->fibs[t->outer_fib_index].table_id);
4495 rmp->sw_if_index = htonl(t->sw_if_index);
4496 rmp->context = context;
4498 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4501 static void vl_api_gre_tunnel_dump_t_handler
4502 (vl_api_gre_tunnel_dump_t * mp)
4504 unix_shared_memory_queue_t * q;
4505 gre_main_t * gm = &gre_main;
4509 q = vl_api_client_index_to_input_queue (mp->client_index);
4514 sw_if_index = ntohl(mp->sw_if_index);
4516 if (~0 == sw_if_index) {
4517 pool_foreach (t, gm->tunnels,
4519 send_gre_tunnel_details(t, q, mp->context);
4522 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4523 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4526 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4527 send_gre_tunnel_details(t, q, mp->context);
4532 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4534 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4536 vl_api_l2_patch_add_del_reply_t * rmp;
4537 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4541 VALIDATE_RX_SW_IF_INDEX(mp);
4542 VALIDATE_TX_SW_IF_INDEX(mp);
4544 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4545 ntohl(mp->tx_sw_if_index),
4546 (int)(mp->is_add != 0));
4548 BAD_RX_SW_IF_INDEX_LABEL;
4549 BAD_TX_SW_IF_INDEX_LABEL;
4551 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4555 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4556 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4558 vl_api_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4560 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4561 u32 encap_fib_index, decap_fib_index;
4564 ip4_main_t * im = &ip4_main;
4565 u32 sw_if_index = ~0;
4568 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4570 rv = VNET_API_ERROR_NO_SUCH_FIB;
4573 encap_fib_index = p[0];
4575 protocol = mp->protocol;
4577 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4578 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT) {
4579 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4581 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4584 decap_fib_index = p[0];
4586 decap_fib_index = ntohl(mp->decap_vrf_id);
4589 /* Check src & dst are different */
4590 if ((mp->is_ipv6 && memcmp(mp->local, mp->remote, 16) == 0) ||
4591 (!mp->is_ipv6 && memcmp(mp->local, mp->remote, 4) == 0)) {
4592 rv = VNET_API_ERROR_SAME_SRC_DST;
4595 memset (a, 0, sizeof (*a));
4597 a->is_add = mp->is_add;
4598 a->is_ip6 = mp->is_ipv6;
4599 /* ip addresses sent in network byte order */
4601 clib_memcpy(&(a->local.ip6), mp->local, 16);
4602 clib_memcpy(&(a->remote.ip6), mp->remote, 16);
4604 clib_memcpy(&(a->local.ip4), mp->local, 4);
4605 clib_memcpy(&(a->remote.ip4), mp->remote, 4);
4607 a->encap_fib_index = encap_fib_index;
4608 a->decap_fib_index = decap_fib_index;
4609 a->protocol = protocol;
4610 a->vni = ntohl(mp->vni);
4611 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4614 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4616 rmp->sw_if_index = ntohl (sw_if_index);
4620 static void send_vxlan_gpe_tunnel_details
4621 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4623 vl_api_vxlan_gpe_tunnel_details_t * rmp;
4624 ip4_main_t * im4 = &ip4_main;
4625 ip6_main_t * im6 = &ip6_main;
4626 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
4628 rmp = vl_msg_api_alloc (sizeof (*rmp));
4629 memset (rmp, 0, sizeof (*rmp));
4630 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_GPE_TUNNEL_DETAILS);
4632 memcpy(rmp->local, &(t->local.ip6), 16);
4633 memcpy(rmp->remote, &(t->remote.ip6), 16);
4634 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4635 rmp->decap_vrf_id = htonl(im6->fibs[t->decap_fib_index].table_id);
4637 memcpy(rmp->local, &(t->local.ip4), 4);
4638 memcpy(rmp->remote, &(t->remote.ip4), 4);
4639 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4640 rmp->decap_vrf_id = htonl(im4->fibs[t->decap_fib_index].table_id);
4642 rmp->vni = htonl(t->vni);
4643 rmp->protocol = t->protocol;
4644 rmp->sw_if_index = htonl(t->sw_if_index);
4645 rmp->is_ipv6 = is_ipv6;
4646 rmp->context = context;
4648 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4651 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
4652 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
4654 unix_shared_memory_queue_t * q;
4655 vxlan_gpe_main_t * vgm = &vxlan_gpe_main;
4656 vxlan_gpe_tunnel_t * t;
4659 q = vl_api_client_index_to_input_queue (mp->client_index);
4664 sw_if_index = ntohl(mp->sw_if_index);
4666 if (~0 == sw_if_index) {
4667 pool_foreach (t, vgm->tunnels,
4669 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4672 if ((sw_if_index >= vec_len(vgm->tunnel_index_by_sw_if_index)) ||
4673 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index])) {
4676 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
4677 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4682 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4684 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4686 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4688 u8 *locator_name = NULL;
4690 memset(a, 0, sizeof(a[0]));
4692 locator_name = format(0, "%s", mp->locator_set_name);
4694 a->name = locator_name;
4696 a->is_add = mp->is_add;
4699 rv = vnet_lisp_add_del_locator_set(a, &ls_index);
4701 vec_free(locator_name);
4703 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4707 vl_api_lisp_add_del_locator_t_handler(
4708 vl_api_lisp_add_del_locator_t *mp)
4710 vl_api_lisp_add_del_locator_reply_t *rmp;
4712 locator_t locator, *locators = NULL;
4713 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4715 u8 *locator_name = NULL;
4717 memset(&locator, 0, sizeof(locator));
4718 memset(a, 0, sizeof(a[0]));
4720 locator.sw_if_index = ntohl(mp->sw_if_index);
4721 locator.priority = mp->priority;
4722 locator.weight = mp->weight;
4724 vec_add1(locators, locator);
4726 locator_name = format(0, "%s", mp->locator_set_name);
4728 a->name = locator_name;
4729 a->locators = locators;
4730 a->is_add = mp->is_add;
4733 rv = vnet_lisp_add_del_locator(a, NULL, &ls_index);
4736 vec_free(locator_name);
4738 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4742 vl_api_lisp_add_del_local_eid_t_handler(
4743 vl_api_lisp_add_del_local_eid_t *mp)
4745 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4746 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4748 ip_prefix_t *prefp = NULL;
4749 ip_address_t *ip_eid = NULL;
4752 u32 locator_set_index = ~0, map_index = ~0;
4753 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4756 prefp = &gid_address_ippref(&eid);
4757 ip_eid = &ip_prefix_addr(prefp);
4758 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4761 clib_memcpy(&ip_addr_v6(ip_eid), mp->ip_address,
4762 sizeof(ip_addr_v6(ip_eid)));
4763 ip_addr_version(ip_eid) = IP6;
4765 clib_memcpy(&ip_addr_v4(ip_eid), mp->ip_address,
4766 sizeof(ip_addr_v4(ip_eid)));
4767 ip_addr_version(ip_eid) = IP4;
4769 ip_prefix_len(prefp) = mp->prefix_len;
4771 name = format(0, "%s", mp->locator_set_name);
4772 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4774 rv = VNET_API_ERROR_INVALID_VALUE;
4777 locator_set_index = p[0];
4779 /* XXX treat batch configuration */
4780 a->is_add = mp->is_add;
4782 a->locator_set_index = locator_set_index;
4785 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4790 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4794 lisp_gpe_add_del_fwd_entry_set_address(
4795 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4796 ip_address_t *slocator,
4797 ip_address_t *dlocator,
4800 ip_address_t *ip_eid = NULL;
4801 ip_prefix_t *prefp = NULL;
4803 prefp = &gid_address_ippref(eid);
4804 ip_eid = &ip_prefix_addr(prefp);
4806 if (mp->eid_is_ipv6) {
4807 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4808 sizeof(ip_addr_v6(ip_eid)));
4809 ip_addr_version(ip_eid) = IP6;
4811 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4812 sizeof(ip_addr_v4(ip_eid)));
4813 ip_addr_version(ip_eid) = IP4;
4815 ip_prefix_len(prefp) = mp->eid_prefix_len;
4817 if (mp->address_is_ipv6) {
4818 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4819 sizeof(ip_addr_v6(slocator)));
4820 ip_addr_version(slocator) = IP6;
4821 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4822 sizeof(ip_addr_v6(dlocator)));
4823 ip_addr_version(dlocator) = IP6;
4825 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4826 sizeof(ip_addr_v4(slocator)));
4827 ip_addr_version(slocator) = IP4;
4828 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4829 sizeof(ip_addr_v4(dlocator)));
4830 ip_addr_version(dlocator) = IP4;
4835 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4836 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4838 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4840 ip_address_t slocator, dlocator;
4842 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4844 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4846 memset (&a, 0, sizeof(a));
4848 a.is_add = mp->is_add;
4850 a.slocator = slocator;
4851 a.dlocator = dlocator;
4852 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4854 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4858 vl_api_lisp_add_del_map_resolver_t_handler(
4859 vl_api_lisp_add_del_map_resolver_t *mp)
4861 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4863 ip_address_t *ip_addr = NULL;
4864 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4866 a->is_add = mp->is_add;
4867 ip_addr = &a->address;
4870 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4871 sizeof(ip_addr_v6(ip_addr)));
4872 ip_addr_version(ip_addr) = IP6;
4874 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4875 sizeof(ip_addr_v4(ip_addr)));
4876 ip_addr_version(ip_addr) = IP4;
4879 rv = vnet_lisp_add_del_map_resolver (a);
4881 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4885 vl_api_lisp_gpe_enable_disable_t_handler(
4886 vl_api_lisp_gpe_enable_disable_t *mp)
4888 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4890 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
4892 a->is_en = mp->is_en;
4893 vnet_lisp_gpe_enable_disable (a);
4895 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4899 vl_api_lisp_enable_disable_t_handler(
4900 vl_api_lisp_enable_disable_t *mp)
4902 vl_api_lisp_enable_disable_reply_t *rmp;
4905 vnet_lisp_enable_disable (mp->is_en);
4906 REPLY_MACRO(VL_API_LISP_ENABLE_DISABLE_REPLY);
4910 vl_api_lisp_gpe_add_del_iface_t_handler(
4911 vl_api_lisp_gpe_add_del_iface_t *mp)
4913 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4915 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4917 a->is_add = mp->is_add;
4918 a->table_id = mp->table_id;
4920 vnet_lisp_gpe_add_del_iface (a, 0);
4922 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4926 vl_api_lisp_pitr_set_locator_set_t_handler(
4927 vl_api_lisp_pitr_set_locator_set_t *mp)
4929 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
4933 ls_name = format (0, "%s", mp->ls_name);
4934 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
4937 REPLY_MACRO(VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
4941 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
4942 (vl_api_lisp_add_del_map_request_itr_rlocs_t *mp)
4944 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
4946 u8 * locator_set_name = NULL;
4947 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, * a = &_a;
4949 locator_set_name = format (0, "%s", mp->locator_set_name);
4951 a->is_add = mp->is_add;
4952 a->locator_set_name = locator_set_name;
4954 rv = vnet_lisp_add_del_mreq_itr_rlocs(a);
4956 vec_free(locator_set_name);
4958 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
4961 /** Used for transferring locators via VPP API */
4962 typedef CLIB_PACKED(struct
4964 u8 is_ip4; /**< is locator an IPv4 address */
4965 u8 addr[16]; /**< IPv4/IPv6 address */
4969 send_lisp_locator_set_details_set_address
4970 (vl_api_lisp_locator_set_details_t *rmp,
4971 gid_address_t *gid_address)
4973 ip_prefix_t *ip_addr;
4975 if (gid_address_type(gid_address) != GID_ADDR_IP_PREFIX) {
4979 ip_addr = &gid_address_ippref(gid_address);
4980 rmp->prefix_len = ip_prefix_len(ip_addr);
4981 rmp->is_ipv6 = ip_prefix_version(ip_addr);
4982 ip_address_copy_addr(rmp->ip_address, &ip_prefix_addr(ip_addr));
4986 vl_api_lisp_add_del_remote_mapping_t_handler (
4987 vl_api_lisp_add_del_remote_mapping_t *mp)
4990 ip_address_t rloc, * rlocs = 0;
4991 vl_api_lisp_add_del_remote_mapping_reply_t * rmp;
4993 gid_address_t _seid, * seid = &_seid;
4994 gid_address_t _deid, * deid = &_deid;
4995 ip_prefix_t * seid_pref = &gid_address_ippref(seid);
4996 ip_prefix_t * deid_pref = &gid_address_ippref(deid);
4998 gid_address_type(seid) = GID_ADDR_IP_PREFIX;
4999 gid_address_type(deid) = GID_ADDR_IP_PREFIX;
5000 ip_address_t * seid_addr = &ip_prefix_addr(seid_pref);
5001 ip_address_t * deid_addr = &ip_prefix_addr(deid_pref);
5002 ip_prefix_len(seid_pref) = mp->seid_len;
5003 ip_prefix_len(deid_pref) = mp->deid_len;
5004 gid_address_set_vni (seid, ntohl (mp->vni));
5005 gid_address_set_vni (deid, ntohl (mp->vni));
5007 if (mp->eid_is_ip4) {
5008 ip_prefix_version(seid_pref) = IP4;
5009 ip_prefix_version(deid_pref) = IP4;
5010 clib_memcpy (&ip_addr_v4(seid_addr),
5011 mp->seid, sizeof (ip_addr_v4(seid_addr)));
5012 clib_memcpy (&ip_addr_v4(deid_addr),
5013 mp->deid, sizeof (ip_addr_v4(deid_addr)));
5015 ip_prefix_version(seid_pref) = IP6;
5016 ip_prefix_version(deid_pref) = IP6;
5017 clib_memcpy (&ip_addr_v6(seid_addr),
5018 mp->seid, sizeof (ip_addr_v6(seid_addr)));
5019 clib_memcpy (&ip_addr_v6(deid_addr),
5020 mp->deid, sizeof (ip_addr_v6(deid_addr)));
5023 for (i = 0; i < mp->rloc_num; i++) {
5024 rloc_t * r = &((rloc_t *) mp->rlocs)[i];
5026 clib_memcpy (&ip_addr_v4(&rloc), &r->addr, sizeof (rloc_t));
5027 ip_addr_version (&rloc) = IP4;
5029 clib_memcpy (&ip_addr_v6(&rloc), &r->addr, sizeof (rloc_t));
5030 ip_addr_version (&rloc) = IP6;
5032 vec_add1 (rlocs, rloc);
5035 rv = vnet_lisp_add_del_remote_mapping (deid, seid, rlocs, mp->action,
5036 mp->is_add, mp->del_all);
5038 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5042 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
5043 locator_set_t *lsit,
5044 unix_shared_memory_queue_t *q,
5048 vl_api_lisp_locator_set_details_t *rmp;
5049 locator_t *loc = NULL;
5053 vec_foreach (locit, lsit->locator_indices) {
5054 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5055 rmp = vl_msg_api_alloc (sizeof (*rmp));
5056 memset (rmp, 0, sizeof (*rmp));
5057 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
5058 rmp->local = lsit->local;
5060 ASSERT(lsit->name != NULL);
5061 strncpy((char *) rmp->locator_set_name,
5062 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5063 rmp->sw_if_index = htonl(loc->sw_if_index);
5065 str = format(0, "remote-%d", index);
5066 strncpy((char *) rmp->locator_set_name, (char *) str,
5067 ARRAY_LEN(rmp->locator_set_name) - 1);
5068 send_lisp_locator_set_details_set_address(rmp, &loc->address);
5072 rmp->priority = loc->priority;
5073 rmp->weight = loc->weight;
5074 rmp->context = context;
5076 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5081 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
5083 unix_shared_memory_queue_t * q = NULL;
5084 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5085 locator_set_t * lsit = NULL;
5088 q = vl_api_client_index_to_input_queue (mp->client_index);
5094 pool_foreach (lsit, lcm->locator_set_pool,
5096 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
5101 send_lisp_local_eid_table_details (mapping_t *mapit,
5102 unix_shared_memory_queue_t *q,
5105 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
5106 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5107 locator_set_t *ls = NULL;
5108 gid_address_t *gid = NULL;
5109 ip_prefix_t *ip_prefix = NULL;
5113 ls = pool_elt_at_index (lcm->locator_set_pool,
5114 mapit->locator_set_index);
5117 type = gid_address_type(gid);
5119 if (type != GID_ADDR_IP_PREFIX) {
5123 ip_prefix = &gid_address_ippref(gid);
5125 rmp = vl_msg_api_alloc (sizeof (*rmp));
5126 memset (rmp, 0, sizeof (*rmp));
5127 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
5129 ASSERT(ls->name != NULL);
5130 strncpy((char *) rmp->locator_set_name,
5131 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5133 str = format(0, "remote-%d", mapit->locator_set_index);
5134 strncpy((char *) rmp->locator_set_name, (char *) str,
5135 ARRAY_LEN(rmp->locator_set_name) - 1);
5139 switch (ip_prefix_version(ip_prefix)) {
5141 rmp->eid_is_ipv6 = 0;
5142 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v4(ip_prefix),
5143 sizeof(ip_prefix_v4(ip_prefix)));
5147 rmp->eid_is_ipv6 = 1;
5148 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v6(ip_prefix),
5149 sizeof(ip_prefix_v6(ip_prefix)));
5155 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
5156 rmp->context = context;
5158 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5162 vl_api_lisp_local_eid_table_dump_t_handler (
5163 vl_api_lisp_local_eid_table_dump_t *mp)
5165 unix_shared_memory_queue_t * q = NULL;
5166 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5167 mapping_t * mapit = NULL;
5169 q = vl_api_client_index_to_input_queue (mp->client_index);
5174 pool_foreach (mapit, lcm->mapping_pool,
5176 send_lisp_local_eid_table_details(mapit, q, mp->context);
5181 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5182 unix_shared_memory_queue_t *q,
5185 vl_api_lisp_gpe_tunnel_details_t *rmp;
5186 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5188 rmp = vl_msg_api_alloc (sizeof (*rmp));
5189 memset (rmp, 0, sizeof (*rmp));
5190 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5192 rmp->tunnels = tunnel - lgm->tunnels;
5194 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5195 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5196 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5198 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5199 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5200 rmp->dcap_next = htonl(tunnel->decap_next_index);
5201 rmp->lisp_ver = tunnel->ver_res;
5202 rmp->next_protocol = tunnel->next_protocol;
5203 rmp->flags = tunnel->flags;
5204 rmp->ver_res = tunnel->ver_res;
5205 rmp->res = tunnel->res;
5206 rmp->iid = htonl(tunnel->vni);
5207 rmp->context = context;
5209 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5213 vl_api_lisp_gpe_tunnel_dump_t_handler (
5214 vl_api_lisp_local_eid_table_dump_t *mp)
5216 unix_shared_memory_queue_t * q = NULL;
5217 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5218 lisp_gpe_tunnel_t * tunnel = NULL;
5220 if (pool_elts(lgm->tunnels) == 0) {
5224 q = vl_api_client_index_to_input_queue (mp->client_index);
5229 pool_foreach(tunnel, lgm->tunnels,
5231 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5236 send_lisp_map_resolver_details (ip_address_t *ip,
5237 unix_shared_memory_queue_t *q,
5240 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5242 rmp = vl_msg_api_alloc (sizeof (*rmp));
5243 memset (rmp, 0, sizeof (*rmp));
5244 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5246 switch (ip_addr_version(ip)) {
5249 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5254 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5260 rmp->context = context;
5262 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5266 vl_api_lisp_map_resolver_dump_t_handler (
5267 vl_api_lisp_map_resolver_dump_t *mp)
5269 unix_shared_memory_queue_t * q = NULL;
5270 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5271 ip_address_t *ip = NULL;
5273 q = vl_api_client_index_to_input_queue (mp->client_index);
5278 vec_foreach(ip, lcm->map_resolvers) {
5279 send_lisp_map_resolver_details(ip, q, mp->context);
5285 send_lisp_enable_disable_details (unix_shared_memory_queue_t *q,
5288 vl_api_lisp_enable_disable_status_details_t *rmp = NULL;
5290 rmp = vl_msg_api_alloc (sizeof (*rmp));
5291 memset (rmp, 0, sizeof (*rmp));
5292 rmp->_vl_msg_id = ntohs(VL_API_LISP_ENABLE_DISABLE_STATUS_DETAILS);
5294 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5295 rmp->feature_status = vnet_lisp_enable_disable_status ();
5296 rmp->context = context;
5298 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5302 vl_api_lisp_enable_disable_status_dump_t_handler
5303 (vl_api_lisp_enable_disable_status_dump_t *mp)
5305 unix_shared_memory_queue_t * q = NULL;
5307 q = vl_api_client_index_to_input_queue (mp->client_index);
5312 send_lisp_enable_disable_details(q, mp->context);
5316 vl_api_lisp_get_map_request_itr_rlocs_t_handler (
5317 vl_api_lisp_get_map_request_itr_rlocs_t *mp)
5319 unix_shared_memory_queue_t * q = NULL;
5320 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
5321 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5322 locator_set_t * loc_set = 0;
5326 q = vl_api_client_index_to_input_queue (mp->client_index);
5331 if (~0 == lcm->mreq_itr_rlocs) {
5332 tmp_str = format(0, " ");
5334 loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
5335 tmp_str = format(0, "%s", loc_set->name);
5338 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
5340 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5341 ARRAY_LEN(rmp->locator_set_name) - 1);
5348 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5350 vl_api_interface_name_renumber_reply_t * rmp;
5353 VALIDATE_SW_IF_INDEX(mp);
5355 rv = vnet_interface_name_renumber
5356 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5358 BAD_SW_IF_INDEX_LABEL;
5360 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5363 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5364 u32 sw_if_index, u32 address)
5366 vpe_api_main_t * am = &vpe_api_main;
5367 vlib_main_t * vm = am->vlib_main;
5368 vl_api_ip4_arp_event_t * event;
5369 static f64 arp_event_last_time;
5370 f64 now = vlib_time_now (vm);
5372 if (pool_is_free_index (am->arp_events, pool_index))
5375 event = pool_elt_at_index (am->arp_events, pool_index);
5376 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5377 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5378 } else { /* same mac */
5379 if ((sw_if_index == event->sw_if_index) &&
5381 /* for BD case, also check IP address with 10 sec timeout */
5382 ((address == event->address) &&
5383 ((now - arp_event_last_time) < 10.0))))
5387 arp_event_last_time = now;
5388 event->sw_if_index = sw_if_index;
5389 if (address) event->address = address;
5393 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5395 vpe_api_main_t * am = &vpe_api_main;
5397 if (pool_is_free_index (am->arp_events, pool_index))
5400 pool_put_index (am->arp_events, pool_index);
5405 vl_api_want_ip4_arp_events_t_handler
5406 (vl_api_want_ip4_arp_events_t * mp)
5408 vpe_api_main_t * am = &vpe_api_main;
5409 vnet_main_t * vnm = vnet_get_main();
5410 vl_api_want_ip4_arp_events_reply_t *rmp;
5411 vl_api_ip4_arp_event_t * event;
5414 if (mp->enable_disable) {
5415 pool_get (am->arp_events, event);
5416 memset (event, 0, sizeof (*event));
5418 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5419 event->client_index = mp->client_index;
5420 event->context = mp->context;
5421 event->address = mp->address;
5422 event->pid = mp->pid;
5424 rv = vnet_add_del_ip4_arp_change_event
5425 (vnm, arp_change_data_callback,
5427 &mp->address /* addr, in net byte order */,
5428 vpe_resolver_process_node.index,
5429 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5431 rv = vnet_add_del_ip4_arp_change_event
5432 (vnm, arp_change_delete_callback,
5434 &mp->address /* addr, in net byte order */,
5435 vpe_resolver_process_node.index,
5436 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5438 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5441 static void vl_api_input_acl_set_interface_t_handler
5442 (vl_api_input_acl_set_interface_t * mp)
5444 vlib_main_t *vm = vlib_get_main();
5445 vl_api_input_acl_set_interface_reply_t * rmp;
5447 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5449 ip4_table_index = ntohl(mp->ip4_table_index);
5450 ip6_table_index = ntohl(mp->ip6_table_index);
5451 l2_table_index = ntohl(mp->l2_table_index);
5452 sw_if_index = ntohl(mp->sw_if_index);
5454 VALIDATE_SW_IF_INDEX(mp);
5456 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5457 ip6_table_index, l2_table_index,
5460 BAD_SW_IF_INDEX_LABEL;
5462 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5465 static void vl_api_ipsec_spd_add_del_t_handler
5466 (vl_api_ipsec_spd_add_del_t * mp)
5469 clib_warning ("unimplemented");
5472 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5473 vl_api_ipsec_spd_add_del_reply_t * rmp;
5477 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5479 rv = VNET_API_ERROR_UNIMPLEMENTED;
5482 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5486 static void vl_api_ipsec_interface_add_del_spd_t_handler
5487 (vl_api_ipsec_interface_add_del_spd_t * mp)
5489 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5490 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5492 u32 sw_if_index __attribute__((unused));
5493 u32 spd_id __attribute__((unused));
5495 sw_if_index = ntohl(mp->sw_if_index);
5496 spd_id = ntohl(mp->spd_id);
5498 VALIDATE_SW_IF_INDEX(mp);
5501 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5503 rv = VNET_API_ERROR_UNIMPLEMENTED;
5506 BAD_SW_IF_INDEX_LABEL;
5508 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5511 static void vl_api_ipsec_spd_add_del_entry_t_handler
5512 (vl_api_ipsec_spd_add_del_entry_t * mp)
5514 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5515 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5521 memset(&p, 0, sizeof(p));
5523 p.id = ntohl(mp->spd_id);
5524 p.priority = ntohl(mp->priority);
5525 p.is_outbound = mp->is_outbound;
5526 p.is_ipv6 = mp->is_ipv6;
5528 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5529 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5530 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5531 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5533 p.protocol = mp->protocol;
5534 p.rport.start = ntohs(mp->remote_port_start);
5535 p.rport.stop = ntohs(mp->remote_port_stop);
5536 p.lport.start = ntohs(mp->local_port_start);
5537 p.lport.stop = ntohs(mp->local_port_stop);
5538 /* policy action resolve unsupported */
5539 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5540 clib_warning("unsupported action: 'resolve'");
5541 rv = VNET_API_ERROR_UNIMPLEMENTED;
5544 p.policy = mp->policy;
5545 p.sa_id = ntohl(mp->sa_id);
5547 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5551 if (mp->is_ip_any) {
5553 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5556 rv = VNET_API_ERROR_UNIMPLEMENTED;
5561 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5564 static void vl_api_ipsec_sad_add_del_entry_t_handler
5565 (vl_api_ipsec_sad_add_del_entry_t * mp)
5567 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5568 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5573 memset(&sa, 0, sizeof(sa));
5575 sa.id = ntohl(mp->sad_id);
5576 sa.spi = ntohl(mp->spi);
5577 /* security protocol AH unsupported */
5578 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5579 clib_warning("unsupported security protocol 'AH'");
5580 rv = VNET_API_ERROR_UNIMPLEMENTED;
5583 sa.protocol = mp->protocol;
5584 /* check for unsupported crypto-alg */
5585 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5586 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5587 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5588 mp->crypto_algorithm);
5589 rv = VNET_API_ERROR_UNIMPLEMENTED;
5592 sa.crypto_alg = mp->crypto_algorithm;
5593 sa.crypto_key_len = mp->crypto_key_length;
5594 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5595 /* check for unsupported integ-alg */
5596 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5597 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5598 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5599 mp->integrity_algorithm);
5600 rv = VNET_API_ERROR_UNIMPLEMENTED;
5603 sa.integ_alg = mp->integrity_algorithm;
5604 sa.integ_key_len = mp->integrity_key_length;
5605 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5606 sa.use_esn = mp->use_extended_sequence_number;
5607 sa.is_tunnel = mp->is_tunnel;
5608 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5609 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5610 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5612 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5614 rv = VNET_API_ERROR_UNIMPLEMENTED;
5619 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5623 vl_api_ikev2_profile_add_del_t_handler
5624 (vl_api_ikev2_profile_add_del_t * mp)
5626 vl_api_ikev2_profile_add_del_reply_t * rmp;
5630 vlib_main_t * vm = vlib_get_main();
5631 clib_error_t * error;
5632 u8 * tmp = format(0, "%s", mp->name);
5633 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5636 rv = VNET_API_ERROR_UNSPECIFIED;
5638 rv = VNET_API_ERROR_UNIMPLEMENTED;
5641 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5645 vl_api_ikev2_profile_set_auth_t_handler
5646 (vl_api_ikev2_profile_set_auth_t * mp)
5648 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5652 vlib_main_t * vm = vlib_get_main();
5653 clib_error_t * error;
5654 u8 * tmp = format(0, "%s", mp->name);
5655 u8 * data = vec_new (u8, mp->data_len);
5656 clib_memcpy(data, mp->data, mp->data_len);
5657 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5661 rv = VNET_API_ERROR_UNSPECIFIED;
5663 rv = VNET_API_ERROR_UNIMPLEMENTED;
5666 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5670 vl_api_ikev2_profile_set_id_t_handler
5671 (vl_api_ikev2_profile_set_id_t * mp)
5673 vl_api_ikev2_profile_add_del_reply_t * rmp;
5677 vlib_main_t * vm = vlib_get_main();
5678 clib_error_t * error;
5679 u8 * tmp = format(0, "%s", mp->name);
5680 u8 * data = vec_new (u8, mp->data_len);
5681 clib_memcpy(data, mp->data, mp->data_len);
5682 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
5686 rv = VNET_API_ERROR_UNSPECIFIED;
5688 rv = VNET_API_ERROR_UNIMPLEMENTED;
5691 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5695 vl_api_ikev2_profile_set_ts_t_handler
5696 (vl_api_ikev2_profile_set_ts_t * mp)
5698 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5702 vlib_main_t * vm = vlib_get_main();
5703 clib_error_t * error;
5704 u8 * tmp = format(0, "%s", mp->name);
5705 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
5706 mp->end_port, (ip4_address_t) mp->start_addr,
5707 (ip4_address_t) mp->end_addr, mp->is_local);
5710 rv = VNET_API_ERROR_UNSPECIFIED;
5712 rv = VNET_API_ERROR_UNIMPLEMENTED;
5715 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5719 vl_api_ikev2_set_local_key_t_handler
5720 (vl_api_ikev2_set_local_key_t * mp)
5722 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5726 vlib_main_t * vm = vlib_get_main();
5727 clib_error_t * error;
5729 error = ikev2_set_local_key(vm, mp->key_file);
5731 rv = VNET_API_ERROR_UNSPECIFIED;
5733 rv = VNET_API_ERROR_UNIMPLEMENTED;
5736 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5740 vl_api_map_add_domain_t_handler
5741 (vl_api_map_add_domain_t * mp)
5743 vl_api_map_add_domain_reply_t * rmp;
5746 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
5747 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
5748 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
5749 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
5750 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
5752 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
5754 rmp->index = ntohl(index);
5759 vl_api_map_del_domain_t_handler
5760 (vl_api_map_del_domain_t * mp)
5762 vl_api_map_del_domain_reply_t * rmp;
5765 rv = map_delete_domain(ntohl(mp->index));
5767 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
5771 vl_api_map_add_del_rule_t_handler
5772 (vl_api_map_add_del_rule_t * mp)
5774 vl_api_map_del_domain_reply_t * rmp;
5777 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
5779 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
5783 vl_api_map_domain_dump_t_handler
5784 (vl_api_map_domain_dump_t * mp)
5786 vl_api_map_domain_details_t * rmp;
5787 map_main_t *mm = &map_main;
5789 unix_shared_memory_queue_t * q;
5791 if (pool_elts (mm->domains) == 0)
5794 q = vl_api_client_index_to_input_queue (mp->client_index);
5799 pool_foreach(d, mm->domains, ({
5800 /* Make sure every field is initiated (or don't skip the memset()) */
5801 rmp = vl_msg_api_alloc (sizeof (*rmp));
5802 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
5803 rmp->domain_index = htonl(d - mm->domains);
5804 rmp->ea_bits_len = d->ea_bits_len;
5805 rmp->psid_offset = d->psid_offset;
5806 rmp->psid_length = d->psid_length;
5807 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
5808 rmp->ip4_prefix_len = d->ip4_prefix_len;
5809 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
5810 rmp->ip6_prefix_len = d->ip6_prefix_len;
5811 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
5812 rmp->ip6_src_len = d->ip6_src_len;
5813 rmp->mtu = htons(d->mtu);
5814 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
5815 rmp->context = mp->context;
5817 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5822 vl_api_map_rule_dump_t_handler
5823 (vl_api_map_rule_dump_t * mp)
5825 unix_shared_memory_queue_t * q;
5828 vl_api_map_rule_details_t * rmp;
5829 map_main_t *mm = &map_main;
5830 u32 domain_index = ntohl(mp->domain_index);
5833 if (pool_elts (mm->domains) == 0)
5836 d = pool_elt_at_index(mm->domains, domain_index);
5837 if (!d || !d->rules) {
5841 q = vl_api_client_index_to_input_queue (mp->client_index);
5846 for (i = 0; i < (0x1 << d->psid_length); i++) {
5848 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
5851 rmp = vl_msg_api_alloc(sizeof(*rmp));
5852 memset(rmp, 0, sizeof(*rmp));
5853 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
5854 rmp->psid = htons(i);
5855 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
5856 rmp->context = mp->context;
5857 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5862 vl_api_map_summary_stats_t_handler (
5863 vl_api_map_summary_stats_t *mp)
5865 vl_api_map_summary_stats_reply_t *rmp;
5866 vlib_combined_counter_main_t *cm;
5869 u64 total_pkts[VLIB_N_RX_TX];
5870 u64 total_bytes[VLIB_N_RX_TX];
5871 map_main_t *mm = &map_main;
5872 unix_shared_memory_queue_t *q =
5873 vl_api_client_index_to_input_queue(mp->client_index);
5878 rmp = vl_msg_api_alloc (sizeof (*rmp));
5879 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
5880 rmp->context = mp->context;
5883 memset (total_pkts, 0, sizeof (total_pkts));
5884 memset (total_bytes, 0, sizeof (total_bytes));
5886 map_domain_counter_lock (mm);
5887 vec_foreach(cm, mm->domain_counters) {
5888 which = cm - mm->domain_counters;
5890 for (i = 0; i < vec_len(cm->maxi); i++) {
5891 vlib_get_combined_counter (cm, i, &v);
5892 total_pkts[which] += v.packets;
5893 total_bytes[which] += v.bytes;
5897 map_domain_counter_unlock (mm);
5899 /* Note: in network byte order! */
5900 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
5901 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
5902 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
5903 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
5904 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
5905 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
5906 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));
5907 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));
5909 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5912 static void vl_api_ipsec_sa_set_key_t_handler
5913 (vl_api_ipsec_sa_set_key_t * mp)
5915 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5916 vl_api_ipsec_sa_set_key_reply_t *rmp;
5920 sa.id = ntohl(mp->sa_id);
5921 sa.crypto_key_len = mp->crypto_key_length;
5922 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5923 sa.integ_key_len = mp->integrity_key_length;
5924 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5926 rv = ipsec_set_sa_key(vm, &sa);
5928 rv = VNET_API_ERROR_UNIMPLEMENTED;
5931 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
5934 static void vl_api_cop_interface_enable_disable_t_handler
5935 (vl_api_cop_interface_enable_disable_t * mp)
5937 vl_api_cop_interface_enable_disable_reply_t * rmp;
5939 u32 sw_if_index = ntohl(mp->sw_if_index);
5942 VALIDATE_SW_IF_INDEX(mp);
5944 enable_disable = (int) mp->enable_disable;
5946 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5948 BAD_SW_IF_INDEX_LABEL;
5950 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5953 static void vl_api_cop_whitelist_enable_disable_t_handler
5954 (vl_api_cop_whitelist_enable_disable_t * mp)
5956 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
5957 cop_whitelist_enable_disable_args_t _a, *a=&_a;
5958 u32 sw_if_index = ntohl(mp->sw_if_index);
5961 VALIDATE_SW_IF_INDEX(mp);
5963 a->sw_if_index = sw_if_index;
5966 a->default_cop = mp->default_cop;
5967 a->fib_id = ntohl(mp->fib_id);
5969 rv = cop_whitelist_enable_disable (a);
5971 BAD_SW_IF_INDEX_LABEL;
5973 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5976 static void vl_api_get_node_graph_t_handler
5977 (vl_api_get_node_graph_t * mp)
5981 api_main_t * am = &api_main;
5982 vlib_main_t * vm = vlib_get_main();
5984 vl_api_get_node_graph_reply_t * rmp;
5986 pthread_mutex_lock (&am->vlib_rp->mutex);
5987 oldheap = svm_push_data_heap (am->vlib_rp);
5990 * Keep the number of memcpy ops to a minimum (e.g. 1).
5992 vec_validate (vector, 16384);
5993 vec_reset_length (vector);
5996 vector = vlib_node_serialize (&vm->node_main, vector,
5997 (u32)~0 /* all threads */,
5998 1 /* include nexts */,
5999 1 /* include stats */);
6001 svm_pop_heap (oldheap);
6002 pthread_mutex_unlock (&am->vlib_rp->mutex);
6004 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
6005 rmp->reply_in_shmem = (uword) vector);
6008 static void vl_api_trace_profile_add_t_handler
6009 (vl_api_trace_profile_add_t *mp)
6012 vl_api_trace_profile_add_reply_t * rmp;
6013 clib_error_t *error;
6015 /* Ignoring the profile id as currently a single profile
6017 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
6018 ntohl(mp->node_id), ntohl(mp->trace_app_data),
6019 mp->pow_enable, mp->trace_tsp,
6022 clib_error_report(error);
6023 rv = clib_error_get_code(error);
6026 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
6029 static void vl_api_trace_profile_apply_t_handler
6030 (vl_api_trace_profile_apply_t *mp)
6033 vl_api_trace_profile_apply_reply_t * rmp;
6035 if (mp->enable != 0) {
6036 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
6037 ntohl(mp->prefix_length),
6039 mp->trace_op == IOAM_HBYH_ADD,
6040 mp->trace_op == IOAM_HBYH_POP,
6041 mp->trace_op == IOAM_HBYH_MOD);
6043 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
6045 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
6048 static void vl_api_trace_profile_del_t_handler
6049 (vl_api_trace_profile_del_t *mp)
6052 vl_api_trace_profile_del_reply_t * rmp;
6053 clib_error_t *error;
6055 error = clear_ioam_rewrite_fn();
6057 clib_error_report(error);
6058 rv = clib_error_get_code(error);
6061 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
6065 vl_api_af_packet_create_t_handler
6066 (vl_api_af_packet_create_t *mp)
6068 vlib_main_t *vm = vlib_get_main();
6069 vl_api_af_packet_create_reply_t *rmp;
6071 u8 *host_if_name = NULL;
6074 host_if_name = format(0, "%s", mp->host_if_name);
6075 vec_add1 (host_if_name, 0);
6077 rv = af_packet_create_if(vm, host_if_name,
6078 mp->use_random_hw_addr ? 0 : mp->hw_addr, &sw_if_index);
6080 vec_free(host_if_name);
6082 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
6083 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index));
6087 vl_api_af_packet_delete_t_handler
6088 (vl_api_af_packet_delete_t *mp)
6090 vlib_main_t * vm = vlib_get_main();
6091 vl_api_af_packet_delete_reply_t *rmp;
6093 u8 *host_if_name = NULL;
6095 host_if_name = format(0, "%s", mp->host_if_name);
6096 vec_add1 (host_if_name, 0);
6098 rv = af_packet_delete_if(vm, host_if_name);
6100 vec_free(host_if_name);
6102 REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY);
6106 vl_api_policer_add_del_t_handler
6107 (vl_api_policer_add_del_t *mp)
6109 vlib_main_t * vm = vlib_get_main();
6110 vl_api_policer_add_del_reply_t *rmp;
6113 sse2_qos_pol_cfg_params_st cfg;
6114 clib_error_t * error;
6116 name = format(0, "%s", mp->name);
6118 memset (&cfg, 0, sizeof (cfg));
6120 cfg.rnd_type = mp->round_type;
6121 cfg.rate_type = mp->rate_type;
6122 cfg.rb.kbps.cir_kbps = mp->cir;
6123 cfg.rb.kbps.eir_kbps = mp->eir;
6124 cfg.rb.kbps.cb_bytes = mp->cb;
6125 cfg.rb.kbps.eb_bytes = mp->eb;
6127 error = policer_add_del(vm, name, &cfg, mp->is_add);
6130 rv = VNET_API_ERROR_UNSPECIFIED;
6132 REPLY_MACRO(VL_API_POLICER_ADD_DEL_REPLY);
6136 send_policer_details (u8 *name,
6137 sse2_qos_pol_cfg_params_st *config,
6138 policer_read_response_type_st *templ,
6139 unix_shared_memory_queue_t *q,
6142 vl_api_policer_details_t * mp;
6144 mp = vl_msg_api_alloc (sizeof (*mp));
6145 memset (mp, 0, sizeof (*mp));
6146 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
6147 mp->context = context;
6148 mp->cir = htonl(config->rb.kbps.cir_kbps);
6149 mp->eir = htonl(config->rb.kbps.eir_kbps);
6150 mp->cb = htonl(config->rb.kbps.cb_bytes);
6151 mp->eb = htonl(config->rb.kbps.eb_bytes);
6152 mp->rate_type = config->rate_type;
6153 mp->round_type = config->rnd_type;
6154 mp->type = config->rfc;
6155 mp->single_rate = templ->single_rate ? 1 : 0;
6156 mp->color_aware = templ->color_aware ? 1 : 0;
6157 mp->scale = htonl(templ->scale);
6158 mp->cir_tokens_per_period = htonl(templ->cir_tokens_per_period);
6159 mp->pir_tokens_per_period = htonl(templ->pir_tokens_per_period);
6160 mp->current_limit = htonl(templ->current_limit);
6161 mp->current_bucket = htonl(templ->current_bucket);
6162 mp->extended_limit = htonl(templ->extended_limit);
6163 mp->extended_bucket = htonl(templ->extended_bucket);
6164 mp->last_update_time = clib_host_to_net_u64(templ->last_update_time);
6166 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN(mp->name) - 1);
6168 vl_msg_api_send_shmem (q, (u8 *)&mp);
6172 vl_api_policer_dump_t_handler
6173 (vl_api_policer_dump_t *mp)
6175 unix_shared_memory_queue_t * q;
6176 vnet_policer_main_t * pm = &vnet_policer_main;
6180 u8 * match_name = 0;
6182 sse2_qos_pol_cfg_params_st *config;
6183 policer_read_response_type_st *templ;
6185 q = vl_api_client_index_to_input_queue (mp->client_index);
6189 if (mp->match_name_valid) {
6190 match_name = format(0, "%s%c", mp->match_name, 0);
6193 if (mp->match_name_valid) {
6194 p = hash_get_mem (pm->policer_config_by_name, match_name);
6197 config = pool_elt_at_index (pm->configs, pool_index);
6198 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6199 send_policer_details(match_name, config, templ, q, mp->context);
6202 hash_foreach_pair (hp, pm->policer_config_by_name,
6204 name = (u8 *) hp->key;
6205 pool_index = hp->value[0];
6206 config = pool_elt_at_index (pm->configs, pool_index);
6207 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6208 send_policer_details(name, config, templ, q, mp->context);
6214 vl_api_netmap_create_t_handler
6215 (vl_api_netmap_create_t *mp)
6217 vlib_main_t *vm = vlib_get_main();
6218 vl_api_netmap_create_reply_t *rmp;
6222 if_name = format(0, "%s", mp->netmap_if_name);
6223 vec_add1 (if_name, 0);
6225 rv = netmap_create_if(vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
6226 mp->is_pipe, mp->is_master, 0);
6230 REPLY_MACRO(VL_API_NETMAP_CREATE_REPLY);
6234 vl_api_netmap_delete_t_handler
6235 (vl_api_netmap_delete_t *mp)
6237 vlib_main_t * vm = vlib_get_main();
6238 vl_api_netmap_delete_reply_t *rmp;
6242 if_name = format(0, "%s", mp->netmap_if_name);
6243 vec_add1 (if_name, 0);
6245 rv = netmap_delete_if(vm, if_name);
6249 REPLY_MACRO(VL_API_NETMAP_DELETE_REPLY);
6252 #define BOUNCE_HANDLER(nn) \
6253 static void vl_api_##nn##_t_handler ( \
6254 vl_api_##nn##_t *mp) \
6256 vpe_client_registration_t *reg; \
6257 vpe_api_main_t * vam = &vpe_api_main; \
6258 unix_shared_memory_queue_t * q; \
6260 /* One registration only... */ \
6261 pool_foreach(reg, vam->nn##_registrations, \
6263 q = vl_api_client_index_to_input_queue (reg->client_index); \
6266 * If the queue is stuffed, turf the msg and complain \
6267 * It's unlikely that the intended recipient is \
6268 * alive; avoid deadlock at all costs. \
6270 if (q->cursize == q->maxsize) { \
6271 clib_warning ("ERROR: receiver queue full, drop msg"); \
6272 vl_msg_api_free (mp); \
6275 vl_msg_api_send_shmem (q, (u8 *)&mp); \
6279 vl_msg_api_free (mp); \
6284 * Add vpe's API message handlers to the table.
6285 * vlib has alread mapped shared memory and
6286 * added the client registration handlers.
6287 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
6290 static clib_error_t *
6291 vpe_api_hookup (vlib_main_t *vm)
6293 api_main_t * am = &api_main;
6296 vl_msg_api_set_handlers(VL_API_##N, #n, \
6297 vl_api_##n##_t_handler, \
6299 vl_api_##n##_t_endian, \
6300 vl_api_##n##_t_print, \
6301 sizeof(vl_api_##n##_t), 1);
6302 foreach_vpe_api_msg;
6306 * Manually register the sr tunnel add del msg, so we trace
6307 * enough bytes to capture a typical segment list
6309 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
6310 "sr_tunnel_add_del",
6311 vl_api_sr_tunnel_add_del_t_handler,
6313 vl_api_sr_tunnel_add_del_t_endian,
6314 vl_api_sr_tunnel_add_del_t_print,
6319 * Manually register the sr policy add del msg, so we trace
6320 * enough bytes to capture a typical tunnel name list
6322 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
6323 "sr_policy_add_del",
6324 vl_api_sr_policy_add_del_t_handler,
6326 vl_api_sr_policy_add_del_t_endian,
6327 vl_api_sr_policy_add_del_t_print,
6331 * Trace space for 8 MPLS encap labels, classifier mask+match
6333 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
6334 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
6335 += 5 * sizeof (u32x4);
6336 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
6337 += 5 * sizeof (u32x4);
6338 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
6339 += 16 * sizeof (u32);
6342 * Thread-safe API messages
6344 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
6345 am->is_mp_safe [VL_API_GET_NODE_GRAPH] = 1;
6350 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
6352 static clib_error_t *
6353 vpe_api_init (vlib_main_t *vm)
6355 vpe_api_main_t *am = &vpe_api_main;
6358 am->vnet_main = vnet_get_main();
6359 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
6360 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6361 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6362 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6363 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6364 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
6367 vl_set_memory_region_name ("/vpe-api");
6368 vl_enable_disable_memory_api (vm, 1 /* enable it */);
6373 VLIB_INIT_FUNCTION(vpe_api_init);
6376 static clib_error_t *
6377 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
6382 struct passwd _pw, *pw;
6383 struct group _grp, *grp;
6386 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6388 if (unformat (input, "prefix %s", &chroot_path))
6390 vec_add1 (chroot_path, 0);
6391 vl_set_memory_root_path ((char *)chroot_path);
6393 else if (unformat (input, "uid %d", &uid))
6394 vl_set_memory_uid (uid);
6395 else if (unformat (input, "gid %d", &gid))
6396 vl_set_memory_gid (gid);
6397 else if (unformat (input, "uid %s", &s))
6399 /* lookup the username */
6401 rv = getpwnam_r(s, &_pw, buf, sizeof(buf), &pw);
6404 e = clib_error_return_code(0, rv,
6405 CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
6406 "cannot fetch username %s", s);
6412 e = clib_error_return_fatal(0, "username %s does not exist", s);
6417 vl_set_memory_uid (pw->pw_uid);
6419 else if (unformat (input, "gid %s", &s))
6421 /* lookup the group name */
6423 rv = getgrnam_r(s, &_grp, buf, sizeof(buf), &grp);
6426 e = clib_error_return_code(0, rv,
6427 CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
6428 "cannot fetch group %s", s);
6434 e = clib_error_return_fatal(0, "group %s does not exist", s);
6439 vl_set_memory_gid (grp->gr_gid);
6442 return clib_error_return (0, "unknown input `%U'",
6443 format_unformat_error, input);
6447 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
6449 void * get_unformat_vnet_sw_interface (void)
6451 return (void *) &unformat_vnet_sw_interface;
6454 #undef vl_api_version
6455 #define vl_api_version(n,v) static u32 vpe_api_version = v;
6456 #include <api/vpe.api.h>
6457 #undef vl_api_version
6459 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
6461 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
6462 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
6463 clib_host_to_net_u32 (mp->api_versions[0]),
6470 static u8 * format_arp_event (u8 * s, va_list * args)
6472 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
6474 s = format (s, "pid %d: %U", event->pid,
6475 format_ip4_address, &event->address);
6479 static clib_error_t *
6480 show_ip4_arp_events_fn (vlib_main_t * vm,
6481 unformat_input_t * input,
6482 vlib_cli_command_t * cmd)
6484 vpe_api_main_t * am = &vpe_api_main;
6485 vl_api_ip4_arp_event_t * event;
6487 if (pool_elts (am->arp_events) == 0) {
6488 vlib_cli_output (vm, "No active arp event registrations");
6492 pool_foreach (event, am->arp_events,
6494 vlib_cli_output (vm, "%U", format_arp_event, event);
6500 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
6501 .path = "show arp event registrations",
6502 .function = show_ip4_arp_events_fn,
6503 .short_help = "Show arp event registrations",