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>
33 #include <vppinfra/clib.h>
34 #include <vppinfra/vec.h>
35 #include <vppinfra/hash.h>
36 #include <vppinfra/bitmap.h>
37 #include <vppinfra/fifo.h>
38 #include <vppinfra/time.h>
39 #include <vppinfra/mheap.h>
40 #include <vppinfra/heap.h>
41 #include <vppinfra/pool.h>
42 #include <vppinfra/format.h>
43 #include <vppinfra/error.h>
45 #include <vnet/vnet.h>
46 #include <vnet/l2/l2_input.h>
47 #include <vnet/l2/l2_bd.h>
48 #include <vnet/l2tp/l2tp.h>
49 #include <vnet/ip/ip.h>
50 #include <vnet/unix/tuntap.h>
51 #include <vnet/unix/tapcli.h>
52 #include <vnet/mpls-gre/mpls.h>
53 #include <vnet/dhcp/proxy.h>
54 #include <vnet/dhcp/client.h>
56 #include <vnet/sr/sr.h>
58 #include <vnet/dhcpv6/proxy.h>
59 #include <vlib/vlib.h>
60 #include <vlib/unix/unix.h>
61 #include <vlibapi/api.h>
62 #include <vlibmemory/api.h>
63 #include <vnet/classify/vnet_classify.h>
64 #include <vnet/classify/input_acl.h>
65 #include <vnet/l2/l2_classify.h>
66 #include <vnet/vxlan/vxlan.h>
67 #include <vnet/l2/l2_vtr.h>
68 #include <vnet/nsh-gre/nsh_gre.h>
69 #include <vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.h>
70 #include <vnet/lisp-gpe/lisp_gpe.h>
71 #include <vnet/lisp-cp/control.h>
72 #include <vnet/map/map.h>
73 #include <vnet/cop/cop.h>
74 #include <vnet/ip/ip6_hop_by_hop.h>
77 #undef __included_bihash_template_h__
78 #include <vnet/l2/l2_fib.h>
81 #include <vnet/ipsec/ipsec.h>
82 #include <vnet/ipsec/ikev2.h>
85 #include <vnet/devices/virtio/vhost-user.h>
88 #include <stats/stats.h>
91 #include <vnet/ethernet/ethernet.h>
92 #include <vnet/ethernet/arp_packet.h>
93 #include <vnet/interface.h>
95 #include <vnet/l2/l2_fib.h>
96 #include <vnet/l2/l2_bd.h>
97 #include <api/vpe_msg_enum.h>
100 #define f64_print(a,b)
102 #define vl_typedefs /* define message structures */
103 #include <api/vpe_all_api_h.h>
106 #define vl_endianfun /* define message structures */
107 #include <api/vpe_all_api_h.h>
110 /* instantiate all the print functions we know about */
111 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
113 #include <api/vpe_all_api_h.h>
116 #define REPLY_MACRO(t) \
118 unix_shared_memory_queue_t * q; \
119 rv = vl_msg_api_pd_handler (mp, rv); \
120 q = vl_api_client_index_to_input_queue (mp->client_index); \
124 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
125 rmp->_vl_msg_id = ntohs((t)); \
126 rmp->context = mp->context; \
127 rmp->retval = ntohl(rv); \
129 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
132 #define REPLY_MACRO2(t, body) \
134 unix_shared_memory_queue_t * q; \
135 rv = vl_msg_api_pd_handler (mp, rv); \
136 q = vl_api_client_index_to_input_queue (mp->client_index); \
140 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
141 rmp->_vl_msg_id = ntohs((t)); \
142 rmp->context = mp->context; \
143 rmp->retval = ntohl(rv); \
144 do {body;} while (0); \
145 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
148 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
150 #define VALIDATE_SW_IF_INDEX(mp) \
151 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
152 vnet_main_t *__vnm = vnet_get_main(); \
153 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
155 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
156 goto bad_sw_if_index; \
160 #define BAD_SW_IF_INDEX_LABEL \
166 #define VALIDATE_RX_SW_IF_INDEX(mp) \
167 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
168 vnet_main_t *__vnm = vnet_get_main(); \
169 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
170 __rx_sw_if_index)) { \
171 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
172 goto bad_rx_sw_if_index; \
176 #define BAD_RX_SW_IF_INDEX_LABEL \
178 bad_rx_sw_if_index: \
182 #define VALIDATE_TX_SW_IF_INDEX(mp) \
183 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
184 vnet_main_t *__vnm = vnet_get_main(); \
185 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
186 __tx_sw_if_index)) { \
187 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
188 goto bad_tx_sw_if_index; \
192 #define BAD_TX_SW_IF_INDEX_LABEL \
194 bad_tx_sw_if_index: \
200 #define VALIDATE_SW_IF_INDEX(mp)
201 #define BAD_SW_IF_INDEX_LABEL
202 #define VALIDATE_RX_SW_IF_INDEX(mp)
203 #define BAD_RX_SW_IF_INDEX_LABEL
204 #define VALIDATE_TX_SW_IF_INDEX(mp)
205 #define BAD_TX_SW_IF_INDEX_LABEL
207 #endif /* CLIB_DEBUG > 0 */
209 #define foreach_vpe_api_msg \
210 _(WANT_INTERFACE_EVENTS, want_interface_events) \
211 _(WANT_FROM_NETCONF_SERVER, want_from_netconf_server) \
212 _(WANT_TO_NETCONF_SERVER, want_to_netconf_server) \
213 _(WANT_FROM_NETCONF_CLIENT, want_from_netconf_client) \
214 _(WANT_TO_NETCONF_CLIENT, want_to_netconf_client) \
215 _(FROM_NETCONF_SERVER, from_netconf_server) \
216 _(TO_NETCONF_SERVER, to_netconf_server) \
217 _(FROM_NETCONF_CLIENT, from_netconf_client) \
218 _(TO_NETCONF_CLIENT, to_netconf_client) \
219 _(WANT_OAM_EVENTS, want_oam_events) \
220 _(OAM_ADD_DEL, oam_add_del) \
221 _(SW_INTERFACE_DUMP, sw_interface_dump) \
222 _(SW_INTERFACE_DETAILS, sw_interface_details) \
223 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
224 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
225 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
226 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
227 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
228 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
229 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
230 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
231 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
232 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
233 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
234 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
235 _(L2FIB_ADD_DEL, l2fib_add_del) \
236 _(L2_FLAGS, l2_flags) \
237 _(BRIDGE_FLAGS, bridge_flags) \
238 _(TAP_CONNECT, tap_connect) \
239 _(TAP_MODIFY, tap_modify) \
240 _(TAP_DELETE, tap_delete) \
241 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
242 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
243 _(CREATE_SUBIF, create_subif) \
244 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
245 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
246 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
247 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
248 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
249 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
250 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
251 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
252 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
253 _(RESET_FIB, reset_fib) \
254 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
255 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
256 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
257 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
258 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
259 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
260 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
261 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
262 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
263 sw_interface_ip6_set_link_local_address) \
264 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
265 _(CREATE_LOOPBACK, create_loopback) \
266 _(CONTROL_PING, control_ping) \
267 _(CLI_REQUEST, cli_request) \
268 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
269 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
270 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
271 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
272 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
273 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
274 _(GET_NODE_INDEX, get_node_index) \
275 _(ADD_NODE_NEXT, add_node_next) \
276 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
277 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
278 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
279 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
280 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
281 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
282 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
283 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
284 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
285 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
286 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
287 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
288 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
289 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
290 _(IP_ADDRESS_DUMP, ip_address_dump) \
291 _(IP_DUMP, ip_dump) \
292 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
293 _(SHOW_VERSION, show_version) \
294 _(NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel) \
295 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
296 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
297 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel) \
298 _(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel) \
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_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
333 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
334 _(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump) \
335 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
336 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump)
339 #define QUOTE(x) QUOTE_(x)
341 #define foreach_registration_hash \
342 _(interface_events) \
343 _(to_netconf_server) \
344 _(from_netconf_server) \
345 _(to_netconf_client) \
346 _(from_netconf_client) \
350 RESOLVE_IP4_ADD_DEL_ROUTE=1,
351 RESOLVE_IP6_ADD_DEL_ROUTE,
352 RESOLVE_MPLS_ETHERNET_ADD_DEL,
358 vl_api_ip_add_del_route_t r;
359 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
365 #define _(a) uword *a##_registration_hash; \
366 vpe_client_registration_t * a##_registrations;
367 foreach_registration_hash
370 /* notifications happen really early in the game */
371 u8 link_state_process_up;
373 /* ip4 pending route adds */
374 pending_route_t * pending_routes;
376 /* ip4 arp event registration pool */
377 vl_api_ip4_arp_event_t * arp_events;
380 vlib_main_t * vlib_main;
381 vnet_main_t * vnet_main;
384 static vlib_node_registration_t vpe_resolver_process_node;
385 static vpe_api_main_t vpe_api_main;
387 static void send_sw_interface_flags (vpe_api_main_t * am,
388 unix_shared_memory_queue_t *q,
389 vnet_sw_interface_t * swif);
390 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
391 unix_shared_memory_queue_t *q,
394 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
397 /* Clean up all registrations belonging to the indicated client */
398 int vl_api_memclnt_delete_callback (u32 client_index)
400 vpe_api_main_t * vam = &vpe_api_main;
401 vpe_client_registration_t *rp;
403 int stats_memclnt_delete_callback (u32 client_index);
405 stats_memclnt_delete_callback (client_index);
408 p = hash_get (vam->a##_registration_hash, client_index); \
410 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
411 pool_put (vam->a##_registrations, rp); \
412 hash_unset (vam->a##_registration_hash, client_index); \
414 foreach_registration_hash;
419 #define API_LINK_STATE_EVENT 1
420 #define API_ADMIN_UP_DOWN_EVENT 2
423 event_data_cmp (void * a1, void * a2)
428 return (word) e1[0] - (word) e2[0];
432 link_state_process (vlib_main_t * vm,
433 vlib_node_runtime_t * rt,
436 vpe_api_main_t * vam = &vpe_api_main;
437 vnet_main_t * vnm = vam->vnet_main;
438 vnet_sw_interface_t * swif;
439 uword * event_data = 0;
440 vpe_client_registration_t *reg;
442 u32 prev_sw_if_index;
443 unix_shared_memory_queue_t * q;
445 vam->link_state_process_up = 1;
448 vlib_process_wait_for_event (vm);
450 /* Unified list of changed link or admin state sw_if_indices */
451 vlib_process_get_events_with_type
452 (vm, &event_data, API_LINK_STATE_EVENT);
453 vlib_process_get_events_with_type
454 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
456 /* Sort, so we can eliminate duplicates */
457 vec_sort_with_function (event_data, event_data_cmp);
459 prev_sw_if_index = ~0;
461 for (i = 0; i < vec_len(event_data); i++) {
462 /* Only one message per swif */
463 if (prev_sw_if_index == event_data[i])
465 prev_sw_if_index = event_data[i];
467 pool_foreach(reg, vam->interface_events_registrations,
469 q = vl_api_client_index_to_input_queue (reg->client_index);
471 // sw_interface may be deleted already
472 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
475 swif = vnet_get_sw_interface (vnm, event_data[i]);
476 send_sw_interface_flags (vam, q, swif);
481 vec_reset_length (event_data);
487 static clib_error_t *
488 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
489 static clib_error_t *
490 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
492 VLIB_REGISTER_NODE (link_state_process_node,static) = {
493 .function = link_state_process,
494 .type = VLIB_NODE_TYPE_PROCESS,
495 .name = "vpe-link-state-process",
498 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
499 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
501 static clib_error_t *
502 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
504 vpe_api_main_t * vam = &vpe_api_main;
505 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
507 if (vam->link_state_process_up)
508 vlib_process_signal_event (vam->vlib_main,
509 link_state_process_node.index,
510 API_LINK_STATE_EVENT,
515 static clib_error_t *
516 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
518 vpe_api_main_t * vam = &vpe_api_main;
521 * Note: it's perfectly fair to set a subif admin up / admin down.
522 * Note the subtle distinction between this routine and the previous
525 if (vam->link_state_process_up)
526 vlib_process_signal_event (vam->vlib_main,
527 link_state_process_node.index,
528 API_ADMIN_UP_DOWN_EVENT,
533 #define pub_sub_handler(lca,UCA) \
534 static void vl_api_want_##lca##_t_handler ( \
535 vl_api_want_##lca##_t *mp) \
537 vpe_api_main_t *vam = &vpe_api_main; \
538 vpe_client_registration_t *rp; \
539 vl_api_want_##lca##_reply_t *rmp; \
543 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
545 if (mp->enable_disable) { \
546 clib_warning ("pid %d: already enabled...", mp->pid); \
547 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
550 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
551 pool_put (vam->lca##_registrations, rp); \
552 hash_unset (vam->lca##_registration_hash, \
557 if (mp->enable_disable == 0) { \
558 clib_warning ("pid %d: already disabled...", mp->pid); \
559 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
562 pool_get (vam->lca##_registrations, rp); \
563 rp->client_index = mp->client_index; \
564 rp->client_pid = mp->pid; \
565 hash_set (vam->lca##_registration_hash, rp->client_index, \
566 rp - vam->lca##_registrations); \
569 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
572 pub_sub_handler (interface_events,INTERFACE_EVENTS)
573 pub_sub_handler (from_netconf_server,FROM_NETCONF_SERVER)
574 pub_sub_handler (to_netconf_server,TO_NETCONF_SERVER)
575 pub_sub_handler (from_netconf_client,FROM_NETCONF_CLIENT)
576 pub_sub_handler (to_netconf_client,TO_NETCONF_CLIENT)
577 pub_sub_handler (oam_events,OAM_EVENTS)
579 #define RESOLUTION_EVENT 1
580 #define RESOLUTION_PENDING_EVENT 2
581 #define IP4_ARP_EVENT 3
583 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
584 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
585 static int mpls_ethernet_add_del_tunnel_2_t_handler
586 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
588 void handle_ip4_arp_event (u32 pool_index)
590 vpe_api_main_t * vam = &vpe_api_main;
591 vnet_main_t * vnm = vam->vnet_main;
592 vlib_main_t * vm = vam->vlib_main;
593 vl_api_ip4_arp_event_t * event;
594 vl_api_ip4_arp_event_t * mp;
595 unix_shared_memory_queue_t * q;
597 /* Client can cancel, die, etc. */
598 if (pool_is_free_index (vam->arp_events, pool_index))
601 event = pool_elt_at_index (vam->arp_events, pool_index);
603 q = vl_api_client_index_to_input_queue (event->client_index);
605 (void) vnet_add_del_ip4_arp_change_event
606 (vnm, arp_change_delete_callback,
607 event->pid, &event->address,
608 vpe_resolver_process_node.index, IP4_ARP_EVENT,
609 ~0 /* pool index, notused */, 0 /* is_add */);
613 if (q->cursize < q->maxsize) {
614 mp = vl_msg_api_alloc (sizeof (*mp));
615 memcpy (mp, event, sizeof (*mp));
616 vl_msg_api_send_shmem (q, (u8 *)&mp);
618 static f64 last_time;
620 * Throttle syslog msgs.
621 * It's pretty tempting to just revoke the registration...
623 if (vlib_time_now (vm) > last_time + 10.0) {
624 clib_warning ("arp event for %U to pid %d: queue stuffed!",
625 format_ip4_address, &event->address, event->pid);
626 last_time = vlib_time_now(vm);
632 resolver_process (vlib_main_t * vm,
633 vlib_node_runtime_t * rt,
637 uword *event_data = 0;
639 vpe_api_main_t * vam = &vpe_api_main;
640 pending_route_t * pr;
641 vl_api_ip_add_del_route_t * adr;
642 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
643 u32 * resolution_failures = 0;
648 vlib_process_wait_for_event_or_clock (vm, timeout);
650 event_type = vlib_process_get_events (vm, &event_data);
652 switch (event_type) {
653 case RESOLUTION_PENDING_EVENT:
657 case RESOLUTION_EVENT:
658 for (i = 0; i < vec_len(event_data); i++) {
660 * Resolution events can occur long after the
661 * original request has timed out. $$$ add a cancel
664 if (pool_is_free_index (vam->pending_routes, event_data[i]))
667 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
671 switch (pr->resolve_type) {
672 case RESOLVE_IP4_ADD_DEL_ROUTE:
673 rv = ip4_add_del_route_t_handler (adr);
674 clib_warning ("resolver: add %U/%d via %U %s",
676 (ip4_address_t *)&(adr->dst_address),
677 adr->dst_address_length,
679 (ip4_address_t *)&(adr->next_hop_address),
680 (rv >= 0) ? "succeeded" : "failed");
683 case RESOLVE_IP6_ADD_DEL_ROUTE:
684 rv = ip6_add_del_route_t_handler (adr);
685 clib_warning ("resolver: add %U/%d via %U %s",
687 (ip6_address_t *)&(adr->dst_address),
688 adr->dst_address_length,
690 (ip6_address_t *)&(adr->next_hop_address),
691 (rv >= 0) ? "succeeded" : "failed");
694 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
695 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
696 clib_warning ("resolver: add mpls-o-e via %U %s",
698 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
699 (rv >= 0) ? "succeeded" : "failed");
703 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
705 pool_put (vam->pending_routes, pr);
710 for (i = 0; i < vec_len(event_data); i++)
711 handle_ip4_arp_event (event_data[i]);
714 case ~0: /* timeout, retry pending resolutions */
715 pool_foreach (pr, vam->pending_routes,
721 /* May fail, e.g. due to interface down */
722 switch (pr->resolve_type) {
723 case RESOLVE_IP4_ADD_DEL_ROUTE:
724 e = ip4_probe_neighbor
725 (vm, (ip4_address_t *)&(adr->next_hop_address),
726 ntohl(adr->next_hop_sw_if_index));
729 case RESOLVE_IP6_ADD_DEL_ROUTE:
730 e = ip6_probe_neighbor
731 (vm, (ip6_address_t *)&(adr->next_hop_address),
732 ntohl(adr->next_hop_sw_if_index));
735 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
737 e = ip4_probe_neighbor
739 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
740 pme->resolve_opaque);
744 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
748 clib_error_report (e);
750 adr->resolve_attempts = 1;
752 pme->resolve_attempts = 1;
756 adr->resolve_attempts -= 1;
757 if (adr->resolve_attempts == 0)
758 vec_add1 (resolution_failures,
759 pr - vam->pending_routes);
761 pme->resolve_attempts -= 1;
762 if (pme->resolve_attempts == 0)
763 vec_add1 (resolution_failures,
764 pr - vam->pending_routes);
768 for (i = 0; i < vec_len (resolution_failures); i++) {
769 pr = pool_elt_at_index (vam->pending_routes,
770 resolution_failures[i]);
774 switch (pr->resolve_type) {
775 case RESOLVE_IP4_ADD_DEL_ROUTE:
776 clib_warning ("resolver: add %U/%d via %U retry failure",
778 (ip4_address_t *)&(adr->dst_address),
779 adr->dst_address_length,
781 (ip4_address_t *)&(adr->next_hop_address));
784 case RESOLVE_IP6_ADD_DEL_ROUTE:
785 clib_warning ("resolver: add %U/%d via %U retry failure",
787 (ip6_address_t *)&(adr->dst_address),
788 adr->dst_address_length,
790 (ip6_address_t *)&(adr->next_hop_address));
793 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
794 clib_warning ("resolver: add mpls-o-e via %U retry failure",
796 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
800 clib_warning ("BUG");
802 pool_put(vam->pending_routes, pr);
804 vec_reset_length (resolution_failures);
807 if (pool_elts (vam->pending_routes) == 0)
809 vec_reset_length (event_data);
811 return 0; /* or not */
814 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
815 .function = resolver_process,
816 .type = VLIB_NODE_TYPE_PROCESS,
817 .name = "vpe-route-resolver-process",
820 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
822 ip4_main_t * im = &ip4_main;
823 ip_lookup_main_t * lm = &im->lookup_main;
824 vnet_classify_main_t * cm = &vnet_classify_main;
825 stats_main_t * sm = &stats_main;
826 ip4_add_del_route_args_t a;
827 ip4_address_t next_hop_address;
829 vpe_api_main_t * vam = &vpe_api_main;
830 vnet_main_t * vnm = vam->vnet_main;
831 vlib_main_t * vm = vlib_get_main();
832 pending_route_t * pr;
833 vl_api_ip_add_del_route_t * adr;
837 ip_adjacency_t *nh_adj, *add_adj = 0;
839 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
841 if (mp->create_vrf_if_needed) {
843 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
845 fib_index = f->index;
847 /* No such VRF, and we weren't asked to create one */
848 return VNET_API_ERROR_NO_SUCH_FIB;
854 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
855 ntohl(mp->next_hop_sw_if_index)))
856 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
858 memcpy (next_hop_address.data, mp->next_hop_address,
859 sizeof (next_hop_address.data));
861 /* Arp for the next_hop if necessary */
862 if (mp->is_add && mp->resolve_if_needed) {
864 ip_adjacency_t * adj;
866 lookup_result = ip4_fib_lookup_with_table
867 (im, fib_index, &next_hop_address, 1 /* disable default route */);
869 adj = ip_get_adjacency (lm, lookup_result);
871 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
872 pool_get (vam->pending_routes, pr);
873 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
875 memcpy (adr, mp, sizeof (*adr));
876 /* recursion block, "just in case" */
877 adr->resolve_if_needed = 0;
878 adr->resolve_attempts = ntohl(mp->resolve_attempts);
879 vnet_register_ip4_arp_resolution_event
880 (vnm, &next_hop_address, vpe_resolver_process_node.index,
881 RESOLUTION_EVENT, pr - vam->pending_routes);
883 vlib_process_signal_event
884 (vm, vpe_resolver_process_node.index,
885 RESOLUTION_PENDING_EVENT, 0 /* data */);
887 /* The interface may be down, etc. */
888 e = ip4_probe_neighbor
889 (vm, (ip4_address_t *)&(mp->next_hop_address),
890 ntohl(mp->next_hop_sw_if_index));
893 clib_error_report(e);
895 return VNET_API_ERROR_IN_PROGRESS;
899 if (mp->is_multipath) {
902 dslock (sm, 1 /* release hint */, 10 /* tag */);
905 flags = IP4_ROUTE_FLAG_ADD;
907 flags = IP4_ROUTE_FLAG_DEL;
910 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
912 ip4_add_del_route_next_hop (im, flags,
913 (ip4_address_t *) mp->dst_address,
914 (u32) mp->dst_address_length,
915 (ip4_address_t *) mp->next_hop_address,
916 ntohl(mp->next_hop_sw_if_index),
917 (u32) mp->next_hop_weight,
924 memset (&a, 0, sizeof (a));
925 memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
927 a.dst_address_length = mp->dst_address_length;
929 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
930 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
931 a.table_index_or_table_id = fib_index;
936 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
938 dslock (sm, 1 /* release hint */, 2 /* tag */);
942 ai = lm->drop_adj_index;
943 else if (mp->is_local)
944 ai = lm->local_adj_index;
945 else if (mp->is_classify) {
947 memset(&cadj, 0, sizeof(cadj));
948 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
949 cadj.classify.table_index = ntohl(mp->classify_table_index);
950 if (pool_is_free_index (cm->tables, cadj.classify.table_index)) {
952 return VNET_API_ERROR_NO_SUCH_TABLE;
954 vec_add1 (add_adj, cadj);
958 ai = ip4_fib_lookup_with_table
959 (im, fib_index, &next_hop_address,
960 1 /* disable default route */);
961 if (ai == lm->miss_adj_index) {
963 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
967 nh_adj = ip_get_adjacency (lm, ai);
968 vec_add1 (add_adj, nh_adj[0]);
969 if (mp->lookup_in_vrf) {
970 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
972 add_adj[0].explicit_fib_index = p[0];
976 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
980 ip_adjacency_t * adj;
981 int disable_default_route = 1;
983 /* Trying to delete the default route? */
984 if (a.dst_address.as_u32 == 0 &&
985 a.dst_address_length == 0)
986 disable_default_route = 0;
988 ai = ip4_fib_lookup_with_table
989 (im, fib_index, &a.dst_address, disable_default_route);
990 if (ai == lm->miss_adj_index) {
992 return VNET_API_ERROR_UNKNOWN_DESTINATION;
995 adj = ip_get_adjacency (lm, ai);
996 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
998 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1004 a.add_adj = add_adj;
1005 a.n_add_adj = vec_len(add_adj);
1006 ip4_add_del_route (im, &a);
1014 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1016 ip6_main_t * im = &ip6_main;
1017 ip_lookup_main_t * lm = &im->lookup_main;
1018 vnet_main_t * vnm = vnet_get_main();
1019 vlib_main_t * vm = vlib_get_main();
1020 vpe_api_main_t * vam = &vpe_api_main;
1021 stats_main_t * sm = &stats_main;
1022 ip6_add_del_route_args_t a;
1023 ip6_address_t next_hop_address;
1024 pending_route_t * pr;
1025 vl_api_ip_add_del_route_t * adr;
1030 ip_adjacency_t * nh_adj, * add_adj = 0;
1033 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1036 if (mp->create_vrf_if_needed) {
1038 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1040 fib_index = f->index;
1042 /* No such VRF, and we weren't asked to create one */
1043 return VNET_API_ERROR_NO_SUCH_FIB;
1049 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1050 ntohl(mp->next_hop_sw_if_index)))
1051 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1053 memcpy (next_hop_address.as_u8, mp->next_hop_address,
1054 sizeof (next_hop_address.as_u8));
1056 /* Arp for the next_hop if necessary */
1057 if (mp->is_add && mp->resolve_if_needed) {
1059 ip_adjacency_t * adj;
1061 lookup_result = ip6_fib_lookup_with_table
1062 (im, fib_index, &next_hop_address);
1064 adj = ip_get_adjacency (lm, lookup_result);
1066 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1067 pool_get (vam->pending_routes, pr);
1069 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1070 memcpy (adr, mp, sizeof (*adr));
1071 /* recursion block, "just in case" */
1072 adr->resolve_if_needed = 0;
1073 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1074 vnet_register_ip6_neighbor_resolution_event
1075 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1076 RESOLUTION_EVENT, pr - vam->pending_routes);
1078 vlib_process_signal_event
1079 (vm, vpe_resolver_process_node.index,
1080 RESOLUTION_PENDING_EVENT, 0 /* data */);
1082 /* The interface may be down, etc. */
1083 e = ip6_probe_neighbor
1084 (vm, (ip6_address_t *)&(mp->next_hop_address),
1085 ntohl(mp->next_hop_sw_if_index));
1088 clib_error_report(e);
1090 return VNET_API_ERROR_IN_PROGRESS;
1094 if (mp->is_multipath) {
1097 dslock (sm, 1 /* release hint */, 11 /* tag */);
1100 flags = IP6_ROUTE_FLAG_ADD;
1102 flags = IP6_ROUTE_FLAG_DEL;
1105 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1107 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1108 (u32) mp->dst_address_length,
1109 (ip6_address_t *)mp->next_hop_address,
1110 ntohl(mp->next_hop_sw_if_index),
1111 (u32) mp->next_hop_weight,
1118 memset (&a, 0, sizeof (a));
1119 memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1121 a.dst_address_length = mp->dst_address_length;
1123 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1124 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1125 a.table_index_or_table_id = fib_index;
1130 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1132 dslock (sm, 1 /* release hint */, 3 /* tag */);
1136 ai = lm->drop_adj_index;
1137 else if (mp->is_local)
1138 ai = lm->local_adj_index;
1140 ai = ip6_fib_lookup_with_table
1141 (im, fib_index, &next_hop_address);
1142 if (ai == lm->miss_adj_index) {
1144 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1148 nh_adj = ip_get_adjacency (lm, ai);
1149 vec_add1 (add_adj, nh_adj[0]);
1150 if (mp->lookup_in_vrf) {
1151 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1153 add_adj[0].explicit_fib_index = p[0];
1157 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1161 ip_adjacency_t * adj;
1163 ai = ip6_fib_lookup_with_table
1164 (im, fib_index, &a.dst_address);
1165 if (ai == lm->miss_adj_index) {
1167 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1169 adj = ip_get_adjacency (lm, ai);
1170 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1172 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1177 a.add_adj = add_adj;
1178 a.n_add_adj = vec_len(add_adj);
1179 ip6_add_del_route (im, &a);
1187 void vl_api_ip_add_del_route_t_handler (
1188 vl_api_ip_add_del_route_t *mp)
1190 vl_api_ip_add_del_route_reply_t * rmp;
1192 vnet_main_t * vnm = vnet_get_main();
1197 rv = ip6_add_del_route_t_handler (mp);
1199 rv = ip4_add_del_route_t_handler (mp);
1201 rv = (rv == 0) ? vnm->api_errno : rv;
1203 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1206 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1207 u32 sw_if_index, u8 *next_hop_addr)
1209 vl_api_ip_add_del_route_t mp;
1212 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1215 * Configure default IP route:
1216 * - ip route add 0.0.0.0/1 via <GW IP>
1217 * - ip route add 128.0.0.0/1 via <GW IP>
1219 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1221 mp.resolve_attempts = ~0;
1222 mp.resolve_if_needed = 1;
1224 mp.is_ipv6 = is_ipv6;
1225 mp.next_hop_weight = 1;
1227 memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1230 rv = ip6_add_del_route_t_handler (&mp);
1233 mp.dst_address_length = 1;
1235 mp.dst_address[0] = 0;
1236 rv = ip4_add_del_route_t_handler (&mp);
1238 mp.dst_address[0] = 128;
1239 rv |= ip4_add_del_route_t_handler (&mp);
1243 clib_error_return (0, "failed to config default IP route");
1248 vl_api_sw_interface_add_del_address_t_handler
1249 (vl_api_sw_interface_add_del_address_t *mp)
1251 vlib_main_t *vm = vlib_get_main();
1252 vl_api_sw_interface_add_del_address_reply_t * rmp;
1256 VALIDATE_SW_IF_INDEX(mp);
1258 is_del = mp->is_add == 0;
1261 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1262 else if (mp->is_ipv6)
1263 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1264 (void *)mp->address,
1265 mp->address_length, is_del);
1267 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1268 (void *) mp->address,
1269 mp->address_length, is_del);
1271 BAD_SW_IF_INDEX_LABEL;
1273 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1277 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1280 u32 table_id = ntohl(mp->vrf_id);
1281 u32 sw_if_index = ntohl(mp->sw_if_index);
1282 vl_api_sw_interface_set_table_reply_t * rmp;
1283 stats_main_t * sm = &stats_main;
1285 VALIDATE_SW_IF_INDEX(mp);
1287 dslock (sm, 1 /* release hint */, 4 /* tag */);
1290 ip6_main_t * im = &ip6_main;
1292 find_ip6_fib_by_table_index_or_id (im, table_id,
1293 IP6_ROUTE_FLAG_TABLE_ID);
1295 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1296 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1298 rv = VNET_API_ERROR_NO_SUCH_FIB;
1301 ip4_main_t * im = &ip4_main;
1302 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1303 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1305 /* Truthfully this can't fail */
1307 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1308 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1310 rv = VNET_API_ERROR_NO_SUCH_FIB;
1315 BAD_SW_IF_INDEX_LABEL;
1317 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1321 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1323 vlib_main_t *vm = vlib_get_main();
1324 vl_api_sw_interface_set_vpath_reply_t * rmp;
1327 u32 sw_if_index = ntohl(mp->sw_if_index);
1328 ip4_main_t *ip4m = &ip4_main;
1329 ip6_main_t *ip6m = &ip6_main;
1330 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1331 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1332 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1333 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1334 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1335 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1337 VALIDATE_SW_IF_INDEX(mp);
1339 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1341 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1342 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1343 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1344 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1345 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1346 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1347 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1348 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1349 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1350 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1351 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1352 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1353 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1354 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1355 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1356 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1358 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1359 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1360 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1361 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1362 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1363 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1364 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1365 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1366 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1367 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1368 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1369 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1370 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1371 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1372 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1373 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1376 BAD_SW_IF_INDEX_LABEL;
1378 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1382 vl_api_sw_interface_set_l2_xconnect_t_handler (
1383 vl_api_sw_interface_set_l2_xconnect_t *mp)
1385 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1387 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1388 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1389 vlib_main_t *vm = vlib_get_main();
1390 vnet_main_t *vnm = vnet_get_main();
1392 VALIDATE_RX_SW_IF_INDEX(mp);
1395 VALIDATE_TX_SW_IF_INDEX(mp);
1396 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1397 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1399 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1402 BAD_RX_SW_IF_INDEX_LABEL;
1403 BAD_TX_SW_IF_INDEX_LABEL;
1405 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1409 vl_api_sw_interface_set_l2_bridge_t_handler (
1410 vl_api_sw_interface_set_l2_bridge_t *mp)
1412 bd_main_t * bdm = &bd_main;
1413 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1415 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1416 u32 bd_id = ntohl(mp->bd_id);
1420 vlib_main_t *vm = vlib_get_main();
1421 vnet_main_t *vnm = vnet_get_main();
1423 VALIDATE_RX_SW_IF_INDEX(mp);
1425 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1428 //VALIDATE_TX_SW_IF_INDEX(mp);
1429 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1430 rx_sw_if_index, bd_index, bvi, shg, 0);
1432 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1435 BAD_RX_SW_IF_INDEX_LABEL;
1437 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1441 vl_api_bridge_domain_add_del_t_handler (
1442 vl_api_bridge_domain_add_del_t *mp)
1444 vlib_main_t * vm = vlib_get_main ();
1445 bd_main_t * bdm = &bd_main;
1446 vl_api_bridge_domain_add_del_reply_t * rmp;
1448 u32 enable_flags = 0, disable_flags = 0;
1449 u32 bd_id = ntohl(mp->bd_id);
1453 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1456 enable_flags |= L2_FLOOD;
1458 disable_flags |= L2_FLOOD;
1461 enable_flags |= L2_UU_FLOOD;
1463 disable_flags |= L2_UU_FLOOD;
1466 enable_flags |= L2_FWD;
1468 disable_flags |= L2_FWD;
1471 enable_flags |= L2_ARP_TERM;
1473 disable_flags |= L2_ARP_TERM;
1476 enable_flags |= L2_LEARN;
1478 disable_flags |= L2_LEARN;
1481 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1484 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1487 rv = bd_delete_bd_index(bdm, bd_id);
1489 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1492 static void vl_api_bridge_domain_details_t_handler (
1493 vl_api_bridge_domain_details_t * mp)
1495 clib_warning ("BUG");
1498 static void vl_api_bridge_domain_sw_if_details_t_handler (
1499 vl_api_bridge_domain_sw_if_details_t * mp)
1501 clib_warning ("BUG");
1504 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1505 l2_bridge_domain_t * bd_config,
1508 vl_api_bridge_domain_details_t * mp;
1510 mp = vl_msg_api_alloc (sizeof (*mp));
1511 memset (mp, 0, sizeof (*mp));
1512 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1513 mp->bd_id = ntohl (bd_config->bd_id);
1514 mp->flood = bd_feature_flood (bd_config);
1515 mp->uu_flood = bd_feature_uu_flood (bd_config);
1516 mp->forward = bd_feature_forward (bd_config);
1517 mp->learn = bd_feature_learn (bd_config);
1518 mp->arp_term = bd_feature_arp_term (bd_config);
1519 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1520 mp->n_sw_ifs = ntohl (n_sw_ifs);
1522 vl_msg_api_send_shmem (q, (u8 *)&mp);
1525 static void send_bd_sw_if_details (l2input_main_t * l2im,
1526 unix_shared_memory_queue_t *q,
1527 l2_flood_member_t * member, u32 bd_id)
1529 vl_api_bridge_domain_sw_if_details_t * mp;
1530 l2_input_config_t * input_cfg;
1532 mp = vl_msg_api_alloc (sizeof (*mp));
1533 memset (mp, 0, sizeof (*mp));
1534 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1535 mp->bd_id = ntohl (bd_id);
1536 mp->sw_if_index = ntohl (member->sw_if_index);
1537 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1538 mp->shg = input_cfg->shg;
1540 vl_msg_api_send_shmem (q, (u8 *)&mp);
1543 static void vl_api_bridge_domain_dump_t_handler (
1544 vl_api_bridge_domain_dump_t *mp)
1546 bd_main_t * bdm = &bd_main;
1547 l2input_main_t * l2im = &l2input_main;
1548 unix_shared_memory_queue_t * q;
1549 l2_bridge_domain_t * bd_config;
1550 u32 bd_id, bd_index;
1553 q = vl_api_client_index_to_input_queue (mp->client_index);
1558 bd_id = ntohl(mp->bd_id);
1560 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1561 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1562 for (; bd_index < end; bd_index++) {
1563 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1564 /* skip dummy bd_id 0 */
1565 if (bd_config && (bd_config->bd_id > 0)) {
1567 l2_flood_member_t * m;
1569 n_sw_ifs = vec_len (bd_config->members);
1570 send_bridge_domain_details (q, bd_config, n_sw_ifs);
1572 vec_foreach (m, bd_config->members) {
1573 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id);
1580 vl_api_l2fib_add_del_t_handler (
1581 vl_api_l2fib_add_del_t *mp)
1583 bd_main_t * bdm = &bd_main;
1584 l2input_main_t * l2im = &l2input_main;
1585 vl_api_l2fib_add_del_reply_t * rmp;
1588 u32 sw_if_index = ntohl(mp->sw_if_index);
1589 u32 bd_id = ntohl(mp->bd_id);
1597 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1599 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1600 goto bad_sw_if_index;
1605 VALIDATE_SW_IF_INDEX(mp);
1606 if (vec_len(l2im->configs) <= sw_if_index) {
1607 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1608 goto bad_sw_if_index;
1610 l2_input_config_t * config;
1611 config = vec_elt_at_index(l2im->configs, sw_if_index);
1612 if (config->bridge == 0) {
1613 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1614 goto bad_sw_if_index;
1617 static_mac = mp->static_mac ? 1 : 0;
1618 filter_mac = mp->filter_mac ? 1 : 0;
1619 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1622 l2fib_del_entry(mac, bd_index);
1625 BAD_SW_IF_INDEX_LABEL;
1627 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1631 vl_api_l2_flags_t_handler (
1632 vl_api_l2_flags_t *mp)
1634 vl_api_l2_flags_reply_t * rmp;
1636 u32 sw_if_index = ntohl(mp->sw_if_index);
1637 u32 flags = ntohl(mp->feature_bitmap);
1640 VALIDATE_SW_IF_INDEX(mp);
1643 if (flags & L2INPUT_FEAT_ ## a) \
1644 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1645 foreach_l2input_feat;
1648 BAD_SW_IF_INDEX_LABEL;
1650 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1654 vl_api_bridge_flags_t_handler (
1655 vl_api_bridge_flags_t *mp)
1657 vlib_main_t *vm = vlib_get_main();
1658 bd_main_t * bdm = &bd_main;
1659 vl_api_bridge_flags_reply_t * rmp;
1661 u32 bd_id = ntohl(mp->bd_id);
1663 u32 flags = ntohl(mp->feature_bitmap);
1666 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1668 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1674 bd_set_flags(vm, bd_index, flags, mp->is_set);
1677 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1678 rmp->resulting_feature_bitmap = ntohl(flags));
1682 vl_api_bd_ip_mac_add_del_t_handler (
1683 vl_api_bd_ip_mac_add_del_t *mp)
1685 bd_main_t * bdm = &bd_main;
1686 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1688 u32 bd_id = ntohl(mp->bd_id);
1692 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1694 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1699 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1700 mp->mac_address, mp->is_ipv6, mp->is_add))
1701 rv = VNET_API_ERROR_UNSPECIFIED;
1704 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1708 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1711 vl_api_tap_connect_reply_t * rmp;
1712 unix_shared_memory_queue_t * q;
1713 u32 sw_if_index = (u32)~0;
1715 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1716 mp->use_random_mac ? 0 : mp->mac_address,
1717 &sw_if_index, mp->renumber,
1718 ntohl(mp->custom_dev_instance));
1720 q = vl_api_client_index_to_input_queue (mp->client_index);
1724 rmp = vl_msg_api_alloc (sizeof (*rmp));
1725 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1726 rmp->context = mp->context;
1727 rmp->retval = ntohl(rv);
1728 rmp->sw_if_index = ntohl(sw_if_index);
1730 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1734 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1737 vl_api_tap_modify_reply_t * rmp;
1738 unix_shared_memory_queue_t * q;
1739 u32 sw_if_index = (u32)~0;
1741 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1742 mp->use_random_mac ? 0 : mp->mac_address,
1743 &sw_if_index, mp->renumber,
1744 ntohl(mp->custom_dev_instance));
1746 q = vl_api_client_index_to_input_queue (mp->client_index);
1750 rmp = vl_msg_api_alloc (sizeof (*rmp));
1751 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1752 rmp->context = mp->context;
1753 rmp->retval = ntohl(rv);
1754 rmp->sw_if_index = ntohl(sw_if_index);
1756 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1760 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1763 vpe_api_main_t * vam = &vpe_api_main;
1764 vl_api_tap_delete_reply_t * rmp;
1765 unix_shared_memory_queue_t * q;
1766 u32 sw_if_index = ntohl(mp->sw_if_index);
1768 rv = vnet_tap_delete (vm, sw_if_index);
1770 q = vl_api_client_index_to_input_queue (mp->client_index);
1774 rmp = vl_msg_api_alloc (sizeof (*rmp));
1775 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1776 rmp->context = mp->context;
1777 rmp->retval = ntohl(rv);
1779 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1782 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1786 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1788 vl_api_create_vlan_subif_reply_t * rmp;
1789 vnet_main_t * vnm = vnet_get_main();
1790 u32 hw_if_index, sw_if_index = (u32)~0;
1791 vnet_hw_interface_t * hi;
1794 vnet_sw_interface_t template;
1796 vnet_interface_main_t * im = &vnm->interface_main;
1797 u64 sup_and_sub_key;
1799 unix_shared_memory_queue_t * q;
1800 clib_error_t * error;
1802 VALIDATE_SW_IF_INDEX(mp);
1804 hw_if_index = ntohl(mp->sw_if_index);
1805 hi = vnet_get_hw_interface (vnm, hw_if_index);
1807 id = ntohl(mp->vlan_id);
1808 if (id == 0 || id > 4095) {
1809 rv = VNET_API_ERROR_INVALID_VLAN;
1813 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1815 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1817 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1821 kp = clib_mem_alloc (sizeof (*kp));
1822 *kp = sup_and_sub_key;
1824 memset (&template, 0, sizeof (template));
1825 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1826 template.sup_sw_if_index = hi->sw_if_index;
1827 template.sub.id = id;
1828 template.sub.eth.raw_flags = 0;
1829 template.sub.eth.flags.one_tag = 1;
1830 template.sub.eth.outer_vlan_id = id;
1831 template.sub.eth.flags.exact_match = 1;
1833 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1835 clib_error_report(error);
1836 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1839 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1840 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1842 BAD_SW_IF_INDEX_LABEL;
1845 q = vl_api_client_index_to_input_queue (mp->client_index);
1849 rmp = vl_msg_api_alloc (sizeof (*rmp));
1850 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1851 rmp->context = mp->context;
1852 rmp->retval = ntohl(rv);
1853 rmp->sw_if_index = ntohl(sw_if_index);
1854 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1858 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1860 vl_api_create_subif_reply_t * rmp;
1861 vnet_main_t * vnm = vnet_get_main();
1862 u32 sw_if_index = ~0;
1865 vnet_sw_interface_t *si;
1866 vnet_hw_interface_t *hi;
1867 vnet_sw_interface_t template;
1869 vnet_interface_main_t * im = &vnm->interface_main;
1870 u64 sup_and_sub_key;
1872 clib_error_t * error;
1874 VALIDATE_SW_IF_INDEX(mp);
1876 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1877 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1879 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1880 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1884 sw_if_index = si->sw_if_index;
1885 sub_id = ntohl(mp->sub_id);
1887 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1889 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1892 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1893 sw_if_index, sub_id);
1894 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1898 kp = clib_mem_alloc (sizeof (*kp));
1899 *kp = sup_and_sub_key;
1901 memset (&template, 0, sizeof (template));
1902 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1903 template.sup_sw_if_index = sw_if_index;
1904 template.sub.id = sub_id;
1905 template.sub.eth.flags.no_tags = mp->no_tags;
1906 template.sub.eth.flags.one_tag = mp->one_tag;
1907 template.sub.eth.flags.two_tags = mp->two_tags;
1908 template.sub.eth.flags.dot1ad = mp->dot1ad;
1909 template.sub.eth.flags.exact_match = mp->exact_match;
1910 template.sub.eth.flags.default_sub = mp->default_sub;
1911 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1912 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1913 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1914 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1916 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1918 clib_error_report (error);
1919 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1923 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1924 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1926 BAD_SW_IF_INDEX_LABEL;
1930 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1932 rmp->sw_if_index = ntohl(sw_if_index);
1937 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1939 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1941 stats_main_t * sm = &stats_main;
1942 u32 tunnel_sw_if_index = ~0;
1944 dslock (sm, 1 /* release hint */, 5 /* tag */);
1946 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1947 (ip4_address_t *)(mp->dst_address),
1948 (ip4_address_t *)(mp->intfc_address),
1949 (u32)(mp->intfc_address_length),
1950 ntohl(mp->inner_vrf_id),
1951 ntohl(mp->outer_vrf_id),
1952 &tunnel_sw_if_index,
1957 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1959 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1964 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1965 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1967 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1969 stats_main_t * sm = &stats_main;
1970 u32 tunnel_sw_if_index;
1972 dslock (sm, 1 /* release hint */, 5 /* tag */);
1974 rv = vnet_mpls_ethernet_add_del_tunnel
1975 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1976 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1977 ntohl(mp->tx_sw_if_index),
1978 &tunnel_sw_if_index,
1984 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1986 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1991 * This piece of misery brought to you because the control-plane
1992 * can't figure out the tx interface + dst-mac address all by itself
1994 static int mpls_ethernet_add_del_tunnel_2_t_handler
1995 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
1997 pending_route_t * pr;
1998 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
1999 vnet_main_t * vnm = vnet_get_main();
2000 vlib_main_t * vm = vlib_get_main();
2001 stats_main_t * sm = &stats_main;
2002 vpe_api_main_t * vam = &vpe_api_main;
2003 u32 inner_fib_index, outer_fib_index;
2004 ip4_main_t * im = &ip4_main;
2005 ip_lookup_main_t * lm = &im->lookup_main;
2006 ip_adjacency_t * adj = 0;
2009 u8 * dst_mac_address;
2013 u32 tunnel_sw_if_index;
2015 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2017 return VNET_API_ERROR_NO_SUCH_FIB;
2019 outer_fib_index = p[0];
2022 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2024 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2026 inner_fib_index = p[0];
2028 if (inner_fib_index == outer_fib_index)
2029 return VNET_API_ERROR_INVALID_VALUE;
2031 lookup_result = ip4_fib_lookup_with_table
2032 (im, outer_fib_index,
2033 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2034 1 /* disable default route */);
2036 adj = ip_get_adjacency (lm, lookup_result);
2037 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2039 if (mp->is_add && mp->resolve_if_needed) {
2040 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2041 pool_get (vam->pending_routes, pr);
2042 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2044 memcpy (pme, mp, sizeof (*pme));
2045 /* recursion block, "just in case" */
2046 pme->resolve_if_needed = 0;
2047 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2048 pme->resolve_opaque = tx_sw_if_index;
2049 vnet_register_ip4_arp_resolution_event
2051 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2052 vpe_resolver_process_node.index,
2053 RESOLUTION_EVENT, pr - vam->pending_routes);
2055 vlib_process_signal_event
2056 (vm, vpe_resolver_process_node.index,
2057 RESOLUTION_PENDING_EVENT, 0 /* data */);
2059 /* The interface may be down, etc. */
2060 e = ip4_probe_neighbor
2061 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2065 clib_error_report(e);
2067 return VNET_API_ERROR_IN_PROGRESS;
2071 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2072 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2075 vnet_rewrite_get_data_internal
2076 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2078 dslock (sm, 1 /* release hint */, 10 /* tag */);
2080 rv = vnet_mpls_ethernet_add_del_tunnel
2081 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2082 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2083 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2091 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2092 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2094 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2097 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2099 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2104 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2106 vl_api_mpls_add_del_encap_reply_t * rmp;
2108 static u32 * labels;
2111 vec_reset_length (labels);
2113 for (i = 0; i < mp->nlabels; i++)
2114 vec_add1 (labels, ntohl(mp->labels[i]));
2117 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2118 ntohl(mp->vrf_id), labels,
2119 ~0 /* policy_tunnel_index */,
2120 0 /* no_dst_hash */,
2124 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2128 vl_api_mpls_add_del_decap_t_handler
2129 (vl_api_mpls_add_del_decap_t *mp)
2131 vl_api_mpls_add_del_decap_reply_t * rmp;
2134 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2135 ntohl(mp->label), ntohl(mp->next_index),
2136 mp->s_bit, mp->is_add);
2138 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2142 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2144 vl_api_proxy_arp_add_del_reply_t * rmp;
2147 ip4_main_t * im = &ip4_main;
2148 stats_main_t * sm = &stats_main;
2149 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2150 ip4_address_t *hi_addr,
2151 u32 fib_index, int is_del);
2154 dslock (sm, 1 /* release hint */, 6 /* tag */);
2156 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2159 rv = VNET_API_ERROR_NO_SUCH_FIB;
2165 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2166 (ip4_address_t *)mp->hi_address,
2167 fib_index, mp->is_add == 0);
2171 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2175 vl_api_proxy_arp_intfc_enable_disable_t_handler
2176 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2179 vnet_main_t * vnm = vnet_get_main();
2180 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2181 vnet_sw_interface_t * si;
2184 VALIDATE_SW_IF_INDEX(mp);
2186 sw_if_index = ntohl(mp->sw_if_index);
2188 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2190 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2194 si = vnet_get_sw_interface (vnm, sw_if_index);
2198 if (mp->enable_disable)
2199 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2201 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2203 BAD_SW_IF_INDEX_LABEL;
2206 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2210 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2212 vl_api_ip_neighbor_add_del_reply_t * rmp;
2213 vnet_main_t * vnm = vnet_get_main();
2216 stats_main_t * sm = &stats_main;
2218 VALIDATE_SW_IF_INDEX(mp);
2220 dslock (sm, 1 /* release hint */, 7 /* tag */);
2224 rv = vnet_set_ip6_ethernet_neighbor
2225 (vm, ntohl(mp->sw_if_index),
2226 (ip6_address_t *)(mp->dst_address),
2227 mp->mac_address, sizeof (mp->mac_address));
2229 rv = vnet_unset_ip6_ethernet_neighbor
2230 (vm, ntohl(mp->sw_if_index),
2231 (ip6_address_t *)(mp->dst_address),
2232 mp->mac_address, sizeof(mp->mac_address));
2234 ip4_main_t * im = &ip4_main;
2235 ip_lookup_main_t * lm = &im->lookup_main;
2236 ethernet_arp_ip4_over_ethernet_address_t a;
2238 ip_adjacency_t *nh_adj;
2240 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2242 rv = VNET_API_ERROR_NO_SUCH_FIB;
2248 * Unfortunately, folks have a penchant for
2249 * adding interface addresses to the ARP cache, and
2250 * wondering why the forwarder eventually ASSERTs...
2252 ai = ip4_fib_lookup_with_table
2253 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2254 1 /* disable default route */);
2257 nh_adj = ip_get_adjacency (lm, ai);
2258 /* Never allow manipulation of a local adj! */
2259 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2260 clib_warning("%U matches local adj",
2262 (ip4_address_t *)(mp->dst_address));
2263 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2268 memcpy (&a.ethernet, mp->mac_address, 6);
2269 memcpy (&a.ip4, mp->dst_address, 4);
2272 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2273 fib_index, &a, mp->is_static);
2275 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2279 BAD_SW_IF_INDEX_LABEL;
2282 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2286 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2289 vpe_main_t *rm = &vpe_main;
2290 ip4_main_t *im4 = &ip4_main;
2291 ip6_main_t *im6 = &ip6_main;
2292 ip_lookup_main_t * lm;
2297 u32 adj_index, sw_if_index;
2298 vl_api_is_address_reachable_t *rmp;
2299 ip_adjacency_t * adj;
2300 unix_shared_memory_queue_t *q;
2302 q = vl_api_client_index_to_input_queue (mp->client_index);
2304 increment_missing_api_client_counter (rm->vlib_main);
2308 rmp = vl_msg_api_alloc (sizeof (*rmp));
2309 memcpy (rmp, mp, sizeof (*rmp));
2311 sw_if_index = mp->next_hop_sw_if_index;
2312 memcpy (&addr, mp->address, sizeof (addr));
2314 lm = &im6->lookup_main;
2316 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2318 lm = &im4->lookup_main;
2320 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2322 if (adj_index == ~0) {
2326 adj = ip_get_adjacency (lm, adj_index);
2328 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2329 && adj->rewrite_header.sw_if_index == sw_if_index) {
2332 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2333 && adj->rewrite_header.sw_if_index == sw_if_index) {
2335 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2337 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2338 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2346 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2350 static void vl_api_sw_interface_details_t_handler (
2351 vl_api_sw_interface_details_t * mp)
2353 clib_warning ("BUG");
2356 static void vl_api_sw_interface_set_flags_t_handler (
2357 vl_api_sw_interface_set_flags_t * mp)
2359 vl_api_sw_interface_set_flags_reply_t *rmp;
2360 vnet_main_t * vnm = vnet_get_main();
2362 clib_error_t * error;
2365 VALIDATE_SW_IF_INDEX(mp);
2367 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2369 error = vnet_sw_interface_set_flags (vnm,
2370 ntohl(mp->sw_if_index),
2374 clib_error_report (error);
2377 BAD_SW_IF_INDEX_LABEL;
2378 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2381 static void vl_api_sw_interface_clear_stats_t_handler (
2382 vl_api_sw_interface_clear_stats_t * mp)
2384 vl_api_sw_interface_clear_stats_reply_t *rmp;
2386 vnet_main_t * vnm = vnet_get_main();
2387 vnet_interface_main_t * im = &vnm->interface_main;
2388 vlib_simple_counter_main_t * sm;
2389 vlib_combined_counter_main_t * cm;
2390 static vnet_main_t ** my_vnet_mains;
2391 int i, j, n_counters;
2395 vec_reset_length (my_vnet_mains);
2397 for (i = 0; i < vec_len (vnet_mains); i++)
2400 vec_add1 (my_vnet_mains, vnet_mains[i]);
2403 if (vec_len (vnet_mains) == 0)
2404 vec_add1 (my_vnet_mains, vnm);
2406 n_counters = vec_len (im->combined_sw_if_counters);
2408 for (j = 0; j < n_counters; j++)
2410 for (i = 0; i < vec_len(my_vnet_mains); i++)
2412 im = &my_vnet_mains[i]->interface_main;
2413 cm = im->combined_sw_if_counters + j;
2414 if (mp->sw_if_index == (u32)~0)
2415 vlib_clear_combined_counters (cm);
2417 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2421 n_counters = vec_len (im->sw_if_counters);
2423 for (j = 0; j < n_counters; j++)
2425 for (i = 0; i < vec_len(my_vnet_mains); i++)
2427 im = &my_vnet_mains[i]->interface_main;
2428 sm = im->sw_if_counters + j;
2429 if (mp->sw_if_index == (u32)~0)
2430 vlib_clear_simple_counters (sm);
2432 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2436 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2439 static void send_sw_interface_details (vpe_api_main_t * am,
2440 unix_shared_memory_queue_t *q,
2441 vnet_sw_interface_t * swif,
2442 u8 * interface_name)
2444 vl_api_sw_interface_details_t * mp;
2445 vnet_hw_interface_t * hi;
2447 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2449 mp = vl_msg_api_alloc (sizeof (*mp));
2450 memset (mp, 0, sizeof (*mp));
2451 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2452 mp->sw_if_index = ntohl(swif->sw_if_index);
2453 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2454 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2456 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2458 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2459 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2460 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2461 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2462 mp->link_mtu = ntohs(hi->max_packet_bytes);
2464 strncpy ((char *) mp->interface_name,
2465 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2467 /* Send the L2 address for ethernet physical intfcs */
2468 if (swif->sup_sw_if_index == swif->sw_if_index
2469 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2470 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2471 ethernet_interface_t *ei;
2473 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2474 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2475 memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2476 mp->l2_address_length = ntohl(sizeof (ei->address));
2477 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2478 vnet_sub_interface_t *sub = &swif->sub;
2479 mp->sub_id = ntohl(sub->id);
2480 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2481 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2482 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2483 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2484 mp->sub_exact_match = sub->eth.flags.exact_match;
2485 mp->sub_default = sub->eth.flags.default_sub;
2486 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2487 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2489 /* vlan tag rewrite data */
2490 u32 vtr_op = L2_VTR_DISABLED;
2491 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2493 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2494 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2495 // error - default to disabled
2496 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2497 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2500 mp->vtr_op = ntohl(vtr_op);
2501 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2502 mp->vtr_tag1 = ntohl(vtr_tag1);
2503 mp->vtr_tag2 = ntohl(vtr_tag2);
2507 vl_msg_api_send_shmem (q, (u8 *)&mp);
2510 static void send_sw_interface_flags (vpe_api_main_t * am,
2511 unix_shared_memory_queue_t *q,
2512 vnet_sw_interface_t * swif)
2514 vl_api_sw_interface_set_flags_t *mp;
2515 vnet_main_t * vnm = am->vnet_main;
2517 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2519 mp = vl_msg_api_alloc (sizeof (*mp));
2520 memset (mp, 0, sizeof (*mp));
2521 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2522 mp->sw_if_index = ntohl(swif->sw_if_index);
2524 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2526 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2528 vl_msg_api_send_shmem (q, (u8 *)&mp);
2531 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2532 unix_shared_memory_queue_t *q,
2534 __attribute__((unused));
2536 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2537 unix_shared_memory_queue_t *q,
2540 vl_api_sw_interface_set_flags_t *mp;
2542 mp = vl_msg_api_alloc (sizeof (*mp));
2543 memset (mp, 0, sizeof (*mp));
2544 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2545 mp->sw_if_index = ntohl(sw_if_index);
2547 mp->admin_up_down = 0;
2548 mp->link_up_down = 0;
2550 vl_msg_api_send_shmem (q, (u8 *)&mp);
2553 static void vl_api_sw_interface_dump_t_handler (
2554 vl_api_sw_interface_dump_t *mp)
2556 vpe_api_main_t * am = &vpe_api_main;
2557 vnet_sw_interface_t * swif;
2558 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2559 u8 * filter_string = 0, * name_string = 0;
2560 unix_shared_memory_queue_t * q;
2561 char * strcasestr (char *, char *); /* lnx hdr file botch */
2563 q = vl_api_client_index_to_input_queue (mp->client_index);
2568 if (mp->name_filter_valid) {
2569 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2570 filter_string = format (0, "%s%c", mp->name_filter, 0);
2573 pool_foreach (swif, im->sw_interfaces,
2575 name_string = format (name_string, "%U%c",
2576 format_vnet_sw_interface_name,
2577 am->vnet_main, swif, 0);
2579 if (mp->name_filter_valid == 0 ||
2580 strcasestr((char *) name_string, (char *) filter_string)) {
2582 send_sw_interface_details (am, q, swif, name_string);
2583 send_sw_interface_flags (am, q, swif);
2585 _vec_len (name_string) = 0;
2588 vec_free (name_string);
2589 vec_free (filter_string);
2592 void send_oam_event (oam_target_t * t)
2594 vpe_api_main_t * vam = &vpe_api_main;
2595 unix_shared_memory_queue_t * q;
2596 vpe_client_registration_t *reg;
2597 vl_api_oam_event_t * mp;
2599 pool_foreach(reg, vam->oam_events_registrations,
2601 q = vl_api_client_index_to_input_queue (reg->client_index);
2603 mp = vl_msg_api_alloc (sizeof (*mp));
2604 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2605 memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2606 mp->state = t->state;
2607 vl_msg_api_send_shmem (q, (u8 *)&mp);
2613 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2615 vl_api_oam_add_del_reply_t * rmp;
2618 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2619 (ip4_address_t *)mp->dst_address,
2623 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2627 vl_api_vnet_get_summary_stats_t_handler (
2628 vl_api_vnet_get_summary_stats_t *mp)
2630 stats_main_t * sm = &stats_main;
2631 vnet_interface_main_t * im = sm->interface_main;
2632 vl_api_vnet_summary_stats_reply_t *rmp;
2633 vlib_combined_counter_main_t * cm;
2636 u64 total_pkts[VLIB_N_RX_TX];
2637 u64 total_bytes[VLIB_N_RX_TX];
2639 unix_shared_memory_queue_t * q =
2640 vl_api_client_index_to_input_queue (mp->client_index);
2645 rmp = vl_msg_api_alloc (sizeof (*rmp));
2646 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2647 rmp->context = mp->context;
2650 memset (total_pkts, 0, sizeof (total_pkts));
2651 memset (total_bytes, 0, sizeof (total_bytes));
2653 vnet_interface_counter_lock (im);
2655 vec_foreach (cm, im->combined_sw_if_counters) {
2656 which = cm - im->combined_sw_if_counters;
2658 for (i = 0; i < vec_len (cm->maxi); i++) {
2659 vlib_get_combined_counter (cm, i, &v);
2660 total_pkts[which] += v.packets;
2661 total_bytes[which] += v.bytes;
2664 vnet_interface_counter_unlock (im);
2666 /* Note: in HOST byte order! */
2667 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2668 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2669 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2670 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2671 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2673 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2676 typedef CLIB_PACKED (struct {
2677 ip4_address_t address;
2679 u32 address_length : 6;
2684 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2686 vnet_main_t * vnm = vnet_get_main();
2687 vnet_interface_main_t * im = &vnm->interface_main;
2688 ip4_main_t * im4 = &ip4_main;
2689 static ip4_route_t * routes;
2690 static u32 * sw_if_indices_to_shut;
2691 stats_main_t * sm = &stats_main;
2696 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2697 u32 target_fib_id = ntohl(mp->vrf_id);
2699 dslock (sm, 1 /* release hint */, 8 /* tag */);
2701 vec_foreach (fib, im4->fibs) {
2702 vnet_sw_interface_t * si;
2704 if (fib->table_id != target_fib_id)
2707 /* remove any mpls/gre tunnels in this fib */
2708 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2710 /* remove any mpls encap/decap labels */
2711 mpls_fib_reset_labels (fib->table_id);
2713 /* remove any proxy arps in this fib */
2714 vnet_proxy_arp_fib_reset (fib->table_id);
2716 /* Set the flow hash for this fib to the default */
2717 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2719 vec_reset_length (sw_if_indices_to_shut);
2721 /* Shut down interfaces in this FIB / clean out intfc routes */
2722 pool_foreach (si, im->sw_interfaces,
2724 u32 sw_if_index = si->sw_if_index;
2726 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2727 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2729 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2732 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2733 sw_if_index = sw_if_indices_to_shut[i];
2734 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2736 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2737 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2738 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2741 vec_reset_length (routes);
2743 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2744 uword * hash = fib->adj_index_by_dst_address[i];
2748 x.address_length = i;
2750 hash_foreach_pair (p, hash,
2752 x.address.data_u32 = p->key;
2753 vec_add1 (routes, x);
2757 vec_foreach (r, routes) {
2758 ip4_add_del_route_args_t a;
2760 memset (&a, 0, sizeof (a));
2761 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2762 a.table_index_or_table_id = fib - im4->fibs;
2763 a.dst_address = r->address;
2764 a.dst_address_length = r->address_length;
2767 ip4_add_del_route (im4, &a);
2768 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2769 IP4_ROUTE_FLAG_FIB_INDEX);
2773 } /* vec_foreach (fib) */
2780 ip6_address_t address;
2787 ip6_route_t ** routep;
2788 } add_routes_in_fib_arg_t;
2790 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2792 add_routes_in_fib_arg_t * ap = arg;
2794 if (kvp->key[2]>>32 == ap->fib_index)
2796 ip6_address_t *addr;
2798 addr = (ip6_address_t *) kvp;
2799 vec_add2 (*ap->routep, r, 1);
2800 r->address = addr[0];
2801 r->address_length = kvp->key[2] & 0xFF;
2802 r->index = kvp->value;
2806 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2808 vnet_main_t * vnm = vnet_get_main();
2809 vnet_interface_main_t * im = &vnm->interface_main;
2810 ip6_main_t * im6 = &ip6_main;
2811 stats_main_t * sm = &stats_main;
2812 static ip6_route_t * routes;
2813 static u32 * sw_if_indices_to_shut;
2818 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2819 u32 target_fib_id = ntohl(mp->vrf_id);
2820 add_routes_in_fib_arg_t _a, *a=&_a;
2821 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2823 dslock (sm, 1 /* release hint */, 9 /* tag */);
2825 vec_foreach (fib, im6->fibs) {
2826 vnet_sw_interface_t * si;
2828 if (fib->table_id != target_fib_id)
2831 vec_reset_length (sw_if_indices_to_shut);
2833 /* Shut down interfaces in this FIB / clean out intfc routes */
2834 pool_foreach (si, im->sw_interfaces,
2836 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2838 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2841 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2842 sw_if_index = sw_if_indices_to_shut[i];
2843 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2845 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2846 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2847 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2850 vec_reset_length (routes);
2852 a->fib_index = fib - im6->fibs;
2853 a->routep = &routes;
2855 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2857 vec_foreach (r, routes) {
2858 ip6_add_del_route_args_t a;
2860 memset (&a, 0, sizeof (a));
2861 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2862 a.table_index_or_table_id = fib - im6->fibs;
2863 a.dst_address = r->address;
2864 a.dst_address_length = r->address_length;
2867 ip6_add_del_route (im6, &a);
2868 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2869 IP6_ROUTE_FLAG_FIB_INDEX);
2872 /* Reinstall the neighbor / router discovery routes */
2873 vnet_ip6_fib_init (im6, fib - im6->fibs);
2875 } /* vec_foreach (fib) */
2881 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2884 vl_api_reset_fib_reply_t * rmp;
2887 rv = ip6_reset_fib_t_handler (mp);
2889 rv = ip4_reset_fib_t_handler (mp);
2891 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2896 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2898 vl_api_dhcp_proxy_config_reply_t * rmp;
2901 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2902 (ip4_address_t *)(&mp->dhcp_src_address),
2903 (u32) ntohl(mp->vrf_id),
2904 (int) mp->insert_circuit_id,
2905 (int) (mp->is_add == 0));
2907 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2912 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2914 vl_api_dhcp_proxy_config_reply_t * rmp;
2917 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2918 (ip6_address_t *)(&mp->dhcp_src_address),
2919 (u32) ntohl(mp->vrf_id),
2920 (int) mp->insert_circuit_id,
2921 (int) (mp->is_add == 0));
2923 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2927 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2929 vl_api_dhcp_proxy_config_reply_t * rmp;
2932 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2933 (ip4_address_t *)(&mp->dhcp_src_address),
2934 (u32) ntohl(mp->rx_vrf_id),
2935 (u32) ntohl(mp->server_vrf_id),
2936 (int) mp->insert_circuit_id,
2937 (int) (mp->is_add == 0));
2939 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2944 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2946 vl_api_dhcp_proxy_config_reply_t * rmp;
2950 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2951 (ip6_address_t *)(&mp->dhcp_src_address),
2952 (u32) ntohl(mp->rx_vrf_id),
2953 (u32) ntohl(mp->server_vrf_id),
2954 (int) mp->insert_circuit_id,
2955 (int) (mp->is_add == 0));
2957 rv = VNET_API_ERROR_UNIMPLEMENTED;
2960 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2965 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2967 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2970 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2973 (int)mp->is_add == 0);
2975 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2978 (int)mp->is_add == 0);
2980 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2984 static void vl_api_dhcp_proxy_config_t_handler
2985 (vl_api_dhcp_proxy_config_t *mp)
2987 if (mp->is_ipv6 == 0)
2988 dhcpv4_proxy_config (mp);
2990 dhcpv6_proxy_config (mp);
2993 static void vl_api_dhcp_proxy_config_2_t_handler
2994 (vl_api_dhcp_proxy_config_2_t *mp)
2996 if (mp->is_ipv6 == 0)
2997 dhcpv4_proxy_config_2 (mp);
2999 dhcpv6_proxy_config_2 (mp);
3002 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3003 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3005 unix_shared_memory_queue_t * q;
3006 vl_api_dhcp_compl_event_t * mp;
3008 q = vl_api_client_index_to_input_queue (client_index);
3012 mp = vl_msg_api_alloc (sizeof (*mp));
3013 mp->client_index = client_index;
3015 mp->is_ipv6 = is_ipv6;
3016 memcpy (&mp->hostname, hostname, vec_len(hostname));
3017 mp->hostname[vec_len(hostname) + 1] = '\n';
3018 memcpy (&mp->host_address[0], host_address, 16);
3019 memcpy (&mp->router_address[0], router_address, 16);
3020 memcpy (&mp->host_mac[0], host_mac, 6);
3022 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3024 vl_msg_api_send_shmem (q, (u8 *)&mp);
3027 static void vl_api_dhcp_client_config_t_handler
3028 (vl_api_dhcp_client_config_t *mp)
3030 vlib_main_t *vm = vlib_get_main();
3031 vl_api_dhcp_client_config_reply_t * rmp;
3034 VALIDATE_SW_IF_INDEX(mp);
3036 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3037 mp->hostname, mp->is_add, mp->client_index,
3038 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3041 BAD_SW_IF_INDEX_LABEL;
3043 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3047 vl_api_sw_interface_ip6nd_ra_config_t_handler
3048 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3050 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3052 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3054 is_no = mp->is_no == 1;
3055 surpress = mp->surpress == 1;
3056 managed = mp->managed == 1;
3057 other = mp->other == 1;
3058 ll_option = mp->ll_option == 1;
3059 send_unicast = mp->send_unicast == 1;
3060 cease = mp->cease == 1;
3061 default_router = mp->default_router == 1;
3063 VALIDATE_SW_IF_INDEX(mp);
3065 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3066 surpress, managed, other,
3067 ll_option, send_unicast, cease,
3068 default_router, ntohl (mp->lifetime),
3069 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3070 ntohl(mp->max_interval), ntohl( mp->min_interval),
3073 BAD_SW_IF_INDEX_LABEL;
3075 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3079 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3080 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3082 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3084 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3086 VALIDATE_SW_IF_INDEX(mp);
3088 is_no = mp->is_no == 1;
3089 use_default = mp->use_default == 1;
3090 no_advertise = mp->no_advertise == 1;
3091 off_link = mp->off_link == 1;
3092 no_autoconfig = mp->no_autoconfig == 1;
3093 no_onlink = mp->no_onlink == 1;
3095 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3096 (ip6_address_t *)mp->address, mp->address_length,
3097 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3098 no_advertise, off_link, no_autoconfig, no_onlink,
3101 BAD_SW_IF_INDEX_LABEL;
3102 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3106 vl_api_sw_interface_ip6_enable_disable_t_handler
3107 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3109 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3110 vnet_main_t * vnm = vnet_get_main();
3112 clib_error_t * error;
3116 VALIDATE_SW_IF_INDEX(mp);
3118 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3119 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3122 clib_error_report(error);
3123 rv = VNET_API_ERROR_UNSPECIFIED;
3125 rv = vnm->api_errno;
3128 BAD_SW_IF_INDEX_LABEL;
3130 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3134 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3135 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3137 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3139 clib_error_t * error;
3140 vnet_main_t * vnm = vnet_get_main();
3144 VALIDATE_SW_IF_INDEX(mp);
3146 error = set_ip6_link_local_address(vm,
3147 ntohl(mp->sw_if_index),
3148 (ip6_address_t *)mp->address,
3149 mp->address_length);
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_SET_LINK_LOCAL_ADDRESS_REPLY);
3162 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3164 vl_api_set_ip_flow_hash_reply_t *rmp;
3165 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3167 clib_warning ("unimplemented...");
3169 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3172 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3174 vl_api_set_ip_flow_hash_reply_t *rmp;
3177 u32 flow_hash_config = 0;
3179 table_id = ntohl(mp->vrf_id);
3181 #define _(a,b) if (mp->a) flow_hash_config |= b;
3182 foreach_flow_hash_bit;
3185 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3187 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3191 static void vl_api_set_ip_flow_hash_t_handler
3192 (vl_api_set_ip_flow_hash_t *mp)
3194 if (mp->is_ipv6 == 0)
3195 set_ip4_flow_hash (mp);
3197 set_ip6_flow_hash (mp);
3200 static void vl_api_sw_interface_set_unnumbered_t_handler
3201 (vl_api_sw_interface_set_unnumbered_t *mp)
3203 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3205 vnet_sw_interface_t * si;
3206 vnet_main_t *vnm = vnet_get_main();
3207 u32 sw_if_index, unnumbered_sw_if_index;
3209 sw_if_index = ntohl(mp->sw_if_index);
3210 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3213 * The API message field names are backwards from
3214 * the underlying data structure names.
3215 * It's not worth changing them now.
3217 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3218 unnumbered_sw_if_index)) {
3219 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3223 /* Only check the "use loop0" field when setting the binding */
3225 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3226 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3230 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3233 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3234 si->unnumbered_sw_if_index = sw_if_index;
3236 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3237 si->unnumbered_sw_if_index = (u32)~0;
3241 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3244 static void vl_api_create_loopback_t_handler
3245 (vl_api_create_loopback_t *mp)
3247 vl_api_create_loopback_reply_t * rmp;
3251 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3253 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3255 rmp->sw_if_index = ntohl (sw_if_index);
3259 static void vl_api_delete_loopback_t_handler
3260 (vl_api_delete_loopback_t *mp)
3262 vl_api_delete_loopback_reply_t * rmp;
3266 sw_if_index = ntohl (mp->sw_if_index);
3267 rv = vnet_delete_loopback_interface (sw_if_index);
3269 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3272 static void vl_api_control_ping_t_handler
3273 (vl_api_control_ping_t *mp)
3275 vl_api_control_ping_reply_t * rmp;
3278 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3280 rmp->vpe_pid = ntohl (getpid());
3284 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3286 u8 **shmem_vecp = (u8 **)arg;
3289 api_main_t * am = &api_main;
3292 shmem_vec = *shmem_vecp;
3294 offset = vec_len (shmem_vec);
3296 pthread_mutex_lock (&am->vlib_rp->mutex);
3297 oldheap = svm_push_data_heap (am->vlib_rp);
3299 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3301 memcpy (shmem_vec + offset, buffer, buffer_bytes);
3303 svm_pop_heap (oldheap);
3304 pthread_mutex_unlock (&am->vlib_rp->mutex);
3306 *shmem_vecp = shmem_vec;
3310 static void vl_api_cli_request_t_handler
3311 (vl_api_cli_request_t *mp)
3313 vl_api_cli_reply_t *rp;
3314 unix_shared_memory_queue_t *q;
3315 vlib_main_t * vm = vlib_get_main();
3316 api_main_t * am = &api_main;
3317 unformat_input_t input;
3321 q = vl_api_client_index_to_input_queue (mp->client_index);
3325 rp = vl_msg_api_alloc (sizeof (*rp));
3326 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3327 rp->context = mp->context;
3329 unformat_init_vector (&input, (u8 *)mp->cmd_in_shmem);
3331 vlib_cli_input (vm, &input, shmem_cli_output,
3334 pthread_mutex_lock (&am->vlib_rp->mutex);
3335 oldheap = svm_push_data_heap (am->vlib_rp);
3337 vec_add1(shmem_vec, 0);
3339 svm_pop_heap (oldheap);
3340 pthread_mutex_unlock (&am->vlib_rp->mutex);
3342 rp->reply_in_shmem = (uword)shmem_vec;
3344 vl_msg_api_send_shmem (q, (u8 *)&rp);
3347 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3350 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3351 vnet_main_t *vnm = vnet_get_main();
3352 clib_error_t * error;
3357 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3359 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3362 clib_error_report(error);
3363 rv = VNET_API_ERROR_UNSPECIFIED;
3365 rv = vnm->api_errno;
3368 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3371 static void vl_api_sr_tunnel_add_del_t_handler
3372 (vl_api_sr_tunnel_add_del_t *mp)
3375 clib_warning ("unimplemented");
3377 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3379 vl_api_sr_tunnel_add_del_reply_t * rmp;
3380 ip6_address_t * segments = 0, * seg;
3381 ip6_address_t * tags = 0, *tag;
3382 ip6_address_t * this_address;
3385 if (mp->n_segments == 0) {
3390 memset (a, 0, sizeof (*a));
3391 a->src_address = (ip6_address_t *)&mp->src_address;
3392 a->dst_address = (ip6_address_t *)&mp->dst_address;
3393 a->dst_mask_width = mp->dst_mask_width;
3394 a->flags_net_byte_order = mp->flags_net_byte_order;
3395 a->is_del = (mp->is_add == 0);
3396 a->rx_table_id = ntohl(mp->outer_vrf_id);
3397 a->tx_table_id = ntohl(mp->inner_vrf_id);
3399 /* Yank segments and tags out of the API message */
3400 this_address = (ip6_address_t *)mp->segs_and_tags;
3401 for (i = 0; i < mp->n_segments; i++) {
3402 vec_add2 (segments, seg, 1);
3403 memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3406 for (i = 0; i < mp->n_tags; i++) {
3407 vec_add2 (tags, tag, 1);
3408 memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3412 a->segments = segments;
3415 rv = ip6_sr_add_del_tunnel (a);
3419 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3423 #define foreach_classify_add_del_table_field \
3428 _(match_n_vectors) \
3429 _(next_table_index) \
3432 static void vl_api_classify_add_del_table_t_handler
3433 (vl_api_classify_add_del_table_t * mp)
3435 vl_api_classify_add_del_table_reply_t * rmp;
3436 vnet_classify_main_t * cm = &vnet_classify_main;
3437 vnet_classify_table_t * t;
3441 foreach_classify_add_del_table_field;
3444 #define _(a) a = ntohl(mp->a);
3445 foreach_classify_add_del_table_field;
3448 /* The underlying API fails silently, on purpose, so check here */
3449 if (mp->is_add == 0)
3450 if (pool_is_free_index (cm->tables, table_index)) {
3451 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3455 rv = vnet_classify_add_del_table
3456 (cm, mp->mask, nbuckets, memory_size,
3457 skip_n_vectors, match_n_vectors,
3458 next_table_index, miss_next_index,
3459 &table_index, mp->is_add);
3462 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3464 if (rv == 0 && mp->is_add) {
3465 t = pool_elt_at_index (cm->tables, table_index);
3466 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3467 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3468 rmp->new_table_index = ntohl(table_index);
3470 rmp->skip_n_vectors = ~0;
3471 rmp->match_n_vectors = ~0;
3472 rmp->new_table_index = ~0;
3477 static void vl_api_classify_add_del_session_t_handler
3478 (vl_api_classify_add_del_session_t * mp)
3480 vnet_classify_main_t * cm = &vnet_classify_main;
3481 vl_api_classify_add_del_session_reply_t * rmp;
3483 u32 table_index, hit_next_index, opaque_index;
3486 table_index = ntohl (mp->table_index);
3487 hit_next_index = ntohl (mp->hit_next_index);
3488 opaque_index = ntohl (mp->opaque_index);
3489 advance = ntohl (mp->advance);
3491 rv = vnet_classify_add_del_session
3492 (cm, table_index, mp->match, hit_next_index, opaque_index,
3493 advance, mp->is_add);
3495 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3498 static void vl_api_classify_set_interface_ip_table_t_handler
3499 (vl_api_classify_set_interface_ip_table_t * mp)
3501 vlib_main_t * vm = vlib_get_main();
3502 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3504 u32 table_index, sw_if_index;
3506 table_index = ntohl (mp->table_index);
3507 sw_if_index = ntohl (mp->sw_if_index);
3509 VALIDATE_SW_IF_INDEX(mp);
3512 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3514 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3516 BAD_SW_IF_INDEX_LABEL;
3518 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3521 static void vl_api_classify_set_interface_l2_tables_t_handler
3522 (vl_api_classify_set_interface_l2_tables_t * mp)
3524 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3526 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3529 ip4_table_index = ntohl(mp->ip4_table_index);
3530 ip6_table_index = ntohl(mp->ip6_table_index);
3531 other_table_index = ntohl(mp->other_table_index);
3532 sw_if_index = ntohl(mp->sw_if_index);
3534 VALIDATE_SW_IF_INDEX(mp);
3536 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3537 ip6_table_index, other_table_index);
3540 if (ip4_table_index != ~0 || ip6_table_index != ~0
3541 || other_table_index != ~0)
3546 vnet_l2_classify_enable_disable (sw_if_index, enable);
3549 BAD_SW_IF_INDEX_LABEL;
3551 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3555 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3558 vl_api_l2_fib_clear_table_reply_t * rmp;
3560 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3561 * that is not currently implemented. When that TODO is fixed
3562 * this call should be changed to pass 1 instead of 0.
3564 l2fib_clear_table (0);
3566 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3569 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3574 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3577 vl_api_l2_interface_efp_filter_reply_t * rmp;
3578 vnet_main_t *vnm = vnet_get_main();
3580 // enable/disable the feature
3581 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3582 rv = vnm->api_errno;
3584 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3588 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3591 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3592 vnet_main_t * vnm = vnet_get_main();
3593 vlib_main_t * vm = vlib_get_main();
3596 VALIDATE_SW_IF_INDEX(mp);
3598 vtr_op = ntohl(mp->vtr_op);
3600 /* The L2 code is unsuspicious */
3602 case L2_VTR_DISABLED:
3607 case L2_VTR_TRANSLATE_1_1:
3608 case L2_VTR_TRANSLATE_1_2:
3609 case L2_VTR_TRANSLATE_2_1:
3610 case L2_VTR_TRANSLATE_2_2:
3614 rv = VNET_API_ERROR_INVALID_VALUE;
3615 goto bad_sw_if_index;
3618 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3619 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3622 BAD_SW_IF_INDEX_LABEL;
3624 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3628 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3632 vl_api_create_vhost_user_if_reply_t * rmp;
3633 u32 sw_if_index = (u32)~0;
3635 vnet_main_t * vnm = vnet_get_main();
3636 vlib_main_t * vm = vlib_get_main();
3638 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3639 mp->is_server, &sw_if_index, (u64)~0,
3640 mp->renumber, ntohl(mp->custom_dev_instance),
3641 (mp->use_custom_mac)?mp->mac_address:NULL);
3643 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3645 rmp->sw_if_index = ntohl (sw_if_index);
3651 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3655 vl_api_modify_vhost_user_if_reply_t * rmp;
3656 u32 sw_if_index = ntohl(mp->sw_if_index);
3658 vnet_main_t * vnm = vnet_get_main();
3659 vlib_main_t * vm = vlib_get_main();
3661 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3662 mp->is_server, sw_if_index, (u64)~0,
3663 mp->renumber, ntohl(mp->custom_dev_instance));
3665 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3670 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3674 vpe_api_main_t * vam = &vpe_api_main;
3675 vl_api_delete_vhost_user_if_reply_t * rmp;
3676 u32 sw_if_index = ntohl(mp->sw_if_index);
3678 vnet_main_t * vnm = vnet_get_main();
3679 vlib_main_t * vm = vlib_get_main();
3681 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3683 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3685 unix_shared_memory_queue_t * q =
3686 vl_api_client_index_to_input_queue (mp->client_index);
3690 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3695 static void vl_api_sw_interface_vhost_user_details_t_handler (
3696 vl_api_sw_interface_vhost_user_details_t * mp)
3698 clib_warning ("BUG");
3702 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3703 unix_shared_memory_queue_t *q,
3704 vhost_user_intf_details_t * vui)
3706 vl_api_sw_interface_vhost_user_details_t * mp;
3708 mp = vl_msg_api_alloc (sizeof (*mp));
3709 memset (mp, 0, sizeof (*mp));
3710 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3711 mp->sw_if_index = ntohl(vui->sw_if_index);
3712 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3713 mp->features = clib_net_to_host_u64 (vui->features);
3714 mp->is_server = vui->is_server;
3715 mp->num_regions = ntohl(vui->num_regions);
3716 mp->sock_errno = ntohl(vui->sock_errno);
3718 strncpy ((char *) mp->sock_filename,
3719 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3720 strncpy ((char *) mp->interface_name,
3721 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3723 vl_msg_api_send_shmem (q, (u8 *)&mp);
3728 vl_api_sw_interface_vhost_user_dump_t_handler (
3729 vl_api_sw_interface_vhost_user_dump_t *mp)
3733 vpe_api_main_t * am = &vpe_api_main;
3734 vnet_main_t * vnm = vnet_get_main();
3735 vlib_main_t * vm = vlib_get_main();
3736 vhost_user_intf_details_t *ifaces = NULL;
3737 vhost_user_intf_details_t *vuid = NULL;
3738 unix_shared_memory_queue_t * q;
3740 q = vl_api_client_index_to_input_queue (mp->client_index);
3744 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3748 vec_foreach (vuid, ifaces) {
3749 send_sw_interface_vhost_user_details (am, q, vuid);
3755 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3756 unix_shared_memory_queue_t *q,
3760 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3761 u8 * if_name = NULL;
3762 vnet_sw_interface_t * si = NULL;
3764 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3766 if_name = format(if_name, "%U",
3767 format_vnet_sw_interface_name, lm->vnet_main, si);
3769 mp = vl_msg_api_alloc (sizeof (*mp));
3770 memset (mp, 0, sizeof (*mp));
3771 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3772 strncpy((char *)mp->interface_name,
3773 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3774 mp->sw_if_index = ntohl(si->sw_if_index);
3775 mp->local_session_id = s->local_session_id;
3776 mp->remote_session_id = s->remote_session_id;
3777 mp->local_cookie[0] = s->local_cookie[0];
3778 mp->local_cookie[1] = s->local_cookie[1];
3779 mp->remote_cookie = s->remote_cookie;
3780 memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3781 memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3782 mp->l2_sublayer_present = s->l2_sublayer_present;
3784 vl_msg_api_send_shmem (q, (u8 *)&mp);
3787 static void send_ip_address_details (vpe_api_main_t * am,
3788 unix_shared_memory_queue_t * q,
3793 vl_api_ip_address_details_t * mp;
3795 mp = vl_msg_api_alloc (sizeof (*mp));
3796 memset (mp, 0, sizeof (*mp));
3797 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3800 memcpy(&mp->ip, ip, sizeof(mp->ip));
3802 u32 * tp = (u32 *)mp->ip;
3803 *tp = ntohl(*(u32*)ip);
3805 mp->prefix_length = prefix_length;
3807 vl_msg_api_send_shmem (q, (u8 *)&mp);
3811 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3813 vpe_api_main_t * am = &vpe_api_main;
3814 unix_shared_memory_queue_t * q;
3817 ip6_main_t * im6 = &ip6_main;
3818 ip4_main_t * im4 = &ip4_main;
3819 ip_lookup_main_t * lm6 = &im6->lookup_main;
3820 ip_lookup_main_t * lm4 = &im4->lookup_main;
3821 ip_interface_address_t * ia = 0;
3822 u32 sw_if_index = ~0;
3824 sw_if_index = ntohl(mp->sw_if_index);
3826 q = vl_api_client_index_to_input_queue (mp->client_index);
3832 foreach_ip_interface_address (lm6, ia, sw_if_index,
3833 1 /* honor unnumbered */,
3835 r6 = ip_interface_address_get_address (lm6, ia);
3836 u16 prefix_length = ia->address_length;
3837 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1);
3840 foreach_ip_interface_address (lm4, ia, sw_if_index,
3841 1 /* honor unnumbered */,
3843 r4 = ip_interface_address_get_address (lm4, ia);
3844 u16 prefix_length = ia->address_length;
3845 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0);
3850 static void send_ip_details (vpe_api_main_t * am,
3851 unix_shared_memory_queue_t *q,
3854 vl_api_ip_details_t * mp;
3856 mp = vl_msg_api_alloc (sizeof (*mp));
3857 memset (mp, 0, sizeof (*mp));
3858 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3860 mp->sw_if_index = ntohl(sw_if_index);
3862 vl_msg_api_send_shmem (q, (u8 *)&mp);
3866 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3867 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3869 vpe_api_main_t * am = &vpe_api_main;
3870 l2t_main_t * lm = &l2t_main;
3871 unix_shared_memory_queue_t * q;
3872 l2t_session_t *session;
3874 q = vl_api_client_index_to_input_queue (mp->client_index);
3878 pool_foreach (session, lm->sessions,
3880 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm);
3885 static void send_sw_interface_tap_details (vpe_api_main_t * am,
3886 unix_shared_memory_queue_t *q,
3887 tapcli_interface_details_t *tap_if)
3889 vl_api_sw_interface_tap_details_t * mp;
3890 mp = vl_msg_api_alloc (sizeof (*mp));
3891 memset (mp, 0, sizeof (*mp));
3892 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
3893 mp->sw_if_index = ntohl(tap_if->sw_if_index);
3894 strncpy((char *)mp->dev_name,
3895 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
3897 vl_msg_api_send_shmem (q, (u8 *)&mp);
3901 vl_api_sw_interface_tap_dump_t_handler (
3902 vl_api_sw_interface_tap_dump_t *mp)
3905 vpe_api_main_t * am = &vpe_api_main;
3906 unix_shared_memory_queue_t * q;
3907 tapcli_interface_details_t *tapifs = NULL;
3908 tapcli_interface_details_t *tap_if = NULL;
3910 q = vl_api_client_index_to_input_queue (mp->client_index);
3914 rv = vnet_tap_dump_ifs(&tapifs);
3918 vec_foreach(tap_if, tapifs) {
3919 send_sw_interface_tap_details(am, q, tap_if);
3926 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
3928 vpe_api_main_t * am = &vpe_api_main;
3929 vnet_main_t * vnm = vnet_get_main();
3930 vlib_main_t * vm = vlib_get_main();
3931 vnet_interface_main_t * im = &vnm->interface_main;
3932 unix_shared_memory_queue_t * q;
3933 vnet_sw_interface_t * si, * sorted_sis;
3934 u32 sw_if_index = ~0;
3936 q = vl_api_client_index_to_input_queue (mp->client_index);
3941 /* Gather interfaces. */
3942 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
3943 _vec_len (sorted_sis) = 0;
3944 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
3946 vec_foreach (si, sorted_sis) {
3947 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
3948 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
3951 sw_if_index = si->sw_if_index;
3952 send_ip_details(am, q, sw_if_index);
3957 static void vl_api_l2_fib_table_entry_t_handler (
3958 vl_api_l2_fib_table_entry_t * mp)
3960 clib_warning ("BUG");
3963 static void send_l2fib_table_entry (vpe_api_main_t * am,
3964 unix_shared_memory_queue_t *q,
3965 l2fib_entry_key_t * l2fe_key,
3966 l2fib_entry_result_t * l2fe_res)
3968 vl_api_l2_fib_table_entry_t * mp;
3970 mp = vl_msg_api_alloc (sizeof (*mp));
3971 memset (mp, 0, sizeof (*mp));
3972 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
3974 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
3976 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
3977 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
3978 mp->static_mac = l2fe_res->fields.static_mac;
3979 mp->filter_mac = l2fe_res->fields.filter;
3980 mp->bvi_mac = l2fe_res->fields.bvi;
3982 vl_msg_api_send_shmem (q, (u8 *)&mp);
3986 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
3988 vpe_api_main_t * am = &vpe_api_main;
3989 bd_main_t * bdm = &bd_main;
3990 l2fib_entry_key_t *l2fe_key = NULL;
3991 l2fib_entry_result_t *l2fe_res = NULL;
3992 u32 ni, bd_id = ntohl (mp->bd_id);
3994 unix_shared_memory_queue_t * q;
3997 q = vl_api_client_index_to_input_queue (mp->client_index);
4001 /* see l2fib_table_dump: ~0 means "any" */
4005 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4012 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4014 vec_foreach_index (ni, l2fe_key) {
4015 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4016 vec_elt_at_index(l2fe_res, ni));
4023 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4025 vl_api_show_version_reply_t *rmp;
4027 char * vpe_api_get_build_directory(void);
4028 char * vpe_api_get_version(void);
4029 char * vpe_api_get_build_date(void);
4031 unix_shared_memory_queue_t * q =
4032 vl_api_client_index_to_input_queue (mp->client_index);
4037 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4039 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4040 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4041 ARRAY_LEN(rmp->build_directory)-1);
4042 strncpy ((char *) rmp->version, vpe_api_get_version(),
4043 ARRAY_LEN(rmp->version)-1);
4044 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4045 ARRAY_LEN(rmp->build_date)-1);
4049 static void vl_api_get_node_index_t_handler
4050 (vl_api_get_node_index_t * mp)
4052 vlib_main_t * vm = vlib_get_main();
4053 vl_api_get_node_index_reply_t * rmp;
4056 u32 node_index = ~0;
4058 n = vlib_get_node_by_name (vm, mp->node_name);
4061 rv = VNET_API_ERROR_NO_SUCH_NODE;
4063 node_index = n->index;
4065 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4067 rmp->node_index = ntohl(node_index);
4071 static void vl_api_add_node_next_t_handler
4072 (vl_api_add_node_next_t * mp)
4074 vlib_main_t * vm = vlib_get_main();
4075 vl_api_add_node_next_reply_t * rmp;
4076 vlib_node_t * n, * next;
4078 u32 next_index = ~0;
4080 n = vlib_get_node_by_name (vm, mp->node_name);
4083 rv = VNET_API_ERROR_NO_SUCH_NODE;
4087 next = vlib_get_node_by_name (vm, mp->next_name);
4090 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4092 next_index = vlib_node_add_next (vm, n->index, next->index);
4095 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4097 rmp->next_index = ntohl(next_index);
4101 static void vl_api_l2tpv3_create_tunnel_t_handler
4102 (vl_api_l2tpv3_create_tunnel_t *mp)
4104 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4105 l2t_main_t *lm = &l2t_main;
4106 u32 sw_if_index = (u32)~0;
4109 if (mp->is_ipv6 != 1) {
4110 rv = VNET_API_ERROR_UNIMPLEMENTED;
4114 rv = create_l2tpv3_ipv6_tunnel (lm,
4115 (ip6_address_t *) mp->client_address,
4116 (ip6_address_t *) mp->our_address,
4117 ntohl(mp->local_session_id),
4118 ntohl(mp->remote_session_id),
4119 clib_net_to_host_u64(mp->local_cookie),
4120 clib_net_to_host_u64(mp->remote_cookie),
4121 mp->l2_sublayer_present,
4125 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4127 rmp->sw_if_index = ntohl (sw_if_index);
4131 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4132 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4134 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4135 l2t_main_t *lm = &l2t_main;
4138 VALIDATE_SW_IF_INDEX(mp);
4140 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4141 clib_net_to_host_u64(mp->new_local_cookie),
4142 clib_net_to_host_u64(mp->new_remote_cookie));
4144 BAD_SW_IF_INDEX_LABEL;
4146 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4149 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4150 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4153 vnet_main_t * vnm = vnet_get_main();
4154 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4156 VALIDATE_SW_IF_INDEX(mp);
4158 rv = l2tpv3_interface_enable_disable
4159 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4161 BAD_SW_IF_INDEX_LABEL;
4163 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4166 static void vl_api_l2tpv3_set_lookup_key_t_handler
4167 (vl_api_l2tpv3_set_lookup_key_t * mp)
4170 l2t_main_t *lm = &l2t_main;
4171 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4173 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4174 rv = VNET_API_ERROR_INVALID_VALUE;
4178 lm->lookup_type = mp->key;
4181 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4184 static void vl_api_vxlan_add_del_tunnel_t_handler
4185 (vl_api_vxlan_add_del_tunnel_t * mp)
4187 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4189 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4190 u32 encap_fib_index;
4192 ip4_main_t * im = &ip4_main;
4193 u32 sw_if_index = ~0;
4195 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4197 rv = VNET_API_ERROR_NO_SUCH_FIB;
4200 encap_fib_index = p[0];
4202 memset (a, 0, sizeof (*a));
4204 a->is_add = mp->is_add;
4206 /* ip addresses sent in network byte order */
4207 a->src.as_u32 = mp->src_address;
4208 a->dst.as_u32 = mp->dst_address;
4210 a->encap_fib_index = encap_fib_index;
4211 a->decap_next_index = ntohl(mp->decap_next_index);
4212 a->vni = ntohl(mp->vni);
4213 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4216 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4218 rmp->sw_if_index = ntohl (sw_if_index);
4222 static void send_vxlan_tunnel_details
4223 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q)
4225 vl_api_vxlan_tunnel_details_t * rmp;
4226 ip4_main_t * im = &ip4_main;
4228 rmp = vl_msg_api_alloc (sizeof (*rmp));
4229 memset (rmp, 0, sizeof (*rmp));
4230 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4231 rmp->src_address = t->src.data_u32;
4232 rmp->dst_address = t->dst.data_u32;
4233 rmp->encap_vrf_id = htonl(im->fibs[t->encap_fib_index].table_id);
4234 rmp->vni = htonl(t->vni);
4235 rmp->decap_next_index = htonl(t->decap_next_index);
4236 rmp->sw_if_index = htonl(t->sw_if_index);
4238 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4241 static void vl_api_vxlan_tunnel_dump_t_handler
4242 (vl_api_vxlan_tunnel_dump_t * mp)
4244 unix_shared_memory_queue_t * q;
4245 vxlan_main_t * vxm = &vxlan_main;
4249 q = vl_api_client_index_to_input_queue (mp->client_index);
4254 sw_if_index = ntohl(mp->sw_if_index);
4256 if (~0 == sw_if_index) {
4257 pool_foreach (t, vxm->tunnels,
4259 send_vxlan_tunnel_details(t, q);
4262 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4263 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4266 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4267 send_vxlan_tunnel_details(t, q);
4272 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4274 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4276 vl_api_l2_patch_add_del_reply_t * rmp;
4277 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4281 VALIDATE_RX_SW_IF_INDEX(mp);
4282 VALIDATE_TX_SW_IF_INDEX(mp);
4284 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4285 ntohl(mp->tx_sw_if_index),
4286 (int)(mp->is_add != 0));
4288 BAD_RX_SW_IF_INDEX_LABEL;
4289 BAD_TX_SW_IF_INDEX_LABEL;
4291 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4295 vl_api_nsh_gre_add_del_tunnel_t_handler
4296 (vl_api_nsh_gre_add_del_tunnel_t * mp)
4298 vl_api_nsh_gre_add_del_tunnel_reply_t * rmp;
4300 vnet_nsh_gre_add_del_tunnel_args_t _a, *a = &_a;
4301 u32 encap_fib_index, decap_fib_index;
4302 u32 decap_next_index;
4304 ip4_main_t * im = &ip4_main;
4306 u32 sw_if_index = ~0;
4309 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4311 rv = VNET_API_ERROR_NO_SUCH_FIB;
4314 encap_fib_index = p[0];
4316 decap_next_index = ntohl(mp->decap_next_index);
4318 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4319 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4320 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4322 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4325 decap_fib_index = p[0];
4327 decap_fib_index = ntohl(mp->decap_vrf_id);
4330 memset (a, 0, sizeof (*a));
4332 a->is_add = mp->is_add;
4333 /* ip addresses sent in network byte order */
4334 a->src.as_u32 = ntohl(mp->src);
4335 a->dst.as_u32 = ntohl(mp->dst);
4336 a->encap_fib_index = encap_fib_index;
4337 a->decap_fib_index = decap_fib_index;
4338 a->decap_next_index = decap_next_index;
4339 a->ver_o_c = mp->ver_o_c;
4340 a->length = mp->length;
4341 a->md_type = mp->md_type;
4342 a->next_protocol = mp->next_protocol;
4343 a->spi_si = ntohl(mp->spi_si);
4344 a->c1 = ntohl(mp->c1);
4345 a->c2 = ntohl(mp->c2);
4346 a->c3 = ntohl(mp->c3);
4347 a->c4 = ntohl(mp->c4);
4349 for (i = 0; i < mp->tlv_len_in_words; i++)
4350 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4354 rv = vnet_nsh_gre_add_del_tunnel (a, &sw_if_index);
4357 REPLY_MACRO2(VL_API_NSH_GRE_ADD_DEL_TUNNEL_REPLY,
4359 rmp->sw_if_index = ntohl (sw_if_index);
4364 vl_api_nsh_vxlan_gpe_add_del_tunnel_t_handler
4365 (vl_api_nsh_vxlan_gpe_add_del_tunnel_t * mp)
4367 vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4369 vnet_nsh_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4370 u32 encap_fib_index, decap_fib_index;
4371 u32 decap_next_index;
4373 ip4_main_t * im = &ip4_main;
4375 u32 sw_if_index = ~0;
4378 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4380 rv = VNET_API_ERROR_NO_SUCH_FIB;
4383 encap_fib_index = p[0];
4385 decap_next_index = ntohl(mp->decap_next_index);
4387 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4388 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4389 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4391 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4394 decap_fib_index = p[0];
4396 decap_fib_index = ntohl(mp->decap_vrf_id);
4399 memset (a, 0, sizeof (*a));
4401 a->is_add = mp->is_add;
4402 /* ip addresses sent in network byte order */
4403 a->src.as_u32 = ntohl(mp->src);
4404 a->dst.as_u32 = ntohl(mp->dst);
4405 a->encap_fib_index = encap_fib_index;
4406 a->decap_fib_index = decap_fib_index;
4407 a->decap_next_index = decap_next_index;
4408 a->vni = ntohl(mp->vni);
4409 a->ver_o_c = mp->ver_o_c;
4410 a->length = mp->length;
4411 a->md_type = mp->md_type;
4412 a->next_protocol = mp->next_protocol;
4413 a->spi_si = ntohl(mp->spi_si);
4414 a->c1 = ntohl(mp->c1);
4415 a->c2 = ntohl(mp->c2);
4416 a->c3 = ntohl(mp->c3);
4417 a->c4 = ntohl(mp->c4);
4419 for (i = 0; i < mp->tlv_len_in_words; i++)
4420 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4424 rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4427 REPLY_MACRO2(VL_API_NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4429 rmp->sw_if_index = ntohl (sw_if_index);
4434 vl_api_lisp_gpe_add_del_tunnel_t_handler
4435 (vl_api_lisp_gpe_add_del_tunnel_t * mp)
4437 vl_api_lisp_gpe_add_del_tunnel_reply_t * rmp;
4439 vnet_lisp_gpe_add_del_tunnel_args_t _a, *a = &_a;
4440 u32 encap_fib_index, decap_fib_index;
4441 u32 decap_next_index;
4443 ip4_main_t * im = &ip4_main;
4444 u32 sw_if_index = ~0;
4446 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4448 rv = VNET_API_ERROR_NO_SUCH_FIB;
4451 encap_fib_index = p[0];
4453 decap_next_index = ntohl(mp->decap_next_index);
4455 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4456 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4457 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4459 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4462 decap_fib_index = p[0];
4464 decap_fib_index = ntohl(mp->decap_vrf_id);
4467 memset (a, 0, sizeof (*a));
4469 a->is_add = mp->is_add;
4470 /* ip addresses sent in network byte order */
4471 a->src.as_u32 = mp->src;
4472 a->dst.as_u32 = mp->dst;
4473 a->encap_fib_index = encap_fib_index;
4474 a->decap_fib_index = decap_fib_index;
4475 a->decap_next_index = decap_next_index;
4476 a->flags = mp->flags;
4477 a->ver_res = mp->ver_res;
4479 a->next_protocol = mp->next_protocol;
4480 a->iid = clib_net_to_host_u32 (mp->iid);
4482 rv = vnet_lisp_gpe_add_del_tunnel (a, &sw_if_index);
4485 REPLY_MACRO2(VL_API_LISP_GPE_ADD_DEL_TUNNEL_REPLY,
4487 rmp->sw_if_index = ntohl (sw_if_index);
4492 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4494 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4496 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4498 u8 *locator_name = NULL;
4500 memset(a, 0, sizeof(a[0]));
4502 locator_name = format(0, "%s", mp->locator_set_name);
4504 a->name = locator_name;
4506 a->is_add = mp->is_add;
4509 rv = vnet_lisp_add_del_locator_set_name(a, &ls_index);
4511 vec_free(locator_name);
4513 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4517 vl_api_lisp_add_del_locator_t_handler(
4518 vl_api_lisp_add_del_locator_t *mp)
4520 vl_api_lisp_add_del_locator_reply_t *rmp;
4522 locator_t locator, *locators = NULL;
4523 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4525 u8 *locator_name = NULL;
4527 memset(&locator, 0, sizeof(locator));
4528 memset(a, 0, sizeof(a[0]));
4530 locator.sw_if_index = ntohl(mp->sw_if_index);
4531 locator.priority = mp->priority;
4532 locator.weight = mp->weight;
4534 vec_add1(locators, locator);
4536 locator_name = format(0, "%s", mp->locator_set_name);
4538 a->name = locator_name;
4539 a->locators = locators;
4540 a->is_add = mp->is_add;
4543 rv = vnet_lisp_add_del_locator(a, &ls_index);
4546 vec_free(locator_name);
4548 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4552 vl_api_lisp_add_del_local_eid_t_handler(
4553 vl_api_lisp_add_del_local_eid_t *mp)
4555 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4556 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4558 ip_prefix_t *prefp = NULL;
4559 ip_address_t *ip_eid = NULL;
4562 u32 locator_set_index = ~0, map_index = ~0;
4563 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4566 prefp = &gid_address_ippref(&eid);
4567 ip_eid = &ip_prefix_addr(prefp);
4568 gid_address_type (&eid) = IP_PREFIX;
4571 memcpy(&ip_addr_v6(ip_eid), mp->ip_address,
4572 sizeof(ip_addr_v6(ip_eid)));
4573 ip_addr_version(ip_eid) = IP6;
4575 memcpy(&ip_addr_v4(ip_eid), mp->ip_address,
4576 sizeof(ip_addr_v4(ip_eid)));
4577 ip_addr_version(ip_eid) = IP4;
4579 ip_prefix_len(prefp) = mp->prefix_len;
4581 name = format(0, "%s", mp->locator_set_name);
4582 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4584 rv = VNET_API_ERROR_INVALID_VALUE;
4587 locator_set_index = p[0];
4589 /* XXX treat batch configuration */
4590 a->is_add = mp->is_add;
4592 a->locator_set_index = locator_set_index;
4595 rv = vnet_lisp_add_del_mapping(a, &map_index);
4600 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4604 lisp_gpe_add_del_fwd_entry_set_address(
4605 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4606 ip_address_t *slocator,
4607 ip_address_t *dlocator,
4610 ip_address_t *ip_eid = NULL;
4611 ip_prefix_t *prefp = NULL;
4613 prefp = &gid_address_ippref(eid);
4614 ip_eid = &ip_prefix_addr(prefp);
4616 if (mp->eid_is_ipv6) {
4617 memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4618 sizeof(ip_addr_v6(ip_eid)));
4619 ip_addr_version(ip_eid) = IP6;
4621 memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4622 sizeof(ip_addr_v4(ip_eid)));
4623 ip_addr_version(ip_eid) = IP4;
4625 ip_prefix_len(prefp) = mp->eid_prefix_len;
4627 if (mp->address_is_ipv6) {
4628 memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4629 sizeof(ip_addr_v6(slocator)));
4630 ip_addr_version(slocator) = IP6;
4631 memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4632 sizeof(ip_addr_v6(dlocator)));
4633 ip_addr_version(dlocator) = IP6;
4635 memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4636 sizeof(ip_addr_v4(slocator)));
4637 ip_addr_version(slocator) = IP4;
4638 memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4639 sizeof(ip_addr_v4(dlocator)));
4640 ip_addr_version(dlocator) = IP4;
4645 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4646 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4648 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4650 ip_address_t slocator, dlocator;
4651 ip_prefix_t * prefp = NULL;
4653 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4655 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4657 memset (&a, 0, sizeof(a));
4659 a.is_add = mp->is_add;
4661 a.slocator = slocator;
4662 a.dlocator = dlocator;
4663 prefp = &gid_address_ippref(&a.deid);
4664 a.decap_next_index = (ip_prefix_version(prefp) == IP4) ?
4665 LISP_GPE_INPUT_NEXT_IP4_INPUT : LISP_GPE_INPUT_NEXT_IP6_INPUT;
4666 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4668 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4672 vl_api_lisp_add_del_map_resolver_t_handler(
4673 vl_api_lisp_add_del_map_resolver_t *mp)
4675 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4677 ip_address_t *ip_addr = NULL;
4678 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4680 a->is_add = mp->is_add;
4681 ip_addr = &a->address;
4684 memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4685 sizeof(ip_addr_v6(ip_addr)));
4686 ip_addr_version(ip_addr) = IP6;
4688 memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4689 sizeof(ip_addr_v4(ip_addr)));
4690 ip_addr_version(ip_addr) = IP4;
4693 rv = vnet_lisp_add_del_map_resolver (a);
4695 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4699 vl_api_lisp_gpe_add_del_iface_t_handler(
4700 vl_api_lisp_gpe_add_del_iface_t *mp)
4702 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4704 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4706 a->is_add = mp->is_add;
4707 vnet_lisp_gpe_add_del_iface (a, 0);
4709 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4713 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
4714 locator_set_t *lsit,
4715 unix_shared_memory_queue_t *q)
4717 vl_api_lisp_locator_set_details_t *rmp;
4718 locator_t *loc = NULL;
4721 vec_foreach (locit, lsit->locator_indices) {
4722 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4723 rmp = vl_msg_api_alloc (sizeof (*rmp));
4724 memset (rmp, 0, sizeof (*rmp));
4725 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
4726 strncpy((char *) rmp->locator_set_name,
4727 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4728 rmp->sw_if_index = htonl(loc->sw_if_index);
4729 rmp->priority = loc->priority;
4730 rmp->weight = loc->weight;
4732 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4737 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
4739 unix_shared_memory_queue_t * q = NULL;
4740 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4741 locator_set_t * lsit = NULL;
4743 q = vl_api_client_index_to_input_queue (mp->client_index);
4748 pool_foreach (lsit, lcm->locator_set_pool,
4750 send_lisp_locator_set_details(lcm, lsit, q);
4755 send_lisp_local_eid_table_details (mapping_t *mapit,
4756 unix_shared_memory_queue_t *q)
4758 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
4759 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4760 locator_set_t *ls = NULL;
4761 gid_address_t *gid = NULL;
4762 ip_prefix_t *ip_prefix = NULL;
4765 ls = pool_elt_at_index (lcm->locator_set_pool,
4766 mapit->locator_set_index);
4769 type = gid_address_type(gid);
4771 if (type != IP_PREFIX) {
4775 ip_prefix = &gid_address_ippref(gid);
4777 rmp = vl_msg_api_alloc (sizeof (*rmp));
4778 memset (rmp, 0, sizeof (*rmp));
4779 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
4780 strncpy((char *) rmp->locator_set_name,
4781 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4783 switch (ip_prefix_version(ip_prefix)) {
4785 rmp->eid_is_ipv6 = 0;
4786 memcpy(rmp->eid_ip_address, &ip_prefix_v4(ip_prefix),
4787 sizeof(ip_prefix_v4(ip_prefix)));
4791 rmp->eid_is_ipv6 = 1;
4792 memcpy(rmp->eid_ip_address, &ip_prefix_v6(ip_prefix),
4793 sizeof(ip_prefix_v6(ip_prefix)));
4799 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
4801 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4805 vl_api_lisp_local_eid_table_dump_t_handler (
4806 vl_api_lisp_local_eid_table_dump_t *mp)
4808 unix_shared_memory_queue_t * q = NULL;
4809 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4810 mapping_t * mapit = NULL;
4812 q = vl_api_client_index_to_input_queue (mp->client_index);
4817 pool_foreach (mapit, lcm->mapping_pool,
4819 send_lisp_local_eid_table_details(mapit, q);
4824 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
4825 unix_shared_memory_queue_t *q)
4827 vl_api_lisp_gpe_tunnel_details_t *rmp;
4828 lisp_gpe_main_t * lgm = &lisp_gpe_main;
4829 ip4_address_t *ip4 = NULL;
4831 rmp = vl_msg_api_alloc (sizeof (*rmp));
4832 memset (rmp, 0, sizeof (*rmp));
4833 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
4835 rmp->tunnels = tunnel - lgm->tunnels;
4837 /*list_gpe_tunnel now support only IPv4*/
4840 memcpy(rmp->source_ip, ip4, sizeof(*ip4));
4842 memcpy(rmp->destination_ip, ip4, sizeof(*ip4));
4844 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
4845 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
4846 rmp->dcap_next = htonl(tunnel->decap_next_index);
4847 rmp->lisp_ver = tunnel->ver_res;
4848 rmp->next_protocol = tunnel->next_protocol;
4849 rmp->flags = tunnel->flags;
4850 rmp->ver_res = tunnel->ver_res;
4851 rmp->res = tunnel->res;
4852 rmp->iid = htonl(tunnel->iid);
4854 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4858 vl_api_lisp_gpe_tunnel_dump_t_handler (
4859 vl_api_lisp_local_eid_table_dump_t *mp)
4861 unix_shared_memory_queue_t * q = NULL;
4862 lisp_gpe_main_t * lgm = &lisp_gpe_main;
4863 lisp_gpe_tunnel_t * tunnel = NULL;
4865 if (pool_elts(lgm->tunnels) == 0) {
4869 q = vl_api_client_index_to_input_queue (mp->client_index);
4874 pool_foreach(tunnel, lgm->tunnels,
4876 send_lisp_gpe_tunnel_details(tunnel, q);
4881 send_lisp_map_resolver_details (ip_address_t *ip,
4882 unix_shared_memory_queue_t *q)
4884 vl_api_lisp_map_resolver_details_t *rmp = NULL;
4886 rmp = vl_msg_api_alloc (sizeof (*rmp));
4887 memset (rmp, 0, sizeof (*rmp));
4888 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
4890 switch (ip_addr_version(ip)) {
4893 memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
4898 memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
4905 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4909 vl_api_lisp_map_resolver_dump_t_handler (
4910 vl_api_lisp_local_eid_table_dump_t *mp)
4912 unix_shared_memory_queue_t * q = NULL;
4913 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4914 ip_address_t *ip = NULL;
4916 q = vl_api_client_index_to_input_queue (mp->client_index);
4921 vec_foreach(ip, lcm->map_resolvers) {
4922 send_lisp_map_resolver_details(ip, q);
4928 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
4930 vl_api_interface_name_renumber_reply_t * rmp;
4933 VALIDATE_SW_IF_INDEX(mp);
4935 rv = vnet_interface_name_renumber
4936 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
4938 BAD_SW_IF_INDEX_LABEL;
4940 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
4943 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
4944 u32 sw_if_index, u32 address)
4946 vpe_api_main_t * am = &vpe_api_main;
4947 vlib_main_t * vm = am->vlib_main;
4948 vl_api_ip4_arp_event_t * event;
4949 static f64 arp_event_last_time;
4950 f64 now = vlib_time_now (vm);
4952 if (pool_is_free_index (am->arp_events, pool_index))
4955 event = pool_elt_at_index (am->arp_events, pool_index);
4956 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
4957 memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
4958 } else { /* same mac */
4959 if ((sw_if_index == event->sw_if_index) &&
4961 /* for BD case, also check IP address with 10 sec timeout */
4962 ((address == event->address) &&
4963 ((now - arp_event_last_time) < 10.0))))
4967 arp_event_last_time = now;
4968 event->sw_if_index = sw_if_index;
4969 if (address) event->address = address;
4973 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
4975 vpe_api_main_t * am = &vpe_api_main;
4977 if (pool_is_free_index (am->arp_events, pool_index))
4980 pool_put_index (am->arp_events, pool_index);
4985 vl_api_want_ip4_arp_events_t_handler
4986 (vl_api_want_ip4_arp_events_t * mp)
4988 vpe_api_main_t * am = &vpe_api_main;
4989 vnet_main_t * vnm = vnet_get_main();
4990 vl_api_want_ip4_arp_events_reply_t *rmp;
4991 vl_api_ip4_arp_event_t * event;
4994 if (mp->enable_disable) {
4995 pool_get (am->arp_events, event);
4996 memset (event, 0, sizeof (*event));
4998 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
4999 event->client_index = mp->client_index;
5000 event->context = mp->context;
5001 event->address = mp->address;
5002 event->pid = mp->pid;
5004 rv = vnet_add_del_ip4_arp_change_event
5005 (vnm, arp_change_data_callback,
5007 &mp->address /* addr, in net byte order */,
5008 vpe_resolver_process_node.index,
5009 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5011 rv = vnet_add_del_ip4_arp_change_event
5012 (vnm, arp_change_delete_callback,
5014 &mp->address /* addr, in net byte order */,
5015 vpe_resolver_process_node.index,
5016 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5018 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5021 static void vl_api_input_acl_set_interface_t_handler
5022 (vl_api_input_acl_set_interface_t * mp)
5024 vlib_main_t *vm = vlib_get_main();
5025 vl_api_input_acl_set_interface_reply_t * rmp;
5027 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5029 ip4_table_index = ntohl(mp->ip4_table_index);
5030 ip6_table_index = ntohl(mp->ip6_table_index);
5031 l2_table_index = ntohl(mp->l2_table_index);
5032 sw_if_index = ntohl(mp->sw_if_index);
5034 VALIDATE_SW_IF_INDEX(mp);
5036 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5037 ip6_table_index, l2_table_index,
5040 BAD_SW_IF_INDEX_LABEL;
5042 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5045 static void vl_api_ipsec_spd_add_del_t_handler
5046 (vl_api_ipsec_spd_add_del_t * mp)
5049 clib_warning ("unimplemented");
5052 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5053 vl_api_ipsec_spd_add_del_reply_t * rmp;
5057 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5059 rv = VNET_API_ERROR_UNIMPLEMENTED;
5062 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5066 static void vl_api_ipsec_interface_add_del_spd_t_handler
5067 (vl_api_ipsec_interface_add_del_spd_t * mp)
5069 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5070 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5072 u32 sw_if_index __attribute__((unused));
5073 u32 spd_id __attribute__((unused));
5075 sw_if_index = ntohl(mp->sw_if_index);
5076 spd_id = ntohl(mp->spd_id);
5078 VALIDATE_SW_IF_INDEX(mp);
5081 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5083 rv = VNET_API_ERROR_UNIMPLEMENTED;
5086 BAD_SW_IF_INDEX_LABEL;
5088 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5091 static void vl_api_ipsec_spd_add_del_entry_t_handler
5092 (vl_api_ipsec_spd_add_del_entry_t * mp)
5094 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5095 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5101 memset(&p, 0, sizeof(p));
5103 p.id = ntohl(mp->spd_id);
5104 p.priority = ntohl(mp->priority);
5105 p.is_outbound = mp->is_outbound;
5106 p.is_ipv6 = mp->is_ipv6;
5108 memcpy(&p.raddr.start, mp->remote_address_start, 16);
5109 memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5110 memcpy(&p.laddr.start, mp->local_address_start, 16);
5111 memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5113 p.protocol = mp->protocol;
5114 p.rport.start = ntohs(mp->remote_port_start);
5115 p.rport.stop = ntohs(mp->remote_port_stop);
5116 p.lport.start = ntohs(mp->local_port_start);
5117 p.lport.stop = ntohs(mp->local_port_stop);
5118 /* policy action resolve unsupported */
5119 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5120 clib_warning("unsupported action: 'resolve'");
5121 rv = VNET_API_ERROR_UNIMPLEMENTED;
5124 p.policy = mp->policy;
5125 p.sa_id = ntohl(mp->sa_id);
5127 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5131 if (mp->is_ip_any) {
5133 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5136 rv = VNET_API_ERROR_UNIMPLEMENTED;
5141 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5144 static void vl_api_ipsec_sad_add_del_entry_t_handler
5145 (vl_api_ipsec_sad_add_del_entry_t * mp)
5147 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5148 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5153 memset(&sa, 0, sizeof(sa));
5155 sa.id = ntohl(mp->sad_id);
5156 sa.spi = ntohl(mp->spi);
5157 /* security protocol AH unsupported */
5158 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5159 clib_warning("unsupported security protocol 'AH'");
5160 rv = VNET_API_ERROR_UNIMPLEMENTED;
5163 sa.protocol = mp->protocol;
5164 /* check for unsupported crypto-alg */
5165 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5166 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5167 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5168 mp->crypto_algorithm);
5169 rv = VNET_API_ERROR_UNIMPLEMENTED;
5172 sa.crypto_alg = mp->crypto_algorithm;
5173 sa.crypto_key_len = mp->crypto_key_length;
5174 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5175 /* check for unsupported integ-alg */
5176 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5177 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5178 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5179 mp->integrity_algorithm);
5180 rv = VNET_API_ERROR_UNIMPLEMENTED;
5183 sa.integ_alg = mp->integrity_algorithm;
5184 sa.integ_key_len = mp->integrity_key_length;
5185 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5186 sa.use_esn = mp->use_extended_sequence_number;
5187 sa.is_tunnel = mp->is_tunnel;
5188 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5189 memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5190 memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5192 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5194 rv = VNET_API_ERROR_UNIMPLEMENTED;
5199 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5203 vl_api_ikev2_profile_add_del_t_handler
5204 (vl_api_ikev2_profile_add_del_t * mp)
5206 vlib_main_t * vm = vlib_get_main();
5207 vl_api_ikev2_profile_add_del_reply_t * rmp;
5211 clib_error_t * error;
5212 u8 * tmp = format(0, "%s", mp->name);
5213 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5216 rv = VNET_API_ERROR_UNSPECIFIED;
5218 rv = VNET_API_ERROR_UNIMPLEMENTED;
5221 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5225 vl_api_ikev2_profile_set_auth_t_handler
5226 (vl_api_ikev2_profile_set_auth_t * mp)
5228 vlib_main_t * vm = vlib_get_main();
5229 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5233 clib_error_t * error;
5234 u8 * tmp = format(0, "%s", mp->name);
5235 u8 * data = vec_new (u8, mp->data_len);
5236 memcpy(data, mp->data, mp->data_len);
5237 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5241 rv = VNET_API_ERROR_UNSPECIFIED;
5243 rv = VNET_API_ERROR_UNIMPLEMENTED;
5246 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5250 vl_api_ikev2_profile_set_id_t_handler
5251 (vl_api_ikev2_profile_set_id_t * mp)
5253 vlib_main_t * vm = vlib_get_main();
5254 vl_api_ikev2_profile_set_id_reply_t * rmp;
5258 clib_error_t * error;
5259 u8 * tmp = format(0, "%s", mp->name);
5260 u8 * data = vec_new (u8, mp->data_len);
5261 memcpy(data, mp->data, mp->data_len);
5262 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
5266 rv = VNET_API_ERROR_UNSPECIFIED;
5268 rv = VNET_API_ERROR_UNIMPLEMENTED;
5271 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5275 vl_api_ikev2_profile_set_ts_t_handler
5276 (vl_api_ikev2_profile_set_ts_t * mp)
5278 vlib_main_t * vm = vlib_get_main();
5279 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5283 clib_error_t * error;
5284 u8 * tmp = format(0, "%s", mp->name);
5285 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
5286 mp->end_port, (ip4_address_t) mp->start_addr,
5287 (ip4_address_t) mp->end_addr, mp->is_local);
5290 rv = VNET_API_ERROR_UNSPECIFIED;
5292 rv = VNET_API_ERROR_UNIMPLEMENTED;
5295 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5299 vl_api_ikev2_set_local_key_t_handler
5300 (vl_api_ikev2_set_local_key_t * mp)
5302 vlib_main_t * vm = vlib_get_main();
5303 vl_api_ikev2_set_local_key_reply_t * rmp;
5307 clib_error_t * error;
5309 error = ikev2_set_local_key(vm, mp->key_file);
5311 rv = VNET_API_ERROR_UNSPECIFIED;
5313 rv = VNET_API_ERROR_UNIMPLEMENTED;
5316 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5320 vl_api_map_add_domain_t_handler
5321 (vl_api_map_add_domain_t * mp)
5323 vl_api_map_add_domain_reply_t * rmp;
5326 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
5327 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
5328 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
5329 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
5330 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
5332 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
5334 rmp->index = ntohl(index);
5339 vl_api_map_del_domain_t_handler
5340 (vl_api_map_del_domain_t * mp)
5342 vl_api_map_del_domain_reply_t * rmp;
5345 rv = map_delete_domain(ntohl(mp->index));
5347 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
5351 vl_api_map_add_del_rule_t_handler
5352 (vl_api_map_add_del_rule_t * mp)
5354 vl_api_map_del_domain_reply_t * rmp;
5357 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
5359 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
5363 vl_api_map_domain_dump_t_handler
5364 (vl_api_map_domain_dump_t * mp)
5366 vl_api_map_domain_details_t * rmp;
5367 map_main_t *mm = &map_main;
5369 unix_shared_memory_queue_t * q;
5371 if (pool_elts (mm->domains) == 0)
5374 q = vl_api_client_index_to_input_queue (mp->client_index);
5379 pool_foreach(d, mm->domains, ({
5380 rmp = vl_msg_api_alloc (sizeof (*rmp));
5381 memset (rmp, 0, sizeof (*rmp));
5382 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
5383 rmp->domain_index = htonl(d - mm->domains);
5384 rmp->ea_bits_len = d->ea_bits_len;
5385 rmp->psid_offset = d->psid_offset;
5386 rmp->psid_length = d->psid_length;
5387 memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
5388 rmp->ip4_prefix_len = d->ip4_prefix_len;
5389 memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
5390 rmp->ip6_prefix_len = d->ip6_prefix_len;
5391 memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
5392 rmp->ip6_src_len = d->ip6_src_len;
5393 rmp->mtu = htons(d->mtu);
5394 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
5396 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5401 vl_api_map_rule_dump_t_handler
5402 (vl_api_map_rule_dump_t * mp)
5404 unix_shared_memory_queue_t * q;
5407 vl_api_map_rule_details_t * rmp;
5408 map_main_t *mm = &map_main;
5409 u32 domain_index = ntohl(mp->domain_index);
5412 if (pool_elts (mm->domains) == 0)
5415 d = pool_elt_at_index(mm->domains, domain_index);
5416 if (!d || !d->rules) {
5420 q = vl_api_client_index_to_input_queue (mp->client_index);
5425 for (i = 0; i < (0x1 << d->psid_length); i++) {
5427 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
5430 rmp = vl_msg_api_alloc(sizeof(*rmp));
5431 memset(rmp, 0, sizeof(*rmp));
5432 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
5433 rmp->psid = htons(i);
5434 memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
5435 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5440 vl_api_map_summary_stats_t_handler (
5441 vl_api_map_summary_stats_t *mp)
5443 vl_api_map_summary_stats_reply_t *rmp;
5444 vlib_combined_counter_main_t *cm;
5447 u64 total_pkts[VLIB_N_RX_TX];
5448 u64 total_bytes[VLIB_N_RX_TX];
5449 map_main_t *mm = &map_main;
5450 unix_shared_memory_queue_t *q =
5451 vl_api_client_index_to_input_queue(mp->client_index);
5456 rmp = vl_msg_api_alloc (sizeof (*rmp));
5457 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
5458 rmp->context = mp->context;
5461 memset (total_pkts, 0, sizeof (total_pkts));
5462 memset (total_bytes, 0, sizeof (total_bytes));
5464 map_domain_counter_lock (mm);
5465 vec_foreach(cm, mm->domain_counters) {
5466 which = cm - mm->domain_counters;
5468 for (i = 0; i < vec_len(cm->maxi); i++) {
5469 vlib_get_combined_counter (cm, i, &v);
5470 total_pkts[which] += v.packets;
5471 total_bytes[which] += v.bytes;
5475 map_domain_counter_unlock (mm);
5477 /* Note: in HOST byte order! */
5478 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = total_pkts[MAP_DOMAIN_COUNTER_RX];
5479 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = total_bytes[MAP_DOMAIN_COUNTER_RX];
5480 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = total_pkts[MAP_DOMAIN_COUNTER_TX];
5481 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = total_bytes[MAP_DOMAIN_COUNTER_TX];
5482 rmp->total_bindings = pool_elts(mm->domains);
5483 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
5484 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK);
5485 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK);
5487 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5490 static void vl_api_ipsec_sa_set_key_t_handler
5491 (vl_api_ipsec_sa_set_key_t * mp)
5493 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5494 vl_api_ipsec_sa_set_key_reply_t *rmp;
5498 sa.id = ntohl(mp->sa_id);
5499 sa.crypto_key_len = mp->crypto_key_length;
5500 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5501 sa.integ_key_len = mp->integrity_key_length;
5502 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5504 rv = ipsec_set_sa_key(vm, &sa);
5506 rv = VNET_API_ERROR_UNIMPLEMENTED;
5509 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
5512 static void vl_api_cop_interface_enable_disable_t_handler
5513 (vl_api_cop_interface_enable_disable_t * mp)
5515 vl_api_cop_interface_enable_disable_reply_t * rmp;
5517 u32 sw_if_index = ntohl(mp->sw_if_index);
5520 VALIDATE_SW_IF_INDEX(mp);
5522 enable_disable = (int) mp->enable_disable;
5524 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5526 BAD_SW_IF_INDEX_LABEL;
5528 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5531 static void vl_api_cop_whitelist_enable_disable_t_handler
5532 (vl_api_cop_whitelist_enable_disable_t * mp)
5534 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
5535 cop_whitelist_enable_disable_args_t _a, *a=&_a;
5536 u32 sw_if_index = ntohl(mp->sw_if_index);
5539 VALIDATE_SW_IF_INDEX(mp);
5541 a->sw_if_index = sw_if_index;
5544 a->default_cop = mp->default_cop;
5545 a->fib_id = ntohl(mp->fib_id);
5547 rv = cop_whitelist_enable_disable (a);
5549 BAD_SW_IF_INDEX_LABEL;
5551 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5554 static void vl_api_get_node_graph_t_handler
5555 (vl_api_get_node_graph_t * mp)
5559 api_main_t * am = &api_main;
5560 vlib_main_t * vm = vlib_get_main();
5562 vl_api_get_node_graph_reply_t * rmp;
5564 pthread_mutex_lock (&am->vlib_rp->mutex);
5565 oldheap = svm_push_data_heap (am->vlib_rp);
5568 * Keep the number of memcpy ops to a minimum (e.g. 1).
5569 * The current size of the serialized vector is
5570 * slightly under 4K.
5572 vec_validate (vector, 4095);
5573 vec_reset_length (vector);
5575 vector = vlib_node_serialize (&vm->node_main, vector);
5577 svm_pop_heap (oldheap);
5578 pthread_mutex_unlock (&am->vlib_rp->mutex);
5580 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5581 rmp->reply_in_shmem = (uword) vector);
5584 static void vl_api_trace_profile_add_t_handler
5585 (vl_api_trace_profile_add_t *mp)
5588 vl_api_trace_profile_add_reply_t * rmp;
5589 clib_error_t *error;
5591 /* Ignoring the profile id as currently a single profile
5593 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5594 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5595 mp->pow_enable, mp->trace_tsp,
5598 clib_error_report(error);
5599 rv = clib_error_get_code(error);
5602 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5605 static void vl_api_trace_profile_apply_t_handler
5606 (vl_api_trace_profile_apply_t *mp)
5609 vl_api_trace_profile_apply_reply_t * rmp;
5611 if (mp->enable != 0) {
5612 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5613 ntohl(mp->prefix_length),
5615 mp->trace_op == IOAM_HBYH_ADD,
5616 mp->trace_op == IOAM_HBYH_POP,
5617 mp->trace_op == IOAM_HBYH_MOD);
5619 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5621 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5624 static void vl_api_trace_profile_del_t_handler
5625 (vl_api_trace_profile_del_t *mp)
5628 vl_api_trace_profile_del_reply_t * rmp;
5629 clib_error_t *error;
5631 error = clear_ioam_rewrite_fn();
5633 clib_error_report(error);
5634 rv = clib_error_get_code(error);
5637 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5641 #define BOUNCE_HANDLER(nn) \
5642 static void vl_api_##nn##_t_handler ( \
5643 vl_api_##nn##_t *mp) \
5645 vpe_client_registration_t *reg; \
5646 vpe_api_main_t * vam = &vpe_api_main; \
5647 unix_shared_memory_queue_t * q; \
5649 /* One registration only... */ \
5650 pool_foreach(reg, vam->nn##_registrations, \
5652 q = vl_api_client_index_to_input_queue (reg->client_index); \
5655 * If the queue is stuffed, turf the msg and complain \
5656 * It's unlikely that the intended recipient is \
5657 * alive; avoid deadlock at all costs. \
5659 if (q->cursize == q->maxsize) { \
5660 clib_warning ("ERROR: receiver queue full, drop msg"); \
5661 vl_msg_api_free (mp); \
5664 vl_msg_api_send_shmem (q, (u8 *)&mp); \
5668 vl_msg_api_free (mp); \
5671 BOUNCE_HANDLER(to_netconf_server);
5672 BOUNCE_HANDLER(from_netconf_server);
5673 BOUNCE_HANDLER(to_netconf_client);
5674 BOUNCE_HANDLER(from_netconf_client);
5678 * Add vpe's API message handlers to the table.
5679 * vlib has alread mapped shared memory and
5680 * added the client registration handlers.
5681 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
5684 static clib_error_t *
5685 vpe_api_hookup (vlib_main_t *vm)
5687 api_main_t * am = &api_main;
5690 vl_msg_api_set_handlers(VL_API_##N, #n, \
5691 vl_api_##n##_t_handler, \
5693 vl_api_##n##_t_endian, \
5694 vl_api_##n##_t_print, \
5695 sizeof(vl_api_##n##_t), 1);
5696 foreach_vpe_api_msg;
5700 * Manually register the sr tunnel add del msg, so we trace
5701 * enough bytes to capture a typical segment list
5703 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
5704 "sr_tunnel_add_del",
5705 vl_api_sr_tunnel_add_del_t_handler,
5707 vl_api_sr_tunnel_add_del_t_endian,
5708 vl_api_sr_tunnel_add_del_t_print,
5711 am->message_bounce [VL_API_FROM_NETCONF_SERVER] = 1;
5712 am->message_bounce [VL_API_TO_NETCONF_SERVER] = 1;
5713 am->message_bounce [VL_API_FROM_NETCONF_CLIENT] = 1;
5714 am->message_bounce [VL_API_TO_NETCONF_CLIENT] = 1;
5717 * Trace space for 8 MPLS encap labels, classifier mask+match
5719 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
5720 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
5721 += 5 * sizeof (u32x4);
5722 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
5723 += 5 * sizeof (u32x4);
5724 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
5725 += 16 * sizeof (u32);
5728 * trace space for 4 nsh-gre variable TLV words
5730 am->api_trace_cfg [VL_API_NSH_GRE_ADD_DEL_TUNNEL].size
5731 += 4 * sizeof (u32);
5734 * Thread-safe API messages
5736 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
5741 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
5743 static clib_error_t *
5744 vpe_api_init (vlib_main_t *vm)
5746 vpe_api_main_t *am = &vpe_api_main;
5749 am->vnet_main = vnet_get_main();
5750 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
5751 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5752 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5753 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5754 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5755 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
5758 vl_set_memory_region_name ("/vpe-api");
5759 vl_enable_disable_memory_api (vm, 1 /* enable it */);
5764 VLIB_INIT_FUNCTION(vpe_api_init);
5766 static clib_error_t *
5767 chroot_config (vlib_main_t * vm, unformat_input_t * input)
5771 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5773 if (unformat (input, "prefix %s", &chroot_path))
5775 vec_add1 (chroot_path, 0);
5776 vl_set_memory_root_path ((char *)chroot_path);
5779 return clib_error_return (0, "unknown input `%U'",
5780 format_unformat_error, input);
5784 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
5786 void * get_unformat_vnet_sw_interface (void)
5788 return (void *) &unformat_vnet_sw_interface;
5791 #undef vl_api_version
5792 #define vl_api_version(n,v) static u32 vpe_api_version = v;
5793 #include <api/vpe.api.h>
5794 #undef vl_api_version
5796 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
5798 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
5799 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
5800 clib_host_to_net_u32 (mp->api_versions[0]),
5807 static u8 * format_arp_event (u8 * s, va_list * args)
5809 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
5811 s = format (s, "pid %d: %U", event->pid,
5812 format_ip4_address, &event->address);
5816 static clib_error_t *
5817 show_ip4_arp_events_fn (vlib_main_t * vm,
5818 unformat_input_t * input,
5819 vlib_cli_command_t * cmd)
5821 vpe_api_main_t * am = &vpe_api_main;
5822 vl_api_ip4_arp_event_t * event;
5824 if (pool_elts (am->arp_events) == 0) {
5825 vlib_cli_output (vm, "No active arp event registrations");
5829 pool_foreach (event, am->arp_events,
5831 vlib_cli_output (vm, "%U", format_arp_event, event);
5837 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
5838 .path = "show arp event registrations",
5839 .function = show_ip4_arp_events_fn,
5840 .short_help = "Show arp event registrations",