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>
79 #undef __included_bihash_template_h__
80 #include <vnet/l2/l2_fib.h>
83 #include <vnet/ipsec/ipsec.h>
84 #include <vnet/ipsec/ikev2.h>
87 #include <vnet/devices/virtio/vhost-user.h>
90 #include <stats/stats.h>
93 #include <vnet/ethernet/ethernet.h>
94 #include <vnet/ethernet/arp_packet.h>
95 #include <vnet/interface.h>
97 #include <vnet/l2/l2_fib.h>
98 #include <vnet/l2/l2_bd.h>
99 #include <api/vpe_msg_enum.h>
101 #define f64_endian(a)
102 #define f64_print(a,b)
104 #define vl_typedefs /* define message structures */
105 #include <api/vpe_all_api_h.h>
108 #define vl_endianfun /* define message structures */
109 #include <api/vpe_all_api_h.h>
112 /* instantiate all the print functions we know about */
113 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
115 #include <api/vpe_all_api_h.h>
118 #define REPLY_MACRO(t) \
120 unix_shared_memory_queue_t * q; \
121 rv = vl_msg_api_pd_handler (mp, rv); \
122 q = vl_api_client_index_to_input_queue (mp->client_index); \
126 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
127 rmp->_vl_msg_id = ntohs((t)); \
128 rmp->context = mp->context; \
129 rmp->retval = ntohl(rv); \
131 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
134 #define REPLY_MACRO2(t, body) \
136 unix_shared_memory_queue_t * q; \
137 rv = vl_msg_api_pd_handler (mp, rv); \
138 q = vl_api_client_index_to_input_queue (mp->client_index); \
142 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
143 rmp->_vl_msg_id = ntohs((t)); \
144 rmp->context = mp->context; \
145 rmp->retval = ntohl(rv); \
146 do {body;} while (0); \
147 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
150 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
152 #define VALIDATE_SW_IF_INDEX(mp) \
153 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
154 vnet_main_t *__vnm = vnet_get_main(); \
155 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
157 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
158 goto bad_sw_if_index; \
162 #define BAD_SW_IF_INDEX_LABEL \
168 #define VALIDATE_RX_SW_IF_INDEX(mp) \
169 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
170 vnet_main_t *__vnm = vnet_get_main(); \
171 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
172 __rx_sw_if_index)) { \
173 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
174 goto bad_rx_sw_if_index; \
178 #define BAD_RX_SW_IF_INDEX_LABEL \
180 bad_rx_sw_if_index: \
184 #define VALIDATE_TX_SW_IF_INDEX(mp) \
185 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
186 vnet_main_t *__vnm = vnet_get_main(); \
187 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
188 __tx_sw_if_index)) { \
189 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
190 goto bad_tx_sw_if_index; \
194 #define BAD_TX_SW_IF_INDEX_LABEL \
196 bad_tx_sw_if_index: \
202 #define VALIDATE_SW_IF_INDEX(mp)
203 #define BAD_SW_IF_INDEX_LABEL
204 #define VALIDATE_RX_SW_IF_INDEX(mp)
205 #define BAD_RX_SW_IF_INDEX_LABEL
206 #define VALIDATE_TX_SW_IF_INDEX(mp)
207 #define BAD_TX_SW_IF_INDEX_LABEL
209 #endif /* CLIB_DEBUG > 0 */
211 #define foreach_vpe_api_msg \
212 _(WANT_INTERFACE_EVENTS, want_interface_events) \
213 _(WANT_OAM_EVENTS, want_oam_events) \
214 _(OAM_ADD_DEL, oam_add_del) \
215 _(SW_INTERFACE_DUMP, sw_interface_dump) \
216 _(SW_INTERFACE_DETAILS, sw_interface_details) \
217 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
218 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
219 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
220 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
221 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
222 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
223 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
224 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
225 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
226 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
227 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
228 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
229 _(L2FIB_ADD_DEL, l2fib_add_del) \
230 _(L2_FLAGS, l2_flags) \
231 _(BRIDGE_FLAGS, bridge_flags) \
232 _(TAP_CONNECT, tap_connect) \
233 _(TAP_MODIFY, tap_modify) \
234 _(TAP_DELETE, tap_delete) \
235 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
236 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
237 _(CREATE_SUBIF, create_subif) \
238 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
239 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
240 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
241 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
242 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
243 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
244 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
245 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
246 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
247 _(RESET_FIB, reset_fib) \
248 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
249 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
250 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
251 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
252 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
253 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
254 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
255 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
256 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
257 sw_interface_ip6_set_link_local_address) \
258 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
259 _(CREATE_LOOPBACK, create_loopback) \
260 _(CONTROL_PING, control_ping) \
261 _(CLI_REQUEST, cli_request) \
262 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
263 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
264 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
265 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
266 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
267 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
268 _(GET_NODE_INDEX, get_node_index) \
269 _(ADD_NODE_NEXT, add_node_next) \
270 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
271 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
272 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
273 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
274 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
275 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
276 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
277 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
278 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
279 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
280 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
281 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
282 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
283 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
284 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
285 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
286 _(IP_ADDRESS_DUMP, ip_address_dump) \
287 _(IP_DUMP, ip_dump) \
288 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
289 _(SHOW_VERSION, show_version) \
290 _(NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel) \
291 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
292 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
293 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel) \
294 _(LISP_GPE_ADD_DEL_TUNNEL, lisp_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_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
330 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
331 _(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump) \
332 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
333 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
334 _(LISP_GPE_ENABLE_DISABLE_STATUS_DUMP, \
335 lisp_gpe_enable_disable_status_dump) \
336 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del)
339 #define QUOTE(x) QUOTE_(x)
341 #define foreach_registration_hash \
342 _(interface_events) \
343 _(to_netconf_server) \
344 _(from_netconf_server) \
345 _(to_netconf_client) \
346 _(from_netconf_client) \
350 RESOLVE_IP4_ADD_DEL_ROUTE=1,
351 RESOLVE_IP6_ADD_DEL_ROUTE,
352 RESOLVE_MPLS_ETHERNET_ADD_DEL,
358 vl_api_ip_add_del_route_t r;
359 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
365 #define _(a) uword *a##_registration_hash; \
366 vpe_client_registration_t * a##_registrations;
367 foreach_registration_hash
370 /* notifications happen really early in the game */
371 u8 link_state_process_up;
373 /* ip4 pending route adds */
374 pending_route_t * pending_routes;
376 /* ip4 arp event registration pool */
377 vl_api_ip4_arp_event_t * arp_events;
380 vlib_main_t * vlib_main;
381 vnet_main_t * vnet_main;
384 static vlib_node_registration_t vpe_resolver_process_node;
385 static vpe_api_main_t vpe_api_main;
387 static void send_sw_interface_flags (vpe_api_main_t * am,
388 unix_shared_memory_queue_t *q,
389 vnet_sw_interface_t * swif);
390 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
391 unix_shared_memory_queue_t *q,
394 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
397 /* Clean up all registrations belonging to the indicated client */
398 int vl_api_memclnt_delete_callback (u32 client_index)
400 vpe_api_main_t * vam = &vpe_api_main;
401 vpe_client_registration_t *rp;
403 int stats_memclnt_delete_callback (u32 client_index);
405 stats_memclnt_delete_callback (client_index);
408 p = hash_get (vam->a##_registration_hash, client_index); \
410 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
411 pool_put (vam->a##_registrations, rp); \
412 hash_unset (vam->a##_registration_hash, client_index); \
414 foreach_registration_hash;
419 #define API_LINK_STATE_EVENT 1
420 #define API_ADMIN_UP_DOWN_EVENT 2
423 event_data_cmp (void * a1, void * a2)
428 return (word) e1[0] - (word) e2[0];
432 link_state_process (vlib_main_t * vm,
433 vlib_node_runtime_t * rt,
436 vpe_api_main_t * vam = &vpe_api_main;
437 vnet_main_t * vnm = vam->vnet_main;
438 vnet_sw_interface_t * swif;
439 uword * event_data = 0;
440 vpe_client_registration_t *reg;
442 u32 prev_sw_if_index;
443 unix_shared_memory_queue_t * q;
445 vam->link_state_process_up = 1;
448 vlib_process_wait_for_event (vm);
450 /* Unified list of changed link or admin state sw_if_indices */
451 vlib_process_get_events_with_type
452 (vm, &event_data, API_LINK_STATE_EVENT);
453 vlib_process_get_events_with_type
454 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
456 /* Sort, so we can eliminate duplicates */
457 vec_sort_with_function (event_data, event_data_cmp);
459 prev_sw_if_index = ~0;
461 for (i = 0; i < vec_len(event_data); i++) {
462 /* Only one message per swif */
463 if (prev_sw_if_index == event_data[i])
465 prev_sw_if_index = event_data[i];
467 pool_foreach(reg, vam->interface_events_registrations,
469 q = vl_api_client_index_to_input_queue (reg->client_index);
471 // sw_interface may be deleted already
472 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
475 swif = vnet_get_sw_interface (vnm, event_data[i]);
476 send_sw_interface_flags (vam, q, swif);
481 vec_reset_length (event_data);
487 static clib_error_t *
488 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
489 static clib_error_t *
490 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
492 VLIB_REGISTER_NODE (link_state_process_node,static) = {
493 .function = link_state_process,
494 .type = VLIB_NODE_TYPE_PROCESS,
495 .name = "vpe-link-state-process",
498 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
499 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
501 static clib_error_t *
502 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
504 vpe_api_main_t * vam = &vpe_api_main;
505 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
507 if (vam->link_state_process_up)
508 vlib_process_signal_event (vam->vlib_main,
509 link_state_process_node.index,
510 API_LINK_STATE_EVENT,
515 static clib_error_t *
516 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
518 vpe_api_main_t * vam = &vpe_api_main;
521 * Note: it's perfectly fair to set a subif admin up / admin down.
522 * Note the subtle distinction between this routine and the previous
525 if (vam->link_state_process_up)
526 vlib_process_signal_event (vam->vlib_main,
527 link_state_process_node.index,
528 API_ADMIN_UP_DOWN_EVENT,
533 #define pub_sub_handler(lca,UCA) \
534 static void vl_api_want_##lca##_t_handler ( \
535 vl_api_want_##lca##_t *mp) \
537 vpe_api_main_t *vam = &vpe_api_main; \
538 vpe_client_registration_t *rp; \
539 vl_api_want_##lca##_reply_t *rmp; \
543 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
545 if (mp->enable_disable) { \
546 clib_warning ("pid %d: already enabled...", mp->pid); \
547 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
550 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
551 pool_put (vam->lca##_registrations, rp); \
552 hash_unset (vam->lca##_registration_hash, \
557 if (mp->enable_disable == 0) { \
558 clib_warning ("pid %d: already disabled...", mp->pid); \
559 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
562 pool_get (vam->lca##_registrations, rp); \
563 rp->client_index = mp->client_index; \
564 rp->client_pid = mp->pid; \
565 hash_set (vam->lca##_registration_hash, rp->client_index, \
566 rp - vam->lca##_registrations); \
569 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
572 pub_sub_handler (interface_events,INTERFACE_EVENTS)
573 pub_sub_handler (oam_events,OAM_EVENTS)
575 #define RESOLUTION_EVENT 1
576 #define RESOLUTION_PENDING_EVENT 2
577 #define IP4_ARP_EVENT 3
579 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
580 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
581 static int mpls_ethernet_add_del_tunnel_2_t_handler
582 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
584 void handle_ip4_arp_event (u32 pool_index)
586 vpe_api_main_t * vam = &vpe_api_main;
587 vnet_main_t * vnm = vam->vnet_main;
588 vlib_main_t * vm = vam->vlib_main;
589 vl_api_ip4_arp_event_t * event;
590 vl_api_ip4_arp_event_t * mp;
591 unix_shared_memory_queue_t * q;
593 /* Client can cancel, die, etc. */
594 if (pool_is_free_index (vam->arp_events, pool_index))
597 event = pool_elt_at_index (vam->arp_events, pool_index);
599 q = vl_api_client_index_to_input_queue (event->client_index);
601 (void) vnet_add_del_ip4_arp_change_event
602 (vnm, arp_change_delete_callback,
603 event->pid, &event->address,
604 vpe_resolver_process_node.index, IP4_ARP_EVENT,
605 ~0 /* pool index, notused */, 0 /* is_add */);
609 if (q->cursize < q->maxsize) {
610 mp = vl_msg_api_alloc (sizeof (*mp));
611 clib_memcpy (mp, event, sizeof (*mp));
612 vl_msg_api_send_shmem (q, (u8 *)&mp);
614 static f64 last_time;
616 * Throttle syslog msgs.
617 * It's pretty tempting to just revoke the registration...
619 if (vlib_time_now (vm) > last_time + 10.0) {
620 clib_warning ("arp event for %U to pid %d: queue stuffed!",
621 format_ip4_address, &event->address, event->pid);
622 last_time = vlib_time_now(vm);
628 resolver_process (vlib_main_t * vm,
629 vlib_node_runtime_t * rt,
633 uword *event_data = 0;
635 vpe_api_main_t * vam = &vpe_api_main;
636 pending_route_t * pr;
637 vl_api_ip_add_del_route_t * adr;
638 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
639 u32 * resolution_failures = 0;
644 vlib_process_wait_for_event_or_clock (vm, timeout);
646 event_type = vlib_process_get_events (vm, &event_data);
648 switch (event_type) {
649 case RESOLUTION_PENDING_EVENT:
653 case RESOLUTION_EVENT:
654 for (i = 0; i < vec_len(event_data); i++) {
656 * Resolution events can occur long after the
657 * original request has timed out. $$$ add a cancel
660 if (pool_is_free_index (vam->pending_routes, event_data[i]))
663 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
667 switch (pr->resolve_type) {
668 case RESOLVE_IP4_ADD_DEL_ROUTE:
669 rv = ip4_add_del_route_t_handler (adr);
670 clib_warning ("resolver: add %U/%d via %U %s",
672 (ip4_address_t *)&(adr->dst_address),
673 adr->dst_address_length,
675 (ip4_address_t *)&(adr->next_hop_address),
676 (rv >= 0) ? "succeeded" : "failed");
679 case RESOLVE_IP6_ADD_DEL_ROUTE:
680 rv = ip6_add_del_route_t_handler (adr);
681 clib_warning ("resolver: add %U/%d via %U %s",
683 (ip6_address_t *)&(adr->dst_address),
684 adr->dst_address_length,
686 (ip6_address_t *)&(adr->next_hop_address),
687 (rv >= 0) ? "succeeded" : "failed");
690 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
691 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
692 clib_warning ("resolver: add mpls-o-e via %U %s",
694 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
695 (rv >= 0) ? "succeeded" : "failed");
699 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
701 pool_put (vam->pending_routes, pr);
706 for (i = 0; i < vec_len(event_data); i++)
707 handle_ip4_arp_event (event_data[i]);
710 case ~0: /* timeout, retry pending resolutions */
711 pool_foreach (pr, vam->pending_routes,
717 /* May fail, e.g. due to interface down */
718 switch (pr->resolve_type) {
719 case RESOLVE_IP4_ADD_DEL_ROUTE:
720 e = ip4_probe_neighbor
721 (vm, (ip4_address_t *)&(adr->next_hop_address),
722 ntohl(adr->next_hop_sw_if_index));
725 case RESOLVE_IP6_ADD_DEL_ROUTE:
726 e = ip6_probe_neighbor
727 (vm, (ip6_address_t *)&(adr->next_hop_address),
728 ntohl(adr->next_hop_sw_if_index));
731 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
733 e = ip4_probe_neighbor
735 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
736 pme->resolve_opaque);
740 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
744 clib_error_report (e);
746 adr->resolve_attempts = 1;
748 pme->resolve_attempts = 1;
752 adr->resolve_attempts -= 1;
753 if (adr->resolve_attempts == 0)
754 vec_add1 (resolution_failures,
755 pr - vam->pending_routes);
757 pme->resolve_attempts -= 1;
758 if (pme->resolve_attempts == 0)
759 vec_add1 (resolution_failures,
760 pr - vam->pending_routes);
764 for (i = 0; i < vec_len (resolution_failures); i++) {
765 pr = pool_elt_at_index (vam->pending_routes,
766 resolution_failures[i]);
770 switch (pr->resolve_type) {
771 case RESOLVE_IP4_ADD_DEL_ROUTE:
772 clib_warning ("resolver: add %U/%d via %U retry failure",
774 (ip4_address_t *)&(adr->dst_address),
775 adr->dst_address_length,
777 (ip4_address_t *)&(adr->next_hop_address));
780 case RESOLVE_IP6_ADD_DEL_ROUTE:
781 clib_warning ("resolver: add %U/%d via %U retry failure",
783 (ip6_address_t *)&(adr->dst_address),
784 adr->dst_address_length,
786 (ip6_address_t *)&(adr->next_hop_address));
789 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
790 clib_warning ("resolver: add mpls-o-e via %U retry failure",
792 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
796 clib_warning ("BUG");
798 pool_put(vam->pending_routes, pr);
800 vec_reset_length (resolution_failures);
803 if (pool_elts (vam->pending_routes) == 0)
805 vec_reset_length (event_data);
807 return 0; /* or not */
810 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
811 .function = resolver_process,
812 .type = VLIB_NODE_TYPE_PROCESS,
813 .name = "vpe-route-resolver-process",
816 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
818 ip4_main_t * im = &ip4_main;
819 ip_lookup_main_t * lm = &im->lookup_main;
820 vnet_classify_main_t * cm = &vnet_classify_main;
821 stats_main_t * sm = &stats_main;
822 ip4_add_del_route_args_t a;
823 ip4_address_t next_hop_address;
825 vpe_api_main_t * vam = &vpe_api_main;
826 vnet_main_t * vnm = vam->vnet_main;
827 vlib_main_t * vm = vlib_get_main();
828 pending_route_t * pr;
829 vl_api_ip_add_del_route_t * adr;
833 ip_adjacency_t *nh_adj, *add_adj = 0;
835 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
837 if (mp->create_vrf_if_needed) {
839 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
841 fib_index = f->index;
843 /* No such VRF, and we weren't asked to create one */
844 return VNET_API_ERROR_NO_SUCH_FIB;
850 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
851 ntohl(mp->next_hop_sw_if_index)))
852 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
854 clib_memcpy (next_hop_address.data, mp->next_hop_address,
855 sizeof (next_hop_address.data));
857 /* Arp for the next_hop if necessary */
858 if (mp->is_add && mp->resolve_if_needed) {
860 ip_adjacency_t * adj;
862 lookup_result = ip4_fib_lookup_with_table
863 (im, fib_index, &next_hop_address, 1 /* disable default route */);
865 adj = ip_get_adjacency (lm, lookup_result);
867 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
868 pool_get (vam->pending_routes, pr);
869 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
871 clib_memcpy (adr, mp, sizeof (*adr));
872 /* recursion block, "just in case" */
873 adr->resolve_if_needed = 0;
874 adr->resolve_attempts = ntohl(mp->resolve_attempts);
875 vnet_register_ip4_arp_resolution_event
876 (vnm, &next_hop_address, vpe_resolver_process_node.index,
877 RESOLUTION_EVENT, pr - vam->pending_routes);
879 vlib_process_signal_event
880 (vm, vpe_resolver_process_node.index,
881 RESOLUTION_PENDING_EVENT, 0 /* data */);
883 /* The interface may be down, etc. */
884 e = ip4_probe_neighbor
885 (vm, (ip4_address_t *)&(mp->next_hop_address),
886 ntohl(mp->next_hop_sw_if_index));
889 clib_error_report(e);
891 return VNET_API_ERROR_IN_PROGRESS;
895 if (mp->is_multipath) {
898 dslock (sm, 1 /* release hint */, 10 /* tag */);
901 flags = IP4_ROUTE_FLAG_ADD;
903 flags = IP4_ROUTE_FLAG_DEL;
906 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
908 ip4_add_del_route_next_hop (im, flags,
909 (ip4_address_t *) mp->dst_address,
910 (u32) mp->dst_address_length,
911 (ip4_address_t *) mp->next_hop_address,
912 ntohl(mp->next_hop_sw_if_index),
913 (u32) mp->next_hop_weight,
920 memset (&a, 0, sizeof (a));
921 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
923 a.dst_address_length = mp->dst_address_length;
925 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
926 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
927 a.table_index_or_table_id = fib_index;
932 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
934 dslock (sm, 1 /* release hint */, 2 /* tag */);
938 ai = lm->drop_adj_index;
939 else if (mp->is_local)
940 ai = lm->local_adj_index;
941 else if (mp->is_classify) {
943 memset(&cadj, 0, sizeof(cadj));
944 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
945 cadj.classify.table_index = ntohl(mp->classify_table_index);
946 if (pool_is_free_index (cm->tables, cadj.classify.table_index)) {
948 return VNET_API_ERROR_NO_SUCH_TABLE;
950 vec_add1 (add_adj, cadj);
954 ai = ip4_fib_lookup_with_table
955 (im, fib_index, &next_hop_address,
956 1 /* disable default route */);
957 if (ai == lm->miss_adj_index) {
959 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
963 nh_adj = ip_get_adjacency (lm, ai);
964 vec_add1 (add_adj, nh_adj[0]);
965 if (mp->lookup_in_vrf) {
966 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
968 add_adj[0].explicit_fib_index = p[0];
972 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
976 ip_adjacency_t * adj;
977 int disable_default_route = 1;
979 /* Trying to delete the default route? */
980 if (a.dst_address.as_u32 == 0 &&
981 a.dst_address_length == 0)
982 disable_default_route = 0;
984 ai = ip4_fib_lookup_with_table
985 (im, fib_index, &a.dst_address, disable_default_route);
986 if (ai == lm->miss_adj_index) {
988 return VNET_API_ERROR_UNKNOWN_DESTINATION;
991 adj = ip_get_adjacency (lm, ai);
992 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
994 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1000 a.add_adj = add_adj;
1001 a.n_add_adj = vec_len(add_adj);
1002 ip4_add_del_route (im, &a);
1010 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1012 ip6_main_t * im = &ip6_main;
1013 ip_lookup_main_t * lm = &im->lookup_main;
1014 vnet_main_t * vnm = vnet_get_main();
1015 vlib_main_t * vm = vlib_get_main();
1016 vpe_api_main_t * vam = &vpe_api_main;
1017 stats_main_t * sm = &stats_main;
1018 ip6_add_del_route_args_t a;
1019 ip6_address_t next_hop_address;
1020 pending_route_t * pr;
1021 vl_api_ip_add_del_route_t * adr;
1026 ip_adjacency_t * nh_adj, * add_adj = 0;
1029 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1032 if (mp->create_vrf_if_needed) {
1034 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1036 fib_index = f->index;
1038 /* No such VRF, and we weren't asked to create one */
1039 return VNET_API_ERROR_NO_SUCH_FIB;
1045 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1046 ntohl(mp->next_hop_sw_if_index)))
1047 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1049 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1050 sizeof (next_hop_address.as_u8));
1052 /* Arp for the next_hop if necessary */
1053 if (mp->is_add && mp->resolve_if_needed) {
1055 ip_adjacency_t * adj;
1057 lookup_result = ip6_fib_lookup_with_table
1058 (im, fib_index, &next_hop_address);
1060 adj = ip_get_adjacency (lm, lookup_result);
1062 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1063 pool_get (vam->pending_routes, pr);
1065 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1066 clib_memcpy (adr, mp, sizeof (*adr));
1067 /* recursion block, "just in case" */
1068 adr->resolve_if_needed = 0;
1069 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1070 vnet_register_ip6_neighbor_resolution_event
1071 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1072 RESOLUTION_EVENT, pr - vam->pending_routes);
1074 vlib_process_signal_event
1075 (vm, vpe_resolver_process_node.index,
1076 RESOLUTION_PENDING_EVENT, 0 /* data */);
1078 /* The interface may be down, etc. */
1079 e = ip6_probe_neighbor
1080 (vm, (ip6_address_t *)&(mp->next_hop_address),
1081 ntohl(mp->next_hop_sw_if_index));
1084 clib_error_report(e);
1086 return VNET_API_ERROR_IN_PROGRESS;
1090 if (mp->is_multipath) {
1093 dslock (sm, 1 /* release hint */, 11 /* tag */);
1096 flags = IP6_ROUTE_FLAG_ADD;
1098 flags = IP6_ROUTE_FLAG_DEL;
1101 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1103 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1104 (u32) mp->dst_address_length,
1105 (ip6_address_t *)mp->next_hop_address,
1106 ntohl(mp->next_hop_sw_if_index),
1107 (u32) mp->next_hop_weight,
1114 memset (&a, 0, sizeof (a));
1115 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1117 a.dst_address_length = mp->dst_address_length;
1119 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1120 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1121 a.table_index_or_table_id = fib_index;
1126 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1128 dslock (sm, 1 /* release hint */, 3 /* tag */);
1132 ai = lm->drop_adj_index;
1133 else if (mp->is_local)
1134 ai = lm->local_adj_index;
1136 ai = ip6_fib_lookup_with_table
1137 (im, fib_index, &next_hop_address);
1138 if (ai == lm->miss_adj_index) {
1140 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1144 nh_adj = ip_get_adjacency (lm, ai);
1145 vec_add1 (add_adj, nh_adj[0]);
1146 if (mp->lookup_in_vrf) {
1147 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1149 add_adj[0].explicit_fib_index = p[0];
1153 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1157 ip_adjacency_t * adj;
1159 ai = ip6_fib_lookup_with_table
1160 (im, fib_index, &a.dst_address);
1161 if (ai == lm->miss_adj_index) {
1163 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1165 adj = ip_get_adjacency (lm, ai);
1166 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1168 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1173 a.add_adj = add_adj;
1174 a.n_add_adj = vec_len(add_adj);
1175 ip6_add_del_route (im, &a);
1183 void vl_api_ip_add_del_route_t_handler (
1184 vl_api_ip_add_del_route_t *mp)
1186 vl_api_ip_add_del_route_reply_t * rmp;
1188 vnet_main_t * vnm = vnet_get_main();
1193 rv = ip6_add_del_route_t_handler (mp);
1195 rv = ip4_add_del_route_t_handler (mp);
1197 rv = (rv == 0) ? vnm->api_errno : rv;
1199 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1202 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1203 u32 sw_if_index, u8 *next_hop_addr)
1205 vl_api_ip_add_del_route_t mp;
1208 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1211 * Configure default IP route:
1212 * - ip route add 0.0.0.0/1 via <GW IP>
1213 * - ip route add 128.0.0.0/1 via <GW IP>
1215 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1217 mp.resolve_attempts = ~0;
1218 mp.resolve_if_needed = 1;
1220 mp.is_ipv6 = is_ipv6;
1221 mp.next_hop_weight = 1;
1223 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1226 rv = ip6_add_del_route_t_handler (&mp);
1229 mp.dst_address_length = 1;
1231 mp.dst_address[0] = 0;
1232 rv = ip4_add_del_route_t_handler (&mp);
1234 mp.dst_address[0] = 128;
1235 rv |= ip4_add_del_route_t_handler (&mp);
1239 clib_error_return (0, "failed to config default IP route");
1244 vl_api_sw_interface_add_del_address_t_handler
1245 (vl_api_sw_interface_add_del_address_t *mp)
1247 vlib_main_t *vm = vlib_get_main();
1248 vl_api_sw_interface_add_del_address_reply_t * rmp;
1252 VALIDATE_SW_IF_INDEX(mp);
1254 is_del = mp->is_add == 0;
1257 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1258 else if (mp->is_ipv6)
1259 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1260 (void *)mp->address,
1261 mp->address_length, is_del);
1263 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1264 (void *) mp->address,
1265 mp->address_length, is_del);
1267 BAD_SW_IF_INDEX_LABEL;
1269 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1273 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1276 u32 table_id = ntohl(mp->vrf_id);
1277 u32 sw_if_index = ntohl(mp->sw_if_index);
1278 vl_api_sw_interface_set_table_reply_t * rmp;
1279 stats_main_t * sm = &stats_main;
1281 VALIDATE_SW_IF_INDEX(mp);
1283 dslock (sm, 1 /* release hint */, 4 /* tag */);
1286 ip6_main_t * im = &ip6_main;
1288 find_ip6_fib_by_table_index_or_id (im, table_id,
1289 IP6_ROUTE_FLAG_TABLE_ID);
1291 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1292 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1294 rv = VNET_API_ERROR_NO_SUCH_FIB;
1297 ip4_main_t * im = &ip4_main;
1298 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1299 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1301 /* Truthfully this can't fail */
1303 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1304 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1306 rv = VNET_API_ERROR_NO_SUCH_FIB;
1311 BAD_SW_IF_INDEX_LABEL;
1313 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1317 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1319 vlib_main_t *vm = vlib_get_main();
1320 vl_api_sw_interface_set_vpath_reply_t * rmp;
1323 u32 sw_if_index = ntohl(mp->sw_if_index);
1324 ip4_main_t *ip4m = &ip4_main;
1325 ip6_main_t *ip6m = &ip6_main;
1326 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1327 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1328 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1329 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1330 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1331 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1333 VALIDATE_SW_IF_INDEX(mp);
1335 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1337 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1338 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1339 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1340 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1341 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1342 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1343 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1344 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1345 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1346 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1347 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1348 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1349 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1350 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1351 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1352 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1354 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1355 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1356 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1357 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1358 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1359 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1360 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1361 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1362 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1363 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1364 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1365 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1366 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1367 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1368 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1369 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1372 BAD_SW_IF_INDEX_LABEL;
1374 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1378 vl_api_sw_interface_set_l2_xconnect_t_handler (
1379 vl_api_sw_interface_set_l2_xconnect_t *mp)
1381 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1383 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1384 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1385 vlib_main_t *vm = vlib_get_main();
1386 vnet_main_t *vnm = vnet_get_main();
1388 VALIDATE_RX_SW_IF_INDEX(mp);
1391 VALIDATE_TX_SW_IF_INDEX(mp);
1392 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1393 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1395 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1398 BAD_RX_SW_IF_INDEX_LABEL;
1399 BAD_TX_SW_IF_INDEX_LABEL;
1401 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1405 vl_api_sw_interface_set_l2_bridge_t_handler (
1406 vl_api_sw_interface_set_l2_bridge_t *mp)
1408 bd_main_t * bdm = &bd_main;
1409 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1411 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1412 u32 bd_id = ntohl(mp->bd_id);
1416 vlib_main_t *vm = vlib_get_main();
1417 vnet_main_t *vnm = vnet_get_main();
1419 VALIDATE_RX_SW_IF_INDEX(mp);
1421 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1424 //VALIDATE_TX_SW_IF_INDEX(mp);
1425 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1426 rx_sw_if_index, bd_index, bvi, shg, 0);
1428 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1431 BAD_RX_SW_IF_INDEX_LABEL;
1433 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1437 vl_api_bridge_domain_add_del_t_handler (
1438 vl_api_bridge_domain_add_del_t *mp)
1440 vlib_main_t * vm = vlib_get_main ();
1441 bd_main_t * bdm = &bd_main;
1442 vl_api_bridge_domain_add_del_reply_t * rmp;
1444 u32 enable_flags = 0, disable_flags = 0;
1445 u32 bd_id = ntohl(mp->bd_id);
1449 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1452 enable_flags |= L2_FLOOD;
1454 disable_flags |= L2_FLOOD;
1457 enable_flags |= L2_UU_FLOOD;
1459 disable_flags |= L2_UU_FLOOD;
1462 enable_flags |= L2_FWD;
1464 disable_flags |= L2_FWD;
1467 enable_flags |= L2_ARP_TERM;
1469 disable_flags |= L2_ARP_TERM;
1472 enable_flags |= L2_LEARN;
1474 disable_flags |= L2_LEARN;
1477 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1480 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1483 rv = bd_delete_bd_index(bdm, bd_id);
1485 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1488 static void vl_api_bridge_domain_details_t_handler (
1489 vl_api_bridge_domain_details_t * mp)
1491 clib_warning ("BUG");
1494 static void vl_api_bridge_domain_sw_if_details_t_handler (
1495 vl_api_bridge_domain_sw_if_details_t * mp)
1497 clib_warning ("BUG");
1500 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1501 l2_bridge_domain_t * bd_config,
1505 vl_api_bridge_domain_details_t * mp;
1507 mp = vl_msg_api_alloc (sizeof (*mp));
1508 memset (mp, 0, sizeof (*mp));
1509 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1510 mp->bd_id = ntohl (bd_config->bd_id);
1511 mp->flood = bd_feature_flood (bd_config);
1512 mp->uu_flood = bd_feature_uu_flood (bd_config);
1513 mp->forward = bd_feature_forward (bd_config);
1514 mp->learn = bd_feature_learn (bd_config);
1515 mp->arp_term = bd_feature_arp_term (bd_config);
1516 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1517 mp->n_sw_ifs = ntohl (n_sw_ifs);
1518 mp->context = context;
1520 vl_msg_api_send_shmem (q, (u8 *)&mp);
1523 static void send_bd_sw_if_details (l2input_main_t * l2im,
1524 unix_shared_memory_queue_t *q,
1525 l2_flood_member_t * member, u32 bd_id,
1528 vl_api_bridge_domain_sw_if_details_t * mp;
1529 l2_input_config_t * input_cfg;
1531 mp = vl_msg_api_alloc (sizeof (*mp));
1532 memset (mp, 0, sizeof (*mp));
1533 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1534 mp->bd_id = ntohl (bd_id);
1535 mp->sw_if_index = ntohl (member->sw_if_index);
1536 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1537 mp->shg = input_cfg->shg;
1538 mp->context = context;
1540 vl_msg_api_send_shmem (q, (u8 *)&mp);
1543 static void vl_api_bridge_domain_dump_t_handler (
1544 vl_api_bridge_domain_dump_t *mp)
1546 bd_main_t * bdm = &bd_main;
1547 l2input_main_t * l2im = &l2input_main;
1548 unix_shared_memory_queue_t * q;
1549 l2_bridge_domain_t * bd_config;
1550 u32 bd_id, bd_index;
1553 q = vl_api_client_index_to_input_queue (mp->client_index);
1558 bd_id = ntohl(mp->bd_id);
1560 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1561 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1562 for (; bd_index < end; bd_index++) {
1563 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1564 /* skip dummy bd_id 0 */
1565 if (bd_config && (bd_config->bd_id > 0)) {
1567 l2_flood_member_t * m;
1569 n_sw_ifs = vec_len (bd_config->members);
1570 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1572 vec_foreach (m, bd_config->members) {
1573 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1580 vl_api_l2fib_add_del_t_handler (
1581 vl_api_l2fib_add_del_t *mp)
1583 bd_main_t * bdm = &bd_main;
1584 l2input_main_t * l2im = &l2input_main;
1585 vl_api_l2fib_add_del_reply_t * rmp;
1588 u32 sw_if_index = ntohl(mp->sw_if_index);
1589 u32 bd_id = ntohl(mp->bd_id);
1597 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1599 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1600 goto bad_sw_if_index;
1605 VALIDATE_SW_IF_INDEX(mp);
1606 if (vec_len(l2im->configs) <= sw_if_index) {
1607 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1608 goto bad_sw_if_index;
1610 l2_input_config_t * config;
1611 config = vec_elt_at_index(l2im->configs, sw_if_index);
1612 if (config->bridge == 0) {
1613 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1614 goto bad_sw_if_index;
1617 static_mac = mp->static_mac ? 1 : 0;
1618 filter_mac = mp->filter_mac ? 1 : 0;
1619 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1622 l2fib_del_entry(mac, bd_index);
1625 BAD_SW_IF_INDEX_LABEL;
1627 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1631 vl_api_l2_flags_t_handler (
1632 vl_api_l2_flags_t *mp)
1634 vl_api_l2_flags_reply_t * rmp;
1636 u32 sw_if_index = ntohl(mp->sw_if_index);
1637 u32 flags = ntohl(mp->feature_bitmap);
1640 VALIDATE_SW_IF_INDEX(mp);
1643 if (flags & L2INPUT_FEAT_ ## a) \
1644 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1645 foreach_l2input_feat;
1648 BAD_SW_IF_INDEX_LABEL;
1650 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1654 vl_api_bridge_flags_t_handler (
1655 vl_api_bridge_flags_t *mp)
1657 vlib_main_t *vm = vlib_get_main();
1658 bd_main_t * bdm = &bd_main;
1659 vl_api_bridge_flags_reply_t * rmp;
1661 u32 bd_id = ntohl(mp->bd_id);
1663 u32 flags = ntohl(mp->feature_bitmap);
1666 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1668 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1674 bd_set_flags(vm, bd_index, flags, mp->is_set);
1677 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1678 rmp->resulting_feature_bitmap = ntohl(flags));
1682 vl_api_bd_ip_mac_add_del_t_handler (
1683 vl_api_bd_ip_mac_add_del_t *mp)
1685 bd_main_t * bdm = &bd_main;
1686 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1688 u32 bd_id = ntohl(mp->bd_id);
1692 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1694 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1699 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1700 mp->mac_address, mp->is_ipv6, mp->is_add))
1701 rv = VNET_API_ERROR_UNSPECIFIED;
1704 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1708 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1711 vl_api_tap_connect_reply_t * rmp;
1712 unix_shared_memory_queue_t * q;
1713 u32 sw_if_index = (u32)~0;
1715 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1716 mp->use_random_mac ? 0 : mp->mac_address,
1717 &sw_if_index, mp->renumber,
1718 ntohl(mp->custom_dev_instance));
1720 q = vl_api_client_index_to_input_queue (mp->client_index);
1724 rmp = vl_msg_api_alloc (sizeof (*rmp));
1725 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1726 rmp->context = mp->context;
1727 rmp->retval = ntohl(rv);
1728 rmp->sw_if_index = ntohl(sw_if_index);
1730 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1734 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1737 vl_api_tap_modify_reply_t * rmp;
1738 unix_shared_memory_queue_t * q;
1739 u32 sw_if_index = (u32)~0;
1741 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1742 mp->use_random_mac ? 0 : mp->mac_address,
1743 &sw_if_index, mp->renumber,
1744 ntohl(mp->custom_dev_instance));
1746 q = vl_api_client_index_to_input_queue (mp->client_index);
1750 rmp = vl_msg_api_alloc (sizeof (*rmp));
1751 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1752 rmp->context = mp->context;
1753 rmp->retval = ntohl(rv);
1754 rmp->sw_if_index = ntohl(sw_if_index);
1756 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1760 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1763 vpe_api_main_t * vam = &vpe_api_main;
1764 vl_api_tap_delete_reply_t * rmp;
1765 unix_shared_memory_queue_t * q;
1766 u32 sw_if_index = ntohl(mp->sw_if_index);
1768 rv = vnet_tap_delete (vm, sw_if_index);
1770 q = vl_api_client_index_to_input_queue (mp->client_index);
1774 rmp = vl_msg_api_alloc (sizeof (*rmp));
1775 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1776 rmp->context = mp->context;
1777 rmp->retval = ntohl(rv);
1779 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1782 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1786 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1788 vl_api_create_vlan_subif_reply_t * rmp;
1789 vnet_main_t * vnm = vnet_get_main();
1790 u32 hw_if_index, sw_if_index = (u32)~0;
1791 vnet_hw_interface_t * hi;
1794 vnet_sw_interface_t template;
1796 vnet_interface_main_t * im = &vnm->interface_main;
1797 u64 sup_and_sub_key;
1799 unix_shared_memory_queue_t * q;
1800 clib_error_t * error;
1802 VALIDATE_SW_IF_INDEX(mp);
1804 hw_if_index = ntohl(mp->sw_if_index);
1805 hi = vnet_get_hw_interface (vnm, hw_if_index);
1807 id = ntohl(mp->vlan_id);
1808 if (id == 0 || id > 4095) {
1809 rv = VNET_API_ERROR_INVALID_VLAN;
1813 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1815 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1817 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1821 kp = clib_mem_alloc (sizeof (*kp));
1822 *kp = sup_and_sub_key;
1824 memset (&template, 0, sizeof (template));
1825 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1826 template.sup_sw_if_index = hi->sw_if_index;
1827 template.sub.id = id;
1828 template.sub.eth.raw_flags = 0;
1829 template.sub.eth.flags.one_tag = 1;
1830 template.sub.eth.outer_vlan_id = id;
1831 template.sub.eth.flags.exact_match = 1;
1833 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1835 clib_error_report(error);
1836 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1839 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1840 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1842 BAD_SW_IF_INDEX_LABEL;
1845 q = vl_api_client_index_to_input_queue (mp->client_index);
1849 rmp = vl_msg_api_alloc (sizeof (*rmp));
1850 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1851 rmp->context = mp->context;
1852 rmp->retval = ntohl(rv);
1853 rmp->sw_if_index = ntohl(sw_if_index);
1854 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1858 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1860 vl_api_create_subif_reply_t * rmp;
1861 vnet_main_t * vnm = vnet_get_main();
1862 u32 sw_if_index = ~0;
1865 vnet_sw_interface_t *si;
1866 vnet_hw_interface_t *hi;
1867 vnet_sw_interface_t template;
1869 vnet_interface_main_t * im = &vnm->interface_main;
1870 u64 sup_and_sub_key;
1872 clib_error_t * error;
1874 VALIDATE_SW_IF_INDEX(mp);
1876 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1877 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1879 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1880 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1884 sw_if_index = si->sw_if_index;
1885 sub_id = ntohl(mp->sub_id);
1887 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1889 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1892 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1893 sw_if_index, sub_id);
1894 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1898 kp = clib_mem_alloc (sizeof (*kp));
1899 *kp = sup_and_sub_key;
1901 memset (&template, 0, sizeof (template));
1902 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1903 template.sup_sw_if_index = sw_if_index;
1904 template.sub.id = sub_id;
1905 template.sub.eth.flags.no_tags = mp->no_tags;
1906 template.sub.eth.flags.one_tag = mp->one_tag;
1907 template.sub.eth.flags.two_tags = mp->two_tags;
1908 template.sub.eth.flags.dot1ad = mp->dot1ad;
1909 template.sub.eth.flags.exact_match = mp->exact_match;
1910 template.sub.eth.flags.default_sub = mp->default_sub;
1911 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1912 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1913 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1914 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1916 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1918 clib_error_report (error);
1919 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1923 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1924 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1926 BAD_SW_IF_INDEX_LABEL;
1930 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1932 rmp->sw_if_index = ntohl(sw_if_index);
1937 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1939 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1941 stats_main_t * sm = &stats_main;
1942 u32 tunnel_sw_if_index = ~0;
1944 dslock (sm, 1 /* release hint */, 5 /* tag */);
1946 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1947 (ip4_address_t *)(mp->dst_address),
1948 (ip4_address_t *)(mp->intfc_address),
1949 (u32)(mp->intfc_address_length),
1950 ntohl(mp->inner_vrf_id),
1951 ntohl(mp->outer_vrf_id),
1952 &tunnel_sw_if_index,
1957 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1959 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1964 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1965 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1967 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1969 stats_main_t * sm = &stats_main;
1970 u32 tunnel_sw_if_index;
1972 dslock (sm, 1 /* release hint */, 5 /* tag */);
1974 rv = vnet_mpls_ethernet_add_del_tunnel
1975 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1976 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1977 ntohl(mp->tx_sw_if_index),
1978 &tunnel_sw_if_index,
1984 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1986 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1991 * This piece of misery brought to you because the control-plane
1992 * can't figure out the tx interface + dst-mac address all by itself
1994 static int mpls_ethernet_add_del_tunnel_2_t_handler
1995 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
1997 pending_route_t * pr;
1998 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
1999 vnet_main_t * vnm = vnet_get_main();
2000 vlib_main_t * vm = vlib_get_main();
2001 stats_main_t * sm = &stats_main;
2002 vpe_api_main_t * vam = &vpe_api_main;
2003 u32 inner_fib_index, outer_fib_index;
2004 ip4_main_t * im = &ip4_main;
2005 ip_lookup_main_t * lm = &im->lookup_main;
2006 ip_adjacency_t * adj = 0;
2009 u8 * dst_mac_address;
2013 u32 tunnel_sw_if_index;
2015 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2017 return VNET_API_ERROR_NO_SUCH_FIB;
2019 outer_fib_index = p[0];
2022 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2024 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2026 inner_fib_index = p[0];
2028 if (inner_fib_index == outer_fib_index)
2029 return VNET_API_ERROR_INVALID_VALUE;
2031 lookup_result = ip4_fib_lookup_with_table
2032 (im, outer_fib_index,
2033 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2034 1 /* disable default route */);
2036 adj = ip_get_adjacency (lm, lookup_result);
2037 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2039 if (mp->is_add && mp->resolve_if_needed) {
2040 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2041 pool_get (vam->pending_routes, pr);
2042 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2044 clib_memcpy (pme, mp, sizeof (*pme));
2045 /* recursion block, "just in case" */
2046 pme->resolve_if_needed = 0;
2047 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2048 pme->resolve_opaque = tx_sw_if_index;
2049 vnet_register_ip4_arp_resolution_event
2051 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2052 vpe_resolver_process_node.index,
2053 RESOLUTION_EVENT, pr - vam->pending_routes);
2055 vlib_process_signal_event
2056 (vm, vpe_resolver_process_node.index,
2057 RESOLUTION_PENDING_EVENT, 0 /* data */);
2059 /* The interface may be down, etc. */
2060 e = ip4_probe_neighbor
2061 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2065 clib_error_report(e);
2067 return VNET_API_ERROR_IN_PROGRESS;
2071 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2072 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2075 vnet_rewrite_get_data_internal
2076 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2078 dslock (sm, 1 /* release hint */, 10 /* tag */);
2080 rv = vnet_mpls_ethernet_add_del_tunnel
2081 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2082 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2083 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2091 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2092 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2094 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2097 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2099 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2104 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2106 vl_api_mpls_add_del_encap_reply_t * rmp;
2108 static u32 * labels;
2111 vec_reset_length (labels);
2113 for (i = 0; i < mp->nlabels; i++)
2114 vec_add1 (labels, ntohl(mp->labels[i]));
2117 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2118 ntohl(mp->vrf_id), labels,
2119 ~0 /* policy_tunnel_index */,
2120 0 /* no_dst_hash */,
2124 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2128 vl_api_mpls_add_del_decap_t_handler
2129 (vl_api_mpls_add_del_decap_t *mp)
2131 vl_api_mpls_add_del_decap_reply_t * rmp;
2134 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2135 ntohl(mp->label), ntohl(mp->next_index),
2136 mp->s_bit, mp->is_add);
2138 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2142 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2144 vl_api_proxy_arp_add_del_reply_t * rmp;
2147 ip4_main_t * im = &ip4_main;
2148 stats_main_t * sm = &stats_main;
2149 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2150 ip4_address_t *hi_addr,
2151 u32 fib_index, int is_del);
2154 dslock (sm, 1 /* release hint */, 6 /* tag */);
2156 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2159 rv = VNET_API_ERROR_NO_SUCH_FIB;
2165 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2166 (ip4_address_t *)mp->hi_address,
2167 fib_index, mp->is_add == 0);
2171 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2175 vl_api_proxy_arp_intfc_enable_disable_t_handler
2176 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2179 vnet_main_t * vnm = vnet_get_main();
2180 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2181 vnet_sw_interface_t * si;
2184 VALIDATE_SW_IF_INDEX(mp);
2186 sw_if_index = ntohl(mp->sw_if_index);
2188 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2190 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2194 si = vnet_get_sw_interface (vnm, sw_if_index);
2198 if (mp->enable_disable)
2199 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2201 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2203 BAD_SW_IF_INDEX_LABEL;
2206 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2210 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2212 vl_api_ip_neighbor_add_del_reply_t * rmp;
2213 vnet_main_t * vnm = vnet_get_main();
2216 stats_main_t * sm = &stats_main;
2218 VALIDATE_SW_IF_INDEX(mp);
2220 dslock (sm, 1 /* release hint */, 7 /* tag */);
2224 rv = vnet_set_ip6_ethernet_neighbor
2225 (vm, ntohl(mp->sw_if_index),
2226 (ip6_address_t *)(mp->dst_address),
2227 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2229 rv = vnet_unset_ip6_ethernet_neighbor
2230 (vm, ntohl(mp->sw_if_index),
2231 (ip6_address_t *)(mp->dst_address),
2232 mp->mac_address, sizeof(mp->mac_address));
2234 ip4_main_t * im = &ip4_main;
2235 ip_lookup_main_t * lm = &im->lookup_main;
2236 ethernet_arp_ip4_over_ethernet_address_t a;
2238 ip_adjacency_t *nh_adj;
2240 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2242 rv = VNET_API_ERROR_NO_SUCH_FIB;
2248 * Unfortunately, folks have a penchant for
2249 * adding interface addresses to the ARP cache, and
2250 * wondering why the forwarder eventually ASSERTs...
2252 ai = ip4_fib_lookup_with_table
2253 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2254 1 /* disable default route */);
2257 nh_adj = ip_get_adjacency (lm, ai);
2258 /* Never allow manipulation of a local adj! */
2259 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2260 clib_warning("%U matches local adj",
2262 (ip4_address_t *)(mp->dst_address));
2263 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2268 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2269 clib_memcpy (&a.ip4, mp->dst_address, 4);
2272 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2273 fib_index, &a, mp->is_static);
2275 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2279 BAD_SW_IF_INDEX_LABEL;
2282 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2286 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2289 vpe_main_t *rm = &vpe_main;
2290 ip4_main_t *im4 = &ip4_main;
2291 ip6_main_t *im6 = &ip6_main;
2292 ip_lookup_main_t * lm;
2297 u32 adj_index, sw_if_index;
2298 vl_api_is_address_reachable_t *rmp;
2299 ip_adjacency_t * adj;
2300 unix_shared_memory_queue_t *q;
2302 q = vl_api_client_index_to_input_queue (mp->client_index);
2304 increment_missing_api_client_counter (rm->vlib_main);
2308 rmp = vl_msg_api_alloc (sizeof (*rmp));
2309 clib_memcpy (rmp, mp, sizeof (*rmp));
2311 sw_if_index = mp->next_hop_sw_if_index;
2312 clib_memcpy (&addr, mp->address, sizeof (addr));
2314 lm = &im6->lookup_main;
2316 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2318 lm = &im4->lookup_main;
2320 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2322 if (adj_index == ~0) {
2326 adj = ip_get_adjacency (lm, adj_index);
2328 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2329 && adj->rewrite_header.sw_if_index == sw_if_index) {
2332 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2333 && adj->rewrite_header.sw_if_index == sw_if_index) {
2335 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2337 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2338 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2346 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2350 static void vl_api_sw_interface_details_t_handler (
2351 vl_api_sw_interface_details_t * mp)
2353 clib_warning ("BUG");
2356 static void vl_api_sw_interface_set_flags_t_handler (
2357 vl_api_sw_interface_set_flags_t * mp)
2359 vl_api_sw_interface_set_flags_reply_t *rmp;
2360 vnet_main_t * vnm = vnet_get_main();
2362 clib_error_t * error;
2365 VALIDATE_SW_IF_INDEX(mp);
2367 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2369 error = vnet_sw_interface_set_flags (vnm,
2370 ntohl(mp->sw_if_index),
2374 clib_error_report (error);
2377 BAD_SW_IF_INDEX_LABEL;
2378 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2381 static void vl_api_sw_interface_clear_stats_t_handler (
2382 vl_api_sw_interface_clear_stats_t * mp)
2384 vl_api_sw_interface_clear_stats_reply_t *rmp;
2386 vnet_main_t * vnm = vnet_get_main();
2387 vnet_interface_main_t * im = &vnm->interface_main;
2388 vlib_simple_counter_main_t * sm;
2389 vlib_combined_counter_main_t * cm;
2390 static vnet_main_t ** my_vnet_mains;
2391 int i, j, n_counters;
2395 vec_reset_length (my_vnet_mains);
2397 for (i = 0; i < vec_len (vnet_mains); i++)
2400 vec_add1 (my_vnet_mains, vnet_mains[i]);
2403 if (vec_len (vnet_mains) == 0)
2404 vec_add1 (my_vnet_mains, vnm);
2406 n_counters = vec_len (im->combined_sw_if_counters);
2408 for (j = 0; j < n_counters; j++)
2410 for (i = 0; i < vec_len(my_vnet_mains); i++)
2412 im = &my_vnet_mains[i]->interface_main;
2413 cm = im->combined_sw_if_counters + j;
2414 if (mp->sw_if_index == (u32)~0)
2415 vlib_clear_combined_counters (cm);
2417 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2421 n_counters = vec_len (im->sw_if_counters);
2423 for (j = 0; j < n_counters; j++)
2425 for (i = 0; i < vec_len(my_vnet_mains); i++)
2427 im = &my_vnet_mains[i]->interface_main;
2428 sm = im->sw_if_counters + j;
2429 if (mp->sw_if_index == (u32)~0)
2430 vlib_clear_simple_counters (sm);
2432 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2436 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2439 static void send_sw_interface_details (vpe_api_main_t * am,
2440 unix_shared_memory_queue_t *q,
2441 vnet_sw_interface_t * swif,
2442 u8 * interface_name,
2445 vl_api_sw_interface_details_t * mp;
2446 vnet_hw_interface_t * hi;
2448 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2450 mp = vl_msg_api_alloc (sizeof (*mp));
2451 memset (mp, 0, sizeof (*mp));
2452 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2453 mp->sw_if_index = ntohl(swif->sw_if_index);
2454 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2455 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2457 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2459 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2460 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2461 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2462 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2463 mp->link_mtu = ntohs(hi->max_packet_bytes);
2464 mp->context = context;
2466 strncpy ((char *) mp->interface_name,
2467 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2469 /* Send the L2 address for ethernet physical intfcs */
2470 if (swif->sup_sw_if_index == swif->sw_if_index
2471 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2472 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2473 ethernet_interface_t *ei;
2475 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2476 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2477 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2478 mp->l2_address_length = ntohl(sizeof (ei->address));
2479 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2480 vnet_sub_interface_t *sub = &swif->sub;
2481 mp->sub_id = ntohl(sub->id);
2482 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2483 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2484 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2485 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2486 mp->sub_exact_match = sub->eth.flags.exact_match;
2487 mp->sub_default = sub->eth.flags.default_sub;
2488 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2489 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2491 /* vlan tag rewrite data */
2492 u32 vtr_op = L2_VTR_DISABLED;
2493 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2495 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2496 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2497 // error - default to disabled
2498 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2499 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2502 mp->vtr_op = ntohl(vtr_op);
2503 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2504 mp->vtr_tag1 = ntohl(vtr_tag1);
2505 mp->vtr_tag2 = ntohl(vtr_tag2);
2509 vl_msg_api_send_shmem (q, (u8 *)&mp);
2512 static void send_sw_interface_flags (vpe_api_main_t * am,
2513 unix_shared_memory_queue_t *q,
2514 vnet_sw_interface_t * swif)
2516 vl_api_sw_interface_set_flags_t *mp;
2517 vnet_main_t * vnm = am->vnet_main;
2519 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2521 mp = vl_msg_api_alloc (sizeof (*mp));
2522 memset (mp, 0, sizeof (*mp));
2523 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2524 mp->sw_if_index = ntohl(swif->sw_if_index);
2526 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2528 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2530 vl_msg_api_send_shmem (q, (u8 *)&mp);
2533 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2534 unix_shared_memory_queue_t *q,
2536 __attribute__((unused));
2538 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2539 unix_shared_memory_queue_t *q,
2542 vl_api_sw_interface_set_flags_t *mp;
2544 mp = vl_msg_api_alloc (sizeof (*mp));
2545 memset (mp, 0, sizeof (*mp));
2546 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2547 mp->sw_if_index = ntohl(sw_if_index);
2549 mp->admin_up_down = 0;
2550 mp->link_up_down = 0;
2552 vl_msg_api_send_shmem (q, (u8 *)&mp);
2555 static void vl_api_sw_interface_dump_t_handler (
2556 vl_api_sw_interface_dump_t *mp)
2558 vpe_api_main_t * am = &vpe_api_main;
2559 vnet_sw_interface_t * swif;
2560 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2561 u8 * filter_string = 0, * name_string = 0;
2562 unix_shared_memory_queue_t * q;
2563 char * strcasestr (char *, char *); /* lnx hdr file botch */
2565 q = vl_api_client_index_to_input_queue (mp->client_index);
2570 if (mp->name_filter_valid) {
2571 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2572 filter_string = format (0, "%s%c", mp->name_filter, 0);
2575 pool_foreach (swif, im->sw_interfaces,
2577 name_string = format (name_string, "%U%c",
2578 format_vnet_sw_interface_name,
2579 am->vnet_main, swif, 0);
2581 if (mp->name_filter_valid == 0 ||
2582 strcasestr((char *) name_string, (char *) filter_string)) {
2584 send_sw_interface_details (am, q, swif, name_string, mp->context);
2585 send_sw_interface_flags (am, q, swif);
2587 _vec_len (name_string) = 0;
2590 vec_free (name_string);
2591 vec_free (filter_string);
2594 void send_oam_event (oam_target_t * t)
2596 vpe_api_main_t * vam = &vpe_api_main;
2597 unix_shared_memory_queue_t * q;
2598 vpe_client_registration_t *reg;
2599 vl_api_oam_event_t * mp;
2601 pool_foreach(reg, vam->oam_events_registrations,
2603 q = vl_api_client_index_to_input_queue (reg->client_index);
2605 mp = vl_msg_api_alloc (sizeof (*mp));
2606 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2607 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2608 mp->state = t->state;
2609 vl_msg_api_send_shmem (q, (u8 *)&mp);
2615 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2617 vl_api_oam_add_del_reply_t * rmp;
2620 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2621 (ip4_address_t *)mp->dst_address,
2625 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2629 vl_api_vnet_get_summary_stats_t_handler (
2630 vl_api_vnet_get_summary_stats_t *mp)
2632 stats_main_t * sm = &stats_main;
2633 vnet_interface_main_t * im = sm->interface_main;
2634 vl_api_vnet_summary_stats_reply_t *rmp;
2635 vlib_combined_counter_main_t * cm;
2638 u64 total_pkts[VLIB_N_RX_TX];
2639 u64 total_bytes[VLIB_N_RX_TX];
2641 unix_shared_memory_queue_t * q =
2642 vl_api_client_index_to_input_queue (mp->client_index);
2647 rmp = vl_msg_api_alloc (sizeof (*rmp));
2648 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2649 rmp->context = mp->context;
2652 memset (total_pkts, 0, sizeof (total_pkts));
2653 memset (total_bytes, 0, sizeof (total_bytes));
2655 vnet_interface_counter_lock (im);
2657 vec_foreach (cm, im->combined_sw_if_counters) {
2658 which = cm - im->combined_sw_if_counters;
2660 for (i = 0; i < vec_len (cm->maxi); i++) {
2661 vlib_get_combined_counter (cm, i, &v);
2662 total_pkts[which] += v.packets;
2663 total_bytes[which] += v.bytes;
2666 vnet_interface_counter_unlock (im);
2668 /* Note: in HOST byte order! */
2669 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2670 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2671 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2672 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2673 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2675 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2678 typedef CLIB_PACKED (struct {
2679 ip4_address_t address;
2681 u32 address_length : 6;
2686 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2688 vnet_main_t * vnm = vnet_get_main();
2689 vnet_interface_main_t * im = &vnm->interface_main;
2690 ip4_main_t * im4 = &ip4_main;
2691 static ip4_route_t * routes;
2692 static u32 * sw_if_indices_to_shut;
2693 stats_main_t * sm = &stats_main;
2698 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2699 u32 target_fib_id = ntohl(mp->vrf_id);
2701 dslock (sm, 1 /* release hint */, 8 /* tag */);
2703 vec_foreach (fib, im4->fibs) {
2704 vnet_sw_interface_t * si;
2706 if (fib->table_id != target_fib_id)
2709 /* remove any mpls/gre tunnels in this fib */
2710 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2712 /* remove any mpls encap/decap labels */
2713 mpls_fib_reset_labels (fib->table_id);
2715 /* remove any proxy arps in this fib */
2716 vnet_proxy_arp_fib_reset (fib->table_id);
2718 /* Set the flow hash for this fib to the default */
2719 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2721 vec_reset_length (sw_if_indices_to_shut);
2723 /* Shut down interfaces in this FIB / clean out intfc routes */
2724 pool_foreach (si, im->sw_interfaces,
2726 u32 sw_if_index = si->sw_if_index;
2728 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2729 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2731 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2734 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2735 sw_if_index = sw_if_indices_to_shut[i];
2736 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2738 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2739 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2740 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2743 vec_reset_length (routes);
2745 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2746 uword * hash = fib->adj_index_by_dst_address[i];
2750 x.address_length = i;
2752 hash_foreach_pair (p, hash,
2754 x.address.data_u32 = p->key;
2755 vec_add1 (routes, x);
2759 vec_foreach (r, routes) {
2760 ip4_add_del_route_args_t a;
2762 memset (&a, 0, sizeof (a));
2763 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2764 a.table_index_or_table_id = fib - im4->fibs;
2765 a.dst_address = r->address;
2766 a.dst_address_length = r->address_length;
2769 ip4_add_del_route (im4, &a);
2770 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2771 IP4_ROUTE_FLAG_FIB_INDEX);
2775 } /* vec_foreach (fib) */
2782 ip6_address_t address;
2789 ip6_route_t ** routep;
2790 } add_routes_in_fib_arg_t;
2792 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2794 add_routes_in_fib_arg_t * ap = arg;
2796 if (kvp->key[2]>>32 == ap->fib_index)
2798 ip6_address_t *addr;
2800 addr = (ip6_address_t *) kvp;
2801 vec_add2 (*ap->routep, r, 1);
2802 r->address = addr[0];
2803 r->address_length = kvp->key[2] & 0xFF;
2804 r->index = kvp->value;
2808 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2810 vnet_main_t * vnm = vnet_get_main();
2811 vnet_interface_main_t * im = &vnm->interface_main;
2812 ip6_main_t * im6 = &ip6_main;
2813 stats_main_t * sm = &stats_main;
2814 static ip6_route_t * routes;
2815 static u32 * sw_if_indices_to_shut;
2820 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2821 u32 target_fib_id = ntohl(mp->vrf_id);
2822 add_routes_in_fib_arg_t _a, *a=&_a;
2823 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2825 dslock (sm, 1 /* release hint */, 9 /* tag */);
2827 vec_foreach (fib, im6->fibs) {
2828 vnet_sw_interface_t * si;
2830 if (fib->table_id != target_fib_id)
2833 vec_reset_length (sw_if_indices_to_shut);
2835 /* Shut down interfaces in this FIB / clean out intfc routes */
2836 pool_foreach (si, im->sw_interfaces,
2838 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2840 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2843 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2844 sw_if_index = sw_if_indices_to_shut[i];
2845 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2847 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2848 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2849 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2852 vec_reset_length (routes);
2854 a->fib_index = fib - im6->fibs;
2855 a->routep = &routes;
2857 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2859 vec_foreach (r, routes) {
2860 ip6_add_del_route_args_t a;
2862 memset (&a, 0, sizeof (a));
2863 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2864 a.table_index_or_table_id = fib - im6->fibs;
2865 a.dst_address = r->address;
2866 a.dst_address_length = r->address_length;
2869 ip6_add_del_route (im6, &a);
2870 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2871 IP6_ROUTE_FLAG_FIB_INDEX);
2874 /* Reinstall the neighbor / router discovery routes */
2875 vnet_ip6_fib_init (im6, fib - im6->fibs);
2877 } /* vec_foreach (fib) */
2883 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2886 vl_api_reset_fib_reply_t * rmp;
2889 rv = ip6_reset_fib_t_handler (mp);
2891 rv = ip4_reset_fib_t_handler (mp);
2893 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2898 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2900 vl_api_dhcp_proxy_config_reply_t * rmp;
2903 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2904 (ip4_address_t *)(&mp->dhcp_src_address),
2905 (u32) ntohl(mp->vrf_id),
2906 (int) mp->insert_circuit_id,
2907 (int) (mp->is_add == 0));
2909 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2914 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2916 vl_api_dhcp_proxy_config_reply_t * rmp;
2919 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2920 (ip6_address_t *)(&mp->dhcp_src_address),
2921 (u32) ntohl(mp->vrf_id),
2922 (int) mp->insert_circuit_id,
2923 (int) (mp->is_add == 0));
2925 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2929 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2931 vl_api_dhcp_proxy_config_reply_t * rmp;
2934 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2935 (ip4_address_t *)(&mp->dhcp_src_address),
2936 (u32) ntohl(mp->rx_vrf_id),
2937 (u32) ntohl(mp->server_vrf_id),
2938 (int) mp->insert_circuit_id,
2939 (int) (mp->is_add == 0));
2941 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2946 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2948 vl_api_dhcp_proxy_config_reply_t * rmp;
2952 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2953 (ip6_address_t *)(&mp->dhcp_src_address),
2954 (u32) ntohl(mp->rx_vrf_id),
2955 (u32) ntohl(mp->server_vrf_id),
2956 (int) mp->insert_circuit_id,
2957 (int) (mp->is_add == 0));
2959 rv = VNET_API_ERROR_UNIMPLEMENTED;
2962 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2967 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2969 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2972 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2975 (int)mp->is_add == 0);
2977 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2980 (int)mp->is_add == 0);
2982 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2986 static void vl_api_dhcp_proxy_config_t_handler
2987 (vl_api_dhcp_proxy_config_t *mp)
2989 if (mp->is_ipv6 == 0)
2990 dhcpv4_proxy_config (mp);
2992 dhcpv6_proxy_config (mp);
2995 static void vl_api_dhcp_proxy_config_2_t_handler
2996 (vl_api_dhcp_proxy_config_2_t *mp)
2998 if (mp->is_ipv6 == 0)
2999 dhcpv4_proxy_config_2 (mp);
3001 dhcpv6_proxy_config_2 (mp);
3004 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3005 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3007 unix_shared_memory_queue_t * q;
3008 vl_api_dhcp_compl_event_t * mp;
3010 q = vl_api_client_index_to_input_queue (client_index);
3014 mp = vl_msg_api_alloc (sizeof (*mp));
3015 mp->client_index = client_index;
3017 mp->is_ipv6 = is_ipv6;
3018 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3019 mp->hostname[vec_len(hostname) + 1] = '\n';
3020 clib_memcpy (&mp->host_address[0], host_address, 16);
3021 clib_memcpy (&mp->router_address[0], router_address, 16);
3022 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3024 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3026 vl_msg_api_send_shmem (q, (u8 *)&mp);
3029 static void vl_api_dhcp_client_config_t_handler
3030 (vl_api_dhcp_client_config_t *mp)
3032 vlib_main_t *vm = vlib_get_main();
3033 vl_api_dhcp_client_config_reply_t * rmp;
3036 VALIDATE_SW_IF_INDEX(mp);
3038 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3039 mp->hostname, mp->is_add, mp->client_index,
3040 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3043 BAD_SW_IF_INDEX_LABEL;
3045 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3049 vl_api_sw_interface_ip6nd_ra_config_t_handler
3050 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3052 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3054 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3056 is_no = mp->is_no == 1;
3057 surpress = mp->surpress == 1;
3058 managed = mp->managed == 1;
3059 other = mp->other == 1;
3060 ll_option = mp->ll_option == 1;
3061 send_unicast = mp->send_unicast == 1;
3062 cease = mp->cease == 1;
3063 default_router = mp->default_router == 1;
3065 VALIDATE_SW_IF_INDEX(mp);
3067 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3068 surpress, managed, other,
3069 ll_option, send_unicast, cease,
3070 default_router, ntohl (mp->lifetime),
3071 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3072 ntohl(mp->max_interval), ntohl( mp->min_interval),
3075 BAD_SW_IF_INDEX_LABEL;
3077 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3081 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3082 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3084 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3086 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3088 VALIDATE_SW_IF_INDEX(mp);
3090 is_no = mp->is_no == 1;
3091 use_default = mp->use_default == 1;
3092 no_advertise = mp->no_advertise == 1;
3093 off_link = mp->off_link == 1;
3094 no_autoconfig = mp->no_autoconfig == 1;
3095 no_onlink = mp->no_onlink == 1;
3097 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3098 (ip6_address_t *)mp->address, mp->address_length,
3099 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3100 no_advertise, off_link, no_autoconfig, no_onlink,
3103 BAD_SW_IF_INDEX_LABEL;
3104 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3108 vl_api_sw_interface_ip6_enable_disable_t_handler
3109 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3111 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3112 vnet_main_t * vnm = vnet_get_main();
3114 clib_error_t * error;
3118 VALIDATE_SW_IF_INDEX(mp);
3120 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3121 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3124 clib_error_report(error);
3125 rv = VNET_API_ERROR_UNSPECIFIED;
3127 rv = vnm->api_errno;
3130 BAD_SW_IF_INDEX_LABEL;
3132 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3136 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3137 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3139 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3141 clib_error_t * error;
3142 vnet_main_t * vnm = vnet_get_main();
3146 VALIDATE_SW_IF_INDEX(mp);
3148 error = set_ip6_link_local_address(vm,
3149 ntohl(mp->sw_if_index),
3150 (ip6_address_t *)mp->address,
3151 mp->address_length);
3153 clib_error_report(error);
3154 rv = VNET_API_ERROR_UNSPECIFIED;
3156 rv = vnm->api_errno;
3159 BAD_SW_IF_INDEX_LABEL;
3161 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3164 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3166 vl_api_set_ip_flow_hash_reply_t *rmp;
3167 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3169 clib_warning ("unimplemented...");
3171 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3174 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3176 vl_api_set_ip_flow_hash_reply_t *rmp;
3179 u32 flow_hash_config = 0;
3181 table_id = ntohl(mp->vrf_id);
3183 #define _(a,b) if (mp->a) flow_hash_config |= b;
3184 foreach_flow_hash_bit;
3187 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3189 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3193 static void vl_api_set_ip_flow_hash_t_handler
3194 (vl_api_set_ip_flow_hash_t *mp)
3196 if (mp->is_ipv6 == 0)
3197 set_ip4_flow_hash (mp);
3199 set_ip6_flow_hash (mp);
3202 static void vl_api_sw_interface_set_unnumbered_t_handler
3203 (vl_api_sw_interface_set_unnumbered_t *mp)
3205 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3207 vnet_sw_interface_t * si;
3208 vnet_main_t *vnm = vnet_get_main();
3209 u32 sw_if_index, unnumbered_sw_if_index;
3211 sw_if_index = ntohl(mp->sw_if_index);
3212 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3215 * The API message field names are backwards from
3216 * the underlying data structure names.
3217 * It's not worth changing them now.
3219 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3220 unnumbered_sw_if_index)) {
3221 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3225 /* Only check the "use loop0" field when setting the binding */
3227 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3228 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3232 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3235 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3236 si->unnumbered_sw_if_index = sw_if_index;
3238 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3239 si->unnumbered_sw_if_index = (u32)~0;
3243 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3246 static void vl_api_create_loopback_t_handler
3247 (vl_api_create_loopback_t *mp)
3249 vl_api_create_loopback_reply_t * rmp;
3253 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3255 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3257 rmp->sw_if_index = ntohl (sw_if_index);
3261 static void vl_api_delete_loopback_t_handler
3262 (vl_api_delete_loopback_t *mp)
3264 vl_api_delete_loopback_reply_t * rmp;
3268 sw_if_index = ntohl (mp->sw_if_index);
3269 rv = vnet_delete_loopback_interface (sw_if_index);
3271 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3274 static void vl_api_control_ping_t_handler
3275 (vl_api_control_ping_t *mp)
3277 vl_api_control_ping_reply_t * rmp;
3280 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3282 rmp->vpe_pid = ntohl (getpid());
3286 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3288 u8 **shmem_vecp = (u8 **)arg;
3291 api_main_t * am = &api_main;
3294 shmem_vec = *shmem_vecp;
3296 offset = vec_len (shmem_vec);
3298 pthread_mutex_lock (&am->vlib_rp->mutex);
3299 oldheap = svm_push_data_heap (am->vlib_rp);
3301 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3303 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3305 svm_pop_heap (oldheap);
3306 pthread_mutex_unlock (&am->vlib_rp->mutex);
3308 *shmem_vecp = shmem_vec;
3312 static void vl_api_cli_request_t_handler
3313 (vl_api_cli_request_t *mp)
3315 vl_api_cli_reply_t *rp;
3316 unix_shared_memory_queue_t *q;
3317 vlib_main_t * vm = vlib_get_main();
3318 api_main_t * am = &api_main;
3319 unformat_input_t input;
3323 q = vl_api_client_index_to_input_queue (mp->client_index);
3327 rp = vl_msg_api_alloc (sizeof (*rp));
3328 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3329 rp->context = mp->context;
3331 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3333 vlib_cli_input (vm, &input, shmem_cli_output,
3336 pthread_mutex_lock (&am->vlib_rp->mutex);
3337 oldheap = svm_push_data_heap (am->vlib_rp);
3339 vec_add1(shmem_vec, 0);
3341 svm_pop_heap (oldheap);
3342 pthread_mutex_unlock (&am->vlib_rp->mutex);
3344 rp->reply_in_shmem = (uword)shmem_vec;
3346 vl_msg_api_send_shmem (q, (u8 *)&rp);
3349 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3352 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3353 vnet_main_t *vnm = vnet_get_main();
3354 clib_error_t * error;
3359 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3361 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3364 clib_error_report(error);
3365 rv = VNET_API_ERROR_UNSPECIFIED;
3367 rv = vnm->api_errno;
3370 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3373 static void vl_api_sr_tunnel_add_del_t_handler
3374 (vl_api_sr_tunnel_add_del_t *mp)
3377 clib_warning ("unimplemented");
3379 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3381 vl_api_sr_tunnel_add_del_reply_t * rmp;
3382 ip6_address_t * segments = 0, * seg;
3383 ip6_address_t * tags = 0, *tag;
3384 ip6_address_t * this_address;
3387 if (mp->n_segments == 0) {
3392 memset (a, 0, sizeof (*a));
3393 a->src_address = (ip6_address_t *)&mp->src_address;
3394 a->dst_address = (ip6_address_t *)&mp->dst_address;
3395 a->dst_mask_width = mp->dst_mask_width;
3396 a->flags_net_byte_order = mp->flags_net_byte_order;
3397 a->is_del = (mp->is_add == 0);
3398 a->rx_table_id = ntohl(mp->outer_vrf_id);
3399 a->tx_table_id = ntohl(mp->inner_vrf_id);
3401 a->name = format(0, "%s", mp->name);
3402 if (!(vec_len(a->name)))
3405 a->policy_name = format(0, "%s", mp->policy_name);
3406 if (!(vec_len(a->policy_name)))
3409 /* Yank segments and tags out of the API message */
3410 this_address = (ip6_address_t *)mp->segs_and_tags;
3411 for (i = 0; i < mp->n_segments; i++) {
3412 vec_add2 (segments, seg, 1);
3413 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3416 for (i = 0; i < mp->n_tags; i++) {
3417 vec_add2 (tags, tag, 1);
3418 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3422 a->segments = segments;
3425 rv = ip6_sr_add_del_tunnel (a);
3429 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3433 static void vl_api_sr_policy_add_del_t_handler
3434 (vl_api_sr_policy_add_del_t *mp)
3437 clib_warning ("unimplemented");
3439 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3441 vl_api_sr_policy_add_del_reply_t * rmp;
3444 memset (a, 0, sizeof (*a));
3445 a->is_del = (mp->is_add == 0);
3447 a->name = format(0, "%s", mp->name);
3448 if (!(vec_len(a->name)))
3450 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3454 if (!(mp->tunnel_names))
3456 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3460 // start deserializing tunnel_names
3461 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3462 u8 * deser_tun_names = mp->tunnel_names;
3463 deser_tun_names += 1; //moving along
3466 int tun_name_len = 0;
3468 for (i=0; i < num_tunnels; i++)
3470 tun_name_len= *deser_tun_names;
3471 deser_tun_names += 1;
3472 vec_resize (tun_name, tun_name_len);
3473 memcpy(tun_name, deser_tun_names, tun_name_len);
3474 vec_add1 (a->tunnel_names, tun_name);
3475 deser_tun_names += tun_name_len;
3479 rv = ip6_sr_add_del_policy (a);
3483 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3487 static void vl_api_sr_multicast_map_add_del_t_handler
3488 (vl_api_sr_multicast_map_add_del_t *mp)
3491 clib_warning ("unimplemented");
3493 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3495 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3497 memset (a, 0, sizeof (*a));
3498 a->is_del = (mp->is_add == 0);
3500 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3501 a->policy_name = format(0, "%s", mp->policy_name);
3503 if (a->multicast_address == 0)
3509 if (!(a->policy_name))
3515 #if DPDK > 0 /* Cannot call replicate without DPDK */
3516 rv = ip6_sr_add_del_multicastmap (a);
3518 clib_warning ("multicast replication without DPDK not implemented");
3519 rv = VNET_API_ERROR_UNIMPLEMENTED;
3524 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3528 #define foreach_classify_add_del_table_field \
3533 _(match_n_vectors) \
3534 _(next_table_index) \
3537 static void vl_api_classify_add_del_table_t_handler
3538 (vl_api_classify_add_del_table_t * mp)
3540 vl_api_classify_add_del_table_reply_t * rmp;
3541 vnet_classify_main_t * cm = &vnet_classify_main;
3542 vnet_classify_table_t * t;
3546 foreach_classify_add_del_table_field;
3549 #define _(a) a = ntohl(mp->a);
3550 foreach_classify_add_del_table_field;
3553 /* The underlying API fails silently, on purpose, so check here */
3554 if (mp->is_add == 0)
3555 if (pool_is_free_index (cm->tables, table_index)) {
3556 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3560 rv = vnet_classify_add_del_table
3561 (cm, mp->mask, nbuckets, memory_size,
3562 skip_n_vectors, match_n_vectors,
3563 next_table_index, miss_next_index,
3564 &table_index, mp->is_add);
3567 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3569 if (rv == 0 && mp->is_add) {
3570 t = pool_elt_at_index (cm->tables, table_index);
3571 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3572 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3573 rmp->new_table_index = ntohl(table_index);
3575 rmp->skip_n_vectors = ~0;
3576 rmp->match_n_vectors = ~0;
3577 rmp->new_table_index = ~0;
3582 static void vl_api_classify_add_del_session_t_handler
3583 (vl_api_classify_add_del_session_t * mp)
3585 vnet_classify_main_t * cm = &vnet_classify_main;
3586 vl_api_classify_add_del_session_reply_t * rmp;
3588 u32 table_index, hit_next_index, opaque_index;
3591 table_index = ntohl (mp->table_index);
3592 hit_next_index = ntohl (mp->hit_next_index);
3593 opaque_index = ntohl (mp->opaque_index);
3594 advance = ntohl (mp->advance);
3596 rv = vnet_classify_add_del_session
3597 (cm, table_index, mp->match, hit_next_index, opaque_index,
3598 advance, mp->is_add);
3600 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3603 static void vl_api_classify_set_interface_ip_table_t_handler
3604 (vl_api_classify_set_interface_ip_table_t * mp)
3606 vlib_main_t * vm = vlib_get_main();
3607 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3609 u32 table_index, sw_if_index;
3611 table_index = ntohl (mp->table_index);
3612 sw_if_index = ntohl (mp->sw_if_index);
3614 VALIDATE_SW_IF_INDEX(mp);
3617 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3619 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3621 BAD_SW_IF_INDEX_LABEL;
3623 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3626 static void vl_api_classify_set_interface_l2_tables_t_handler
3627 (vl_api_classify_set_interface_l2_tables_t * mp)
3629 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3631 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3634 ip4_table_index = ntohl(mp->ip4_table_index);
3635 ip6_table_index = ntohl(mp->ip6_table_index);
3636 other_table_index = ntohl(mp->other_table_index);
3637 sw_if_index = ntohl(mp->sw_if_index);
3639 VALIDATE_SW_IF_INDEX(mp);
3641 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3642 ip6_table_index, other_table_index);
3645 if (ip4_table_index != ~0 || ip6_table_index != ~0
3646 || other_table_index != ~0)
3651 vnet_l2_classify_enable_disable (sw_if_index, enable);
3654 BAD_SW_IF_INDEX_LABEL;
3656 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3660 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3663 vl_api_l2_fib_clear_table_reply_t * rmp;
3665 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3666 * that is not currently implemented. When that TODO is fixed
3667 * this call should be changed to pass 1 instead of 0.
3669 l2fib_clear_table (0);
3671 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3674 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3679 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3682 vl_api_l2_interface_efp_filter_reply_t * rmp;
3683 vnet_main_t *vnm = vnet_get_main();
3685 // enable/disable the feature
3686 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3687 rv = vnm->api_errno;
3689 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3693 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3696 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3697 vnet_main_t * vnm = vnet_get_main();
3698 vlib_main_t * vm = vlib_get_main();
3701 VALIDATE_SW_IF_INDEX(mp);
3703 vtr_op = ntohl(mp->vtr_op);
3705 /* The L2 code is unsuspicious */
3707 case L2_VTR_DISABLED:
3712 case L2_VTR_TRANSLATE_1_1:
3713 case L2_VTR_TRANSLATE_1_2:
3714 case L2_VTR_TRANSLATE_2_1:
3715 case L2_VTR_TRANSLATE_2_2:
3719 rv = VNET_API_ERROR_INVALID_VALUE;
3720 goto bad_sw_if_index;
3723 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3724 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3727 BAD_SW_IF_INDEX_LABEL;
3729 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3733 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3737 vl_api_create_vhost_user_if_reply_t * rmp;
3738 u32 sw_if_index = (u32)~0;
3740 vnet_main_t * vnm = vnet_get_main();
3741 vlib_main_t * vm = vlib_get_main();
3743 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3744 mp->is_server, &sw_if_index, (u64)~0,
3745 mp->renumber, ntohl(mp->custom_dev_instance),
3746 (mp->use_custom_mac)?mp->mac_address:NULL);
3748 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3750 rmp->sw_if_index = ntohl (sw_if_index);
3756 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3760 vl_api_modify_vhost_user_if_reply_t * rmp;
3761 u32 sw_if_index = ntohl(mp->sw_if_index);
3763 vnet_main_t * vnm = vnet_get_main();
3764 vlib_main_t * vm = vlib_get_main();
3766 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3767 mp->is_server, sw_if_index, (u64)~0,
3768 mp->renumber, ntohl(mp->custom_dev_instance));
3770 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3775 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3779 vpe_api_main_t * vam = &vpe_api_main;
3780 vl_api_delete_vhost_user_if_reply_t * rmp;
3781 u32 sw_if_index = ntohl(mp->sw_if_index);
3783 vnet_main_t * vnm = vnet_get_main();
3784 vlib_main_t * vm = vlib_get_main();
3786 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3788 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3790 unix_shared_memory_queue_t * q =
3791 vl_api_client_index_to_input_queue (mp->client_index);
3795 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3800 static void vl_api_sw_interface_vhost_user_details_t_handler (
3801 vl_api_sw_interface_vhost_user_details_t * mp)
3803 clib_warning ("BUG");
3807 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3808 unix_shared_memory_queue_t *q,
3809 vhost_user_intf_details_t * vui,
3812 vl_api_sw_interface_vhost_user_details_t * mp;
3814 mp = vl_msg_api_alloc (sizeof (*mp));
3815 memset (mp, 0, sizeof (*mp));
3816 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3817 mp->sw_if_index = ntohl(vui->sw_if_index);
3818 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3819 mp->features = clib_net_to_host_u64 (vui->features);
3820 mp->is_server = vui->is_server;
3821 mp->num_regions = ntohl(vui->num_regions);
3822 mp->sock_errno = ntohl(vui->sock_errno);
3823 mp->context = context;
3825 strncpy ((char *) mp->sock_filename,
3826 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3827 strncpy ((char *) mp->interface_name,
3828 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3830 vl_msg_api_send_shmem (q, (u8 *)&mp);
3835 vl_api_sw_interface_vhost_user_dump_t_handler (
3836 vl_api_sw_interface_vhost_user_dump_t *mp)
3840 vpe_api_main_t * am = &vpe_api_main;
3841 vnet_main_t * vnm = vnet_get_main();
3842 vlib_main_t * vm = vlib_get_main();
3843 vhost_user_intf_details_t *ifaces = NULL;
3844 vhost_user_intf_details_t *vuid = NULL;
3845 unix_shared_memory_queue_t * q;
3847 q = vl_api_client_index_to_input_queue (mp->client_index);
3851 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3855 vec_foreach (vuid, ifaces) {
3856 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3862 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3863 unix_shared_memory_queue_t *q,
3868 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3869 u8 * if_name = NULL;
3870 vnet_sw_interface_t * si = NULL;
3872 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3874 if_name = format(if_name, "%U",
3875 format_vnet_sw_interface_name, lm->vnet_main, si);
3877 mp = vl_msg_api_alloc (sizeof (*mp));
3878 memset (mp, 0, sizeof (*mp));
3879 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3880 strncpy((char *)mp->interface_name,
3881 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3882 mp->sw_if_index = ntohl(si->sw_if_index);
3883 mp->local_session_id = s->local_session_id;
3884 mp->remote_session_id = s->remote_session_id;
3885 mp->local_cookie[0] = s->local_cookie[0];
3886 mp->local_cookie[1] = s->local_cookie[1];
3887 mp->remote_cookie = s->remote_cookie;
3888 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3889 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3890 mp->l2_sublayer_present = s->l2_sublayer_present;
3891 mp->context = context;
3893 vl_msg_api_send_shmem (q, (u8 *)&mp);
3896 static void send_ip_address_details (vpe_api_main_t * am,
3897 unix_shared_memory_queue_t * q,
3903 vl_api_ip_address_details_t * mp;
3905 mp = vl_msg_api_alloc (sizeof (*mp));
3906 memset (mp, 0, sizeof (*mp));
3907 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3910 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3912 u32 * tp = (u32 *)mp->ip;
3913 *tp = ntohl(*(u32*)ip);
3915 mp->prefix_length = prefix_length;
3916 mp->context = context;
3918 vl_msg_api_send_shmem (q, (u8 *)&mp);
3922 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3924 vpe_api_main_t * am = &vpe_api_main;
3925 unix_shared_memory_queue_t * q;
3928 ip6_main_t * im6 = &ip6_main;
3929 ip4_main_t * im4 = &ip4_main;
3930 ip_lookup_main_t * lm6 = &im6->lookup_main;
3931 ip_lookup_main_t * lm4 = &im4->lookup_main;
3932 ip_interface_address_t * ia = 0;
3933 u32 sw_if_index = ~0;
3935 sw_if_index = ntohl(mp->sw_if_index);
3937 q = vl_api_client_index_to_input_queue (mp->client_index);
3943 foreach_ip_interface_address (lm6, ia, sw_if_index,
3944 1 /* honor unnumbered */,
3946 r6 = ip_interface_address_get_address (lm6, ia);
3947 u16 prefix_length = ia->address_length;
3948 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
3951 foreach_ip_interface_address (lm4, ia, sw_if_index,
3952 1 /* honor unnumbered */,
3954 r4 = ip_interface_address_get_address (lm4, ia);
3955 u16 prefix_length = ia->address_length;
3956 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
3961 static void send_ip_details (vpe_api_main_t * am,
3962 unix_shared_memory_queue_t *q,
3966 vl_api_ip_details_t * mp;
3968 mp = vl_msg_api_alloc (sizeof (*mp));
3969 memset (mp, 0, sizeof (*mp));
3970 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3972 mp->sw_if_index = ntohl(sw_if_index);
3973 mp->context = context;
3975 vl_msg_api_send_shmem (q, (u8 *)&mp);
3979 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3980 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3982 vpe_api_main_t * am = &vpe_api_main;
3983 l2t_main_t * lm = &l2t_main;
3984 unix_shared_memory_queue_t * q;
3985 l2t_session_t *session;
3987 q = vl_api_client_index_to_input_queue (mp->client_index);
3991 pool_foreach (session, lm->sessions,
3993 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
3998 static void send_sw_interface_tap_details (vpe_api_main_t * am,
3999 unix_shared_memory_queue_t *q,
4000 tapcli_interface_details_t *tap_if,
4003 vl_api_sw_interface_tap_details_t * mp;
4004 mp = vl_msg_api_alloc (sizeof (*mp));
4005 memset (mp, 0, sizeof (*mp));
4006 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4007 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4008 strncpy((char *)mp->dev_name,
4009 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4010 mp->context = context;
4012 vl_msg_api_send_shmem (q, (u8 *)&mp);
4016 vl_api_sw_interface_tap_dump_t_handler (
4017 vl_api_sw_interface_tap_dump_t *mp)
4020 vpe_api_main_t * am = &vpe_api_main;
4021 unix_shared_memory_queue_t * q;
4022 tapcli_interface_details_t *tapifs = NULL;
4023 tapcli_interface_details_t *tap_if = NULL;
4025 q = vl_api_client_index_to_input_queue (mp->client_index);
4029 rv = vnet_tap_dump_ifs(&tapifs);
4033 vec_foreach(tap_if, tapifs) {
4034 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4041 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4043 vpe_api_main_t * am = &vpe_api_main;
4044 vnet_main_t * vnm = vnet_get_main();
4045 vlib_main_t * vm = vlib_get_main();
4046 vnet_interface_main_t * im = &vnm->interface_main;
4047 unix_shared_memory_queue_t * q;
4048 vnet_sw_interface_t * si, * sorted_sis;
4049 u32 sw_if_index = ~0;
4051 q = vl_api_client_index_to_input_queue (mp->client_index);
4056 /* Gather interfaces. */
4057 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4058 _vec_len (sorted_sis) = 0;
4059 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4061 vec_foreach (si, sorted_sis) {
4062 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4063 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4066 sw_if_index = si->sw_if_index;
4067 send_ip_details(am, q, sw_if_index, mp->context);
4072 static void vl_api_l2_fib_table_entry_t_handler (
4073 vl_api_l2_fib_table_entry_t * mp)
4075 clib_warning ("BUG");
4078 static void send_l2fib_table_entry (vpe_api_main_t * am,
4079 unix_shared_memory_queue_t *q,
4080 l2fib_entry_key_t * l2fe_key,
4081 l2fib_entry_result_t * l2fe_res,
4084 vl_api_l2_fib_table_entry_t * mp;
4086 mp = vl_msg_api_alloc (sizeof (*mp));
4087 memset (mp, 0, sizeof (*mp));
4088 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4090 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4092 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4093 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4094 mp->static_mac = l2fe_res->fields.static_mac;
4095 mp->filter_mac = l2fe_res->fields.filter;
4096 mp->bvi_mac = l2fe_res->fields.bvi;
4097 mp->context = context;
4099 vl_msg_api_send_shmem (q, (u8 *)&mp);
4103 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4105 vpe_api_main_t * am = &vpe_api_main;
4106 bd_main_t * bdm = &bd_main;
4107 l2fib_entry_key_t *l2fe_key = NULL;
4108 l2fib_entry_result_t *l2fe_res = NULL;
4109 u32 ni, bd_id = ntohl (mp->bd_id);
4111 unix_shared_memory_queue_t * q;
4114 q = vl_api_client_index_to_input_queue (mp->client_index);
4118 /* see l2fib_table_dump: ~0 means "any" */
4122 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4129 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4131 vec_foreach_index (ni, l2fe_key) {
4132 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4133 vec_elt_at_index(l2fe_res, ni), mp->context);
4140 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4142 vl_api_show_version_reply_t *rmp;
4144 char * vpe_api_get_build_directory(void);
4145 char * vpe_api_get_version(void);
4146 char * vpe_api_get_build_date(void);
4148 unix_shared_memory_queue_t * q =
4149 vl_api_client_index_to_input_queue (mp->client_index);
4154 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4156 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4157 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4158 ARRAY_LEN(rmp->build_directory)-1);
4159 strncpy ((char *) rmp->version, vpe_api_get_version(),
4160 ARRAY_LEN(rmp->version)-1);
4161 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4162 ARRAY_LEN(rmp->build_date)-1);
4166 static void vl_api_get_node_index_t_handler
4167 (vl_api_get_node_index_t * mp)
4169 vlib_main_t * vm = vlib_get_main();
4170 vl_api_get_node_index_reply_t * rmp;
4173 u32 node_index = ~0;
4175 n = vlib_get_node_by_name (vm, mp->node_name);
4178 rv = VNET_API_ERROR_NO_SUCH_NODE;
4180 node_index = n->index;
4182 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4184 rmp->node_index = ntohl(node_index);
4188 static void vl_api_add_node_next_t_handler
4189 (vl_api_add_node_next_t * mp)
4191 vlib_main_t * vm = vlib_get_main();
4192 vl_api_add_node_next_reply_t * rmp;
4193 vlib_node_t * n, * next;
4195 u32 next_index = ~0;
4197 n = vlib_get_node_by_name (vm, mp->node_name);
4200 rv = VNET_API_ERROR_NO_SUCH_NODE;
4204 next = vlib_get_node_by_name (vm, mp->next_name);
4207 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4209 next_index = vlib_node_add_next (vm, n->index, next->index);
4212 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4214 rmp->next_index = ntohl(next_index);
4218 static void vl_api_l2tpv3_create_tunnel_t_handler
4219 (vl_api_l2tpv3_create_tunnel_t *mp)
4221 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4222 l2t_main_t *lm = &l2t_main;
4223 u32 sw_if_index = (u32)~0;
4226 if (mp->is_ipv6 != 1) {
4227 rv = VNET_API_ERROR_UNIMPLEMENTED;
4231 rv = create_l2tpv3_ipv6_tunnel (lm,
4232 (ip6_address_t *) mp->client_address,
4233 (ip6_address_t *) mp->our_address,
4234 ntohl(mp->local_session_id),
4235 ntohl(mp->remote_session_id),
4236 clib_net_to_host_u64(mp->local_cookie),
4237 clib_net_to_host_u64(mp->remote_cookie),
4238 mp->l2_sublayer_present,
4242 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4244 rmp->sw_if_index = ntohl (sw_if_index);
4248 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4249 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4251 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4252 l2t_main_t *lm = &l2t_main;
4255 VALIDATE_SW_IF_INDEX(mp);
4257 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4258 clib_net_to_host_u64(mp->new_local_cookie),
4259 clib_net_to_host_u64(mp->new_remote_cookie));
4261 BAD_SW_IF_INDEX_LABEL;
4263 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4266 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4267 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4270 vnet_main_t * vnm = vnet_get_main();
4271 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4273 VALIDATE_SW_IF_INDEX(mp);
4275 rv = l2tpv3_interface_enable_disable
4276 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4278 BAD_SW_IF_INDEX_LABEL;
4280 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4283 static void vl_api_l2tpv3_set_lookup_key_t_handler
4284 (vl_api_l2tpv3_set_lookup_key_t * mp)
4287 l2t_main_t *lm = &l2t_main;
4288 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4290 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4291 rv = VNET_API_ERROR_INVALID_VALUE;
4295 lm->lookup_type = mp->key;
4298 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4301 static void vl_api_vxlan_add_del_tunnel_t_handler
4302 (vl_api_vxlan_add_del_tunnel_t * mp)
4304 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4306 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4307 u32 encap_fib_index;
4309 ip4_main_t * im = &ip4_main;
4310 u32 sw_if_index = ~0;
4312 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4314 rv = VNET_API_ERROR_NO_SUCH_FIB;
4317 encap_fib_index = p[0];
4319 /* Check src & dst are different */
4320 if ((a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4321 (!a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4322 rv = VNET_API_ERROR_SAME_SRC_DST;
4325 memset (a, 0, sizeof (*a));
4327 a->is_add = mp->is_add;
4328 a->is_ip6 = mp->is_ipv6;
4330 /* ip addresses sent in network byte order */
4332 memcpy(&(a->src.ip6), mp->src_address, 16);
4333 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4335 memcpy(&(a->src.ip4), mp->src_address, 4);
4336 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4339 a->encap_fib_index = encap_fib_index;
4340 a->decap_next_index = ntohl(mp->decap_next_index);
4341 a->vni = ntohl(mp->vni);
4342 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4345 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4347 rmp->sw_if_index = ntohl (sw_if_index);
4351 static void send_vxlan_tunnel_details
4352 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4354 vl_api_vxlan_tunnel_details_t * rmp;
4355 ip4_main_t * im4 = &ip4_main;
4356 ip6_main_t * im6 = &ip6_main;
4357 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4359 rmp = vl_msg_api_alloc (sizeof (*rmp));
4360 memset (rmp, 0, sizeof (*rmp));
4361 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4363 memcpy(rmp->src_address, &(t->src.ip6), 16);
4364 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4365 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4367 memcpy(rmp->src_address, &(t->src.ip4), 4);
4368 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4369 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4371 rmp->vni = htonl(t->vni);
4372 rmp->decap_next_index = htonl(t->decap_next_index);
4373 rmp->sw_if_index = htonl(t->sw_if_index);
4374 rmp->is_ipv6 = is_ipv6;
4375 rmp->context = context;
4377 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4380 static void vl_api_vxlan_tunnel_dump_t_handler
4381 (vl_api_vxlan_tunnel_dump_t * mp)
4383 unix_shared_memory_queue_t * q;
4384 vxlan_main_t * vxm = &vxlan_main;
4388 q = vl_api_client_index_to_input_queue (mp->client_index);
4393 sw_if_index = ntohl(mp->sw_if_index);
4395 if (~0 == sw_if_index) {
4396 pool_foreach (t, vxm->tunnels,
4398 send_vxlan_tunnel_details(t, q, mp->context);
4401 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4402 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4405 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4406 send_vxlan_tunnel_details(t, q, mp->context);
4410 static void vl_api_gre_add_del_tunnel_t_handler
4411 (vl_api_gre_add_del_tunnel_t * mp)
4413 vl_api_gre_add_del_tunnel_reply_t * rmp;
4415 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4418 ip4_main_t * im = &ip4_main;
4419 u32 sw_if_index = ~0;
4421 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_table_id));
4423 rv = VNET_API_ERROR_NO_SUCH_FIB;
4426 outer_table_id = p[0];
4428 /* Check src & dst are different */
4429 if (memcmp(&mp->src_address, &mp->dst_address, 4) == 0) {
4430 rv = VNET_API_ERROR_SAME_SRC_DST;
4434 memset (a, 0, sizeof (*a));
4436 a->is_add = mp->is_add;
4438 /* ip addresses sent in network byte order */
4439 a->src.as_u32 = mp->src_address;
4440 a->dst.as_u32 = mp->dst_address;
4442 a->outer_table_id = outer_table_id;
4443 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4446 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4448 rmp->sw_if_index = ntohl (sw_if_index);
4452 static void send_gre_tunnel_details
4453 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4455 vl_api_gre_tunnel_details_t * rmp;
4456 ip4_main_t * im = &ip4_main;
4458 rmp = vl_msg_api_alloc (sizeof (*rmp));
4459 memset (rmp, 0, sizeof (*rmp));
4460 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4461 rmp->src_address = t->tunnel_src.data_u32;
4462 rmp->dst_address = t->tunnel_dst.data_u32;
4463 rmp->outer_table_id = htonl(im->fibs[t->outer_fib_index].table_id);
4464 rmp->sw_if_index = htonl(t->sw_if_index);
4465 rmp->context = context;
4467 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4470 static void vl_api_gre_tunnel_dump_t_handler
4471 (vl_api_gre_tunnel_dump_t * mp)
4473 unix_shared_memory_queue_t * q;
4474 gre_main_t * gm = &gre_main;
4478 q = vl_api_client_index_to_input_queue (mp->client_index);
4483 sw_if_index = ntohl(mp->sw_if_index);
4485 if (~0 == sw_if_index) {
4486 pool_foreach (t, gm->tunnels,
4488 send_gre_tunnel_details(t, q, mp->context);
4491 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4492 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4495 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4496 send_gre_tunnel_details(t, q, mp->context);
4501 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4503 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4505 vl_api_l2_patch_add_del_reply_t * rmp;
4506 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4510 VALIDATE_RX_SW_IF_INDEX(mp);
4511 VALIDATE_TX_SW_IF_INDEX(mp);
4513 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4514 ntohl(mp->tx_sw_if_index),
4515 (int)(mp->is_add != 0));
4517 BAD_RX_SW_IF_INDEX_LABEL;
4518 BAD_TX_SW_IF_INDEX_LABEL;
4520 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4524 vl_api_nsh_gre_add_del_tunnel_t_handler
4525 (vl_api_nsh_gre_add_del_tunnel_t * mp)
4527 vl_api_nsh_gre_add_del_tunnel_reply_t * rmp;
4529 vnet_nsh_gre_add_del_tunnel_args_t _a, *a = &_a;
4530 u32 encap_fib_index, decap_fib_index;
4531 u32 decap_next_index;
4533 ip4_main_t * im = &ip4_main;
4535 u32 sw_if_index = ~0;
4538 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4540 rv = VNET_API_ERROR_NO_SUCH_FIB;
4543 encap_fib_index = p[0];
4545 decap_next_index = ntohl(mp->decap_next_index);
4547 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4548 if (decap_next_index == NSH_GRE_INPUT_NEXT_IP4_INPUT) {
4549 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4551 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4554 decap_fib_index = p[0];
4556 decap_fib_index = ntohl(mp->decap_vrf_id);
4559 memset (a, 0, sizeof (*a));
4561 a->is_add = mp->is_add;
4562 /* ip addresses sent in network byte order */
4563 a->src.as_u32 = ntohl(mp->src);
4564 a->dst.as_u32 = ntohl(mp->dst);
4565 a->encap_fib_index = encap_fib_index;
4566 a->decap_fib_index = decap_fib_index;
4567 a->decap_next_index = decap_next_index;
4568 a->nsh_hdr.ver_o_c = mp->ver_o_c;
4569 a->nsh_hdr.length = mp->length;
4570 a->nsh_hdr.md_type = mp->md_type;
4571 a->nsh_hdr.next_protocol = mp->next_protocol;
4572 a->nsh_hdr.spi_si = ntohl(mp->spi_si);
4573 a->nsh_hdr.c1 = ntohl(mp->c1);
4574 a->nsh_hdr.c2 = ntohl(mp->c2);
4575 a->nsh_hdr.c3 = ntohl(mp->c3);
4576 a->nsh_hdr.c4 = ntohl(mp->c4);
4578 for (i = 0; i < mp->tlv_len_in_words; i++)
4579 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4581 a->nsh_hdr.tlvs = tlvs;
4583 rv = vnet_nsh_gre_add_del_tunnel (a, &sw_if_index);
4586 REPLY_MACRO2(VL_API_NSH_GRE_ADD_DEL_TUNNEL_REPLY,
4588 rmp->sw_if_index = ntohl (sw_if_index);
4593 vl_api_nsh_vxlan_gpe_add_del_tunnel_t_handler
4594 (vl_api_nsh_vxlan_gpe_add_del_tunnel_t * mp)
4596 vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4598 vnet_nsh_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4599 u32 encap_fib_index, decap_fib_index;
4600 u32 decap_next_index;
4602 ip4_main_t * im = &ip4_main;
4604 u32 sw_if_index = ~0;
4607 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4609 rv = VNET_API_ERROR_NO_SUCH_FIB;
4612 encap_fib_index = p[0];
4614 decap_next_index = ntohl(mp->decap_next_index);
4616 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4617 if (decap_next_index == NSH_GRE_INPUT_NEXT_IP4_INPUT) {
4618 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4620 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4623 decap_fib_index = p[0];
4625 decap_fib_index = ntohl(mp->decap_vrf_id);
4628 memset (a, 0, sizeof (*a));
4630 a->is_add = mp->is_add;
4631 /* ip addresses sent in network byte order */
4632 a->src.as_u32 = ntohl(mp->src);
4633 a->dst.as_u32 = ntohl(mp->dst);
4634 a->encap_fib_index = encap_fib_index;
4635 a->decap_fib_index = decap_fib_index;
4636 a->decap_next_index = decap_next_index;
4637 a->vni = ntohl(mp->vni);
4638 a->nsh_hdr.ver_o_c = mp->ver_o_c;
4639 a->nsh_hdr.length = mp->length;
4640 a->nsh_hdr.md_type = mp->md_type;
4641 a->nsh_hdr.next_protocol = mp->next_protocol;
4642 a->nsh_hdr.spi_si = ntohl(mp->spi_si);
4643 a->nsh_hdr.c1 = ntohl(mp->c1);
4644 a->nsh_hdr.c2 = ntohl(mp->c2);
4645 a->nsh_hdr.c3 = ntohl(mp->c3);
4646 a->nsh_hdr.c4 = ntohl(mp->c4);
4648 for (i = 0; i < mp->tlv_len_in_words; i++)
4649 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4651 a->nsh_hdr.tlvs = tlvs;
4653 rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4656 REPLY_MACRO2(VL_API_NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4658 rmp->sw_if_index = ntohl (sw_if_index);
4663 vl_api_lisp_gpe_add_del_tunnel_t_handler
4664 (vl_api_lisp_gpe_add_del_tunnel_t * mp)
4666 vl_api_lisp_gpe_add_del_tunnel_reply_t * rmp;
4668 vnet_lisp_gpe_add_del_tunnel_args_t _a, *a = &_a;
4669 u32 encap_fib_index, decap_fib_index;
4670 u32 decap_next_index;
4672 ip4_main_t * im = &ip4_main;
4673 u32 sw_if_index = ~0;
4675 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4677 rv = VNET_API_ERROR_NO_SUCH_FIB;
4680 encap_fib_index = p[0];
4682 decap_next_index = ntohl(mp->decap_next_index);
4684 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4685 if (decap_next_index == NSH_GRE_INPUT_NEXT_IP4_INPUT) {
4686 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4688 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4691 decap_fib_index = p[0];
4693 decap_fib_index = ntohl(mp->decap_vrf_id);
4696 memset (a, 0, sizeof (*a));
4698 a->is_add = mp->is_add;
4699 /* ip addresses sent in network byte order */
4700 a->src.as_u32 = mp->src;
4701 a->dst.as_u32 = mp->dst;
4702 a->encap_fib_index = encap_fib_index;
4703 a->decap_fib_index = decap_fib_index;
4704 a->decap_next_index = decap_next_index;
4705 a->flags = mp->flags;
4706 a->ver_res = mp->ver_res;
4708 a->next_protocol = mp->next_protocol;
4709 a->vni = clib_net_to_host_u32 (mp->iid);
4711 rv = vnet_lisp_gpe_add_del_tunnel (a, &sw_if_index);
4714 REPLY_MACRO2(VL_API_LISP_GPE_ADD_DEL_TUNNEL_REPLY,
4716 rmp->sw_if_index = ntohl (sw_if_index);
4721 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4723 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4725 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4727 u8 *locator_name = NULL;
4729 memset(a, 0, sizeof(a[0]));
4731 locator_name = format(0, "%s", mp->locator_set_name);
4733 a->name = locator_name;
4735 a->is_add = mp->is_add;
4738 rv = vnet_lisp_add_del_locator_set_name(a, &ls_index);
4740 vec_free(locator_name);
4742 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4746 vl_api_lisp_add_del_locator_t_handler(
4747 vl_api_lisp_add_del_locator_t *mp)
4749 vl_api_lisp_add_del_locator_reply_t *rmp;
4751 locator_t locator, *locators = NULL;
4752 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4754 u8 *locator_name = NULL;
4756 memset(&locator, 0, sizeof(locator));
4757 memset(a, 0, sizeof(a[0]));
4759 locator.sw_if_index = ntohl(mp->sw_if_index);
4760 locator.priority = mp->priority;
4761 locator.weight = mp->weight;
4763 vec_add1(locators, locator);
4765 locator_name = format(0, "%s", mp->locator_set_name);
4767 a->name = locator_name;
4768 a->locators = locators;
4769 a->is_add = mp->is_add;
4772 rv = vnet_lisp_add_del_locator(a, &ls_index);
4775 vec_free(locator_name);
4777 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4781 vl_api_lisp_add_del_local_eid_t_handler(
4782 vl_api_lisp_add_del_local_eid_t *mp)
4784 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4785 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4787 ip_prefix_t *prefp = NULL;
4788 ip_address_t *ip_eid = NULL;
4791 u32 locator_set_index = ~0, map_index = ~0;
4792 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4795 prefp = &gid_address_ippref(&eid);
4796 ip_eid = &ip_prefix_addr(prefp);
4797 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4800 clib_memcpy(&ip_addr_v6(ip_eid), mp->ip_address,
4801 sizeof(ip_addr_v6(ip_eid)));
4802 ip_addr_version(ip_eid) = IP6;
4804 clib_memcpy(&ip_addr_v4(ip_eid), mp->ip_address,
4805 sizeof(ip_addr_v4(ip_eid)));
4806 ip_addr_version(ip_eid) = IP4;
4808 ip_prefix_len(prefp) = mp->prefix_len;
4810 name = format(0, "%s", mp->locator_set_name);
4811 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4813 rv = VNET_API_ERROR_INVALID_VALUE;
4816 locator_set_index = p[0];
4818 /* XXX treat batch configuration */
4819 a->is_add = mp->is_add;
4821 a->locator_set_index = locator_set_index;
4824 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4829 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4833 lisp_gpe_add_del_fwd_entry_set_address(
4834 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4835 ip_address_t *slocator,
4836 ip_address_t *dlocator,
4839 ip_address_t *ip_eid = NULL;
4840 ip_prefix_t *prefp = NULL;
4842 prefp = &gid_address_ippref(eid);
4843 ip_eid = &ip_prefix_addr(prefp);
4845 if (mp->eid_is_ipv6) {
4846 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4847 sizeof(ip_addr_v6(ip_eid)));
4848 ip_addr_version(ip_eid) = IP6;
4850 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4851 sizeof(ip_addr_v4(ip_eid)));
4852 ip_addr_version(ip_eid) = IP4;
4854 ip_prefix_len(prefp) = mp->eid_prefix_len;
4856 if (mp->address_is_ipv6) {
4857 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4858 sizeof(ip_addr_v6(slocator)));
4859 ip_addr_version(slocator) = IP6;
4860 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4861 sizeof(ip_addr_v6(dlocator)));
4862 ip_addr_version(dlocator) = IP6;
4864 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4865 sizeof(ip_addr_v4(slocator)));
4866 ip_addr_version(slocator) = IP4;
4867 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4868 sizeof(ip_addr_v4(dlocator)));
4869 ip_addr_version(dlocator) = IP4;
4874 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4875 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4877 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4879 ip_address_t slocator, dlocator;
4880 ip_prefix_t * prefp = NULL;
4882 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4884 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4886 memset (&a, 0, sizeof(a));
4888 a.is_add = mp->is_add;
4890 a.slocator = slocator;
4891 a.dlocator = dlocator;
4892 prefp = &gid_address_ippref(&a.deid);
4893 a.decap_next_index = (ip_prefix_version(prefp) == IP4) ?
4894 LISP_GPE_INPUT_NEXT_IP4_INPUT : LISP_GPE_INPUT_NEXT_IP6_INPUT;
4895 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4897 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4901 vl_api_lisp_add_del_map_resolver_t_handler(
4902 vl_api_lisp_add_del_map_resolver_t *mp)
4904 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4906 ip_address_t *ip_addr = NULL;
4907 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4909 a->is_add = mp->is_add;
4910 ip_addr = &a->address;
4913 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4914 sizeof(ip_addr_v6(ip_addr)));
4915 ip_addr_version(ip_addr) = IP6;
4917 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4918 sizeof(ip_addr_v4(ip_addr)));
4919 ip_addr_version(ip_addr) = IP4;
4922 rv = vnet_lisp_add_del_map_resolver (a);
4924 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4928 vl_api_lisp_gpe_enable_disable_t_handler(
4929 vl_api_lisp_gpe_enable_disable_t *mp)
4931 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4933 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
4935 a->is_en = mp->is_en;
4936 vnet_lisp_gpe_enable_disable (a);
4938 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4942 vl_api_lisp_gpe_add_del_iface_t_handler(
4943 vl_api_lisp_gpe_add_del_iface_t *mp)
4945 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4947 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4949 a->is_add = mp->is_add;
4950 a->table_id = mp->table_id;
4952 vnet_lisp_gpe_add_del_iface (a, 0);
4954 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4958 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
4959 locator_set_t *lsit,
4960 unix_shared_memory_queue_t *q,
4963 vl_api_lisp_locator_set_details_t *rmp;
4964 locator_t *loc = NULL;
4967 vec_foreach (locit, lsit->locator_indices) {
4968 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4969 rmp = vl_msg_api_alloc (sizeof (*rmp));
4970 memset (rmp, 0, sizeof (*rmp));
4971 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
4972 strncpy((char *) rmp->locator_set_name,
4973 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4974 rmp->sw_if_index = htonl(loc->sw_if_index);
4975 rmp->priority = loc->priority;
4976 rmp->weight = loc->weight;
4977 rmp->context = context;
4979 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4984 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
4986 unix_shared_memory_queue_t * q = NULL;
4987 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4988 locator_set_t * lsit = NULL;
4990 q = vl_api_client_index_to_input_queue (mp->client_index);
4995 pool_foreach (lsit, lcm->locator_set_pool,
4997 send_lisp_locator_set_details(lcm, lsit, q, mp->context);
5002 send_lisp_local_eid_table_details (mapping_t *mapit,
5003 unix_shared_memory_queue_t *q,
5006 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
5007 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5008 locator_set_t *ls = NULL;
5009 gid_address_t *gid = NULL;
5010 ip_prefix_t *ip_prefix = NULL;
5013 ls = pool_elt_at_index (lcm->locator_set_pool,
5014 mapit->locator_set_index);
5017 type = gid_address_type(gid);
5019 if (type != GID_ADDR_IP_PREFIX) {
5023 ip_prefix = &gid_address_ippref(gid);
5025 rmp = vl_msg_api_alloc (sizeof (*rmp));
5026 memset (rmp, 0, sizeof (*rmp));
5027 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
5028 strncpy((char *) rmp->locator_set_name,
5029 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5031 switch (ip_prefix_version(ip_prefix)) {
5033 rmp->eid_is_ipv6 = 0;
5034 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v4(ip_prefix),
5035 sizeof(ip_prefix_v4(ip_prefix)));
5039 rmp->eid_is_ipv6 = 1;
5040 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v6(ip_prefix),
5041 sizeof(ip_prefix_v6(ip_prefix)));
5047 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
5048 rmp->context = context;
5050 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5054 vl_api_lisp_local_eid_table_dump_t_handler (
5055 vl_api_lisp_local_eid_table_dump_t *mp)
5057 unix_shared_memory_queue_t * q = NULL;
5058 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5059 mapping_t * mapit = NULL;
5061 q = vl_api_client_index_to_input_queue (mp->client_index);
5066 pool_foreach (mapit, lcm->mapping_pool,
5068 send_lisp_local_eid_table_details(mapit, q, mp->context);
5073 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5074 unix_shared_memory_queue_t *q,
5077 vl_api_lisp_gpe_tunnel_details_t *rmp;
5078 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5080 rmp = vl_msg_api_alloc (sizeof (*rmp));
5081 memset (rmp, 0, sizeof (*rmp));
5082 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5084 rmp->tunnels = tunnel - lgm->tunnels;
5086 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5087 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5088 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5090 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5091 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5092 rmp->dcap_next = htonl(tunnel->decap_next_index);
5093 rmp->lisp_ver = tunnel->ver_res;
5094 rmp->next_protocol = tunnel->next_protocol;
5095 rmp->flags = tunnel->flags;
5096 rmp->ver_res = tunnel->ver_res;
5097 rmp->res = tunnel->res;
5098 rmp->iid = htonl(tunnel->vni);
5099 rmp->context = context;
5101 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5105 vl_api_lisp_gpe_tunnel_dump_t_handler (
5106 vl_api_lisp_local_eid_table_dump_t *mp)
5108 unix_shared_memory_queue_t * q = NULL;
5109 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5110 lisp_gpe_tunnel_t * tunnel = NULL;
5112 if (pool_elts(lgm->tunnels) == 0) {
5116 q = vl_api_client_index_to_input_queue (mp->client_index);
5121 pool_foreach(tunnel, lgm->tunnels,
5123 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5128 send_lisp_map_resolver_details (ip_address_t *ip,
5129 unix_shared_memory_queue_t *q,
5132 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5134 rmp = vl_msg_api_alloc (sizeof (*rmp));
5135 memset (rmp, 0, sizeof (*rmp));
5136 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5138 switch (ip_addr_version(ip)) {
5141 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5146 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5152 rmp->context = context;
5154 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5158 vl_api_lisp_map_resolver_dump_t_handler (
5159 vl_api_lisp_local_eid_table_dump_t *mp)
5161 unix_shared_memory_queue_t * q = NULL;
5162 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5163 ip_address_t *ip = NULL;
5165 q = vl_api_client_index_to_input_queue (mp->client_index);
5170 vec_foreach(ip, lcm->map_resolvers) {
5171 send_lisp_map_resolver_details(ip, q, mp->context);
5177 send_lisp_gpe_enable_disable_details (unix_shared_memory_queue_t *q,
5180 vl_api_lisp_gpe_enable_disable_status_details_t *rmp = NULL;
5183 rmp = vl_msg_api_alloc (sizeof (*rmp));
5184 memset (rmp, 0, sizeof (*rmp));
5185 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_ENABLE_DISABLE_STATUS_DETAILS);
5187 is_en = vnet_lisp_gpe_enable_disable_status();
5189 rmp->context = context;
5191 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5195 vl_api_lisp_gpe_enable_disable_status_dump_t_handler
5196 (vl_api_lisp_gpe_enable_disable_status_dump_t *mp)
5198 unix_shared_memory_queue_t * q = NULL;
5200 q = vl_api_client_index_to_input_queue (mp->client_index);
5205 send_lisp_gpe_enable_disable_details(q, mp->context);
5209 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5211 vl_api_interface_name_renumber_reply_t * rmp;
5214 VALIDATE_SW_IF_INDEX(mp);
5216 rv = vnet_interface_name_renumber
5217 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5219 BAD_SW_IF_INDEX_LABEL;
5221 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5224 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5225 u32 sw_if_index, u32 address)
5227 vpe_api_main_t * am = &vpe_api_main;
5228 vlib_main_t * vm = am->vlib_main;
5229 vl_api_ip4_arp_event_t * event;
5230 static f64 arp_event_last_time;
5231 f64 now = vlib_time_now (vm);
5233 if (pool_is_free_index (am->arp_events, pool_index))
5236 event = pool_elt_at_index (am->arp_events, pool_index);
5237 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5238 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5239 } else { /* same mac */
5240 if ((sw_if_index == event->sw_if_index) &&
5242 /* for BD case, also check IP address with 10 sec timeout */
5243 ((address == event->address) &&
5244 ((now - arp_event_last_time) < 10.0))))
5248 arp_event_last_time = now;
5249 event->sw_if_index = sw_if_index;
5250 if (address) event->address = address;
5254 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5256 vpe_api_main_t * am = &vpe_api_main;
5258 if (pool_is_free_index (am->arp_events, pool_index))
5261 pool_put_index (am->arp_events, pool_index);
5266 vl_api_want_ip4_arp_events_t_handler
5267 (vl_api_want_ip4_arp_events_t * mp)
5269 vpe_api_main_t * am = &vpe_api_main;
5270 vnet_main_t * vnm = vnet_get_main();
5271 vl_api_want_ip4_arp_events_reply_t *rmp;
5272 vl_api_ip4_arp_event_t * event;
5275 if (mp->enable_disable) {
5276 pool_get (am->arp_events, event);
5277 memset (event, 0, sizeof (*event));
5279 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5280 event->client_index = mp->client_index;
5281 event->context = mp->context;
5282 event->address = mp->address;
5283 event->pid = mp->pid;
5285 rv = vnet_add_del_ip4_arp_change_event
5286 (vnm, arp_change_data_callback,
5288 &mp->address /* addr, in net byte order */,
5289 vpe_resolver_process_node.index,
5290 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5292 rv = vnet_add_del_ip4_arp_change_event
5293 (vnm, arp_change_delete_callback,
5295 &mp->address /* addr, in net byte order */,
5296 vpe_resolver_process_node.index,
5297 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5299 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5302 static void vl_api_input_acl_set_interface_t_handler
5303 (vl_api_input_acl_set_interface_t * mp)
5305 vlib_main_t *vm = vlib_get_main();
5306 vl_api_input_acl_set_interface_reply_t * rmp;
5308 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5310 ip4_table_index = ntohl(mp->ip4_table_index);
5311 ip6_table_index = ntohl(mp->ip6_table_index);
5312 l2_table_index = ntohl(mp->l2_table_index);
5313 sw_if_index = ntohl(mp->sw_if_index);
5315 VALIDATE_SW_IF_INDEX(mp);
5317 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5318 ip6_table_index, l2_table_index,
5321 BAD_SW_IF_INDEX_LABEL;
5323 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5326 static void vl_api_ipsec_spd_add_del_t_handler
5327 (vl_api_ipsec_spd_add_del_t * mp)
5330 clib_warning ("unimplemented");
5333 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5334 vl_api_ipsec_spd_add_del_reply_t * rmp;
5338 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5340 rv = VNET_API_ERROR_UNIMPLEMENTED;
5343 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5347 static void vl_api_ipsec_interface_add_del_spd_t_handler
5348 (vl_api_ipsec_interface_add_del_spd_t * mp)
5350 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5351 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5353 u32 sw_if_index __attribute__((unused));
5354 u32 spd_id __attribute__((unused));
5356 sw_if_index = ntohl(mp->sw_if_index);
5357 spd_id = ntohl(mp->spd_id);
5359 VALIDATE_SW_IF_INDEX(mp);
5362 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5364 rv = VNET_API_ERROR_UNIMPLEMENTED;
5367 BAD_SW_IF_INDEX_LABEL;
5369 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5372 static void vl_api_ipsec_spd_add_del_entry_t_handler
5373 (vl_api_ipsec_spd_add_del_entry_t * mp)
5375 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5376 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5382 memset(&p, 0, sizeof(p));
5384 p.id = ntohl(mp->spd_id);
5385 p.priority = ntohl(mp->priority);
5386 p.is_outbound = mp->is_outbound;
5387 p.is_ipv6 = mp->is_ipv6;
5389 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5390 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5391 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5392 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5394 p.protocol = mp->protocol;
5395 p.rport.start = ntohs(mp->remote_port_start);
5396 p.rport.stop = ntohs(mp->remote_port_stop);
5397 p.lport.start = ntohs(mp->local_port_start);
5398 p.lport.stop = ntohs(mp->local_port_stop);
5399 /* policy action resolve unsupported */
5400 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5401 clib_warning("unsupported action: 'resolve'");
5402 rv = VNET_API_ERROR_UNIMPLEMENTED;
5405 p.policy = mp->policy;
5406 p.sa_id = ntohl(mp->sa_id);
5408 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5412 if (mp->is_ip_any) {
5414 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5417 rv = VNET_API_ERROR_UNIMPLEMENTED;
5422 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5425 static void vl_api_ipsec_sad_add_del_entry_t_handler
5426 (vl_api_ipsec_sad_add_del_entry_t * mp)
5428 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5429 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5434 memset(&sa, 0, sizeof(sa));
5436 sa.id = ntohl(mp->sad_id);
5437 sa.spi = ntohl(mp->spi);
5438 /* security protocol AH unsupported */
5439 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5440 clib_warning("unsupported security protocol 'AH'");
5441 rv = VNET_API_ERROR_UNIMPLEMENTED;
5444 sa.protocol = mp->protocol;
5445 /* check for unsupported crypto-alg */
5446 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5447 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5448 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5449 mp->crypto_algorithm);
5450 rv = VNET_API_ERROR_UNIMPLEMENTED;
5453 sa.crypto_alg = mp->crypto_algorithm;
5454 sa.crypto_key_len = mp->crypto_key_length;
5455 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5456 /* check for unsupported integ-alg */
5457 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5458 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5459 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5460 mp->integrity_algorithm);
5461 rv = VNET_API_ERROR_UNIMPLEMENTED;
5464 sa.integ_alg = mp->integrity_algorithm;
5465 sa.integ_key_len = mp->integrity_key_length;
5466 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5467 sa.use_esn = mp->use_extended_sequence_number;
5468 sa.is_tunnel = mp->is_tunnel;
5469 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5470 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5471 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5473 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5475 rv = VNET_API_ERROR_UNIMPLEMENTED;
5480 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5484 vl_api_ikev2_profile_add_del_t_handler
5485 (vl_api_ikev2_profile_add_del_t * mp)
5487 vl_api_ikev2_profile_add_del_reply_t * rmp;
5491 vlib_main_t * vm = vlib_get_main();
5492 clib_error_t * error;
5493 u8 * tmp = format(0, "%s", mp->name);
5494 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5497 rv = VNET_API_ERROR_UNSPECIFIED;
5499 rv = VNET_API_ERROR_UNIMPLEMENTED;
5502 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5506 vl_api_ikev2_profile_set_auth_t_handler
5507 (vl_api_ikev2_profile_set_auth_t * mp)
5509 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5513 vlib_main_t * vm = vlib_get_main();
5514 clib_error_t * error;
5515 u8 * tmp = format(0, "%s", mp->name);
5516 u8 * data = vec_new (u8, mp->data_len);
5517 clib_memcpy(data, mp->data, mp->data_len);
5518 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5522 rv = VNET_API_ERROR_UNSPECIFIED;
5524 rv = VNET_API_ERROR_UNIMPLEMENTED;
5527 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5531 vl_api_ikev2_profile_set_id_t_handler
5532 (vl_api_ikev2_profile_set_id_t * mp)
5534 vl_api_ikev2_profile_add_del_reply_t * rmp;
5538 vlib_main_t * vm = vlib_get_main();
5539 clib_error_t * error;
5540 u8 * tmp = format(0, "%s", mp->name);
5541 u8 * data = vec_new (u8, mp->data_len);
5542 clib_memcpy(data, mp->data, mp->data_len);
5543 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
5547 rv = VNET_API_ERROR_UNSPECIFIED;
5549 rv = VNET_API_ERROR_UNIMPLEMENTED;
5552 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5556 vl_api_ikev2_profile_set_ts_t_handler
5557 (vl_api_ikev2_profile_set_ts_t * mp)
5559 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5563 vlib_main_t * vm = vlib_get_main();
5564 clib_error_t * error;
5565 u8 * tmp = format(0, "%s", mp->name);
5566 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
5567 mp->end_port, (ip4_address_t) mp->start_addr,
5568 (ip4_address_t) mp->end_addr, mp->is_local);
5571 rv = VNET_API_ERROR_UNSPECIFIED;
5573 rv = VNET_API_ERROR_UNIMPLEMENTED;
5576 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5580 vl_api_ikev2_set_local_key_t_handler
5581 (vl_api_ikev2_set_local_key_t * mp)
5583 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5587 vlib_main_t * vm = vlib_get_main();
5588 clib_error_t * error;
5590 error = ikev2_set_local_key(vm, mp->key_file);
5592 rv = VNET_API_ERROR_UNSPECIFIED;
5594 rv = VNET_API_ERROR_UNIMPLEMENTED;
5597 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5601 vl_api_map_add_domain_t_handler
5602 (vl_api_map_add_domain_t * mp)
5604 vl_api_map_add_domain_reply_t * rmp;
5607 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
5608 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
5609 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
5610 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
5611 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
5613 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
5615 rmp->index = ntohl(index);
5620 vl_api_map_del_domain_t_handler
5621 (vl_api_map_del_domain_t * mp)
5623 vl_api_map_del_domain_reply_t * rmp;
5626 rv = map_delete_domain(ntohl(mp->index));
5628 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
5632 vl_api_map_add_del_rule_t_handler
5633 (vl_api_map_add_del_rule_t * mp)
5635 vl_api_map_del_domain_reply_t * rmp;
5638 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
5640 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
5644 vl_api_map_domain_dump_t_handler
5645 (vl_api_map_domain_dump_t * mp)
5647 vl_api_map_domain_details_t * rmp;
5648 map_main_t *mm = &map_main;
5650 unix_shared_memory_queue_t * q;
5652 if (pool_elts (mm->domains) == 0)
5655 q = vl_api_client_index_to_input_queue (mp->client_index);
5660 pool_foreach(d, mm->domains, ({
5661 /* Make sure every field is initiated (or don't skip the memset()) */
5662 rmp = vl_msg_api_alloc (sizeof (*rmp));
5663 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
5664 rmp->domain_index = htonl(d - mm->domains);
5665 rmp->ea_bits_len = d->ea_bits_len;
5666 rmp->psid_offset = d->psid_offset;
5667 rmp->psid_length = d->psid_length;
5668 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
5669 rmp->ip4_prefix_len = d->ip4_prefix_len;
5670 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
5671 rmp->ip6_prefix_len = d->ip6_prefix_len;
5672 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
5673 rmp->ip6_src_len = d->ip6_src_len;
5674 rmp->mtu = htons(d->mtu);
5675 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
5676 rmp->context = mp->context;
5678 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5683 vl_api_map_rule_dump_t_handler
5684 (vl_api_map_rule_dump_t * mp)
5686 unix_shared_memory_queue_t * q;
5689 vl_api_map_rule_details_t * rmp;
5690 map_main_t *mm = &map_main;
5691 u32 domain_index = ntohl(mp->domain_index);
5694 if (pool_elts (mm->domains) == 0)
5697 d = pool_elt_at_index(mm->domains, domain_index);
5698 if (!d || !d->rules) {
5702 q = vl_api_client_index_to_input_queue (mp->client_index);
5707 for (i = 0; i < (0x1 << d->psid_length); i++) {
5709 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
5712 rmp = vl_msg_api_alloc(sizeof(*rmp));
5713 memset(rmp, 0, sizeof(*rmp));
5714 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
5715 rmp->psid = htons(i);
5716 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
5717 rmp->context = mp->context;
5718 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5723 vl_api_map_summary_stats_t_handler (
5724 vl_api_map_summary_stats_t *mp)
5726 vl_api_map_summary_stats_reply_t *rmp;
5727 vlib_combined_counter_main_t *cm;
5730 u64 total_pkts[VLIB_N_RX_TX];
5731 u64 total_bytes[VLIB_N_RX_TX];
5732 map_main_t *mm = &map_main;
5733 unix_shared_memory_queue_t *q =
5734 vl_api_client_index_to_input_queue(mp->client_index);
5739 rmp = vl_msg_api_alloc (sizeof (*rmp));
5740 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
5741 rmp->context = mp->context;
5744 memset (total_pkts, 0, sizeof (total_pkts));
5745 memset (total_bytes, 0, sizeof (total_bytes));
5747 map_domain_counter_lock (mm);
5748 vec_foreach(cm, mm->domain_counters) {
5749 which = cm - mm->domain_counters;
5751 for (i = 0; i < vec_len(cm->maxi); i++) {
5752 vlib_get_combined_counter (cm, i, &v);
5753 total_pkts[which] += v.packets;
5754 total_bytes[which] += v.bytes;
5758 map_domain_counter_unlock (mm);
5760 /* Note: in network byte order! */
5761 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
5762 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
5763 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
5764 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
5765 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
5766 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
5767 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));
5768 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));
5770 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5773 static void vl_api_ipsec_sa_set_key_t_handler
5774 (vl_api_ipsec_sa_set_key_t * mp)
5776 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5777 vl_api_ipsec_sa_set_key_reply_t *rmp;
5781 sa.id = ntohl(mp->sa_id);
5782 sa.crypto_key_len = mp->crypto_key_length;
5783 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5784 sa.integ_key_len = mp->integrity_key_length;
5785 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5787 rv = ipsec_set_sa_key(vm, &sa);
5789 rv = VNET_API_ERROR_UNIMPLEMENTED;
5792 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
5795 static void vl_api_cop_interface_enable_disable_t_handler
5796 (vl_api_cop_interface_enable_disable_t * mp)
5798 vl_api_cop_interface_enable_disable_reply_t * rmp;
5800 u32 sw_if_index = ntohl(mp->sw_if_index);
5803 VALIDATE_SW_IF_INDEX(mp);
5805 enable_disable = (int) mp->enable_disable;
5807 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5809 BAD_SW_IF_INDEX_LABEL;
5811 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5814 static void vl_api_cop_whitelist_enable_disable_t_handler
5815 (vl_api_cop_whitelist_enable_disable_t * mp)
5817 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
5818 cop_whitelist_enable_disable_args_t _a, *a=&_a;
5819 u32 sw_if_index = ntohl(mp->sw_if_index);
5822 VALIDATE_SW_IF_INDEX(mp);
5824 a->sw_if_index = sw_if_index;
5827 a->default_cop = mp->default_cop;
5828 a->fib_id = ntohl(mp->fib_id);
5830 rv = cop_whitelist_enable_disable (a);
5832 BAD_SW_IF_INDEX_LABEL;
5834 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5837 static void vl_api_get_node_graph_t_handler
5838 (vl_api_get_node_graph_t * mp)
5842 api_main_t * am = &api_main;
5843 vlib_main_t * vm = vlib_get_main();
5845 vl_api_get_node_graph_reply_t * rmp;
5847 pthread_mutex_lock (&am->vlib_rp->mutex);
5848 oldheap = svm_push_data_heap (am->vlib_rp);
5851 * Keep the number of memcpy ops to a minimum (e.g. 1).
5852 * The current size of the serialized vector is
5853 * slightly under 4K.
5855 vec_validate (vector, 4095);
5856 vec_reset_length (vector);
5858 vector = vlib_node_serialize (&vm->node_main, vector);
5860 svm_pop_heap (oldheap);
5861 pthread_mutex_unlock (&am->vlib_rp->mutex);
5863 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5864 rmp->reply_in_shmem = (uword) vector);
5867 static void vl_api_trace_profile_add_t_handler
5868 (vl_api_trace_profile_add_t *mp)
5871 vl_api_trace_profile_add_reply_t * rmp;
5872 clib_error_t *error;
5874 /* Ignoring the profile id as currently a single profile
5876 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5877 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5878 mp->pow_enable, mp->trace_tsp,
5881 clib_error_report(error);
5882 rv = clib_error_get_code(error);
5885 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5888 static void vl_api_trace_profile_apply_t_handler
5889 (vl_api_trace_profile_apply_t *mp)
5892 vl_api_trace_profile_apply_reply_t * rmp;
5894 if (mp->enable != 0) {
5895 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5896 ntohl(mp->prefix_length),
5898 mp->trace_op == IOAM_HBYH_ADD,
5899 mp->trace_op == IOAM_HBYH_POP,
5900 mp->trace_op == IOAM_HBYH_MOD);
5902 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5904 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5907 static void vl_api_trace_profile_del_t_handler
5908 (vl_api_trace_profile_del_t *mp)
5911 vl_api_trace_profile_del_reply_t * rmp;
5912 clib_error_t *error;
5914 error = clear_ioam_rewrite_fn();
5916 clib_error_report(error);
5917 rv = clib_error_get_code(error);
5920 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5924 #define BOUNCE_HANDLER(nn) \
5925 static void vl_api_##nn##_t_handler ( \
5926 vl_api_##nn##_t *mp) \
5928 vpe_client_registration_t *reg; \
5929 vpe_api_main_t * vam = &vpe_api_main; \
5930 unix_shared_memory_queue_t * q; \
5932 /* One registration only... */ \
5933 pool_foreach(reg, vam->nn##_registrations, \
5935 q = vl_api_client_index_to_input_queue (reg->client_index); \
5938 * If the queue is stuffed, turf the msg and complain \
5939 * It's unlikely that the intended recipient is \
5940 * alive; avoid deadlock at all costs. \
5942 if (q->cursize == q->maxsize) { \
5943 clib_warning ("ERROR: receiver queue full, drop msg"); \
5944 vl_msg_api_free (mp); \
5947 vl_msg_api_send_shmem (q, (u8 *)&mp); \
5951 vl_msg_api_free (mp); \
5956 * Add vpe's API message handlers to the table.
5957 * vlib has alread mapped shared memory and
5958 * added the client registration handlers.
5959 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
5962 static clib_error_t *
5963 vpe_api_hookup (vlib_main_t *vm)
5965 api_main_t * am = &api_main;
5968 vl_msg_api_set_handlers(VL_API_##N, #n, \
5969 vl_api_##n##_t_handler, \
5971 vl_api_##n##_t_endian, \
5972 vl_api_##n##_t_print, \
5973 sizeof(vl_api_##n##_t), 1);
5974 foreach_vpe_api_msg;
5978 * Manually register the sr tunnel add del msg, so we trace
5979 * enough bytes to capture a typical segment list
5981 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
5982 "sr_tunnel_add_del",
5983 vl_api_sr_tunnel_add_del_t_handler,
5985 vl_api_sr_tunnel_add_del_t_endian,
5986 vl_api_sr_tunnel_add_del_t_print,
5991 * Manually register the sr policy add del msg, so we trace
5992 * enough bytes to capture a typical tunnel name list
5994 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
5995 "sr_policy_add_del",
5996 vl_api_sr_policy_add_del_t_handler,
5998 vl_api_sr_policy_add_del_t_endian,
5999 vl_api_sr_policy_add_del_t_print,
6003 * Trace space for 8 MPLS encap labels, classifier mask+match
6005 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
6006 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
6007 += 5 * sizeof (u32x4);
6008 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
6009 += 5 * sizeof (u32x4);
6010 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
6011 += 16 * sizeof (u32);
6014 * trace space for 4 nsh-gre variable TLV words
6016 am->api_trace_cfg [VL_API_NSH_GRE_ADD_DEL_TUNNEL].size
6017 += 4 * sizeof (u32);
6020 * Thread-safe API messages
6022 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
6027 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
6029 static clib_error_t *
6030 vpe_api_init (vlib_main_t *vm)
6032 vpe_api_main_t *am = &vpe_api_main;
6035 am->vnet_main = vnet_get_main();
6036 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
6037 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6038 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6039 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6040 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6041 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
6044 vl_set_memory_region_name ("/vpe-api");
6045 vl_enable_disable_memory_api (vm, 1 /* enable it */);
6050 VLIB_INIT_FUNCTION(vpe_api_init);
6052 static clib_error_t *
6053 chroot_config (vlib_main_t * vm, unformat_input_t * input)
6057 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6059 if (unformat (input, "prefix %s", &chroot_path))
6061 vec_add1 (chroot_path, 0);
6062 vl_set_memory_root_path ((char *)chroot_path);
6065 return clib_error_return (0, "unknown input `%U'",
6066 format_unformat_error, input);
6070 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
6072 void * get_unformat_vnet_sw_interface (void)
6074 return (void *) &unformat_vnet_sw_interface;
6077 #undef vl_api_version
6078 #define vl_api_version(n,v) static u32 vpe_api_version = v;
6079 #include <api/vpe.api.h>
6080 #undef vl_api_version
6082 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
6084 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
6085 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
6086 clib_host_to_net_u32 (mp->api_versions[0]),
6093 static u8 * format_arp_event (u8 * s, va_list * args)
6095 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
6097 s = format (s, "pid %d: %U", event->pid,
6098 format_ip4_address, &event->address);
6102 static clib_error_t *
6103 show_ip4_arp_events_fn (vlib_main_t * vm,
6104 unformat_input_t * input,
6105 vlib_cli_command_t * cmd)
6107 vpe_api_main_t * am = &vpe_api_main;
6108 vl_api_ip4_arp_event_t * event;
6110 if (pool_elts (am->arp_events) == 0) {
6111 vlib_cli_output (vm, "No active arp event registrations");
6115 pool_foreach (event, am->arp_events,
6117 vlib_cli_output (vm, "%U", format_arp_event, event);
6123 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
6124 .path = "show arp event registrations",
6125 .function = show_ip4_arp_events_fn,
6126 .short_help = "Show arp event registrations",