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/api_errno.h> // alagalah TODO : committers please pay note, is this ok?
46 #include <vnet/vnet.h>
47 #include <vnet/l2/l2_input.h>
48 #include <vnet/l2/l2_bd.h>
49 #include <vnet/l2tp/l2tp.h>
50 #include <vnet/ip/ip.h>
51 #include <vnet/unix/tuntap.h>
52 #include <vnet/unix/tapcli.h>
53 #include <vnet/mpls-gre/mpls.h>
54 #include <vnet/dhcp/proxy.h>
55 #include <vnet/dhcp/client.h>
57 #include <vnet/sr/sr.h>
59 #include <vnet/dhcpv6/proxy.h>
60 #include <vlib/vlib.h>
61 #include <vlib/unix/unix.h>
62 #include <vlibapi/api.h>
63 #include <vlibmemory/api.h>
64 #include <vnet/classify/vnet_classify.h>
65 #include <vnet/classify/input_acl.h>
66 #include <vnet/l2/l2_classify.h>
67 #include <vnet/vxlan/vxlan.h>
68 #include <vnet/gre/gre.h>
69 #include <vnet/l2/l2_vtr.h>
70 #include <vnet/nsh-gre/nsh_gre.h>
71 #include <vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.h>
72 #include <vnet/lisp-gpe/lisp_gpe.h>
73 #include <vnet/lisp-cp/control.h>
74 #include <vnet/map/map.h>
75 #include <vnet/cop/cop.h>
76 #include <vnet/ip/ip6_hop_by_hop.h>
77 #include <vnet/devices/af_packet/af_packet.h>
80 #undef __included_bihash_template_h__
81 #include <vnet/l2/l2_fib.h>
84 #include <vnet/ipsec/ipsec.h>
85 #include <vnet/ipsec/ikev2.h>
88 #include <vnet/devices/virtio/vhost-user.h>
91 #include <stats/stats.h>
94 #include <vnet/ethernet/ethernet.h>
95 #include <vnet/ethernet/arp_packet.h>
96 #include <vnet/interface.h>
98 #include <vnet/l2/l2_fib.h>
99 #include <vnet/l2/l2_bd.h>
100 #include <api/vpe_msg_enum.h>
102 #define f64_endian(a)
103 #define f64_print(a,b)
105 #define vl_typedefs /* define message structures */
106 #include <api/vpe_all_api_h.h>
109 #define vl_endianfun /* define message structures */
110 #include <api/vpe_all_api_h.h>
113 /* instantiate all the print functions we know about */
114 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
116 #include <api/vpe_all_api_h.h>
119 #define REPLY_MACRO(t) \
121 unix_shared_memory_queue_t * q; \
122 rv = vl_msg_api_pd_handler (mp, rv); \
123 q = vl_api_client_index_to_input_queue (mp->client_index); \
127 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
128 rmp->_vl_msg_id = ntohs((t)); \
129 rmp->context = mp->context; \
130 rmp->retval = ntohl(rv); \
132 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
135 #define REPLY_MACRO2(t, body) \
137 unix_shared_memory_queue_t * q; \
138 rv = vl_msg_api_pd_handler (mp, rv); \
139 q = vl_api_client_index_to_input_queue (mp->client_index); \
143 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
144 rmp->_vl_msg_id = ntohs((t)); \
145 rmp->context = mp->context; \
146 rmp->retval = ntohl(rv); \
147 do {body;} while (0); \
148 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
151 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
153 #define VALIDATE_SW_IF_INDEX(mp) \
154 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
155 vnet_main_t *__vnm = vnet_get_main(); \
156 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
158 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
159 goto bad_sw_if_index; \
163 #define BAD_SW_IF_INDEX_LABEL \
169 #define VALIDATE_RX_SW_IF_INDEX(mp) \
170 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
171 vnet_main_t *__vnm = vnet_get_main(); \
172 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
173 __rx_sw_if_index)) { \
174 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
175 goto bad_rx_sw_if_index; \
179 #define BAD_RX_SW_IF_INDEX_LABEL \
181 bad_rx_sw_if_index: \
185 #define VALIDATE_TX_SW_IF_INDEX(mp) \
186 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
187 vnet_main_t *__vnm = vnet_get_main(); \
188 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
189 __tx_sw_if_index)) { \
190 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
191 goto bad_tx_sw_if_index; \
195 #define BAD_TX_SW_IF_INDEX_LABEL \
197 bad_tx_sw_if_index: \
203 #define VALIDATE_SW_IF_INDEX(mp)
204 #define BAD_SW_IF_INDEX_LABEL
205 #define VALIDATE_RX_SW_IF_INDEX(mp)
206 #define BAD_RX_SW_IF_INDEX_LABEL
207 #define VALIDATE_TX_SW_IF_INDEX(mp)
208 #define BAD_TX_SW_IF_INDEX_LABEL
210 #endif /* CLIB_DEBUG > 0 */
212 #define foreach_vpe_api_msg \
213 _(WANT_INTERFACE_EVENTS, want_interface_events) \
214 _(WANT_OAM_EVENTS, want_oam_events) \
215 _(OAM_ADD_DEL, oam_add_del) \
216 _(SW_INTERFACE_DUMP, sw_interface_dump) \
217 _(SW_INTERFACE_DETAILS, sw_interface_details) \
218 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
219 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
220 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
221 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
222 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
223 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
224 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
225 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
226 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
227 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
228 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
229 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
230 _(L2FIB_ADD_DEL, l2fib_add_del) \
231 _(L2_FLAGS, l2_flags) \
232 _(BRIDGE_FLAGS, bridge_flags) \
233 _(TAP_CONNECT, tap_connect) \
234 _(TAP_MODIFY, tap_modify) \
235 _(TAP_DELETE, tap_delete) \
236 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
237 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
238 _(CREATE_SUBIF, create_subif) \
239 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
240 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
241 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
242 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
243 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
244 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
245 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
246 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
247 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
248 _(RESET_FIB, reset_fib) \
249 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
250 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
251 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
252 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
253 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
254 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
255 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
256 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
257 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
258 sw_interface_ip6_set_link_local_address) \
259 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
260 _(CREATE_LOOPBACK, create_loopback) \
261 _(CONTROL_PING, control_ping) \
262 _(CLI_REQUEST, cli_request) \
263 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
264 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
265 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
266 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
267 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
268 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
269 _(GET_NODE_INDEX, get_node_index) \
270 _(ADD_NODE_NEXT, add_node_next) \
271 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
272 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
273 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
274 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
275 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
276 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
277 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
278 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
279 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
280 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
281 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
282 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
283 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
284 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
285 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
286 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
287 _(IP_ADDRESS_DUMP, ip_address_dump) \
288 _(IP_DUMP, ip_dump) \
289 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
290 _(SHOW_VERSION, show_version) \
291 _(NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel) \
292 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
293 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
294 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel) \
295 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
296 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
297 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
298 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
299 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
300 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
301 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
302 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
303 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
304 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
305 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
306 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
307 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
308 _(DELETE_LOOPBACK, delete_loopback) \
309 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
310 _(MAP_ADD_DOMAIN, map_add_domain) \
311 _(MAP_DEL_DOMAIN, map_del_domain) \
312 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
313 _(MAP_DOMAIN_DUMP, map_domain_dump) \
314 _(MAP_RULE_DUMP, map_rule_dump) \
315 _(MAP_SUMMARY_STATS, map_summary_stats) \
316 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
317 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
318 _(GET_NODE_GRAPH, get_node_graph) \
319 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
320 _(TRACE_PROFILE_ADD, trace_profile_add) \
321 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
322 _(TRACE_PROFILE_DEL, trace_profile_del) \
323 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
324 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
325 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
326 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
327 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
328 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
329 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
330 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
331 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
332 _(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump) \
333 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
334 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
335 _(LISP_ENABLE_DISABLE_STATUS_DUMP, \
336 lisp_enable_disable_status_dump) \
337 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
338 _(AF_PACKET_CREATE, af_packet_create) \
339 _(AF_PACKET_DELETE, af_packet_delete)
342 #define QUOTE(x) QUOTE_(x)
344 #define foreach_registration_hash \
345 _(interface_events) \
346 _(to_netconf_server) \
347 _(from_netconf_server) \
348 _(to_netconf_client) \
349 _(from_netconf_client) \
353 RESOLVE_IP4_ADD_DEL_ROUTE=1,
354 RESOLVE_IP6_ADD_DEL_ROUTE,
355 RESOLVE_MPLS_ETHERNET_ADD_DEL,
361 vl_api_ip_add_del_route_t r;
362 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
368 #define _(a) uword *a##_registration_hash; \
369 vpe_client_registration_t * a##_registrations;
370 foreach_registration_hash
373 /* notifications happen really early in the game */
374 u8 link_state_process_up;
376 /* ip4 pending route adds */
377 pending_route_t * pending_routes;
379 /* ip4 arp event registration pool */
380 vl_api_ip4_arp_event_t * arp_events;
383 vlib_main_t * vlib_main;
384 vnet_main_t * vnet_main;
387 static vlib_node_registration_t vpe_resolver_process_node;
388 static vpe_api_main_t vpe_api_main;
390 static void send_sw_interface_flags (vpe_api_main_t * am,
391 unix_shared_memory_queue_t *q,
392 vnet_sw_interface_t * swif);
393 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
394 unix_shared_memory_queue_t *q,
397 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
400 /* Clean up all registrations belonging to the indicated client */
401 int vl_api_memclnt_delete_callback (u32 client_index)
403 vpe_api_main_t * vam = &vpe_api_main;
404 vpe_client_registration_t *rp;
406 int stats_memclnt_delete_callback (u32 client_index);
408 stats_memclnt_delete_callback (client_index);
411 p = hash_get (vam->a##_registration_hash, client_index); \
413 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
414 pool_put (vam->a##_registrations, rp); \
415 hash_unset (vam->a##_registration_hash, client_index); \
417 foreach_registration_hash;
422 #define API_LINK_STATE_EVENT 1
423 #define API_ADMIN_UP_DOWN_EVENT 2
426 event_data_cmp (void * a1, void * a2)
431 return (word) e1[0] - (word) e2[0];
435 link_state_process (vlib_main_t * vm,
436 vlib_node_runtime_t * rt,
439 vpe_api_main_t * vam = &vpe_api_main;
440 vnet_main_t * vnm = vam->vnet_main;
441 vnet_sw_interface_t * swif;
442 uword * event_data = 0;
443 vpe_client_registration_t *reg;
445 u32 prev_sw_if_index;
446 unix_shared_memory_queue_t * q;
448 vam->link_state_process_up = 1;
451 vlib_process_wait_for_event (vm);
453 /* Unified list of changed link or admin state sw_if_indices */
454 vlib_process_get_events_with_type
455 (vm, &event_data, API_LINK_STATE_EVENT);
456 vlib_process_get_events_with_type
457 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
459 /* Sort, so we can eliminate duplicates */
460 vec_sort_with_function (event_data, event_data_cmp);
462 prev_sw_if_index = ~0;
464 for (i = 0; i < vec_len(event_data); i++) {
465 /* Only one message per swif */
466 if (prev_sw_if_index == event_data[i])
468 prev_sw_if_index = event_data[i];
470 pool_foreach(reg, vam->interface_events_registrations,
472 q = vl_api_client_index_to_input_queue (reg->client_index);
474 // sw_interface may be deleted already
475 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
478 swif = vnet_get_sw_interface (vnm, event_data[i]);
479 send_sw_interface_flags (vam, q, swif);
484 vec_reset_length (event_data);
490 static clib_error_t *
491 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
492 static clib_error_t *
493 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
495 VLIB_REGISTER_NODE (link_state_process_node,static) = {
496 .function = link_state_process,
497 .type = VLIB_NODE_TYPE_PROCESS,
498 .name = "vpe-link-state-process",
501 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
502 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
504 static clib_error_t *
505 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
507 vpe_api_main_t * vam = &vpe_api_main;
508 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
510 if (vam->link_state_process_up)
511 vlib_process_signal_event (vam->vlib_main,
512 link_state_process_node.index,
513 API_LINK_STATE_EVENT,
518 static clib_error_t *
519 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
521 vpe_api_main_t * vam = &vpe_api_main;
524 * Note: it's perfectly fair to set a subif admin up / admin down.
525 * Note the subtle distinction between this routine and the previous
528 if (vam->link_state_process_up)
529 vlib_process_signal_event (vam->vlib_main,
530 link_state_process_node.index,
531 API_ADMIN_UP_DOWN_EVENT,
536 #define pub_sub_handler(lca,UCA) \
537 static void vl_api_want_##lca##_t_handler ( \
538 vl_api_want_##lca##_t *mp) \
540 vpe_api_main_t *vam = &vpe_api_main; \
541 vpe_client_registration_t *rp; \
542 vl_api_want_##lca##_reply_t *rmp; \
546 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
548 if (mp->enable_disable) { \
549 clib_warning ("pid %d: already enabled...", mp->pid); \
550 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
553 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
554 pool_put (vam->lca##_registrations, rp); \
555 hash_unset (vam->lca##_registration_hash, \
560 if (mp->enable_disable == 0) { \
561 clib_warning ("pid %d: already disabled...", mp->pid); \
562 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
565 pool_get (vam->lca##_registrations, rp); \
566 rp->client_index = mp->client_index; \
567 rp->client_pid = mp->pid; \
568 hash_set (vam->lca##_registration_hash, rp->client_index, \
569 rp - vam->lca##_registrations); \
572 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
575 pub_sub_handler (interface_events,INTERFACE_EVENTS)
576 pub_sub_handler (oam_events,OAM_EVENTS)
578 #define RESOLUTION_EVENT 1
579 #define RESOLUTION_PENDING_EVENT 2
580 #define IP4_ARP_EVENT 3
582 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
583 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
584 static int mpls_ethernet_add_del_tunnel_2_t_handler
585 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
587 void handle_ip4_arp_event (u32 pool_index)
589 vpe_api_main_t * vam = &vpe_api_main;
590 vnet_main_t * vnm = vam->vnet_main;
591 vlib_main_t * vm = vam->vlib_main;
592 vl_api_ip4_arp_event_t * event;
593 vl_api_ip4_arp_event_t * mp;
594 unix_shared_memory_queue_t * q;
596 /* Client can cancel, die, etc. */
597 if (pool_is_free_index (vam->arp_events, pool_index))
600 event = pool_elt_at_index (vam->arp_events, pool_index);
602 q = vl_api_client_index_to_input_queue (event->client_index);
604 (void) vnet_add_del_ip4_arp_change_event
605 (vnm, arp_change_delete_callback,
606 event->pid, &event->address,
607 vpe_resolver_process_node.index, IP4_ARP_EVENT,
608 ~0 /* pool index, notused */, 0 /* is_add */);
612 if (q->cursize < q->maxsize) {
613 mp = vl_msg_api_alloc (sizeof (*mp));
614 clib_memcpy (mp, event, sizeof (*mp));
615 vl_msg_api_send_shmem (q, (u8 *)&mp);
617 static f64 last_time;
619 * Throttle syslog msgs.
620 * It's pretty tempting to just revoke the registration...
622 if (vlib_time_now (vm) > last_time + 10.0) {
623 clib_warning ("arp event for %U to pid %d: queue stuffed!",
624 format_ip4_address, &event->address, event->pid);
625 last_time = vlib_time_now(vm);
631 resolver_process (vlib_main_t * vm,
632 vlib_node_runtime_t * rt,
636 uword *event_data = 0;
638 vpe_api_main_t * vam = &vpe_api_main;
639 pending_route_t * pr;
640 vl_api_ip_add_del_route_t * adr;
641 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
642 u32 * resolution_failures = 0;
647 vlib_process_wait_for_event_or_clock (vm, timeout);
649 event_type = vlib_process_get_events (vm, &event_data);
651 switch (event_type) {
652 case RESOLUTION_PENDING_EVENT:
656 case RESOLUTION_EVENT:
657 for (i = 0; i < vec_len(event_data); i++) {
659 * Resolution events can occur long after the
660 * original request has timed out. $$$ add a cancel
663 if (pool_is_free_index (vam->pending_routes, event_data[i]))
666 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
670 switch (pr->resolve_type) {
671 case RESOLVE_IP4_ADD_DEL_ROUTE:
672 rv = ip4_add_del_route_t_handler (adr);
673 clib_warning ("resolver: add %U/%d via %U %s",
675 (ip4_address_t *)&(adr->dst_address),
676 adr->dst_address_length,
678 (ip4_address_t *)&(adr->next_hop_address),
679 (rv >= 0) ? "succeeded" : "failed");
682 case RESOLVE_IP6_ADD_DEL_ROUTE:
683 rv = ip6_add_del_route_t_handler (adr);
684 clib_warning ("resolver: add %U/%d via %U %s",
686 (ip6_address_t *)&(adr->dst_address),
687 adr->dst_address_length,
689 (ip6_address_t *)&(adr->next_hop_address),
690 (rv >= 0) ? "succeeded" : "failed");
693 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
694 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
695 clib_warning ("resolver: add mpls-o-e via %U %s",
697 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
698 (rv >= 0) ? "succeeded" : "failed");
702 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
704 pool_put (vam->pending_routes, pr);
709 for (i = 0; i < vec_len(event_data); i++)
710 handle_ip4_arp_event (event_data[i]);
713 case ~0: /* timeout, retry pending resolutions */
714 pool_foreach (pr, vam->pending_routes,
720 /* May fail, e.g. due to interface down */
721 switch (pr->resolve_type) {
722 case RESOLVE_IP4_ADD_DEL_ROUTE:
723 e = ip4_probe_neighbor
724 (vm, (ip4_address_t *)&(adr->next_hop_address),
725 ntohl(adr->next_hop_sw_if_index));
728 case RESOLVE_IP6_ADD_DEL_ROUTE:
729 e = ip6_probe_neighbor
730 (vm, (ip6_address_t *)&(adr->next_hop_address),
731 ntohl(adr->next_hop_sw_if_index));
734 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
736 e = ip4_probe_neighbor
738 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
739 pme->resolve_opaque);
743 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
747 clib_error_report (e);
749 adr->resolve_attempts = 1;
751 pme->resolve_attempts = 1;
755 adr->resolve_attempts -= 1;
756 if (adr->resolve_attempts == 0)
757 vec_add1 (resolution_failures,
758 pr - vam->pending_routes);
760 pme->resolve_attempts -= 1;
761 if (pme->resolve_attempts == 0)
762 vec_add1 (resolution_failures,
763 pr - vam->pending_routes);
767 for (i = 0; i < vec_len (resolution_failures); i++) {
768 pr = pool_elt_at_index (vam->pending_routes,
769 resolution_failures[i]);
773 switch (pr->resolve_type) {
774 case RESOLVE_IP4_ADD_DEL_ROUTE:
775 clib_warning ("resolver: add %U/%d via %U retry failure",
777 (ip4_address_t *)&(adr->dst_address),
778 adr->dst_address_length,
780 (ip4_address_t *)&(adr->next_hop_address));
783 case RESOLVE_IP6_ADD_DEL_ROUTE:
784 clib_warning ("resolver: add %U/%d via %U retry failure",
786 (ip6_address_t *)&(adr->dst_address),
787 adr->dst_address_length,
789 (ip6_address_t *)&(adr->next_hop_address));
792 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
793 clib_warning ("resolver: add mpls-o-e via %U retry failure",
795 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
799 clib_warning ("BUG");
801 pool_put(vam->pending_routes, pr);
803 vec_reset_length (resolution_failures);
806 if (pool_elts (vam->pending_routes) == 0)
808 vec_reset_length (event_data);
810 return 0; /* or not */
813 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
814 .function = resolver_process,
815 .type = VLIB_NODE_TYPE_PROCESS,
816 .name = "vpe-route-resolver-process",
819 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
821 ip4_main_t * im = &ip4_main;
822 ip_lookup_main_t * lm = &im->lookup_main;
823 vnet_classify_main_t * cm = &vnet_classify_main;
824 stats_main_t * sm = &stats_main;
825 ip4_add_del_route_args_t a;
826 ip4_address_t next_hop_address;
828 vpe_api_main_t * vam = &vpe_api_main;
829 vnet_main_t * vnm = vam->vnet_main;
830 vlib_main_t * vm = vlib_get_main();
831 pending_route_t * pr;
832 vl_api_ip_add_del_route_t * adr;
836 ip_adjacency_t *nh_adj, *add_adj = 0;
838 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
840 if (mp->create_vrf_if_needed) {
842 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
844 fib_index = f->index;
846 /* No such VRF, and we weren't asked to create one */
847 return VNET_API_ERROR_NO_SUCH_FIB;
853 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
854 ntohl(mp->next_hop_sw_if_index)))
855 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
857 clib_memcpy (next_hop_address.data, mp->next_hop_address,
858 sizeof (next_hop_address.data));
860 /* Arp for the next_hop if necessary */
861 if (mp->is_add && mp->resolve_if_needed) {
863 ip_adjacency_t * adj;
865 lookup_result = ip4_fib_lookup_with_table
866 (im, fib_index, &next_hop_address, 1 /* disable default route */);
868 adj = ip_get_adjacency (lm, lookup_result);
870 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
871 pool_get (vam->pending_routes, pr);
872 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
874 clib_memcpy (adr, mp, sizeof (*adr));
875 /* recursion block, "just in case" */
876 adr->resolve_if_needed = 0;
877 adr->resolve_attempts = ntohl(mp->resolve_attempts);
878 vnet_register_ip4_arp_resolution_event
879 (vnm, &next_hop_address, vpe_resolver_process_node.index,
880 RESOLUTION_EVENT, pr - vam->pending_routes);
882 vlib_process_signal_event
883 (vm, vpe_resolver_process_node.index,
884 RESOLUTION_PENDING_EVENT, 0 /* data */);
886 /* The interface may be down, etc. */
887 e = ip4_probe_neighbor
888 (vm, (ip4_address_t *)&(mp->next_hop_address),
889 ntohl(mp->next_hop_sw_if_index));
892 clib_error_report(e);
894 return VNET_API_ERROR_IN_PROGRESS;
898 if (mp->is_multipath) {
901 dslock (sm, 1 /* release hint */, 10 /* tag */);
904 flags = IP4_ROUTE_FLAG_ADD;
906 flags = IP4_ROUTE_FLAG_DEL;
909 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
911 ip4_add_del_route_next_hop (im, flags,
912 (ip4_address_t *) mp->dst_address,
913 (u32) mp->dst_address_length,
914 (ip4_address_t *) mp->next_hop_address,
915 ntohl(mp->next_hop_sw_if_index),
916 (u32) mp->next_hop_weight,
923 memset (&a, 0, sizeof (a));
924 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
926 a.dst_address_length = mp->dst_address_length;
928 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
929 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
930 a.table_index_or_table_id = fib_index;
935 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
937 dslock (sm, 1 /* release hint */, 2 /* tag */);
941 ai = lm->drop_adj_index;
942 else if (mp->is_local)
943 ai = lm->local_adj_index;
944 else if (mp->is_classify) {
946 memset(&cadj, 0, sizeof(cadj));
947 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
948 cadj.classify.table_index = ntohl(mp->classify_table_index);
949 if (pool_is_free_index (cm->tables, cadj.classify.table_index)) {
951 return VNET_API_ERROR_NO_SUCH_TABLE;
953 vec_add1 (add_adj, cadj);
957 ai = ip4_fib_lookup_with_table
958 (im, fib_index, &next_hop_address,
959 1 /* disable default route */);
960 if (ai == lm->miss_adj_index) {
962 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
966 nh_adj = ip_get_adjacency (lm, ai);
967 vec_add1 (add_adj, nh_adj[0]);
968 if (mp->lookup_in_vrf) {
969 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
971 add_adj[0].explicit_fib_index = p[0];
975 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
979 ip_adjacency_t * adj;
980 int disable_default_route = 1;
982 /* Trying to delete the default route? */
983 if (a.dst_address.as_u32 == 0 &&
984 a.dst_address_length == 0)
985 disable_default_route = 0;
987 ai = ip4_fib_lookup_with_table
988 (im, fib_index, &a.dst_address, disable_default_route);
989 if (ai == lm->miss_adj_index) {
991 return VNET_API_ERROR_UNKNOWN_DESTINATION;
994 adj = ip_get_adjacency (lm, ai);
995 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
997 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1003 a.add_adj = add_adj;
1004 a.n_add_adj = vec_len(add_adj);
1005 ip4_add_del_route (im, &a);
1013 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1015 ip6_main_t * im = &ip6_main;
1016 ip_lookup_main_t * lm = &im->lookup_main;
1017 vnet_main_t * vnm = vnet_get_main();
1018 vlib_main_t * vm = vlib_get_main();
1019 vpe_api_main_t * vam = &vpe_api_main;
1020 stats_main_t * sm = &stats_main;
1021 ip6_add_del_route_args_t a;
1022 ip6_address_t next_hop_address;
1023 pending_route_t * pr;
1024 vl_api_ip_add_del_route_t * adr;
1029 ip_adjacency_t * nh_adj, * add_adj = 0;
1032 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1035 if (mp->create_vrf_if_needed) {
1037 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1039 fib_index = f->index;
1041 /* No such VRF, and we weren't asked to create one */
1042 return VNET_API_ERROR_NO_SUCH_FIB;
1048 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1049 ntohl(mp->next_hop_sw_if_index)))
1050 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1052 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1053 sizeof (next_hop_address.as_u8));
1055 /* Arp for the next_hop if necessary */
1056 if (mp->is_add && mp->resolve_if_needed) {
1058 ip_adjacency_t * adj;
1060 lookup_result = ip6_fib_lookup_with_table
1061 (im, fib_index, &next_hop_address);
1063 adj = ip_get_adjacency (lm, lookup_result);
1065 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1066 pool_get (vam->pending_routes, pr);
1068 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1069 clib_memcpy (adr, mp, sizeof (*adr));
1070 /* recursion block, "just in case" */
1071 adr->resolve_if_needed = 0;
1072 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1073 vnet_register_ip6_neighbor_resolution_event
1074 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1075 RESOLUTION_EVENT, pr - vam->pending_routes);
1077 vlib_process_signal_event
1078 (vm, vpe_resolver_process_node.index,
1079 RESOLUTION_PENDING_EVENT, 0 /* data */);
1081 /* The interface may be down, etc. */
1082 e = ip6_probe_neighbor
1083 (vm, (ip6_address_t *)&(mp->next_hop_address),
1084 ntohl(mp->next_hop_sw_if_index));
1087 clib_error_report(e);
1089 return VNET_API_ERROR_IN_PROGRESS;
1093 if (mp->is_multipath) {
1096 dslock (sm, 1 /* release hint */, 11 /* tag */);
1099 flags = IP6_ROUTE_FLAG_ADD;
1101 flags = IP6_ROUTE_FLAG_DEL;
1104 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1106 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1107 (u32) mp->dst_address_length,
1108 (ip6_address_t *)mp->next_hop_address,
1109 ntohl(mp->next_hop_sw_if_index),
1110 (u32) mp->next_hop_weight,
1117 memset (&a, 0, sizeof (a));
1118 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1120 a.dst_address_length = mp->dst_address_length;
1122 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1123 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1124 a.table_index_or_table_id = fib_index;
1129 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1131 dslock (sm, 1 /* release hint */, 3 /* tag */);
1135 ai = lm->drop_adj_index;
1136 else if (mp->is_local)
1137 ai = lm->local_adj_index;
1139 ai = ip6_fib_lookup_with_table
1140 (im, fib_index, &next_hop_address);
1141 if (ai == lm->miss_adj_index) {
1143 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1147 nh_adj = ip_get_adjacency (lm, ai);
1148 vec_add1 (add_adj, nh_adj[0]);
1149 if (mp->lookup_in_vrf) {
1150 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1152 add_adj[0].explicit_fib_index = p[0];
1156 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1160 ip_adjacency_t * adj;
1162 ai = ip6_fib_lookup_with_table
1163 (im, fib_index, &a.dst_address);
1164 if (ai == lm->miss_adj_index) {
1166 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1168 adj = ip_get_adjacency (lm, ai);
1169 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1171 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1176 a.add_adj = add_adj;
1177 a.n_add_adj = vec_len(add_adj);
1178 ip6_add_del_route (im, &a);
1186 void vl_api_ip_add_del_route_t_handler (
1187 vl_api_ip_add_del_route_t *mp)
1189 vl_api_ip_add_del_route_reply_t * rmp;
1191 vnet_main_t * vnm = vnet_get_main();
1196 rv = ip6_add_del_route_t_handler (mp);
1198 rv = ip4_add_del_route_t_handler (mp);
1200 rv = (rv == 0) ? vnm->api_errno : rv;
1202 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1205 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1206 u32 sw_if_index, u8 *next_hop_addr)
1208 vl_api_ip_add_del_route_t mp;
1211 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1214 * Configure default IP route:
1215 * - ip route add 0.0.0.0/1 via <GW IP>
1216 * - ip route add 128.0.0.0/1 via <GW IP>
1218 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1220 mp.resolve_attempts = ~0;
1221 mp.resolve_if_needed = 1;
1223 mp.is_ipv6 = is_ipv6;
1224 mp.next_hop_weight = 1;
1226 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1229 rv = ip6_add_del_route_t_handler (&mp);
1232 mp.dst_address_length = 1;
1234 mp.dst_address[0] = 0;
1235 rv = ip4_add_del_route_t_handler (&mp);
1237 mp.dst_address[0] = 128;
1238 rv |= ip4_add_del_route_t_handler (&mp);
1242 clib_error_return (0, "failed to config default IP route");
1247 vl_api_sw_interface_add_del_address_t_handler
1248 (vl_api_sw_interface_add_del_address_t *mp)
1250 vlib_main_t *vm = vlib_get_main();
1251 vl_api_sw_interface_add_del_address_reply_t * rmp;
1255 VALIDATE_SW_IF_INDEX(mp);
1257 is_del = mp->is_add == 0;
1260 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1261 else if (mp->is_ipv6)
1262 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1263 (void *)mp->address,
1264 mp->address_length, is_del);
1266 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1267 (void *) mp->address,
1268 mp->address_length, is_del);
1270 BAD_SW_IF_INDEX_LABEL;
1272 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1276 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1279 u32 table_id = ntohl(mp->vrf_id);
1280 u32 sw_if_index = ntohl(mp->sw_if_index);
1281 vl_api_sw_interface_set_table_reply_t * rmp;
1282 stats_main_t * sm = &stats_main;
1284 VALIDATE_SW_IF_INDEX(mp);
1286 dslock (sm, 1 /* release hint */, 4 /* tag */);
1289 ip6_main_t * im = &ip6_main;
1291 find_ip6_fib_by_table_index_or_id (im, table_id,
1292 IP6_ROUTE_FLAG_TABLE_ID);
1294 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1295 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1297 rv = VNET_API_ERROR_NO_SUCH_FIB;
1300 ip4_main_t * im = &ip4_main;
1301 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1302 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1304 /* Truthfully this can't fail */
1306 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1307 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1309 rv = VNET_API_ERROR_NO_SUCH_FIB;
1314 BAD_SW_IF_INDEX_LABEL;
1316 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1320 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1322 vlib_main_t *vm = vlib_get_main();
1323 vl_api_sw_interface_set_vpath_reply_t * rmp;
1326 u32 sw_if_index = ntohl(mp->sw_if_index);
1327 ip4_main_t *ip4m = &ip4_main;
1328 ip6_main_t *ip6m = &ip6_main;
1329 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1330 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1331 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1332 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1333 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1334 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1336 VALIDATE_SW_IF_INDEX(mp);
1338 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1340 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1341 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1342 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1343 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1344 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1345 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1346 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1347 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1348 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1349 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1350 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1351 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1352 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1353 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1354 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1355 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1357 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1358 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1359 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1360 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1361 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1362 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1363 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1364 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1365 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1366 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1367 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1368 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1369 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1370 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1371 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1372 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1375 BAD_SW_IF_INDEX_LABEL;
1377 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1381 vl_api_sw_interface_set_l2_xconnect_t_handler (
1382 vl_api_sw_interface_set_l2_xconnect_t *mp)
1384 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1386 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1387 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1388 vlib_main_t *vm = vlib_get_main();
1389 vnet_main_t *vnm = vnet_get_main();
1391 VALIDATE_RX_SW_IF_INDEX(mp);
1394 VALIDATE_TX_SW_IF_INDEX(mp);
1395 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1396 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1398 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1401 BAD_RX_SW_IF_INDEX_LABEL;
1402 BAD_TX_SW_IF_INDEX_LABEL;
1404 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1408 vl_api_sw_interface_set_l2_bridge_t_handler (
1409 vl_api_sw_interface_set_l2_bridge_t *mp)
1411 bd_main_t * bdm = &bd_main;
1412 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1414 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1415 u32 bd_id = ntohl(mp->bd_id);
1419 vlib_main_t *vm = vlib_get_main();
1420 vnet_main_t *vnm = vnet_get_main();
1422 VALIDATE_RX_SW_IF_INDEX(mp);
1424 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1427 //VALIDATE_TX_SW_IF_INDEX(mp);
1428 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1429 rx_sw_if_index, bd_index, bvi, shg, 0);
1431 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1434 BAD_RX_SW_IF_INDEX_LABEL;
1436 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1440 vl_api_bridge_domain_add_del_t_handler (
1441 vl_api_bridge_domain_add_del_t *mp)
1443 vlib_main_t * vm = vlib_get_main ();
1444 bd_main_t * bdm = &bd_main;
1445 vl_api_bridge_domain_add_del_reply_t * rmp;
1447 u32 enable_flags = 0, disable_flags = 0;
1448 u32 bd_id = ntohl(mp->bd_id);
1452 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1455 enable_flags |= L2_FLOOD;
1457 disable_flags |= L2_FLOOD;
1460 enable_flags |= L2_UU_FLOOD;
1462 disable_flags |= L2_UU_FLOOD;
1465 enable_flags |= L2_FWD;
1467 disable_flags |= L2_FWD;
1470 enable_flags |= L2_ARP_TERM;
1472 disable_flags |= L2_ARP_TERM;
1475 enable_flags |= L2_LEARN;
1477 disable_flags |= L2_LEARN;
1480 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1483 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1486 rv = bd_delete_bd_index(bdm, bd_id);
1488 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1491 static void vl_api_bridge_domain_details_t_handler (
1492 vl_api_bridge_domain_details_t * mp)
1494 clib_warning ("BUG");
1497 static void vl_api_bridge_domain_sw_if_details_t_handler (
1498 vl_api_bridge_domain_sw_if_details_t * mp)
1500 clib_warning ("BUG");
1503 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1504 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);
1521 mp->context = context;
1523 vl_msg_api_send_shmem (q, (u8 *)&mp);
1526 static void send_bd_sw_if_details (l2input_main_t * l2im,
1527 unix_shared_memory_queue_t *q,
1528 l2_flood_member_t * member, u32 bd_id,
1531 vl_api_bridge_domain_sw_if_details_t * mp;
1532 l2_input_config_t * input_cfg;
1534 mp = vl_msg_api_alloc (sizeof (*mp));
1535 memset (mp, 0, sizeof (*mp));
1536 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1537 mp->bd_id = ntohl (bd_id);
1538 mp->sw_if_index = ntohl (member->sw_if_index);
1539 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1540 mp->shg = input_cfg->shg;
1541 mp->context = context;
1543 vl_msg_api_send_shmem (q, (u8 *)&mp);
1546 static void vl_api_bridge_domain_dump_t_handler (
1547 vl_api_bridge_domain_dump_t *mp)
1549 bd_main_t * bdm = &bd_main;
1550 l2input_main_t * l2im = &l2input_main;
1551 unix_shared_memory_queue_t * q;
1552 l2_bridge_domain_t * bd_config;
1553 u32 bd_id, bd_index;
1556 q = vl_api_client_index_to_input_queue (mp->client_index);
1561 bd_id = ntohl(mp->bd_id);
1563 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1564 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1565 for (; bd_index < end; bd_index++) {
1566 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1567 /* skip dummy bd_id 0 */
1568 if (bd_config && (bd_config->bd_id > 0)) {
1570 l2_flood_member_t * m;
1572 n_sw_ifs = vec_len (bd_config->members);
1573 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1575 vec_foreach (m, bd_config->members) {
1576 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1583 vl_api_l2fib_add_del_t_handler (
1584 vl_api_l2fib_add_del_t *mp)
1586 bd_main_t * bdm = &bd_main;
1587 l2input_main_t * l2im = &l2input_main;
1588 vl_api_l2fib_add_del_reply_t * rmp;
1591 u32 sw_if_index = ntohl(mp->sw_if_index);
1592 u32 bd_id = ntohl(mp->bd_id);
1600 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1602 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1603 goto bad_sw_if_index;
1608 VALIDATE_SW_IF_INDEX(mp);
1609 if (vec_len(l2im->configs) <= sw_if_index) {
1610 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1611 goto bad_sw_if_index;
1613 l2_input_config_t * config;
1614 config = vec_elt_at_index(l2im->configs, sw_if_index);
1615 if (config->bridge == 0) {
1616 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1617 goto bad_sw_if_index;
1620 static_mac = mp->static_mac ? 1 : 0;
1621 filter_mac = mp->filter_mac ? 1 : 0;
1622 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1625 l2fib_del_entry(mac, bd_index);
1628 BAD_SW_IF_INDEX_LABEL;
1630 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1634 vl_api_l2_flags_t_handler (
1635 vl_api_l2_flags_t *mp)
1637 vl_api_l2_flags_reply_t * rmp;
1639 u32 sw_if_index = ntohl(mp->sw_if_index);
1640 u32 flags = ntohl(mp->feature_bitmap);
1643 VALIDATE_SW_IF_INDEX(mp);
1646 if (flags & L2INPUT_FEAT_ ## a) \
1647 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1648 foreach_l2input_feat;
1651 BAD_SW_IF_INDEX_LABEL;
1653 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1657 vl_api_bridge_flags_t_handler (
1658 vl_api_bridge_flags_t *mp)
1660 vlib_main_t *vm = vlib_get_main();
1661 bd_main_t * bdm = &bd_main;
1662 vl_api_bridge_flags_reply_t * rmp;
1664 u32 bd_id = ntohl(mp->bd_id);
1666 u32 flags = ntohl(mp->feature_bitmap);
1669 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1671 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1677 bd_set_flags(vm, bd_index, flags, mp->is_set);
1680 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1681 rmp->resulting_feature_bitmap = ntohl(flags));
1685 vl_api_bd_ip_mac_add_del_t_handler (
1686 vl_api_bd_ip_mac_add_del_t *mp)
1688 bd_main_t * bdm = &bd_main;
1689 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1691 u32 bd_id = ntohl(mp->bd_id);
1695 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1697 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1702 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1703 mp->mac_address, mp->is_ipv6, mp->is_add))
1704 rv = VNET_API_ERROR_UNSPECIFIED;
1707 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1711 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1714 vl_api_tap_connect_reply_t * rmp;
1715 unix_shared_memory_queue_t * q;
1716 u32 sw_if_index = (u32)~0;
1718 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1719 mp->use_random_mac ? 0 : mp->mac_address,
1720 &sw_if_index, mp->renumber,
1721 ntohl(mp->custom_dev_instance));
1723 q = vl_api_client_index_to_input_queue (mp->client_index);
1727 rmp = vl_msg_api_alloc (sizeof (*rmp));
1728 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1729 rmp->context = mp->context;
1730 rmp->retval = ntohl(rv);
1731 rmp->sw_if_index = ntohl(sw_if_index);
1733 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1737 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1740 vl_api_tap_modify_reply_t * rmp;
1741 unix_shared_memory_queue_t * q;
1742 u32 sw_if_index = (u32)~0;
1744 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1745 mp->use_random_mac ? 0 : mp->mac_address,
1746 &sw_if_index, mp->renumber,
1747 ntohl(mp->custom_dev_instance));
1749 q = vl_api_client_index_to_input_queue (mp->client_index);
1753 rmp = vl_msg_api_alloc (sizeof (*rmp));
1754 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1755 rmp->context = mp->context;
1756 rmp->retval = ntohl(rv);
1757 rmp->sw_if_index = ntohl(sw_if_index);
1759 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1763 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1766 vpe_api_main_t * vam = &vpe_api_main;
1767 vl_api_tap_delete_reply_t * rmp;
1768 unix_shared_memory_queue_t * q;
1769 u32 sw_if_index = ntohl(mp->sw_if_index);
1771 rv = vnet_tap_delete (vm, sw_if_index);
1773 q = vl_api_client_index_to_input_queue (mp->client_index);
1777 rmp = vl_msg_api_alloc (sizeof (*rmp));
1778 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1779 rmp->context = mp->context;
1780 rmp->retval = ntohl(rv);
1782 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1785 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1789 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1791 vl_api_create_vlan_subif_reply_t * rmp;
1792 vnet_main_t * vnm = vnet_get_main();
1793 u32 hw_if_index, sw_if_index = (u32)~0;
1794 vnet_hw_interface_t * hi;
1797 vnet_sw_interface_t template;
1799 vnet_interface_main_t * im = &vnm->interface_main;
1800 u64 sup_and_sub_key;
1802 unix_shared_memory_queue_t * q;
1803 clib_error_t * error;
1805 VALIDATE_SW_IF_INDEX(mp);
1807 hw_if_index = ntohl(mp->sw_if_index);
1808 hi = vnet_get_hw_interface (vnm, hw_if_index);
1810 id = ntohl(mp->vlan_id);
1811 if (id == 0 || id > 4095) {
1812 rv = VNET_API_ERROR_INVALID_VLAN;
1816 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1818 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1820 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1824 kp = clib_mem_alloc (sizeof (*kp));
1825 *kp = sup_and_sub_key;
1827 memset (&template, 0, sizeof (template));
1828 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1829 template.sup_sw_if_index = hi->sw_if_index;
1830 template.sub.id = id;
1831 template.sub.eth.raw_flags = 0;
1832 template.sub.eth.flags.one_tag = 1;
1833 template.sub.eth.outer_vlan_id = id;
1834 template.sub.eth.flags.exact_match = 1;
1836 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1838 clib_error_report(error);
1839 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1842 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1843 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1845 BAD_SW_IF_INDEX_LABEL;
1848 q = vl_api_client_index_to_input_queue (mp->client_index);
1852 rmp = vl_msg_api_alloc (sizeof (*rmp));
1853 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1854 rmp->context = mp->context;
1855 rmp->retval = ntohl(rv);
1856 rmp->sw_if_index = ntohl(sw_if_index);
1857 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1861 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1863 vl_api_create_subif_reply_t * rmp;
1864 vnet_main_t * vnm = vnet_get_main();
1865 u32 sw_if_index = ~0;
1868 vnet_sw_interface_t *si;
1869 vnet_hw_interface_t *hi;
1870 vnet_sw_interface_t template;
1872 vnet_interface_main_t * im = &vnm->interface_main;
1873 u64 sup_and_sub_key;
1875 clib_error_t * error;
1877 VALIDATE_SW_IF_INDEX(mp);
1879 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1880 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1882 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1883 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1887 sw_if_index = si->sw_if_index;
1888 sub_id = ntohl(mp->sub_id);
1890 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1892 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1895 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1896 sw_if_index, sub_id);
1897 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1901 kp = clib_mem_alloc (sizeof (*kp));
1902 *kp = sup_and_sub_key;
1904 memset (&template, 0, sizeof (template));
1905 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1906 template.sup_sw_if_index = sw_if_index;
1907 template.sub.id = sub_id;
1908 template.sub.eth.flags.no_tags = mp->no_tags;
1909 template.sub.eth.flags.one_tag = mp->one_tag;
1910 template.sub.eth.flags.two_tags = mp->two_tags;
1911 template.sub.eth.flags.dot1ad = mp->dot1ad;
1912 template.sub.eth.flags.exact_match = mp->exact_match;
1913 template.sub.eth.flags.default_sub = mp->default_sub;
1914 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1915 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1916 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1917 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1919 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1921 clib_error_report (error);
1922 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1926 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1927 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1929 BAD_SW_IF_INDEX_LABEL;
1933 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1935 rmp->sw_if_index = ntohl(sw_if_index);
1940 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1942 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1944 stats_main_t * sm = &stats_main;
1945 u32 tunnel_sw_if_index = ~0;
1947 dslock (sm, 1 /* release hint */, 5 /* tag */);
1949 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1950 (ip4_address_t *)(mp->dst_address),
1951 (ip4_address_t *)(mp->intfc_address),
1952 (u32)(mp->intfc_address_length),
1953 ntohl(mp->inner_vrf_id),
1954 ntohl(mp->outer_vrf_id),
1955 &tunnel_sw_if_index,
1960 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1962 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1967 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1968 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1970 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1972 stats_main_t * sm = &stats_main;
1973 u32 tunnel_sw_if_index;
1975 dslock (sm, 1 /* release hint */, 5 /* tag */);
1977 rv = vnet_mpls_ethernet_add_del_tunnel
1978 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1979 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1980 ntohl(mp->tx_sw_if_index),
1981 &tunnel_sw_if_index,
1987 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1989 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1994 * This piece of misery brought to you because the control-plane
1995 * can't figure out the tx interface + dst-mac address all by itself
1997 static int mpls_ethernet_add_del_tunnel_2_t_handler
1998 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2000 pending_route_t * pr;
2001 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2002 vnet_main_t * vnm = vnet_get_main();
2003 vlib_main_t * vm = vlib_get_main();
2004 stats_main_t * sm = &stats_main;
2005 vpe_api_main_t * vam = &vpe_api_main;
2006 u32 inner_fib_index, outer_fib_index;
2007 ip4_main_t * im = &ip4_main;
2008 ip_lookup_main_t * lm = &im->lookup_main;
2009 ip_adjacency_t * adj = 0;
2012 u8 * dst_mac_address;
2016 u32 tunnel_sw_if_index;
2018 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2020 return VNET_API_ERROR_NO_SUCH_FIB;
2022 outer_fib_index = p[0];
2025 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2027 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2029 inner_fib_index = p[0];
2031 if (inner_fib_index == outer_fib_index)
2032 return VNET_API_ERROR_INVALID_VALUE;
2034 lookup_result = ip4_fib_lookup_with_table
2035 (im, outer_fib_index,
2036 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2037 1 /* disable default route */);
2039 adj = ip_get_adjacency (lm, lookup_result);
2040 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2042 if (mp->is_add && mp->resolve_if_needed) {
2043 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2044 pool_get (vam->pending_routes, pr);
2045 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2047 clib_memcpy (pme, mp, sizeof (*pme));
2048 /* recursion block, "just in case" */
2049 pme->resolve_if_needed = 0;
2050 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2051 pme->resolve_opaque = tx_sw_if_index;
2052 vnet_register_ip4_arp_resolution_event
2054 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2055 vpe_resolver_process_node.index,
2056 RESOLUTION_EVENT, pr - vam->pending_routes);
2058 vlib_process_signal_event
2059 (vm, vpe_resolver_process_node.index,
2060 RESOLUTION_PENDING_EVENT, 0 /* data */);
2062 /* The interface may be down, etc. */
2063 e = ip4_probe_neighbor
2064 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2068 clib_error_report(e);
2070 return VNET_API_ERROR_IN_PROGRESS;
2074 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2075 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2078 vnet_rewrite_get_data_internal
2079 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2081 dslock (sm, 1 /* release hint */, 10 /* tag */);
2083 rv = vnet_mpls_ethernet_add_del_tunnel
2084 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2085 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2086 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2094 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2095 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2097 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2100 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2102 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2107 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2109 vl_api_mpls_add_del_encap_reply_t * rmp;
2111 static u32 * labels;
2114 vec_reset_length (labels);
2116 for (i = 0; i < mp->nlabels; i++)
2117 vec_add1 (labels, ntohl(mp->labels[i]));
2120 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2121 ntohl(mp->vrf_id), labels,
2122 ~0 /* policy_tunnel_index */,
2123 0 /* no_dst_hash */,
2127 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2131 vl_api_mpls_add_del_decap_t_handler
2132 (vl_api_mpls_add_del_decap_t *mp)
2134 vl_api_mpls_add_del_decap_reply_t * rmp;
2137 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2138 ntohl(mp->label), ntohl(mp->next_index),
2139 mp->s_bit, mp->is_add);
2141 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2145 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2147 vl_api_proxy_arp_add_del_reply_t * rmp;
2150 ip4_main_t * im = &ip4_main;
2151 stats_main_t * sm = &stats_main;
2152 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2153 ip4_address_t *hi_addr,
2154 u32 fib_index, int is_del);
2157 dslock (sm, 1 /* release hint */, 6 /* tag */);
2159 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2162 rv = VNET_API_ERROR_NO_SUCH_FIB;
2168 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2169 (ip4_address_t *)mp->hi_address,
2170 fib_index, mp->is_add == 0);
2174 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2178 vl_api_proxy_arp_intfc_enable_disable_t_handler
2179 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2182 vnet_main_t * vnm = vnet_get_main();
2183 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2184 vnet_sw_interface_t * si;
2187 VALIDATE_SW_IF_INDEX(mp);
2189 sw_if_index = ntohl(mp->sw_if_index);
2191 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2193 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2197 si = vnet_get_sw_interface (vnm, sw_if_index);
2201 if (mp->enable_disable)
2202 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2204 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2206 BAD_SW_IF_INDEX_LABEL;
2209 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2213 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2215 vl_api_ip_neighbor_add_del_reply_t * rmp;
2216 vnet_main_t * vnm = vnet_get_main();
2219 stats_main_t * sm = &stats_main;
2221 VALIDATE_SW_IF_INDEX(mp);
2223 dslock (sm, 1 /* release hint */, 7 /* tag */);
2227 rv = vnet_set_ip6_ethernet_neighbor
2228 (vm, ntohl(mp->sw_if_index),
2229 (ip6_address_t *)(mp->dst_address),
2230 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2232 rv = vnet_unset_ip6_ethernet_neighbor
2233 (vm, ntohl(mp->sw_if_index),
2234 (ip6_address_t *)(mp->dst_address),
2235 mp->mac_address, sizeof(mp->mac_address));
2237 ip4_main_t * im = &ip4_main;
2238 ip_lookup_main_t * lm = &im->lookup_main;
2239 ethernet_arp_ip4_over_ethernet_address_t a;
2241 ip_adjacency_t *nh_adj;
2243 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2245 rv = VNET_API_ERROR_NO_SUCH_FIB;
2251 * Unfortunately, folks have a penchant for
2252 * adding interface addresses to the ARP cache, and
2253 * wondering why the forwarder eventually ASSERTs...
2255 ai = ip4_fib_lookup_with_table
2256 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2257 1 /* disable default route */);
2260 nh_adj = ip_get_adjacency (lm, ai);
2261 /* Never allow manipulation of a local adj! */
2262 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2263 clib_warning("%U matches local adj",
2265 (ip4_address_t *)(mp->dst_address));
2266 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2271 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2272 clib_memcpy (&a.ip4, mp->dst_address, 4);
2275 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2276 fib_index, &a, mp->is_static);
2278 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2282 BAD_SW_IF_INDEX_LABEL;
2285 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2289 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2292 vpe_main_t *rm = &vpe_main;
2293 ip4_main_t *im4 = &ip4_main;
2294 ip6_main_t *im6 = &ip6_main;
2295 ip_lookup_main_t * lm;
2300 u32 adj_index, sw_if_index;
2301 vl_api_is_address_reachable_t *rmp;
2302 ip_adjacency_t * adj;
2303 unix_shared_memory_queue_t *q;
2305 q = vl_api_client_index_to_input_queue (mp->client_index);
2307 increment_missing_api_client_counter (rm->vlib_main);
2311 rmp = vl_msg_api_alloc (sizeof (*rmp));
2312 clib_memcpy (rmp, mp, sizeof (*rmp));
2314 sw_if_index = mp->next_hop_sw_if_index;
2315 clib_memcpy (&addr, mp->address, sizeof (addr));
2317 lm = &im6->lookup_main;
2319 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2321 lm = &im4->lookup_main;
2323 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2325 if (adj_index == ~0) {
2329 adj = ip_get_adjacency (lm, adj_index);
2331 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2332 && adj->rewrite_header.sw_if_index == sw_if_index) {
2335 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2336 && adj->rewrite_header.sw_if_index == sw_if_index) {
2338 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2340 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2341 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2349 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2353 static void vl_api_sw_interface_details_t_handler (
2354 vl_api_sw_interface_details_t * mp)
2356 clib_warning ("BUG");
2359 static void vl_api_sw_interface_set_flags_t_handler (
2360 vl_api_sw_interface_set_flags_t * mp)
2362 vl_api_sw_interface_set_flags_reply_t *rmp;
2363 vnet_main_t * vnm = vnet_get_main();
2365 clib_error_t * error;
2368 VALIDATE_SW_IF_INDEX(mp);
2370 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2372 error = vnet_sw_interface_set_flags (vnm,
2373 ntohl(mp->sw_if_index),
2377 clib_error_report (error);
2380 BAD_SW_IF_INDEX_LABEL;
2381 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2384 static void vl_api_sw_interface_clear_stats_t_handler (
2385 vl_api_sw_interface_clear_stats_t * mp)
2387 vl_api_sw_interface_clear_stats_reply_t *rmp;
2389 vnet_main_t * vnm = vnet_get_main();
2390 vnet_interface_main_t * im = &vnm->interface_main;
2391 vlib_simple_counter_main_t * sm;
2392 vlib_combined_counter_main_t * cm;
2393 static vnet_main_t ** my_vnet_mains;
2394 int i, j, n_counters;
2398 vec_reset_length (my_vnet_mains);
2400 for (i = 0; i < vec_len (vnet_mains); i++)
2403 vec_add1 (my_vnet_mains, vnet_mains[i]);
2406 if (vec_len (vnet_mains) == 0)
2407 vec_add1 (my_vnet_mains, vnm);
2409 n_counters = vec_len (im->combined_sw_if_counters);
2411 for (j = 0; j < n_counters; j++)
2413 for (i = 0; i < vec_len(my_vnet_mains); i++)
2415 im = &my_vnet_mains[i]->interface_main;
2416 cm = im->combined_sw_if_counters + j;
2417 if (mp->sw_if_index == (u32)~0)
2418 vlib_clear_combined_counters (cm);
2420 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2424 n_counters = vec_len (im->sw_if_counters);
2426 for (j = 0; j < n_counters; j++)
2428 for (i = 0; i < vec_len(my_vnet_mains); i++)
2430 im = &my_vnet_mains[i]->interface_main;
2431 sm = im->sw_if_counters + j;
2432 if (mp->sw_if_index == (u32)~0)
2433 vlib_clear_simple_counters (sm);
2435 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2439 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2442 static void send_sw_interface_details (vpe_api_main_t * am,
2443 unix_shared_memory_queue_t *q,
2444 vnet_sw_interface_t * swif,
2445 u8 * interface_name,
2448 vl_api_sw_interface_details_t * mp;
2449 vnet_hw_interface_t * hi;
2451 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2453 mp = vl_msg_api_alloc (sizeof (*mp));
2454 memset (mp, 0, sizeof (*mp));
2455 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2456 mp->sw_if_index = ntohl(swif->sw_if_index);
2457 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2458 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2460 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2462 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2463 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2464 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2465 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2466 mp->link_mtu = ntohs(hi->max_packet_bytes);
2467 mp->context = context;
2469 strncpy ((char *) mp->interface_name,
2470 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2472 /* Send the L2 address for ethernet physical intfcs */
2473 if (swif->sup_sw_if_index == swif->sw_if_index
2474 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2475 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2476 ethernet_interface_t *ei;
2478 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2479 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2480 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2481 mp->l2_address_length = ntohl(sizeof (ei->address));
2482 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2483 vnet_sub_interface_t *sub = &swif->sub;
2484 mp->sub_id = ntohl(sub->id);
2485 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2486 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2487 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2488 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2489 mp->sub_exact_match = sub->eth.flags.exact_match;
2490 mp->sub_default = sub->eth.flags.default_sub;
2491 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2492 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2494 /* vlan tag rewrite data */
2495 u32 vtr_op = L2_VTR_DISABLED;
2496 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2498 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2499 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2500 // error - default to disabled
2501 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2502 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2505 mp->vtr_op = ntohl(vtr_op);
2506 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2507 mp->vtr_tag1 = ntohl(vtr_tag1);
2508 mp->vtr_tag2 = ntohl(vtr_tag2);
2512 vl_msg_api_send_shmem (q, (u8 *)&mp);
2515 static void send_sw_interface_flags (vpe_api_main_t * am,
2516 unix_shared_memory_queue_t *q,
2517 vnet_sw_interface_t * swif)
2519 vl_api_sw_interface_set_flags_t *mp;
2520 vnet_main_t * vnm = am->vnet_main;
2522 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2524 mp = vl_msg_api_alloc (sizeof (*mp));
2525 memset (mp, 0, sizeof (*mp));
2526 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2527 mp->sw_if_index = ntohl(swif->sw_if_index);
2529 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2531 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2533 vl_msg_api_send_shmem (q, (u8 *)&mp);
2536 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2537 unix_shared_memory_queue_t *q,
2539 __attribute__((unused));
2541 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2542 unix_shared_memory_queue_t *q,
2545 vl_api_sw_interface_set_flags_t *mp;
2547 mp = vl_msg_api_alloc (sizeof (*mp));
2548 memset (mp, 0, sizeof (*mp));
2549 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2550 mp->sw_if_index = ntohl(sw_if_index);
2552 mp->admin_up_down = 0;
2553 mp->link_up_down = 0;
2555 vl_msg_api_send_shmem (q, (u8 *)&mp);
2558 static void vl_api_sw_interface_dump_t_handler (
2559 vl_api_sw_interface_dump_t *mp)
2561 vpe_api_main_t * am = &vpe_api_main;
2562 vnet_sw_interface_t * swif;
2563 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2564 u8 * filter_string = 0, * name_string = 0;
2565 unix_shared_memory_queue_t * q;
2566 char * strcasestr (char *, char *); /* lnx hdr file botch */
2568 q = vl_api_client_index_to_input_queue (mp->client_index);
2573 if (mp->name_filter_valid) {
2574 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2575 filter_string = format (0, "%s%c", mp->name_filter, 0);
2578 pool_foreach (swif, im->sw_interfaces,
2580 name_string = format (name_string, "%U%c",
2581 format_vnet_sw_interface_name,
2582 am->vnet_main, swif, 0);
2584 if (mp->name_filter_valid == 0 ||
2585 strcasestr((char *) name_string, (char *) filter_string)) {
2587 send_sw_interface_details (am, q, swif, name_string, mp->context);
2588 send_sw_interface_flags (am, q, swif);
2590 _vec_len (name_string) = 0;
2593 vec_free (name_string);
2594 vec_free (filter_string);
2597 void send_oam_event (oam_target_t * t)
2599 vpe_api_main_t * vam = &vpe_api_main;
2600 unix_shared_memory_queue_t * q;
2601 vpe_client_registration_t *reg;
2602 vl_api_oam_event_t * mp;
2604 pool_foreach(reg, vam->oam_events_registrations,
2606 q = vl_api_client_index_to_input_queue (reg->client_index);
2608 mp = vl_msg_api_alloc (sizeof (*mp));
2609 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2610 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2611 mp->state = t->state;
2612 vl_msg_api_send_shmem (q, (u8 *)&mp);
2618 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2620 vl_api_oam_add_del_reply_t * rmp;
2623 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2624 (ip4_address_t *)mp->dst_address,
2628 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2632 vl_api_vnet_get_summary_stats_t_handler (
2633 vl_api_vnet_get_summary_stats_t *mp)
2635 stats_main_t * sm = &stats_main;
2636 vnet_interface_main_t * im = sm->interface_main;
2637 vl_api_vnet_summary_stats_reply_t *rmp;
2638 vlib_combined_counter_main_t * cm;
2641 u64 total_pkts[VLIB_N_RX_TX];
2642 u64 total_bytes[VLIB_N_RX_TX];
2644 unix_shared_memory_queue_t * q =
2645 vl_api_client_index_to_input_queue (mp->client_index);
2650 rmp = vl_msg_api_alloc (sizeof (*rmp));
2651 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2652 rmp->context = mp->context;
2655 memset (total_pkts, 0, sizeof (total_pkts));
2656 memset (total_bytes, 0, sizeof (total_bytes));
2658 vnet_interface_counter_lock (im);
2660 vec_foreach (cm, im->combined_sw_if_counters) {
2661 which = cm - im->combined_sw_if_counters;
2663 for (i = 0; i < vec_len (cm->maxi); i++) {
2664 vlib_get_combined_counter (cm, i, &v);
2665 total_pkts[which] += v.packets;
2666 total_bytes[which] += v.bytes;
2669 vnet_interface_counter_unlock (im);
2671 /* Note: in HOST byte order! */
2672 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2673 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2674 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2675 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2676 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2678 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2681 typedef CLIB_PACKED (struct {
2682 ip4_address_t address;
2684 u32 address_length : 6;
2689 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2691 vnet_main_t * vnm = vnet_get_main();
2692 vnet_interface_main_t * im = &vnm->interface_main;
2693 ip4_main_t * im4 = &ip4_main;
2694 static ip4_route_t * routes;
2695 static u32 * sw_if_indices_to_shut;
2696 stats_main_t * sm = &stats_main;
2701 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2702 u32 target_fib_id = ntohl(mp->vrf_id);
2704 dslock (sm, 1 /* release hint */, 8 /* tag */);
2706 vec_foreach (fib, im4->fibs) {
2707 vnet_sw_interface_t * si;
2709 if (fib->table_id != target_fib_id)
2712 /* remove any mpls/gre tunnels in this fib */
2713 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2715 /* remove any mpls encap/decap labels */
2716 mpls_fib_reset_labels (fib->table_id);
2718 /* remove any proxy arps in this fib */
2719 vnet_proxy_arp_fib_reset (fib->table_id);
2721 /* Set the flow hash for this fib to the default */
2722 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2724 vec_reset_length (sw_if_indices_to_shut);
2726 /* Shut down interfaces in this FIB / clean out intfc routes */
2727 pool_foreach (si, im->sw_interfaces,
2729 u32 sw_if_index = si->sw_if_index;
2731 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2732 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2734 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2737 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2738 sw_if_index = sw_if_indices_to_shut[i];
2739 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2741 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2742 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2743 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2746 vec_reset_length (routes);
2748 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2749 uword * hash = fib->adj_index_by_dst_address[i];
2753 x.address_length = i;
2755 hash_foreach_pair (p, hash,
2757 x.address.data_u32 = p->key;
2758 vec_add1 (routes, x);
2762 vec_foreach (r, routes) {
2763 ip4_add_del_route_args_t a;
2765 memset (&a, 0, sizeof (a));
2766 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2767 a.table_index_or_table_id = fib - im4->fibs;
2768 a.dst_address = r->address;
2769 a.dst_address_length = r->address_length;
2772 ip4_add_del_route (im4, &a);
2773 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2774 IP4_ROUTE_FLAG_FIB_INDEX);
2778 } /* vec_foreach (fib) */
2785 ip6_address_t address;
2792 ip6_route_t ** routep;
2793 } add_routes_in_fib_arg_t;
2795 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2797 add_routes_in_fib_arg_t * ap = arg;
2799 if (kvp->key[2]>>32 == ap->fib_index)
2801 ip6_address_t *addr;
2803 addr = (ip6_address_t *) kvp;
2804 vec_add2 (*ap->routep, r, 1);
2805 r->address = addr[0];
2806 r->address_length = kvp->key[2] & 0xFF;
2807 r->index = kvp->value;
2811 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2813 vnet_main_t * vnm = vnet_get_main();
2814 vnet_interface_main_t * im = &vnm->interface_main;
2815 ip6_main_t * im6 = &ip6_main;
2816 stats_main_t * sm = &stats_main;
2817 static ip6_route_t * routes;
2818 static u32 * sw_if_indices_to_shut;
2823 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2824 u32 target_fib_id = ntohl(mp->vrf_id);
2825 add_routes_in_fib_arg_t _a, *a=&_a;
2826 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2828 dslock (sm, 1 /* release hint */, 9 /* tag */);
2830 vec_foreach (fib, im6->fibs) {
2831 vnet_sw_interface_t * si;
2833 if (fib->table_id != target_fib_id)
2836 vec_reset_length (sw_if_indices_to_shut);
2838 /* Shut down interfaces in this FIB / clean out intfc routes */
2839 pool_foreach (si, im->sw_interfaces,
2841 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2843 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2846 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2847 sw_if_index = sw_if_indices_to_shut[i];
2848 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2850 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2851 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2852 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2855 vec_reset_length (routes);
2857 a->fib_index = fib - im6->fibs;
2858 a->routep = &routes;
2860 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2862 vec_foreach (r, routes) {
2863 ip6_add_del_route_args_t a;
2865 memset (&a, 0, sizeof (a));
2866 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2867 a.table_index_or_table_id = fib - im6->fibs;
2868 a.dst_address = r->address;
2869 a.dst_address_length = r->address_length;
2872 ip6_add_del_route (im6, &a);
2873 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2874 IP6_ROUTE_FLAG_FIB_INDEX);
2877 /* Reinstall the neighbor / router discovery routes */
2878 vnet_ip6_fib_init (im6, fib - im6->fibs);
2880 } /* vec_foreach (fib) */
2886 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2889 vl_api_reset_fib_reply_t * rmp;
2892 rv = ip6_reset_fib_t_handler (mp);
2894 rv = ip4_reset_fib_t_handler (mp);
2896 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2901 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2903 vl_api_dhcp_proxy_config_reply_t * rmp;
2906 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2907 (ip4_address_t *)(&mp->dhcp_src_address),
2908 (u32) ntohl(mp->vrf_id),
2909 (int) mp->insert_circuit_id,
2910 (int) (mp->is_add == 0));
2912 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2917 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2919 vl_api_dhcp_proxy_config_reply_t * rmp;
2922 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2923 (ip6_address_t *)(&mp->dhcp_src_address),
2924 (u32) ntohl(mp->vrf_id),
2925 (int) mp->insert_circuit_id,
2926 (int) (mp->is_add == 0));
2928 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2932 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2934 vl_api_dhcp_proxy_config_reply_t * rmp;
2937 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2938 (ip4_address_t *)(&mp->dhcp_src_address),
2939 (u32) ntohl(mp->rx_vrf_id),
2940 (u32) ntohl(mp->server_vrf_id),
2941 (int) mp->insert_circuit_id,
2942 (int) (mp->is_add == 0));
2944 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2949 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2951 vl_api_dhcp_proxy_config_reply_t * rmp;
2955 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2956 (ip6_address_t *)(&mp->dhcp_src_address),
2957 (u32) ntohl(mp->rx_vrf_id),
2958 (u32) ntohl(mp->server_vrf_id),
2959 (int) mp->insert_circuit_id,
2960 (int) (mp->is_add == 0));
2962 rv = VNET_API_ERROR_UNIMPLEMENTED;
2965 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2970 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2972 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2975 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2978 (int)mp->is_add == 0);
2980 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2983 (int)mp->is_add == 0);
2985 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2989 static void vl_api_dhcp_proxy_config_t_handler
2990 (vl_api_dhcp_proxy_config_t *mp)
2992 if (mp->is_ipv6 == 0)
2993 dhcpv4_proxy_config (mp);
2995 dhcpv6_proxy_config (mp);
2998 static void vl_api_dhcp_proxy_config_2_t_handler
2999 (vl_api_dhcp_proxy_config_2_t *mp)
3001 if (mp->is_ipv6 == 0)
3002 dhcpv4_proxy_config_2 (mp);
3004 dhcpv6_proxy_config_2 (mp);
3007 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3008 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3010 unix_shared_memory_queue_t * q;
3011 vl_api_dhcp_compl_event_t * mp;
3013 q = vl_api_client_index_to_input_queue (client_index);
3017 mp = vl_msg_api_alloc (sizeof (*mp));
3018 mp->client_index = client_index;
3020 mp->is_ipv6 = is_ipv6;
3021 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3022 mp->hostname[vec_len(hostname) + 1] = '\n';
3023 clib_memcpy (&mp->host_address[0], host_address, 16);
3024 clib_memcpy (&mp->router_address[0], router_address, 16);
3025 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3027 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3029 vl_msg_api_send_shmem (q, (u8 *)&mp);
3032 static void vl_api_dhcp_client_config_t_handler
3033 (vl_api_dhcp_client_config_t *mp)
3035 vlib_main_t *vm = vlib_get_main();
3036 vl_api_dhcp_client_config_reply_t * rmp;
3039 VALIDATE_SW_IF_INDEX(mp);
3041 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3042 mp->hostname, mp->is_add, mp->client_index,
3043 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3046 BAD_SW_IF_INDEX_LABEL;
3048 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3052 vl_api_sw_interface_ip6nd_ra_config_t_handler
3053 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3055 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3057 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3059 is_no = mp->is_no == 1;
3060 surpress = mp->surpress == 1;
3061 managed = mp->managed == 1;
3062 other = mp->other == 1;
3063 ll_option = mp->ll_option == 1;
3064 send_unicast = mp->send_unicast == 1;
3065 cease = mp->cease == 1;
3066 default_router = mp->default_router == 1;
3068 VALIDATE_SW_IF_INDEX(mp);
3070 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3071 surpress, managed, other,
3072 ll_option, send_unicast, cease,
3073 default_router, ntohl (mp->lifetime),
3074 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3075 ntohl(mp->max_interval), ntohl( mp->min_interval),
3078 BAD_SW_IF_INDEX_LABEL;
3080 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3084 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3085 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3087 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3089 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3091 VALIDATE_SW_IF_INDEX(mp);
3093 is_no = mp->is_no == 1;
3094 use_default = mp->use_default == 1;
3095 no_advertise = mp->no_advertise == 1;
3096 off_link = mp->off_link == 1;
3097 no_autoconfig = mp->no_autoconfig == 1;
3098 no_onlink = mp->no_onlink == 1;
3100 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3101 (ip6_address_t *)mp->address, mp->address_length,
3102 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3103 no_advertise, off_link, no_autoconfig, no_onlink,
3106 BAD_SW_IF_INDEX_LABEL;
3107 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3111 vl_api_sw_interface_ip6_enable_disable_t_handler
3112 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3114 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3115 vnet_main_t * vnm = vnet_get_main();
3117 clib_error_t * error;
3121 VALIDATE_SW_IF_INDEX(mp);
3123 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3124 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3127 clib_error_report(error);
3128 rv = VNET_API_ERROR_UNSPECIFIED;
3130 rv = vnm->api_errno;
3133 BAD_SW_IF_INDEX_LABEL;
3135 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3139 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3140 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3142 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3144 clib_error_t * error;
3145 vnet_main_t * vnm = vnet_get_main();
3149 VALIDATE_SW_IF_INDEX(mp);
3151 error = set_ip6_link_local_address(vm,
3152 ntohl(mp->sw_if_index),
3153 (ip6_address_t *)mp->address,
3154 mp->address_length);
3156 clib_error_report(error);
3157 rv = VNET_API_ERROR_UNSPECIFIED;
3159 rv = vnm->api_errno;
3162 BAD_SW_IF_INDEX_LABEL;
3164 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3167 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3169 vl_api_set_ip_flow_hash_reply_t *rmp;
3170 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3172 clib_warning ("unimplemented...");
3174 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3177 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3179 vl_api_set_ip_flow_hash_reply_t *rmp;
3182 u32 flow_hash_config = 0;
3184 table_id = ntohl(mp->vrf_id);
3186 #define _(a,b) if (mp->a) flow_hash_config |= b;
3187 foreach_flow_hash_bit;
3190 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3192 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3196 static void vl_api_set_ip_flow_hash_t_handler
3197 (vl_api_set_ip_flow_hash_t *mp)
3199 if (mp->is_ipv6 == 0)
3200 set_ip4_flow_hash (mp);
3202 set_ip6_flow_hash (mp);
3205 static void vl_api_sw_interface_set_unnumbered_t_handler
3206 (vl_api_sw_interface_set_unnumbered_t *mp)
3208 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3210 vnet_sw_interface_t * si;
3211 vnet_main_t *vnm = vnet_get_main();
3212 u32 sw_if_index, unnumbered_sw_if_index;
3214 sw_if_index = ntohl(mp->sw_if_index);
3215 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3218 * The API message field names are backwards from
3219 * the underlying data structure names.
3220 * It's not worth changing them now.
3222 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3223 unnumbered_sw_if_index)) {
3224 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3228 /* Only check the "use loop0" field when setting the binding */
3230 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3231 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3235 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3238 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3239 si->unnumbered_sw_if_index = sw_if_index;
3241 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3242 si->unnumbered_sw_if_index = (u32)~0;
3246 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3249 static void vl_api_create_loopback_t_handler
3250 (vl_api_create_loopback_t *mp)
3252 vl_api_create_loopback_reply_t * rmp;
3256 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3258 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3260 rmp->sw_if_index = ntohl (sw_if_index);
3264 static void vl_api_delete_loopback_t_handler
3265 (vl_api_delete_loopback_t *mp)
3267 vl_api_delete_loopback_reply_t * rmp;
3271 sw_if_index = ntohl (mp->sw_if_index);
3272 rv = vnet_delete_loopback_interface (sw_if_index);
3274 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3277 static void vl_api_control_ping_t_handler
3278 (vl_api_control_ping_t *mp)
3280 vl_api_control_ping_reply_t * rmp;
3283 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3285 rmp->vpe_pid = ntohl (getpid());
3289 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3291 u8 **shmem_vecp = (u8 **)arg;
3294 api_main_t * am = &api_main;
3297 shmem_vec = *shmem_vecp;
3299 offset = vec_len (shmem_vec);
3301 pthread_mutex_lock (&am->vlib_rp->mutex);
3302 oldheap = svm_push_data_heap (am->vlib_rp);
3304 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3306 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3308 svm_pop_heap (oldheap);
3309 pthread_mutex_unlock (&am->vlib_rp->mutex);
3311 *shmem_vecp = shmem_vec;
3315 static void vl_api_cli_request_t_handler
3316 (vl_api_cli_request_t *mp)
3318 vl_api_cli_reply_t *rp;
3319 unix_shared_memory_queue_t *q;
3320 vlib_main_t * vm = vlib_get_main();
3321 api_main_t * am = &api_main;
3322 unformat_input_t input;
3326 q = vl_api_client_index_to_input_queue (mp->client_index);
3330 rp = vl_msg_api_alloc (sizeof (*rp));
3331 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3332 rp->context = mp->context;
3334 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3336 vlib_cli_input (vm, &input, shmem_cli_output,
3339 pthread_mutex_lock (&am->vlib_rp->mutex);
3340 oldheap = svm_push_data_heap (am->vlib_rp);
3342 vec_add1(shmem_vec, 0);
3344 svm_pop_heap (oldheap);
3345 pthread_mutex_unlock (&am->vlib_rp->mutex);
3347 rp->reply_in_shmem = (uword)shmem_vec;
3349 vl_msg_api_send_shmem (q, (u8 *)&rp);
3352 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3355 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3356 vnet_main_t *vnm = vnet_get_main();
3357 clib_error_t * error;
3362 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3364 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3367 clib_error_report(error);
3368 rv = VNET_API_ERROR_UNSPECIFIED;
3370 rv = vnm->api_errno;
3373 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3376 static void vl_api_sr_tunnel_add_del_t_handler
3377 (vl_api_sr_tunnel_add_del_t *mp)
3380 clib_warning ("unimplemented");
3382 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3384 vl_api_sr_tunnel_add_del_reply_t * rmp;
3385 ip6_address_t * segments = 0, * seg;
3386 ip6_address_t * tags = 0, *tag;
3387 ip6_address_t * this_address;
3390 if (mp->n_segments == 0) {
3395 memset (a, 0, sizeof (*a));
3396 a->src_address = (ip6_address_t *)&mp->src_address;
3397 a->dst_address = (ip6_address_t *)&mp->dst_address;
3398 a->dst_mask_width = mp->dst_mask_width;
3399 a->flags_net_byte_order = mp->flags_net_byte_order;
3400 a->is_del = (mp->is_add == 0);
3401 a->rx_table_id = ntohl(mp->outer_vrf_id);
3402 a->tx_table_id = ntohl(mp->inner_vrf_id);
3404 a->name = format(0, "%s", mp->name);
3405 if (!(vec_len(a->name)))
3408 a->policy_name = format(0, "%s", mp->policy_name);
3409 if (!(vec_len(a->policy_name)))
3412 /* Yank segments and tags out of the API message */
3413 this_address = (ip6_address_t *)mp->segs_and_tags;
3414 for (i = 0; i < mp->n_segments; i++) {
3415 vec_add2 (segments, seg, 1);
3416 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3419 for (i = 0; i < mp->n_tags; i++) {
3420 vec_add2 (tags, tag, 1);
3421 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3425 a->segments = segments;
3428 rv = ip6_sr_add_del_tunnel (a);
3432 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3436 static void vl_api_sr_policy_add_del_t_handler
3437 (vl_api_sr_policy_add_del_t *mp)
3440 clib_warning ("unimplemented");
3442 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3444 vl_api_sr_policy_add_del_reply_t * rmp;
3447 memset (a, 0, sizeof (*a));
3448 a->is_del = (mp->is_add == 0);
3450 a->name = format(0, "%s", mp->name);
3451 if (!(vec_len(a->name)))
3453 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3457 if (!(mp->tunnel_names[0]))
3459 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3463 // start deserializing tunnel_names
3464 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3465 u8 * deser_tun_names = mp->tunnel_names;
3466 deser_tun_names += 1; //moving along
3469 int tun_name_len = 0;
3471 for (i=0; i < num_tunnels; i++)
3473 tun_name_len= *deser_tun_names;
3474 deser_tun_names += 1;
3475 vec_resize (tun_name, tun_name_len);
3476 memcpy(tun_name, deser_tun_names, tun_name_len);
3477 vec_add1 (a->tunnel_names, tun_name);
3478 deser_tun_names += tun_name_len;
3482 rv = ip6_sr_add_del_policy (a);
3486 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3490 static void vl_api_sr_multicast_map_add_del_t_handler
3491 (vl_api_sr_multicast_map_add_del_t *mp)
3494 clib_warning ("unimplemented");
3496 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3498 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3500 memset (a, 0, sizeof (*a));
3501 a->is_del = (mp->is_add == 0);
3503 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3504 a->policy_name = format(0, "%s", mp->policy_name);
3506 if (a->multicast_address == 0)
3512 if (!(a->policy_name))
3518 #if DPDK > 0 /* Cannot call replicate without DPDK */
3519 rv = ip6_sr_add_del_multicastmap (a);
3521 clib_warning ("multicast replication without DPDK not implemented");
3522 rv = VNET_API_ERROR_UNIMPLEMENTED;
3527 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3531 #define foreach_classify_add_del_table_field \
3536 _(match_n_vectors) \
3537 _(next_table_index) \
3540 static void vl_api_classify_add_del_table_t_handler
3541 (vl_api_classify_add_del_table_t * mp)
3543 vl_api_classify_add_del_table_reply_t * rmp;
3544 vnet_classify_main_t * cm = &vnet_classify_main;
3545 vnet_classify_table_t * t;
3549 foreach_classify_add_del_table_field;
3552 #define _(a) a = ntohl(mp->a);
3553 foreach_classify_add_del_table_field;
3556 /* The underlying API fails silently, on purpose, so check here */
3557 if (mp->is_add == 0)
3558 if (pool_is_free_index (cm->tables, table_index)) {
3559 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3563 rv = vnet_classify_add_del_table
3564 (cm, mp->mask, nbuckets, memory_size,
3565 skip_n_vectors, match_n_vectors,
3566 next_table_index, miss_next_index,
3567 &table_index, mp->is_add);
3570 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3572 if (rv == 0 && mp->is_add) {
3573 t = pool_elt_at_index (cm->tables, table_index);
3574 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3575 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3576 rmp->new_table_index = ntohl(table_index);
3578 rmp->skip_n_vectors = ~0;
3579 rmp->match_n_vectors = ~0;
3580 rmp->new_table_index = ~0;
3585 static void vl_api_classify_add_del_session_t_handler
3586 (vl_api_classify_add_del_session_t * mp)
3588 vnet_classify_main_t * cm = &vnet_classify_main;
3589 vl_api_classify_add_del_session_reply_t * rmp;
3591 u32 table_index, hit_next_index, opaque_index;
3594 table_index = ntohl (mp->table_index);
3595 hit_next_index = ntohl (mp->hit_next_index);
3596 opaque_index = ntohl (mp->opaque_index);
3597 advance = ntohl (mp->advance);
3599 rv = vnet_classify_add_del_session
3600 (cm, table_index, mp->match, hit_next_index, opaque_index,
3601 advance, mp->is_add);
3603 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3606 static void vl_api_classify_set_interface_ip_table_t_handler
3607 (vl_api_classify_set_interface_ip_table_t * mp)
3609 vlib_main_t * vm = vlib_get_main();
3610 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3612 u32 table_index, sw_if_index;
3614 table_index = ntohl (mp->table_index);
3615 sw_if_index = ntohl (mp->sw_if_index);
3617 VALIDATE_SW_IF_INDEX(mp);
3620 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3622 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3624 BAD_SW_IF_INDEX_LABEL;
3626 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3629 static void vl_api_classify_set_interface_l2_tables_t_handler
3630 (vl_api_classify_set_interface_l2_tables_t * mp)
3632 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3634 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3637 ip4_table_index = ntohl(mp->ip4_table_index);
3638 ip6_table_index = ntohl(mp->ip6_table_index);
3639 other_table_index = ntohl(mp->other_table_index);
3640 sw_if_index = ntohl(mp->sw_if_index);
3642 VALIDATE_SW_IF_INDEX(mp);
3644 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3645 ip6_table_index, other_table_index);
3648 if (ip4_table_index != ~0 || ip6_table_index != ~0
3649 || other_table_index != ~0)
3654 vnet_l2_classify_enable_disable (sw_if_index, enable);
3657 BAD_SW_IF_INDEX_LABEL;
3659 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3663 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3666 vl_api_l2_fib_clear_table_reply_t * rmp;
3668 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3669 * that is not currently implemented. When that TODO is fixed
3670 * this call should be changed to pass 1 instead of 0.
3672 l2fib_clear_table (0);
3674 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3677 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3682 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3685 vl_api_l2_interface_efp_filter_reply_t * rmp;
3686 vnet_main_t *vnm = vnet_get_main();
3688 // enable/disable the feature
3689 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3690 rv = vnm->api_errno;
3692 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3696 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3699 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3700 vnet_main_t * vnm = vnet_get_main();
3701 vlib_main_t * vm = vlib_get_main();
3704 VALIDATE_SW_IF_INDEX(mp);
3706 vtr_op = ntohl(mp->vtr_op);
3708 /* The L2 code is unsuspicious */
3710 case L2_VTR_DISABLED:
3715 case L2_VTR_TRANSLATE_1_1:
3716 case L2_VTR_TRANSLATE_1_2:
3717 case L2_VTR_TRANSLATE_2_1:
3718 case L2_VTR_TRANSLATE_2_2:
3722 rv = VNET_API_ERROR_INVALID_VALUE;
3723 goto bad_sw_if_index;
3726 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3727 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3730 BAD_SW_IF_INDEX_LABEL;
3732 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3736 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3740 vl_api_create_vhost_user_if_reply_t * rmp;
3741 u32 sw_if_index = (u32)~0;
3743 vnet_main_t * vnm = vnet_get_main();
3744 vlib_main_t * vm = vlib_get_main();
3746 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3747 mp->is_server, &sw_if_index, (u64)~0,
3748 mp->renumber, ntohl(mp->custom_dev_instance),
3749 (mp->use_custom_mac)?mp->mac_address:NULL);
3751 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3753 rmp->sw_if_index = ntohl (sw_if_index);
3759 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3763 vl_api_modify_vhost_user_if_reply_t * rmp;
3764 u32 sw_if_index = ntohl(mp->sw_if_index);
3766 vnet_main_t * vnm = vnet_get_main();
3767 vlib_main_t * vm = vlib_get_main();
3769 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3770 mp->is_server, sw_if_index, (u64)~0,
3771 mp->renumber, ntohl(mp->custom_dev_instance));
3773 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3778 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3782 vpe_api_main_t * vam = &vpe_api_main;
3783 vl_api_delete_vhost_user_if_reply_t * rmp;
3784 u32 sw_if_index = ntohl(mp->sw_if_index);
3786 vnet_main_t * vnm = vnet_get_main();
3787 vlib_main_t * vm = vlib_get_main();
3789 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3791 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3793 unix_shared_memory_queue_t * q =
3794 vl_api_client_index_to_input_queue (mp->client_index);
3798 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3803 static void vl_api_sw_interface_vhost_user_details_t_handler (
3804 vl_api_sw_interface_vhost_user_details_t * mp)
3806 clib_warning ("BUG");
3810 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3811 unix_shared_memory_queue_t *q,
3812 vhost_user_intf_details_t * vui,
3815 vl_api_sw_interface_vhost_user_details_t * mp;
3817 mp = vl_msg_api_alloc (sizeof (*mp));
3818 memset (mp, 0, sizeof (*mp));
3819 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3820 mp->sw_if_index = ntohl(vui->sw_if_index);
3821 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3822 mp->features = clib_net_to_host_u64 (vui->features);
3823 mp->is_server = vui->is_server;
3824 mp->num_regions = ntohl(vui->num_regions);
3825 mp->sock_errno = ntohl(vui->sock_errno);
3826 mp->context = context;
3828 strncpy ((char *) mp->sock_filename,
3829 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3830 strncpy ((char *) mp->interface_name,
3831 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3833 vl_msg_api_send_shmem (q, (u8 *)&mp);
3838 vl_api_sw_interface_vhost_user_dump_t_handler (
3839 vl_api_sw_interface_vhost_user_dump_t *mp)
3843 vpe_api_main_t * am = &vpe_api_main;
3844 vnet_main_t * vnm = vnet_get_main();
3845 vlib_main_t * vm = vlib_get_main();
3846 vhost_user_intf_details_t *ifaces = NULL;
3847 vhost_user_intf_details_t *vuid = NULL;
3848 unix_shared_memory_queue_t * q;
3850 q = vl_api_client_index_to_input_queue (mp->client_index);
3854 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3858 vec_foreach (vuid, ifaces) {
3859 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3865 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3866 unix_shared_memory_queue_t *q,
3871 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3872 u8 * if_name = NULL;
3873 vnet_sw_interface_t * si = NULL;
3875 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3877 if_name = format(if_name, "%U",
3878 format_vnet_sw_interface_name, lm->vnet_main, si);
3880 mp = vl_msg_api_alloc (sizeof (*mp));
3881 memset (mp, 0, sizeof (*mp));
3882 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3883 strncpy((char *)mp->interface_name,
3884 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3885 mp->sw_if_index = ntohl(si->sw_if_index);
3886 mp->local_session_id = s->local_session_id;
3887 mp->remote_session_id = s->remote_session_id;
3888 mp->local_cookie[0] = s->local_cookie[0];
3889 mp->local_cookie[1] = s->local_cookie[1];
3890 mp->remote_cookie = s->remote_cookie;
3891 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3892 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3893 mp->l2_sublayer_present = s->l2_sublayer_present;
3894 mp->context = context;
3896 vl_msg_api_send_shmem (q, (u8 *)&mp);
3899 static void send_ip_address_details (vpe_api_main_t * am,
3900 unix_shared_memory_queue_t * q,
3906 vl_api_ip_address_details_t * mp;
3908 mp = vl_msg_api_alloc (sizeof (*mp));
3909 memset (mp, 0, sizeof (*mp));
3910 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3913 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3915 u32 * tp = (u32 *)mp->ip;
3916 *tp = ntohl(*(u32*)ip);
3918 mp->prefix_length = prefix_length;
3919 mp->context = context;
3921 vl_msg_api_send_shmem (q, (u8 *)&mp);
3925 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3927 vpe_api_main_t * am = &vpe_api_main;
3928 unix_shared_memory_queue_t * q;
3931 ip6_main_t * im6 = &ip6_main;
3932 ip4_main_t * im4 = &ip4_main;
3933 ip_lookup_main_t * lm6 = &im6->lookup_main;
3934 ip_lookup_main_t * lm4 = &im4->lookup_main;
3935 ip_interface_address_t * ia = 0;
3936 u32 sw_if_index = ~0;
3937 int rv __attribute__ ((unused)) = 0;
3939 VALIDATE_SW_IF_INDEX(mp);
3941 sw_if_index = ntohl(mp->sw_if_index);
3943 q = vl_api_client_index_to_input_queue (mp->client_index);
3949 foreach_ip_interface_address (lm6, ia, sw_if_index,
3950 1 /* honor unnumbered */,
3952 r6 = ip_interface_address_get_address (lm6, ia);
3953 u16 prefix_length = ia->address_length;
3954 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
3957 foreach_ip_interface_address (lm4, ia, sw_if_index,
3958 1 /* honor unnumbered */,
3960 r4 = ip_interface_address_get_address (lm4, ia);
3961 u16 prefix_length = ia->address_length;
3962 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
3965 BAD_SW_IF_INDEX_LABEL;
3968 static void send_ip_details (vpe_api_main_t * am,
3969 unix_shared_memory_queue_t *q,
3973 vl_api_ip_details_t * mp;
3975 mp = vl_msg_api_alloc (sizeof (*mp));
3976 memset (mp, 0, sizeof (*mp));
3977 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3979 mp->sw_if_index = ntohl(sw_if_index);
3980 mp->context = context;
3982 vl_msg_api_send_shmem (q, (u8 *)&mp);
3986 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3987 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3989 vpe_api_main_t * am = &vpe_api_main;
3990 l2t_main_t * lm = &l2t_main;
3991 unix_shared_memory_queue_t * q;
3992 l2t_session_t *session;
3994 q = vl_api_client_index_to_input_queue (mp->client_index);
3998 pool_foreach (session, lm->sessions,
4000 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4005 static void send_sw_interface_tap_details (vpe_api_main_t * am,
4006 unix_shared_memory_queue_t *q,
4007 tapcli_interface_details_t *tap_if,
4010 vl_api_sw_interface_tap_details_t * mp;
4011 mp = vl_msg_api_alloc (sizeof (*mp));
4012 memset (mp, 0, sizeof (*mp));
4013 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4014 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4015 strncpy((char *)mp->dev_name,
4016 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4017 mp->context = context;
4019 vl_msg_api_send_shmem (q, (u8 *)&mp);
4023 vl_api_sw_interface_tap_dump_t_handler (
4024 vl_api_sw_interface_tap_dump_t *mp)
4027 vpe_api_main_t * am = &vpe_api_main;
4028 unix_shared_memory_queue_t * q;
4029 tapcli_interface_details_t *tapifs = NULL;
4030 tapcli_interface_details_t *tap_if = NULL;
4032 q = vl_api_client_index_to_input_queue (mp->client_index);
4036 rv = vnet_tap_dump_ifs(&tapifs);
4040 vec_foreach(tap_if, tapifs) {
4041 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4048 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4050 vpe_api_main_t * am = &vpe_api_main;
4051 vnet_main_t * vnm = vnet_get_main();
4052 vlib_main_t * vm = vlib_get_main();
4053 vnet_interface_main_t * im = &vnm->interface_main;
4054 unix_shared_memory_queue_t * q;
4055 vnet_sw_interface_t * si, * sorted_sis;
4056 u32 sw_if_index = ~0;
4058 q = vl_api_client_index_to_input_queue (mp->client_index);
4063 /* Gather interfaces. */
4064 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4065 _vec_len (sorted_sis) = 0;
4066 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4068 vec_foreach (si, sorted_sis) {
4069 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4070 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4073 sw_if_index = si->sw_if_index;
4074 send_ip_details(am, q, sw_if_index, mp->context);
4079 static void vl_api_l2_fib_table_entry_t_handler (
4080 vl_api_l2_fib_table_entry_t * mp)
4082 clib_warning ("BUG");
4085 static void send_l2fib_table_entry (vpe_api_main_t * am,
4086 unix_shared_memory_queue_t *q,
4087 l2fib_entry_key_t * l2fe_key,
4088 l2fib_entry_result_t * l2fe_res,
4091 vl_api_l2_fib_table_entry_t * mp;
4093 mp = vl_msg_api_alloc (sizeof (*mp));
4094 memset (mp, 0, sizeof (*mp));
4095 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4097 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4099 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4100 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4101 mp->static_mac = l2fe_res->fields.static_mac;
4102 mp->filter_mac = l2fe_res->fields.filter;
4103 mp->bvi_mac = l2fe_res->fields.bvi;
4104 mp->context = context;
4106 vl_msg_api_send_shmem (q, (u8 *)&mp);
4110 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4112 vpe_api_main_t * am = &vpe_api_main;
4113 bd_main_t * bdm = &bd_main;
4114 l2fib_entry_key_t *l2fe_key = NULL;
4115 l2fib_entry_result_t *l2fe_res = NULL;
4116 u32 ni, bd_id = ntohl (mp->bd_id);
4118 unix_shared_memory_queue_t * q;
4121 q = vl_api_client_index_to_input_queue (mp->client_index);
4125 /* see l2fib_table_dump: ~0 means "any" */
4129 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4136 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4138 vec_foreach_index (ni, l2fe_key) {
4139 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4140 vec_elt_at_index(l2fe_res, ni), mp->context);
4147 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4149 vl_api_show_version_reply_t *rmp;
4151 char * vpe_api_get_build_directory(void);
4152 char * vpe_api_get_version(void);
4153 char * vpe_api_get_build_date(void);
4155 unix_shared_memory_queue_t * q =
4156 vl_api_client_index_to_input_queue (mp->client_index);
4161 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4163 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4164 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4165 ARRAY_LEN(rmp->build_directory)-1);
4166 strncpy ((char *) rmp->version, vpe_api_get_version(),
4167 ARRAY_LEN(rmp->version)-1);
4168 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4169 ARRAY_LEN(rmp->build_date)-1);
4173 static void vl_api_get_node_index_t_handler
4174 (vl_api_get_node_index_t * mp)
4176 vlib_main_t * vm = vlib_get_main();
4177 vl_api_get_node_index_reply_t * rmp;
4180 u32 node_index = ~0;
4182 n = vlib_get_node_by_name (vm, mp->node_name);
4185 rv = VNET_API_ERROR_NO_SUCH_NODE;
4187 node_index = n->index;
4189 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4191 rmp->node_index = ntohl(node_index);
4195 static void vl_api_add_node_next_t_handler
4196 (vl_api_add_node_next_t * mp)
4198 vlib_main_t * vm = vlib_get_main();
4199 vl_api_add_node_next_reply_t * rmp;
4200 vlib_node_t * n, * next;
4202 u32 next_index = ~0;
4204 n = vlib_get_node_by_name (vm, mp->node_name);
4207 rv = VNET_API_ERROR_NO_SUCH_NODE;
4211 next = vlib_get_node_by_name (vm, mp->next_name);
4214 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4216 next_index = vlib_node_add_next (vm, n->index, next->index);
4219 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4221 rmp->next_index = ntohl(next_index);
4225 static void vl_api_l2tpv3_create_tunnel_t_handler
4226 (vl_api_l2tpv3_create_tunnel_t *mp)
4228 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4229 l2t_main_t *lm = &l2t_main;
4230 u32 sw_if_index = (u32)~0;
4233 if (mp->is_ipv6 != 1) {
4234 rv = VNET_API_ERROR_UNIMPLEMENTED;
4238 rv = create_l2tpv3_ipv6_tunnel (lm,
4239 (ip6_address_t *) mp->client_address,
4240 (ip6_address_t *) mp->our_address,
4241 ntohl(mp->local_session_id),
4242 ntohl(mp->remote_session_id),
4243 clib_net_to_host_u64(mp->local_cookie),
4244 clib_net_to_host_u64(mp->remote_cookie),
4245 mp->l2_sublayer_present,
4249 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4251 rmp->sw_if_index = ntohl (sw_if_index);
4255 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4256 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4258 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4259 l2t_main_t *lm = &l2t_main;
4262 VALIDATE_SW_IF_INDEX(mp);
4264 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4265 clib_net_to_host_u64(mp->new_local_cookie),
4266 clib_net_to_host_u64(mp->new_remote_cookie));
4268 BAD_SW_IF_INDEX_LABEL;
4270 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4273 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4274 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4277 vnet_main_t * vnm = vnet_get_main();
4278 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4280 VALIDATE_SW_IF_INDEX(mp);
4282 rv = l2tpv3_interface_enable_disable
4283 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4285 BAD_SW_IF_INDEX_LABEL;
4287 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4290 static void vl_api_l2tpv3_set_lookup_key_t_handler
4291 (vl_api_l2tpv3_set_lookup_key_t * mp)
4294 l2t_main_t *lm = &l2t_main;
4295 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4297 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4298 rv = VNET_API_ERROR_INVALID_VALUE;
4302 lm->lookup_type = mp->key;
4305 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4308 static void vl_api_vxlan_add_del_tunnel_t_handler
4309 (vl_api_vxlan_add_del_tunnel_t * mp)
4311 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4313 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4314 u32 encap_fib_index;
4316 ip4_main_t * im = &ip4_main;
4317 u32 sw_if_index = ~0;
4319 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4321 rv = VNET_API_ERROR_NO_SUCH_FIB;
4324 encap_fib_index = p[0];
4326 /* Check src & dst are different */
4327 if ((a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4328 (!a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4329 rv = VNET_API_ERROR_SAME_SRC_DST;
4332 memset (a, 0, sizeof (*a));
4334 a->is_add = mp->is_add;
4335 a->is_ip6 = mp->is_ipv6;
4337 /* ip addresses sent in network byte order */
4339 memcpy(&(a->src.ip6), mp->src_address, 16);
4340 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4342 memcpy(&(a->src.ip4), mp->src_address, 4);
4343 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4346 a->encap_fib_index = encap_fib_index;
4347 a->decap_next_index = ntohl(mp->decap_next_index);
4348 a->vni = ntohl(mp->vni);
4349 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4352 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4354 rmp->sw_if_index = ntohl (sw_if_index);
4358 static void send_vxlan_tunnel_details
4359 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4361 vl_api_vxlan_tunnel_details_t * rmp;
4362 ip4_main_t * im4 = &ip4_main;
4363 ip6_main_t * im6 = &ip6_main;
4364 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4366 rmp = vl_msg_api_alloc (sizeof (*rmp));
4367 memset (rmp, 0, sizeof (*rmp));
4368 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4370 memcpy(rmp->src_address, &(t->src.ip6), 16);
4371 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4372 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4374 memcpy(rmp->src_address, &(t->src.ip4), 4);
4375 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4376 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4378 rmp->vni = htonl(t->vni);
4379 rmp->decap_next_index = htonl(t->decap_next_index);
4380 rmp->sw_if_index = htonl(t->sw_if_index);
4381 rmp->is_ipv6 = is_ipv6;
4382 rmp->context = context;
4384 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4387 static void vl_api_vxlan_tunnel_dump_t_handler
4388 (vl_api_vxlan_tunnel_dump_t * mp)
4390 unix_shared_memory_queue_t * q;
4391 vxlan_main_t * vxm = &vxlan_main;
4395 q = vl_api_client_index_to_input_queue (mp->client_index);
4400 sw_if_index = ntohl(mp->sw_if_index);
4402 if (~0 == sw_if_index) {
4403 pool_foreach (t, vxm->tunnels,
4405 send_vxlan_tunnel_details(t, q, mp->context);
4408 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4409 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4412 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4413 send_vxlan_tunnel_details(t, q, mp->context);
4417 static void vl_api_gre_add_del_tunnel_t_handler
4418 (vl_api_gre_add_del_tunnel_t * mp)
4420 vl_api_gre_add_del_tunnel_reply_t * rmp;
4422 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4425 ip4_main_t * im = &ip4_main;
4426 u32 sw_if_index = ~0;
4428 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_table_id));
4430 rv = VNET_API_ERROR_NO_SUCH_FIB;
4433 outer_table_id = p[0];
4435 /* Check src & dst are different */
4436 if (memcmp(&mp->src_address, &mp->dst_address, 4) == 0) {
4437 rv = VNET_API_ERROR_SAME_SRC_DST;
4441 memset (a, 0, sizeof (*a));
4443 a->is_add = mp->is_add;
4445 /* ip addresses sent in network byte order */
4446 a->src.as_u32 = mp->src_address;
4447 a->dst.as_u32 = mp->dst_address;
4449 a->outer_table_id = outer_table_id;
4450 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4453 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4455 rmp->sw_if_index = ntohl (sw_if_index);
4459 static void send_gre_tunnel_details
4460 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4462 vl_api_gre_tunnel_details_t * rmp;
4463 ip4_main_t * im = &ip4_main;
4465 rmp = vl_msg_api_alloc (sizeof (*rmp));
4466 memset (rmp, 0, sizeof (*rmp));
4467 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4468 rmp->src_address = t->tunnel_src.data_u32;
4469 rmp->dst_address = t->tunnel_dst.data_u32;
4470 rmp->outer_table_id = htonl(im->fibs[t->outer_fib_index].table_id);
4471 rmp->sw_if_index = htonl(t->sw_if_index);
4472 rmp->context = context;
4474 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4477 static void vl_api_gre_tunnel_dump_t_handler
4478 (vl_api_gre_tunnel_dump_t * mp)
4480 unix_shared_memory_queue_t * q;
4481 gre_main_t * gm = &gre_main;
4485 q = vl_api_client_index_to_input_queue (mp->client_index);
4490 sw_if_index = ntohl(mp->sw_if_index);
4492 if (~0 == sw_if_index) {
4493 pool_foreach (t, gm->tunnels,
4495 send_gre_tunnel_details(t, q, mp->context);
4498 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4499 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4502 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4503 send_gre_tunnel_details(t, q, mp->context);
4508 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4510 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4512 vl_api_l2_patch_add_del_reply_t * rmp;
4513 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4517 VALIDATE_RX_SW_IF_INDEX(mp);
4518 VALIDATE_TX_SW_IF_INDEX(mp);
4520 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4521 ntohl(mp->tx_sw_if_index),
4522 (int)(mp->is_add != 0));
4524 BAD_RX_SW_IF_INDEX_LABEL;
4525 BAD_TX_SW_IF_INDEX_LABEL;
4527 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4531 vl_api_nsh_gre_add_del_tunnel_t_handler
4532 (vl_api_nsh_gre_add_del_tunnel_t * mp)
4534 vl_api_nsh_gre_add_del_tunnel_reply_t * rmp;
4536 vnet_nsh_gre_add_del_tunnel_args_t _a, *a = &_a;
4537 u32 encap_fib_index, decap_fib_index;
4538 u32 decap_next_index;
4540 ip4_main_t * im = &ip4_main;
4542 u32 sw_if_index = ~0;
4545 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4547 rv = VNET_API_ERROR_NO_SUCH_FIB;
4550 encap_fib_index = p[0];
4552 decap_next_index = ntohl(mp->decap_next_index);
4554 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4555 if (decap_next_index == NSH_GRE_INPUT_NEXT_IP4_INPUT) {
4556 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4558 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4561 decap_fib_index = p[0];
4563 decap_fib_index = ntohl(mp->decap_vrf_id);
4566 memset (a, 0, sizeof (*a));
4568 a->is_add = mp->is_add;
4569 /* ip addresses sent in network byte order */
4570 a->src.as_u32 = ntohl(mp->src);
4571 a->dst.as_u32 = ntohl(mp->dst);
4572 a->encap_fib_index = encap_fib_index;
4573 a->decap_fib_index = decap_fib_index;
4574 a->decap_next_index = decap_next_index;
4575 a->nsh_hdr.ver_o_c = mp->ver_o_c;
4576 a->nsh_hdr.length = mp->length;
4577 a->nsh_hdr.md_type = mp->md_type;
4578 a->nsh_hdr.next_protocol = mp->next_protocol;
4579 a->nsh_hdr.spi_si = ntohl(mp->spi_si);
4580 a->nsh_hdr.c1 = ntohl(mp->c1);
4581 a->nsh_hdr.c2 = ntohl(mp->c2);
4582 a->nsh_hdr.c3 = ntohl(mp->c3);
4583 a->nsh_hdr.c4 = ntohl(mp->c4);
4585 for (i = 0; i < mp->tlv_len_in_words; i++)
4586 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4588 a->nsh_hdr.tlvs = tlvs;
4590 rv = vnet_nsh_gre_add_del_tunnel (a, &sw_if_index);
4593 REPLY_MACRO2(VL_API_NSH_GRE_ADD_DEL_TUNNEL_REPLY,
4595 rmp->sw_if_index = ntohl (sw_if_index);
4600 vl_api_nsh_vxlan_gpe_add_del_tunnel_t_handler
4601 (vl_api_nsh_vxlan_gpe_add_del_tunnel_t * mp)
4603 vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4605 vnet_nsh_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4606 u32 encap_fib_index, decap_fib_index;
4607 u32 decap_next_index;
4609 ip4_main_t * im = &ip4_main;
4611 u32 sw_if_index = ~0;
4614 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4616 rv = VNET_API_ERROR_NO_SUCH_FIB;
4619 encap_fib_index = p[0];
4621 decap_next_index = ntohl(mp->decap_next_index);
4623 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4624 if (decap_next_index == NSH_GRE_INPUT_NEXT_IP4_INPUT) {
4625 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4627 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4630 decap_fib_index = p[0];
4632 decap_fib_index = ntohl(mp->decap_vrf_id);
4635 memset (a, 0, sizeof (*a));
4637 a->is_add = mp->is_add;
4638 /* ip addresses sent in network byte order */
4639 a->src.as_u32 = ntohl(mp->src);
4640 a->dst.as_u32 = ntohl(mp->dst);
4641 a->encap_fib_index = encap_fib_index;
4642 a->decap_fib_index = decap_fib_index;
4643 a->decap_next_index = decap_next_index;
4644 a->vni = ntohl(mp->vni);
4645 a->nsh_hdr.ver_o_c = mp->ver_o_c;
4646 a->nsh_hdr.length = mp->length;
4647 a->nsh_hdr.md_type = mp->md_type;
4648 a->nsh_hdr.next_protocol = mp->next_protocol;
4649 a->nsh_hdr.spi_si = ntohl(mp->spi_si);
4650 a->nsh_hdr.c1 = ntohl(mp->c1);
4651 a->nsh_hdr.c2 = ntohl(mp->c2);
4652 a->nsh_hdr.c3 = ntohl(mp->c3);
4653 a->nsh_hdr.c4 = ntohl(mp->c4);
4655 for (i = 0; i < mp->tlv_len_in_words; i++)
4656 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4658 a->nsh_hdr.tlvs = tlvs;
4660 rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4663 REPLY_MACRO2(VL_API_NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4665 rmp->sw_if_index = ntohl (sw_if_index);
4670 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4672 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4674 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4676 u8 *locator_name = NULL;
4678 memset(a, 0, sizeof(a[0]));
4680 locator_name = format(0, "%s", mp->locator_set_name);
4682 a->name = locator_name;
4684 a->is_add = mp->is_add;
4687 rv = vnet_lisp_add_del_locator_set_name(a, &ls_index);
4689 vec_free(locator_name);
4691 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4695 vl_api_lisp_add_del_locator_t_handler(
4696 vl_api_lisp_add_del_locator_t *mp)
4698 vl_api_lisp_add_del_locator_reply_t *rmp;
4700 locator_t locator, *locators = NULL;
4701 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4703 u8 *locator_name = NULL;
4705 memset(&locator, 0, sizeof(locator));
4706 memset(a, 0, sizeof(a[0]));
4708 locator.sw_if_index = ntohl(mp->sw_if_index);
4709 locator.priority = mp->priority;
4710 locator.weight = mp->weight;
4712 vec_add1(locators, locator);
4714 locator_name = format(0, "%s", mp->locator_set_name);
4716 a->name = locator_name;
4717 a->locators = locators;
4718 a->is_add = mp->is_add;
4721 rv = vnet_lisp_add_del_locator(a, &ls_index);
4724 vec_free(locator_name);
4726 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4730 vl_api_lisp_add_del_local_eid_t_handler(
4731 vl_api_lisp_add_del_local_eid_t *mp)
4733 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4734 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4736 ip_prefix_t *prefp = NULL;
4737 ip_address_t *ip_eid = NULL;
4740 u32 locator_set_index = ~0, map_index = ~0;
4741 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4744 prefp = &gid_address_ippref(&eid);
4745 ip_eid = &ip_prefix_addr(prefp);
4746 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4749 clib_memcpy(&ip_addr_v6(ip_eid), mp->ip_address,
4750 sizeof(ip_addr_v6(ip_eid)));
4751 ip_addr_version(ip_eid) = IP6;
4753 clib_memcpy(&ip_addr_v4(ip_eid), mp->ip_address,
4754 sizeof(ip_addr_v4(ip_eid)));
4755 ip_addr_version(ip_eid) = IP4;
4757 ip_prefix_len(prefp) = mp->prefix_len;
4759 name = format(0, "%s", mp->locator_set_name);
4760 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4762 rv = VNET_API_ERROR_INVALID_VALUE;
4765 locator_set_index = p[0];
4767 /* XXX treat batch configuration */
4768 a->is_add = mp->is_add;
4770 a->locator_set_index = locator_set_index;
4773 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4778 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4782 lisp_gpe_add_del_fwd_entry_set_address(
4783 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4784 ip_address_t *slocator,
4785 ip_address_t *dlocator,
4788 ip_address_t *ip_eid = NULL;
4789 ip_prefix_t *prefp = NULL;
4791 prefp = &gid_address_ippref(eid);
4792 ip_eid = &ip_prefix_addr(prefp);
4794 if (mp->eid_is_ipv6) {
4795 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4796 sizeof(ip_addr_v6(ip_eid)));
4797 ip_addr_version(ip_eid) = IP6;
4799 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4800 sizeof(ip_addr_v4(ip_eid)));
4801 ip_addr_version(ip_eid) = IP4;
4803 ip_prefix_len(prefp) = mp->eid_prefix_len;
4805 if (mp->address_is_ipv6) {
4806 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4807 sizeof(ip_addr_v6(slocator)));
4808 ip_addr_version(slocator) = IP6;
4809 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4810 sizeof(ip_addr_v6(dlocator)));
4811 ip_addr_version(dlocator) = IP6;
4813 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4814 sizeof(ip_addr_v4(slocator)));
4815 ip_addr_version(slocator) = IP4;
4816 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4817 sizeof(ip_addr_v4(dlocator)));
4818 ip_addr_version(dlocator) = IP4;
4823 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4824 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4826 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4828 ip_address_t slocator, dlocator;
4830 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4832 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4834 memset (&a, 0, sizeof(a));
4836 a.is_add = mp->is_add;
4838 a.slocator = slocator;
4839 a.dlocator = dlocator;
4840 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4842 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4846 vl_api_lisp_add_del_map_resolver_t_handler(
4847 vl_api_lisp_add_del_map_resolver_t *mp)
4849 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4851 ip_address_t *ip_addr = NULL;
4852 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4854 a->is_add = mp->is_add;
4855 ip_addr = &a->address;
4858 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4859 sizeof(ip_addr_v6(ip_addr)));
4860 ip_addr_version(ip_addr) = IP6;
4862 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4863 sizeof(ip_addr_v4(ip_addr)));
4864 ip_addr_version(ip_addr) = IP4;
4867 rv = vnet_lisp_add_del_map_resolver (a);
4869 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4873 vl_api_lisp_gpe_enable_disable_t_handler(
4874 vl_api_lisp_gpe_enable_disable_t *mp)
4876 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4878 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
4880 a->is_en = mp->is_en;
4881 vnet_lisp_gpe_enable_disable (a);
4883 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4887 vl_api_lisp_enable_disable_t_handler(
4888 vl_api_lisp_enable_disable_t *mp)
4890 vl_api_lisp_enable_disable_reply_t *rmp;
4893 vnet_lisp_enable_disable (mp->is_en);
4894 REPLY_MACRO(VL_API_LISP_ENABLE_DISABLE_REPLY);
4898 vl_api_lisp_gpe_add_del_iface_t_handler(
4899 vl_api_lisp_gpe_add_del_iface_t *mp)
4901 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4903 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4905 a->is_add = mp->is_add;
4906 a->table_id = mp->table_id;
4908 vnet_lisp_gpe_add_del_iface (a, 0);
4910 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4914 send_lisp_locator_set_details_set_address
4915 (vl_api_lisp_locator_set_details_t *rmp,
4916 gid_address_t *gid_address)
4918 ip_prefix_t *ip_addr;
4920 if (gid_address_type(gid_address) != GID_ADDR_IP_PREFIX) {
4924 ip_addr = &gid_address_ippref(gid_address);
4925 rmp->prefix_len = ip_prefix_len(ip_addr);
4926 rmp->is_ipv6 = ip_prefix_version(ip_addr);
4927 ip_address_copy_addr(rmp->ip_address, &ip_prefix_addr(ip_addr));
4931 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
4932 locator_set_t *lsit,
4933 unix_shared_memory_queue_t *q,
4937 vl_api_lisp_locator_set_details_t *rmp;
4938 locator_t *loc = NULL;
4942 vec_foreach (locit, lsit->locator_indices) {
4943 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4944 rmp = vl_msg_api_alloc (sizeof (*rmp));
4945 memset (rmp, 0, sizeof (*rmp));
4946 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
4947 rmp->local = lsit->local;
4949 ASSERT(lsit->name != NULL);
4950 strncpy((char *) rmp->locator_set_name,
4951 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4952 rmp->sw_if_index = htonl(loc->sw_if_index);
4954 str = format(0, "remote-%d", index);
4955 strncpy((char *) rmp->locator_set_name, (char *) str,
4956 ARRAY_LEN(rmp->locator_set_name) - 1);
4957 send_lisp_locator_set_details_set_address(rmp, &loc->address);
4961 rmp->priority = loc->priority;
4962 rmp->weight = loc->weight;
4963 rmp->context = context;
4965 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4970 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
4972 unix_shared_memory_queue_t * q = NULL;
4973 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4974 locator_set_t * lsit = NULL;
4977 q = vl_api_client_index_to_input_queue (mp->client_index);
4983 pool_foreach (lsit, lcm->locator_set_pool,
4985 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
4990 send_lisp_local_eid_table_details (mapping_t *mapit,
4991 unix_shared_memory_queue_t *q,
4994 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
4995 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4996 locator_set_t *ls = NULL;
4997 gid_address_t *gid = NULL;
4998 ip_prefix_t *ip_prefix = NULL;
5002 ls = pool_elt_at_index (lcm->locator_set_pool,
5003 mapit->locator_set_index);
5006 type = gid_address_type(gid);
5008 if (type != GID_ADDR_IP_PREFIX) {
5012 ip_prefix = &gid_address_ippref(gid);
5014 rmp = vl_msg_api_alloc (sizeof (*rmp));
5015 memset (rmp, 0, sizeof (*rmp));
5016 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
5018 ASSERT(ls->name != NULL);
5019 strncpy((char *) rmp->locator_set_name,
5020 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5022 str = format(0, "remote-%d", mapit->locator_set_index);
5023 strncpy((char *) rmp->locator_set_name, (char *) str,
5024 ARRAY_LEN(rmp->locator_set_name) - 1);
5028 switch (ip_prefix_version(ip_prefix)) {
5030 rmp->eid_is_ipv6 = 0;
5031 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v4(ip_prefix),
5032 sizeof(ip_prefix_v4(ip_prefix)));
5036 rmp->eid_is_ipv6 = 1;
5037 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v6(ip_prefix),
5038 sizeof(ip_prefix_v6(ip_prefix)));
5044 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
5045 rmp->context = context;
5047 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5051 vl_api_lisp_local_eid_table_dump_t_handler (
5052 vl_api_lisp_local_eid_table_dump_t *mp)
5054 unix_shared_memory_queue_t * q = NULL;
5055 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5056 mapping_t * mapit = NULL;
5058 q = vl_api_client_index_to_input_queue (mp->client_index);
5063 pool_foreach (mapit, lcm->mapping_pool,
5065 send_lisp_local_eid_table_details(mapit, q, mp->context);
5070 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5071 unix_shared_memory_queue_t *q,
5074 vl_api_lisp_gpe_tunnel_details_t *rmp;
5075 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5077 rmp = vl_msg_api_alloc (sizeof (*rmp));
5078 memset (rmp, 0, sizeof (*rmp));
5079 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5081 rmp->tunnels = tunnel - lgm->tunnels;
5083 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5084 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5085 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5087 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5088 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5089 rmp->dcap_next = htonl(tunnel->decap_next_index);
5090 rmp->lisp_ver = tunnel->ver_res;
5091 rmp->next_protocol = tunnel->next_protocol;
5092 rmp->flags = tunnel->flags;
5093 rmp->ver_res = tunnel->ver_res;
5094 rmp->res = tunnel->res;
5095 rmp->iid = htonl(tunnel->vni);
5096 rmp->context = context;
5098 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5102 vl_api_lisp_gpe_tunnel_dump_t_handler (
5103 vl_api_lisp_local_eid_table_dump_t *mp)
5105 unix_shared_memory_queue_t * q = NULL;
5106 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5107 lisp_gpe_tunnel_t * tunnel = NULL;
5109 if (pool_elts(lgm->tunnels) == 0) {
5113 q = vl_api_client_index_to_input_queue (mp->client_index);
5118 pool_foreach(tunnel, lgm->tunnels,
5120 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5125 send_lisp_map_resolver_details (ip_address_t *ip,
5126 unix_shared_memory_queue_t *q,
5129 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5131 rmp = vl_msg_api_alloc (sizeof (*rmp));
5132 memset (rmp, 0, sizeof (*rmp));
5133 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5135 switch (ip_addr_version(ip)) {
5138 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5143 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5149 rmp->context = context;
5151 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5155 vl_api_lisp_map_resolver_dump_t_handler (
5156 vl_api_lisp_local_eid_table_dump_t *mp)
5158 unix_shared_memory_queue_t * q = NULL;
5159 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5160 ip_address_t *ip = NULL;
5162 q = vl_api_client_index_to_input_queue (mp->client_index);
5167 vec_foreach(ip, lcm->map_resolvers) {
5168 send_lisp_map_resolver_details(ip, q, mp->context);
5174 send_lisp_enable_disable_details (unix_shared_memory_queue_t *q,
5177 vl_api_lisp_enable_disable_status_details_t *rmp = NULL;
5179 rmp = vl_msg_api_alloc (sizeof (*rmp));
5180 memset (rmp, 0, sizeof (*rmp));
5181 rmp->_vl_msg_id = ntohs(VL_API_LISP_ENABLE_DISABLE_STATUS_DETAILS);
5183 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5184 rmp->feature_status = vnet_lisp_enable_disable_status ();
5185 rmp->context = context;
5187 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5191 vl_api_lisp_enable_disable_status_dump_t_handler
5192 (vl_api_lisp_enable_disable_status_dump_t *mp)
5194 unix_shared_memory_queue_t * q = NULL;
5196 q = vl_api_client_index_to_input_queue (mp->client_index);
5201 send_lisp_enable_disable_details(q, mp->context);
5205 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5207 vl_api_interface_name_renumber_reply_t * rmp;
5210 VALIDATE_SW_IF_INDEX(mp);
5212 rv = vnet_interface_name_renumber
5213 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5215 BAD_SW_IF_INDEX_LABEL;
5217 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5220 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5221 u32 sw_if_index, u32 address)
5223 vpe_api_main_t * am = &vpe_api_main;
5224 vlib_main_t * vm = am->vlib_main;
5225 vl_api_ip4_arp_event_t * event;
5226 static f64 arp_event_last_time;
5227 f64 now = vlib_time_now (vm);
5229 if (pool_is_free_index (am->arp_events, pool_index))
5232 event = pool_elt_at_index (am->arp_events, pool_index);
5233 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5234 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5235 } else { /* same mac */
5236 if ((sw_if_index == event->sw_if_index) &&
5238 /* for BD case, also check IP address with 10 sec timeout */
5239 ((address == event->address) &&
5240 ((now - arp_event_last_time) < 10.0))))
5244 arp_event_last_time = now;
5245 event->sw_if_index = sw_if_index;
5246 if (address) event->address = address;
5250 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5252 vpe_api_main_t * am = &vpe_api_main;
5254 if (pool_is_free_index (am->arp_events, pool_index))
5257 pool_put_index (am->arp_events, pool_index);
5262 vl_api_want_ip4_arp_events_t_handler
5263 (vl_api_want_ip4_arp_events_t * mp)
5265 vpe_api_main_t * am = &vpe_api_main;
5266 vnet_main_t * vnm = vnet_get_main();
5267 vl_api_want_ip4_arp_events_reply_t *rmp;
5268 vl_api_ip4_arp_event_t * event;
5271 if (mp->enable_disable) {
5272 pool_get (am->arp_events, event);
5273 memset (event, 0, sizeof (*event));
5275 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5276 event->client_index = mp->client_index;
5277 event->context = mp->context;
5278 event->address = mp->address;
5279 event->pid = mp->pid;
5281 rv = vnet_add_del_ip4_arp_change_event
5282 (vnm, arp_change_data_callback,
5284 &mp->address /* addr, in net byte order */,
5285 vpe_resolver_process_node.index,
5286 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5288 rv = vnet_add_del_ip4_arp_change_event
5289 (vnm, arp_change_delete_callback,
5291 &mp->address /* addr, in net byte order */,
5292 vpe_resolver_process_node.index,
5293 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5295 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5298 static void vl_api_input_acl_set_interface_t_handler
5299 (vl_api_input_acl_set_interface_t * mp)
5301 vlib_main_t *vm = vlib_get_main();
5302 vl_api_input_acl_set_interface_reply_t * rmp;
5304 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5306 ip4_table_index = ntohl(mp->ip4_table_index);
5307 ip6_table_index = ntohl(mp->ip6_table_index);
5308 l2_table_index = ntohl(mp->l2_table_index);
5309 sw_if_index = ntohl(mp->sw_if_index);
5311 VALIDATE_SW_IF_INDEX(mp);
5313 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5314 ip6_table_index, l2_table_index,
5317 BAD_SW_IF_INDEX_LABEL;
5319 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5322 static void vl_api_ipsec_spd_add_del_t_handler
5323 (vl_api_ipsec_spd_add_del_t * mp)
5326 clib_warning ("unimplemented");
5329 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5330 vl_api_ipsec_spd_add_del_reply_t * rmp;
5334 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5336 rv = VNET_API_ERROR_UNIMPLEMENTED;
5339 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5343 static void vl_api_ipsec_interface_add_del_spd_t_handler
5344 (vl_api_ipsec_interface_add_del_spd_t * mp)
5346 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5347 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5349 u32 sw_if_index __attribute__((unused));
5350 u32 spd_id __attribute__((unused));
5352 sw_if_index = ntohl(mp->sw_if_index);
5353 spd_id = ntohl(mp->spd_id);
5355 VALIDATE_SW_IF_INDEX(mp);
5358 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5360 rv = VNET_API_ERROR_UNIMPLEMENTED;
5363 BAD_SW_IF_INDEX_LABEL;
5365 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5368 static void vl_api_ipsec_spd_add_del_entry_t_handler
5369 (vl_api_ipsec_spd_add_del_entry_t * mp)
5371 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5372 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5378 memset(&p, 0, sizeof(p));
5380 p.id = ntohl(mp->spd_id);
5381 p.priority = ntohl(mp->priority);
5382 p.is_outbound = mp->is_outbound;
5383 p.is_ipv6 = mp->is_ipv6;
5385 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5386 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5387 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5388 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5390 p.protocol = mp->protocol;
5391 p.rport.start = ntohs(mp->remote_port_start);
5392 p.rport.stop = ntohs(mp->remote_port_stop);
5393 p.lport.start = ntohs(mp->local_port_start);
5394 p.lport.stop = ntohs(mp->local_port_stop);
5395 /* policy action resolve unsupported */
5396 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5397 clib_warning("unsupported action: 'resolve'");
5398 rv = VNET_API_ERROR_UNIMPLEMENTED;
5401 p.policy = mp->policy;
5402 p.sa_id = ntohl(mp->sa_id);
5404 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5408 if (mp->is_ip_any) {
5410 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5413 rv = VNET_API_ERROR_UNIMPLEMENTED;
5418 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5421 static void vl_api_ipsec_sad_add_del_entry_t_handler
5422 (vl_api_ipsec_sad_add_del_entry_t * mp)
5424 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5425 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5430 memset(&sa, 0, sizeof(sa));
5432 sa.id = ntohl(mp->sad_id);
5433 sa.spi = ntohl(mp->spi);
5434 /* security protocol AH unsupported */
5435 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5436 clib_warning("unsupported security protocol 'AH'");
5437 rv = VNET_API_ERROR_UNIMPLEMENTED;
5440 sa.protocol = mp->protocol;
5441 /* check for unsupported crypto-alg */
5442 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5443 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5444 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5445 mp->crypto_algorithm);
5446 rv = VNET_API_ERROR_UNIMPLEMENTED;
5449 sa.crypto_alg = mp->crypto_algorithm;
5450 sa.crypto_key_len = mp->crypto_key_length;
5451 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5452 /* check for unsupported integ-alg */
5453 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5454 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5455 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5456 mp->integrity_algorithm);
5457 rv = VNET_API_ERROR_UNIMPLEMENTED;
5460 sa.integ_alg = mp->integrity_algorithm;
5461 sa.integ_key_len = mp->integrity_key_length;
5462 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5463 sa.use_esn = mp->use_extended_sequence_number;
5464 sa.is_tunnel = mp->is_tunnel;
5465 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5466 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5467 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5469 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5471 rv = VNET_API_ERROR_UNIMPLEMENTED;
5476 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5480 vl_api_ikev2_profile_add_del_t_handler
5481 (vl_api_ikev2_profile_add_del_t * mp)
5483 vl_api_ikev2_profile_add_del_reply_t * rmp;
5487 vlib_main_t * vm = vlib_get_main();
5488 clib_error_t * error;
5489 u8 * tmp = format(0, "%s", mp->name);
5490 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5493 rv = VNET_API_ERROR_UNSPECIFIED;
5495 rv = VNET_API_ERROR_UNIMPLEMENTED;
5498 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5502 vl_api_ikev2_profile_set_auth_t_handler
5503 (vl_api_ikev2_profile_set_auth_t * mp)
5505 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5509 vlib_main_t * vm = vlib_get_main();
5510 clib_error_t * error;
5511 u8 * tmp = format(0, "%s", mp->name);
5512 u8 * data = vec_new (u8, mp->data_len);
5513 clib_memcpy(data, mp->data, mp->data_len);
5514 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5518 rv = VNET_API_ERROR_UNSPECIFIED;
5520 rv = VNET_API_ERROR_UNIMPLEMENTED;
5523 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5527 vl_api_ikev2_profile_set_id_t_handler
5528 (vl_api_ikev2_profile_set_id_t * mp)
5530 vl_api_ikev2_profile_add_del_reply_t * rmp;
5534 vlib_main_t * vm = vlib_get_main();
5535 clib_error_t * error;
5536 u8 * tmp = format(0, "%s", mp->name);
5537 u8 * data = vec_new (u8, mp->data_len);
5538 clib_memcpy(data, mp->data, mp->data_len);
5539 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
5543 rv = VNET_API_ERROR_UNSPECIFIED;
5545 rv = VNET_API_ERROR_UNIMPLEMENTED;
5548 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5552 vl_api_ikev2_profile_set_ts_t_handler
5553 (vl_api_ikev2_profile_set_ts_t * mp)
5555 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5559 vlib_main_t * vm = vlib_get_main();
5560 clib_error_t * error;
5561 u8 * tmp = format(0, "%s", mp->name);
5562 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
5563 mp->end_port, (ip4_address_t) mp->start_addr,
5564 (ip4_address_t) mp->end_addr, mp->is_local);
5567 rv = VNET_API_ERROR_UNSPECIFIED;
5569 rv = VNET_API_ERROR_UNIMPLEMENTED;
5572 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5576 vl_api_ikev2_set_local_key_t_handler
5577 (vl_api_ikev2_set_local_key_t * mp)
5579 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5583 vlib_main_t * vm = vlib_get_main();
5584 clib_error_t * error;
5586 error = ikev2_set_local_key(vm, mp->key_file);
5588 rv = VNET_API_ERROR_UNSPECIFIED;
5590 rv = VNET_API_ERROR_UNIMPLEMENTED;
5593 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5597 vl_api_map_add_domain_t_handler
5598 (vl_api_map_add_domain_t * mp)
5600 vl_api_map_add_domain_reply_t * rmp;
5603 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
5604 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
5605 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
5606 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
5607 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
5609 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
5611 rmp->index = ntohl(index);
5616 vl_api_map_del_domain_t_handler
5617 (vl_api_map_del_domain_t * mp)
5619 vl_api_map_del_domain_reply_t * rmp;
5622 rv = map_delete_domain(ntohl(mp->index));
5624 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
5628 vl_api_map_add_del_rule_t_handler
5629 (vl_api_map_add_del_rule_t * mp)
5631 vl_api_map_del_domain_reply_t * rmp;
5634 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
5636 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
5640 vl_api_map_domain_dump_t_handler
5641 (vl_api_map_domain_dump_t * mp)
5643 vl_api_map_domain_details_t * rmp;
5644 map_main_t *mm = &map_main;
5646 unix_shared_memory_queue_t * q;
5648 if (pool_elts (mm->domains) == 0)
5651 q = vl_api_client_index_to_input_queue (mp->client_index);
5656 pool_foreach(d, mm->domains, ({
5657 /* Make sure every field is initiated (or don't skip the memset()) */
5658 rmp = vl_msg_api_alloc (sizeof (*rmp));
5659 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
5660 rmp->domain_index = htonl(d - mm->domains);
5661 rmp->ea_bits_len = d->ea_bits_len;
5662 rmp->psid_offset = d->psid_offset;
5663 rmp->psid_length = d->psid_length;
5664 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
5665 rmp->ip4_prefix_len = d->ip4_prefix_len;
5666 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
5667 rmp->ip6_prefix_len = d->ip6_prefix_len;
5668 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
5669 rmp->ip6_src_len = d->ip6_src_len;
5670 rmp->mtu = htons(d->mtu);
5671 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
5672 rmp->context = mp->context;
5674 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5679 vl_api_map_rule_dump_t_handler
5680 (vl_api_map_rule_dump_t * mp)
5682 unix_shared_memory_queue_t * q;
5685 vl_api_map_rule_details_t * rmp;
5686 map_main_t *mm = &map_main;
5687 u32 domain_index = ntohl(mp->domain_index);
5690 if (pool_elts (mm->domains) == 0)
5693 d = pool_elt_at_index(mm->domains, domain_index);
5694 if (!d || !d->rules) {
5698 q = vl_api_client_index_to_input_queue (mp->client_index);
5703 for (i = 0; i < (0x1 << d->psid_length); i++) {
5705 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
5708 rmp = vl_msg_api_alloc(sizeof(*rmp));
5709 memset(rmp, 0, sizeof(*rmp));
5710 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
5711 rmp->psid = htons(i);
5712 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
5713 rmp->context = mp->context;
5714 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5719 vl_api_map_summary_stats_t_handler (
5720 vl_api_map_summary_stats_t *mp)
5722 vl_api_map_summary_stats_reply_t *rmp;
5723 vlib_combined_counter_main_t *cm;
5726 u64 total_pkts[VLIB_N_RX_TX];
5727 u64 total_bytes[VLIB_N_RX_TX];
5728 map_main_t *mm = &map_main;
5729 unix_shared_memory_queue_t *q =
5730 vl_api_client_index_to_input_queue(mp->client_index);
5735 rmp = vl_msg_api_alloc (sizeof (*rmp));
5736 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
5737 rmp->context = mp->context;
5740 memset (total_pkts, 0, sizeof (total_pkts));
5741 memset (total_bytes, 0, sizeof (total_bytes));
5743 map_domain_counter_lock (mm);
5744 vec_foreach(cm, mm->domain_counters) {
5745 which = cm - mm->domain_counters;
5747 for (i = 0; i < vec_len(cm->maxi); i++) {
5748 vlib_get_combined_counter (cm, i, &v);
5749 total_pkts[which] += v.packets;
5750 total_bytes[which] += v.bytes;
5754 map_domain_counter_unlock (mm);
5756 /* Note: in network byte order! */
5757 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
5758 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
5759 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
5760 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
5761 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
5762 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
5763 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(map_error_counter_get(ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
5764 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(map_error_counter_get(ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
5766 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5769 static void vl_api_ipsec_sa_set_key_t_handler
5770 (vl_api_ipsec_sa_set_key_t * mp)
5772 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5773 vl_api_ipsec_sa_set_key_reply_t *rmp;
5777 sa.id = ntohl(mp->sa_id);
5778 sa.crypto_key_len = mp->crypto_key_length;
5779 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5780 sa.integ_key_len = mp->integrity_key_length;
5781 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5783 rv = ipsec_set_sa_key(vm, &sa);
5785 rv = VNET_API_ERROR_UNIMPLEMENTED;
5788 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
5791 static void vl_api_cop_interface_enable_disable_t_handler
5792 (vl_api_cop_interface_enable_disable_t * mp)
5794 vl_api_cop_interface_enable_disable_reply_t * rmp;
5796 u32 sw_if_index = ntohl(mp->sw_if_index);
5799 VALIDATE_SW_IF_INDEX(mp);
5801 enable_disable = (int) mp->enable_disable;
5803 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5805 BAD_SW_IF_INDEX_LABEL;
5807 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5810 static void vl_api_cop_whitelist_enable_disable_t_handler
5811 (vl_api_cop_whitelist_enable_disable_t * mp)
5813 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
5814 cop_whitelist_enable_disable_args_t _a, *a=&_a;
5815 u32 sw_if_index = ntohl(mp->sw_if_index);
5818 VALIDATE_SW_IF_INDEX(mp);
5820 a->sw_if_index = sw_if_index;
5823 a->default_cop = mp->default_cop;
5824 a->fib_id = ntohl(mp->fib_id);
5826 rv = cop_whitelist_enable_disable (a);
5828 BAD_SW_IF_INDEX_LABEL;
5830 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5833 static void vl_api_get_node_graph_t_handler
5834 (vl_api_get_node_graph_t * mp)
5838 api_main_t * am = &api_main;
5839 vlib_main_t * vm = vlib_get_main();
5841 vl_api_get_node_graph_reply_t * rmp;
5843 pthread_mutex_lock (&am->vlib_rp->mutex);
5844 oldheap = svm_push_data_heap (am->vlib_rp);
5847 * Keep the number of memcpy ops to a minimum (e.g. 1).
5848 * The current size of the serialized vector is
5849 * slightly under 4K.
5851 vec_validate (vector, 4095);
5852 vec_reset_length (vector);
5854 vector = vlib_node_serialize (&vm->node_main, vector);
5856 svm_pop_heap (oldheap);
5857 pthread_mutex_unlock (&am->vlib_rp->mutex);
5859 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5860 rmp->reply_in_shmem = (uword) vector);
5863 static void vl_api_trace_profile_add_t_handler
5864 (vl_api_trace_profile_add_t *mp)
5867 vl_api_trace_profile_add_reply_t * rmp;
5868 clib_error_t *error;
5870 /* Ignoring the profile id as currently a single profile
5872 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5873 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5874 mp->pow_enable, mp->trace_tsp,
5877 clib_error_report(error);
5878 rv = clib_error_get_code(error);
5881 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5884 static void vl_api_trace_profile_apply_t_handler
5885 (vl_api_trace_profile_apply_t *mp)
5888 vl_api_trace_profile_apply_reply_t * rmp;
5890 if (mp->enable != 0) {
5891 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5892 ntohl(mp->prefix_length),
5894 mp->trace_op == IOAM_HBYH_ADD,
5895 mp->trace_op == IOAM_HBYH_POP,
5896 mp->trace_op == IOAM_HBYH_MOD);
5898 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5900 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5903 static void vl_api_trace_profile_del_t_handler
5904 (vl_api_trace_profile_del_t *mp)
5907 vl_api_trace_profile_del_reply_t * rmp;
5908 clib_error_t *error;
5910 error = clear_ioam_rewrite_fn();
5912 clib_error_report(error);
5913 rv = clib_error_get_code(error);
5916 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5920 vl_api_af_packet_create_t_handler
5921 (vl_api_af_packet_create_t *mp)
5923 vlib_main_t *vm = vlib_get_main();
5924 vl_api_af_packet_create_reply_t *rmp;
5926 u8 *host_if_name = NULL;
5928 host_if_name = format(0, "%s", mp->host_if_name);
5929 vec_add1 (host_if_name, 0);
5931 rv = af_packet_create_if(vm, host_if_name,
5932 mp->use_random_hw_addr ? 0 : mp->hw_addr);
5934 vec_free(host_if_name);
5936 REPLY_MACRO(VL_API_AF_PACKET_CREATE_REPLY);
5940 vl_api_af_packet_delete_t_handler
5941 (vl_api_af_packet_delete_t *mp)
5943 vlib_main_t * vm = vlib_get_main();
5944 vl_api_af_packet_delete_reply_t *rmp;
5946 u8 *host_if_name = NULL;
5948 host_if_name = format(0, "%s", mp->host_if_name);
5949 vec_add1 (host_if_name, 0);
5951 rv = af_packet_delete_if(vm, host_if_name);
5953 vec_free(host_if_name);
5955 REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY);
5958 #define BOUNCE_HANDLER(nn) \
5959 static void vl_api_##nn##_t_handler ( \
5960 vl_api_##nn##_t *mp) \
5962 vpe_client_registration_t *reg; \
5963 vpe_api_main_t * vam = &vpe_api_main; \
5964 unix_shared_memory_queue_t * q; \
5966 /* One registration only... */ \
5967 pool_foreach(reg, vam->nn##_registrations, \
5969 q = vl_api_client_index_to_input_queue (reg->client_index); \
5972 * If the queue is stuffed, turf the msg and complain \
5973 * It's unlikely that the intended recipient is \
5974 * alive; avoid deadlock at all costs. \
5976 if (q->cursize == q->maxsize) { \
5977 clib_warning ("ERROR: receiver queue full, drop msg"); \
5978 vl_msg_api_free (mp); \
5981 vl_msg_api_send_shmem (q, (u8 *)&mp); \
5985 vl_msg_api_free (mp); \
5990 * Add vpe's API message handlers to the table.
5991 * vlib has alread mapped shared memory and
5992 * added the client registration handlers.
5993 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
5996 static clib_error_t *
5997 vpe_api_hookup (vlib_main_t *vm)
5999 api_main_t * am = &api_main;
6002 vl_msg_api_set_handlers(VL_API_##N, #n, \
6003 vl_api_##n##_t_handler, \
6005 vl_api_##n##_t_endian, \
6006 vl_api_##n##_t_print, \
6007 sizeof(vl_api_##n##_t), 1);
6008 foreach_vpe_api_msg;
6012 * Manually register the sr tunnel add del msg, so we trace
6013 * enough bytes to capture a typical segment list
6015 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
6016 "sr_tunnel_add_del",
6017 vl_api_sr_tunnel_add_del_t_handler,
6019 vl_api_sr_tunnel_add_del_t_endian,
6020 vl_api_sr_tunnel_add_del_t_print,
6025 * Manually register the sr policy add del msg, so we trace
6026 * enough bytes to capture a typical tunnel name list
6028 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
6029 "sr_policy_add_del",
6030 vl_api_sr_policy_add_del_t_handler,
6032 vl_api_sr_policy_add_del_t_endian,
6033 vl_api_sr_policy_add_del_t_print,
6037 * Trace space for 8 MPLS encap labels, classifier mask+match
6039 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
6040 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
6041 += 5 * sizeof (u32x4);
6042 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
6043 += 5 * sizeof (u32x4);
6044 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
6045 += 16 * sizeof (u32);
6048 * trace space for 4 nsh-gre variable TLV words
6050 am->api_trace_cfg [VL_API_NSH_GRE_ADD_DEL_TUNNEL].size
6051 += 4 * sizeof (u32);
6054 * Thread-safe API messages
6056 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
6061 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
6063 static clib_error_t *
6064 vpe_api_init (vlib_main_t *vm)
6066 vpe_api_main_t *am = &vpe_api_main;
6069 am->vnet_main = vnet_get_main();
6070 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
6071 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6072 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6073 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6074 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6075 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
6078 vl_set_memory_region_name ("/vpe-api");
6079 vl_enable_disable_memory_api (vm, 1 /* enable it */);
6084 VLIB_INIT_FUNCTION(vpe_api_init);
6086 static clib_error_t *
6087 chroot_config (vlib_main_t * vm, unformat_input_t * input)
6091 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6093 if (unformat (input, "prefix %s", &chroot_path))
6095 vec_add1 (chroot_path, 0);
6096 vl_set_memory_root_path ((char *)chroot_path);
6099 return clib_error_return (0, "unknown input `%U'",
6100 format_unformat_error, input);
6104 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
6106 void * get_unformat_vnet_sw_interface (void)
6108 return (void *) &unformat_vnet_sw_interface;
6111 #undef vl_api_version
6112 #define vl_api_version(n,v) static u32 vpe_api_version = v;
6113 #include <api/vpe.api.h>
6114 #undef vl_api_version
6116 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
6118 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
6119 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
6120 clib_host_to_net_u32 (mp->api_versions[0]),
6127 static u8 * format_arp_event (u8 * s, va_list * args)
6129 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
6131 s = format (s, "pid %d: %U", event->pid,
6132 format_ip4_address, &event->address);
6136 static clib_error_t *
6137 show_ip4_arp_events_fn (vlib_main_t * vm,
6138 unformat_input_t * input,
6139 vlib_cli_command_t * cmd)
6141 vpe_api_main_t * am = &vpe_api_main;
6142 vl_api_ip4_arp_event_t * event;
6144 if (pool_elts (am->arp_events) == 0) {
6145 vlib_cli_output (vm, "No active arp event registrations");
6149 pool_foreach (event, am->arp_events,
6151 vlib_cli_output (vm, "%U", format_arp_event, event);
6157 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
6158 .path = "show arp event registrations",
6159 .function = show_ip4_arp_events_fn,
6160 .short_help = "Show arp event registrations",