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/vxlan-gpe/vxlan_gpe.h>
71 #include <vnet/lisp-gpe/lisp_gpe.h>
72 #include <vnet/lisp-cp/control.h>
73 #include <vnet/map/map.h>
74 #include <vnet/cop/cop.h>
75 #include <vnet/ip/ip6_hop_by_hop.h>
76 #include <vnet/devices/af_packet/af_packet.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 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
291 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
292 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
293 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
294 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
295 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
296 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
297 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
298 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
299 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
300 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
301 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
302 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
303 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
304 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
305 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
306 _(DELETE_LOOPBACK, delete_loopback) \
307 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
308 _(MAP_ADD_DOMAIN, map_add_domain) \
309 _(MAP_DEL_DOMAIN, map_del_domain) \
310 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
311 _(MAP_DOMAIN_DUMP, map_domain_dump) \
312 _(MAP_RULE_DUMP, map_rule_dump) \
313 _(MAP_SUMMARY_STATS, map_summary_stats) \
314 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
315 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
316 _(GET_NODE_GRAPH, get_node_graph) \
317 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
318 _(TRACE_PROFILE_ADD, trace_profile_add) \
319 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
320 _(TRACE_PROFILE_DEL, trace_profile_del) \
321 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
322 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
323 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
324 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
325 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
326 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
327 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
328 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
329 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
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_ENABLE_DISABLE_STATUS_DUMP, \
335 lisp_enable_disable_status_dump) \
336 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
337 _(AF_PACKET_CREATE, af_packet_create) \
338 _(AF_PACKET_DELETE, af_packet_delete)
341 #define QUOTE(x) QUOTE_(x)
343 #define foreach_registration_hash \
344 _(interface_events) \
345 _(to_netconf_server) \
346 _(from_netconf_server) \
347 _(to_netconf_client) \
348 _(from_netconf_client) \
352 RESOLVE_IP4_ADD_DEL_ROUTE=1,
353 RESOLVE_IP6_ADD_DEL_ROUTE,
354 RESOLVE_MPLS_ETHERNET_ADD_DEL,
360 vl_api_ip_add_del_route_t r;
361 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
367 #define _(a) uword *a##_registration_hash; \
368 vpe_client_registration_t * a##_registrations;
369 foreach_registration_hash
372 /* notifications happen really early in the game */
373 u8 link_state_process_up;
375 /* ip4 pending route adds */
376 pending_route_t * pending_routes;
378 /* ip4 arp event registration pool */
379 vl_api_ip4_arp_event_t * arp_events;
382 vlib_main_t * vlib_main;
383 vnet_main_t * vnet_main;
386 static vlib_node_registration_t vpe_resolver_process_node;
387 static vpe_api_main_t vpe_api_main;
389 static void send_sw_interface_flags (vpe_api_main_t * am,
390 unix_shared_memory_queue_t *q,
391 vnet_sw_interface_t * swif);
392 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
393 unix_shared_memory_queue_t *q,
396 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
399 /* Clean up all registrations belonging to the indicated client */
400 int vl_api_memclnt_delete_callback (u32 client_index)
402 vpe_api_main_t * vam = &vpe_api_main;
403 vpe_client_registration_t *rp;
405 int stats_memclnt_delete_callback (u32 client_index);
407 stats_memclnt_delete_callback (client_index);
410 p = hash_get (vam->a##_registration_hash, client_index); \
412 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
413 pool_put (vam->a##_registrations, rp); \
414 hash_unset (vam->a##_registration_hash, client_index); \
416 foreach_registration_hash;
421 #define API_LINK_STATE_EVENT 1
422 #define API_ADMIN_UP_DOWN_EVENT 2
425 event_data_cmp (void * a1, void * a2)
430 return (word) e1[0] - (word) e2[0];
434 link_state_process (vlib_main_t * vm,
435 vlib_node_runtime_t * rt,
438 vpe_api_main_t * vam = &vpe_api_main;
439 vnet_main_t * vnm = vam->vnet_main;
440 vnet_sw_interface_t * swif;
441 uword * event_data = 0;
442 vpe_client_registration_t *reg;
444 u32 prev_sw_if_index;
445 unix_shared_memory_queue_t * q;
447 vam->link_state_process_up = 1;
450 vlib_process_wait_for_event (vm);
452 /* Unified list of changed link or admin state sw_if_indices */
453 vlib_process_get_events_with_type
454 (vm, &event_data, API_LINK_STATE_EVENT);
455 vlib_process_get_events_with_type
456 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
458 /* Sort, so we can eliminate duplicates */
459 vec_sort_with_function (event_data, event_data_cmp);
461 prev_sw_if_index = ~0;
463 for (i = 0; i < vec_len(event_data); i++) {
464 /* Only one message per swif */
465 if (prev_sw_if_index == event_data[i])
467 prev_sw_if_index = event_data[i];
469 pool_foreach(reg, vam->interface_events_registrations,
471 q = vl_api_client_index_to_input_queue (reg->client_index);
473 // sw_interface may be deleted already
474 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
477 swif = vnet_get_sw_interface (vnm, event_data[i]);
478 send_sw_interface_flags (vam, q, swif);
483 vec_reset_length (event_data);
489 static clib_error_t *
490 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
491 static clib_error_t *
492 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
494 VLIB_REGISTER_NODE (link_state_process_node,static) = {
495 .function = link_state_process,
496 .type = VLIB_NODE_TYPE_PROCESS,
497 .name = "vpe-link-state-process",
500 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
501 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
503 static clib_error_t *
504 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
506 vpe_api_main_t * vam = &vpe_api_main;
507 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
509 if (vam->link_state_process_up)
510 vlib_process_signal_event (vam->vlib_main,
511 link_state_process_node.index,
512 API_LINK_STATE_EVENT,
517 static clib_error_t *
518 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
520 vpe_api_main_t * vam = &vpe_api_main;
523 * Note: it's perfectly fair to set a subif admin up / admin down.
524 * Note the subtle distinction between this routine and the previous
527 if (vam->link_state_process_up)
528 vlib_process_signal_event (vam->vlib_main,
529 link_state_process_node.index,
530 API_ADMIN_UP_DOWN_EVENT,
535 #define pub_sub_handler(lca,UCA) \
536 static void vl_api_want_##lca##_t_handler ( \
537 vl_api_want_##lca##_t *mp) \
539 vpe_api_main_t *vam = &vpe_api_main; \
540 vpe_client_registration_t *rp; \
541 vl_api_want_##lca##_reply_t *rmp; \
545 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
547 if (mp->enable_disable) { \
548 clib_warning ("pid %d: already enabled...", mp->pid); \
549 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
552 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
553 pool_put (vam->lca##_registrations, rp); \
554 hash_unset (vam->lca##_registration_hash, \
559 if (mp->enable_disable == 0) { \
560 clib_warning ("pid %d: already disabled...", mp->pid); \
561 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
564 pool_get (vam->lca##_registrations, rp); \
565 rp->client_index = mp->client_index; \
566 rp->client_pid = mp->pid; \
567 hash_set (vam->lca##_registration_hash, rp->client_index, \
568 rp - vam->lca##_registrations); \
571 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
574 pub_sub_handler (interface_events,INTERFACE_EVENTS)
575 pub_sub_handler (oam_events,OAM_EVENTS)
577 #define RESOLUTION_EVENT 1
578 #define RESOLUTION_PENDING_EVENT 2
579 #define IP4_ARP_EVENT 3
581 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
582 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
583 static int mpls_ethernet_add_del_tunnel_2_t_handler
584 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
586 void handle_ip4_arp_event (u32 pool_index)
588 vpe_api_main_t * vam = &vpe_api_main;
589 vnet_main_t * vnm = vam->vnet_main;
590 vlib_main_t * vm = vam->vlib_main;
591 vl_api_ip4_arp_event_t * event;
592 vl_api_ip4_arp_event_t * mp;
593 unix_shared_memory_queue_t * q;
595 /* Client can cancel, die, etc. */
596 if (pool_is_free_index (vam->arp_events, pool_index))
599 event = pool_elt_at_index (vam->arp_events, pool_index);
601 q = vl_api_client_index_to_input_queue (event->client_index);
603 (void) vnet_add_del_ip4_arp_change_event
604 (vnm, arp_change_delete_callback,
605 event->pid, &event->address,
606 vpe_resolver_process_node.index, IP4_ARP_EVENT,
607 ~0 /* pool index, notused */, 0 /* is_add */);
611 if (q->cursize < q->maxsize) {
612 mp = vl_msg_api_alloc (sizeof (*mp));
613 clib_memcpy (mp, event, sizeof (*mp));
614 vl_msg_api_send_shmem (q, (u8 *)&mp);
616 static f64 last_time;
618 * Throttle syslog msgs.
619 * It's pretty tempting to just revoke the registration...
621 if (vlib_time_now (vm) > last_time + 10.0) {
622 clib_warning ("arp event for %U to pid %d: queue stuffed!",
623 format_ip4_address, &event->address, event->pid);
624 last_time = vlib_time_now(vm);
630 resolver_process (vlib_main_t * vm,
631 vlib_node_runtime_t * rt,
635 uword *event_data = 0;
637 vpe_api_main_t * vam = &vpe_api_main;
638 pending_route_t * pr;
639 vl_api_ip_add_del_route_t * adr;
640 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
641 u32 * resolution_failures = 0;
646 vlib_process_wait_for_event_or_clock (vm, timeout);
648 event_type = vlib_process_get_events (vm, &event_data);
650 switch (event_type) {
651 case RESOLUTION_PENDING_EVENT:
655 case RESOLUTION_EVENT:
656 for (i = 0; i < vec_len(event_data); i++) {
658 * Resolution events can occur long after the
659 * original request has timed out. $$$ add a cancel
662 if (pool_is_free_index (vam->pending_routes, event_data[i]))
665 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
669 switch (pr->resolve_type) {
670 case RESOLVE_IP4_ADD_DEL_ROUTE:
671 rv = ip4_add_del_route_t_handler (adr);
672 clib_warning ("resolver: add %U/%d via %U %s",
674 (ip4_address_t *)&(adr->dst_address),
675 adr->dst_address_length,
677 (ip4_address_t *)&(adr->next_hop_address),
678 (rv >= 0) ? "succeeded" : "failed");
681 case RESOLVE_IP6_ADD_DEL_ROUTE:
682 rv = ip6_add_del_route_t_handler (adr);
683 clib_warning ("resolver: add %U/%d via %U %s",
685 (ip6_address_t *)&(adr->dst_address),
686 adr->dst_address_length,
688 (ip6_address_t *)&(adr->next_hop_address),
689 (rv >= 0) ? "succeeded" : "failed");
692 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
693 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
694 clib_warning ("resolver: add mpls-o-e via %U %s",
696 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
697 (rv >= 0) ? "succeeded" : "failed");
701 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
703 pool_put (vam->pending_routes, pr);
708 for (i = 0; i < vec_len(event_data); i++)
709 handle_ip4_arp_event (event_data[i]);
712 case ~0: /* timeout, retry pending resolutions */
713 pool_foreach (pr, vam->pending_routes,
719 /* May fail, e.g. due to interface down */
720 switch (pr->resolve_type) {
721 case RESOLVE_IP4_ADD_DEL_ROUTE:
722 e = ip4_probe_neighbor
723 (vm, (ip4_address_t *)&(adr->next_hop_address),
724 ntohl(adr->next_hop_sw_if_index));
727 case RESOLVE_IP6_ADD_DEL_ROUTE:
728 e = ip6_probe_neighbor
729 (vm, (ip6_address_t *)&(adr->next_hop_address),
730 ntohl(adr->next_hop_sw_if_index));
733 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
735 e = ip4_probe_neighbor
737 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
738 pme->resolve_opaque);
742 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
746 clib_error_report (e);
748 adr->resolve_attempts = 1;
750 pme->resolve_attempts = 1;
754 adr->resolve_attempts -= 1;
755 if (adr->resolve_attempts == 0)
756 vec_add1 (resolution_failures,
757 pr - vam->pending_routes);
759 pme->resolve_attempts -= 1;
760 if (pme->resolve_attempts == 0)
761 vec_add1 (resolution_failures,
762 pr - vam->pending_routes);
766 for (i = 0; i < vec_len (resolution_failures); i++) {
767 pr = pool_elt_at_index (vam->pending_routes,
768 resolution_failures[i]);
772 switch (pr->resolve_type) {
773 case RESOLVE_IP4_ADD_DEL_ROUTE:
774 clib_warning ("resolver: add %U/%d via %U retry failure",
776 (ip4_address_t *)&(adr->dst_address),
777 adr->dst_address_length,
779 (ip4_address_t *)&(adr->next_hop_address));
782 case RESOLVE_IP6_ADD_DEL_ROUTE:
783 clib_warning ("resolver: add %U/%d via %U retry failure",
785 (ip6_address_t *)&(adr->dst_address),
786 adr->dst_address_length,
788 (ip6_address_t *)&(adr->next_hop_address));
791 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
792 clib_warning ("resolver: add mpls-o-e via %U retry failure",
794 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
798 clib_warning ("BUG");
800 pool_put(vam->pending_routes, pr);
802 vec_reset_length (resolution_failures);
805 if (pool_elts (vam->pending_routes) == 0)
807 vec_reset_length (event_data);
809 return 0; /* or not */
812 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
813 .function = resolver_process,
814 .type = VLIB_NODE_TYPE_PROCESS,
815 .name = "vpe-route-resolver-process",
818 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
820 ip4_main_t * im = &ip4_main;
821 ip_lookup_main_t * lm = &im->lookup_main;
822 vnet_classify_main_t * cm = &vnet_classify_main;
823 stats_main_t * sm = &stats_main;
824 ip4_add_del_route_args_t a;
825 ip4_address_t next_hop_address;
827 vpe_api_main_t * vam = &vpe_api_main;
828 vnet_main_t * vnm = vam->vnet_main;
829 vlib_main_t * vm = vlib_get_main();
830 pending_route_t * pr;
831 vl_api_ip_add_del_route_t * adr;
835 ip_adjacency_t *nh_adj, *add_adj = 0;
837 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
839 if (mp->create_vrf_if_needed) {
841 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
843 fib_index = f->index;
845 /* No such VRF, and we weren't asked to create one */
846 return VNET_API_ERROR_NO_SUCH_FIB;
852 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
853 ntohl(mp->next_hop_sw_if_index)))
854 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
856 clib_memcpy (next_hop_address.data, mp->next_hop_address,
857 sizeof (next_hop_address.data));
859 /* Arp for the next_hop if necessary */
860 if (mp->is_add && mp->resolve_if_needed) {
862 ip_adjacency_t * adj;
864 lookup_result = ip4_fib_lookup_with_table
865 (im, fib_index, &next_hop_address, 1 /* disable default route */);
867 adj = ip_get_adjacency (lm, lookup_result);
869 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
870 pool_get (vam->pending_routes, pr);
871 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
873 clib_memcpy (adr, mp, sizeof (*adr));
874 /* recursion block, "just in case" */
875 adr->resolve_if_needed = 0;
876 adr->resolve_attempts = ntohl(mp->resolve_attempts);
877 vnet_register_ip4_arp_resolution_event
878 (vnm, &next_hop_address, vpe_resolver_process_node.index,
879 RESOLUTION_EVENT, pr - vam->pending_routes);
881 vlib_process_signal_event
882 (vm, vpe_resolver_process_node.index,
883 RESOLUTION_PENDING_EVENT, 0 /* data */);
885 /* The interface may be down, etc. */
886 e = ip4_probe_neighbor
887 (vm, (ip4_address_t *)&(mp->next_hop_address),
888 ntohl(mp->next_hop_sw_if_index));
891 clib_error_report(e);
893 return VNET_API_ERROR_IN_PROGRESS;
897 if (mp->is_multipath) {
900 dslock (sm, 1 /* release hint */, 10 /* tag */);
903 flags = IP4_ROUTE_FLAG_ADD;
905 flags = IP4_ROUTE_FLAG_DEL;
908 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
910 ip4_add_del_route_next_hop (im, flags,
911 (ip4_address_t *) mp->dst_address,
912 (u32) mp->dst_address_length,
913 (ip4_address_t *) mp->next_hop_address,
914 ntohl(mp->next_hop_sw_if_index),
915 (u32) mp->next_hop_weight,
922 memset (&a, 0, sizeof (a));
923 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
925 a.dst_address_length = mp->dst_address_length;
927 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
928 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
929 a.table_index_or_table_id = fib_index;
934 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
936 dslock (sm, 1 /* release hint */, 2 /* tag */);
940 ai = lm->drop_adj_index;
941 else if (mp->is_local)
942 ai = lm->local_adj_index;
943 else if (mp->is_classify) {
945 memset(&cadj, 0, sizeof(cadj));
946 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
947 cadj.classify.table_index = ntohl(mp->classify_table_index);
948 if (pool_is_free_index (cm->tables, cadj.classify.table_index)) {
950 return VNET_API_ERROR_NO_SUCH_TABLE;
952 vec_add1 (add_adj, cadj);
956 ai = ip4_fib_lookup_with_table
957 (im, fib_index, &next_hop_address,
958 1 /* disable default route */);
959 if (ai == lm->miss_adj_index) {
961 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
965 nh_adj = ip_get_adjacency (lm, ai);
966 vec_add1 (add_adj, nh_adj[0]);
967 if (mp->lookup_in_vrf) {
968 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
970 add_adj[0].explicit_fib_index = p[0];
974 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
978 ip_adjacency_t * adj;
979 int disable_default_route = 1;
981 /* Trying to delete the default route? */
982 if (a.dst_address.as_u32 == 0 &&
983 a.dst_address_length == 0)
984 disable_default_route = 0;
986 ai = ip4_fib_lookup_with_table
987 (im, fib_index, &a.dst_address, disable_default_route);
988 if (ai == lm->miss_adj_index) {
990 return VNET_API_ERROR_UNKNOWN_DESTINATION;
993 adj = ip_get_adjacency (lm, ai);
994 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
996 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1002 a.add_adj = add_adj;
1003 a.n_add_adj = vec_len(add_adj);
1004 ip4_add_del_route (im, &a);
1012 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1014 ip6_main_t * im = &ip6_main;
1015 ip_lookup_main_t * lm = &im->lookup_main;
1016 vnet_main_t * vnm = vnet_get_main();
1017 vlib_main_t * vm = vlib_get_main();
1018 vpe_api_main_t * vam = &vpe_api_main;
1019 stats_main_t * sm = &stats_main;
1020 ip6_add_del_route_args_t a;
1021 ip6_address_t next_hop_address;
1022 pending_route_t * pr;
1023 vl_api_ip_add_del_route_t * adr;
1028 ip_adjacency_t * nh_adj, * add_adj = 0;
1031 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1034 if (mp->create_vrf_if_needed) {
1036 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1038 fib_index = f->index;
1040 /* No such VRF, and we weren't asked to create one */
1041 return VNET_API_ERROR_NO_SUCH_FIB;
1047 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1048 ntohl(mp->next_hop_sw_if_index)))
1049 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1051 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1052 sizeof (next_hop_address.as_u8));
1054 /* Arp for the next_hop if necessary */
1055 if (mp->is_add && mp->resolve_if_needed) {
1057 ip_adjacency_t * adj;
1059 lookup_result = ip6_fib_lookup_with_table
1060 (im, fib_index, &next_hop_address);
1062 adj = ip_get_adjacency (lm, lookup_result);
1064 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1065 pool_get (vam->pending_routes, pr);
1067 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1068 clib_memcpy (adr, mp, sizeof (*adr));
1069 /* recursion block, "just in case" */
1070 adr->resolve_if_needed = 0;
1071 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1072 vnet_register_ip6_neighbor_resolution_event
1073 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1074 RESOLUTION_EVENT, pr - vam->pending_routes);
1076 vlib_process_signal_event
1077 (vm, vpe_resolver_process_node.index,
1078 RESOLUTION_PENDING_EVENT, 0 /* data */);
1080 /* The interface may be down, etc. */
1081 e = ip6_probe_neighbor
1082 (vm, (ip6_address_t *)&(mp->next_hop_address),
1083 ntohl(mp->next_hop_sw_if_index));
1086 clib_error_report(e);
1088 return VNET_API_ERROR_IN_PROGRESS;
1092 if (mp->is_multipath) {
1095 dslock (sm, 1 /* release hint */, 11 /* tag */);
1098 flags = IP6_ROUTE_FLAG_ADD;
1100 flags = IP6_ROUTE_FLAG_DEL;
1103 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1105 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1106 (u32) mp->dst_address_length,
1107 (ip6_address_t *)mp->next_hop_address,
1108 ntohl(mp->next_hop_sw_if_index),
1109 (u32) mp->next_hop_weight,
1116 memset (&a, 0, sizeof (a));
1117 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1119 a.dst_address_length = mp->dst_address_length;
1121 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1122 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1123 a.table_index_or_table_id = fib_index;
1128 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1130 dslock (sm, 1 /* release hint */, 3 /* tag */);
1134 ai = lm->drop_adj_index;
1135 else if (mp->is_local)
1136 ai = lm->local_adj_index;
1138 ai = ip6_fib_lookup_with_table
1139 (im, fib_index, &next_hop_address);
1140 if (ai == lm->miss_adj_index) {
1142 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1146 nh_adj = ip_get_adjacency (lm, ai);
1147 vec_add1 (add_adj, nh_adj[0]);
1148 if (mp->lookup_in_vrf) {
1149 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1151 add_adj[0].explicit_fib_index = p[0];
1155 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1159 ip_adjacency_t * adj;
1161 ai = ip6_fib_lookup_with_table
1162 (im, fib_index, &a.dst_address);
1163 if (ai == lm->miss_adj_index) {
1165 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1167 adj = ip_get_adjacency (lm, ai);
1168 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1170 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1175 a.add_adj = add_adj;
1176 a.n_add_adj = vec_len(add_adj);
1177 ip6_add_del_route (im, &a);
1185 void vl_api_ip_add_del_route_t_handler (
1186 vl_api_ip_add_del_route_t *mp)
1188 vl_api_ip_add_del_route_reply_t * rmp;
1190 vnet_main_t * vnm = vnet_get_main();
1195 rv = ip6_add_del_route_t_handler (mp);
1197 rv = ip4_add_del_route_t_handler (mp);
1199 rv = (rv == 0) ? vnm->api_errno : rv;
1201 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1204 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1205 u32 sw_if_index, u8 *next_hop_addr)
1207 vl_api_ip_add_del_route_t mp;
1210 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1213 * Configure default IP route:
1214 * - ip route add 0.0.0.0/1 via <GW IP>
1215 * - ip route add 128.0.0.0/1 via <GW IP>
1217 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1219 mp.resolve_attempts = ~0;
1220 mp.resolve_if_needed = 1;
1222 mp.is_ipv6 = is_ipv6;
1223 mp.next_hop_weight = 1;
1225 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1228 rv = ip6_add_del_route_t_handler (&mp);
1231 mp.dst_address_length = 1;
1233 mp.dst_address[0] = 0;
1234 rv = ip4_add_del_route_t_handler (&mp);
1236 mp.dst_address[0] = 128;
1237 rv |= ip4_add_del_route_t_handler (&mp);
1241 clib_error_return (0, "failed to config default IP route");
1246 vl_api_sw_interface_add_del_address_t_handler
1247 (vl_api_sw_interface_add_del_address_t *mp)
1249 vlib_main_t *vm = vlib_get_main();
1250 vl_api_sw_interface_add_del_address_reply_t * rmp;
1254 VALIDATE_SW_IF_INDEX(mp);
1256 is_del = mp->is_add == 0;
1259 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1260 else if (mp->is_ipv6)
1261 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1262 (void *)mp->address,
1263 mp->address_length, is_del);
1265 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1266 (void *) mp->address,
1267 mp->address_length, is_del);
1269 BAD_SW_IF_INDEX_LABEL;
1271 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1275 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1278 u32 table_id = ntohl(mp->vrf_id);
1279 u32 sw_if_index = ntohl(mp->sw_if_index);
1280 vl_api_sw_interface_set_table_reply_t * rmp;
1281 stats_main_t * sm = &stats_main;
1283 VALIDATE_SW_IF_INDEX(mp);
1285 dslock (sm, 1 /* release hint */, 4 /* tag */);
1288 ip6_main_t * im = &ip6_main;
1290 find_ip6_fib_by_table_index_or_id (im, table_id,
1291 IP6_ROUTE_FLAG_TABLE_ID);
1293 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1294 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1296 rv = VNET_API_ERROR_NO_SUCH_FIB;
1299 ip4_main_t * im = &ip4_main;
1300 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1301 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1303 /* Truthfully this can't fail */
1305 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1306 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1308 rv = VNET_API_ERROR_NO_SUCH_FIB;
1313 BAD_SW_IF_INDEX_LABEL;
1315 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1319 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1321 vlib_main_t *vm = vlib_get_main();
1322 vl_api_sw_interface_set_vpath_reply_t * rmp;
1325 u32 sw_if_index = ntohl(mp->sw_if_index);
1326 ip4_main_t *ip4m = &ip4_main;
1327 ip6_main_t *ip6m = &ip6_main;
1328 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1329 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1330 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1331 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1332 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1333 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1335 VALIDATE_SW_IF_INDEX(mp);
1337 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1339 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1340 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1341 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1342 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1343 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1344 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1345 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1346 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1347 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1348 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1349 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1350 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1351 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1352 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1353 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1354 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1356 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1357 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1358 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1359 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1360 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1361 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1362 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1363 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1364 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1365 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1366 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1367 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1368 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1369 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1370 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1371 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1374 BAD_SW_IF_INDEX_LABEL;
1376 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1380 vl_api_sw_interface_set_l2_xconnect_t_handler (
1381 vl_api_sw_interface_set_l2_xconnect_t *mp)
1383 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1385 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1386 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1387 vlib_main_t *vm = vlib_get_main();
1388 vnet_main_t *vnm = vnet_get_main();
1390 VALIDATE_RX_SW_IF_INDEX(mp);
1393 VALIDATE_TX_SW_IF_INDEX(mp);
1394 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1395 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1397 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1400 BAD_RX_SW_IF_INDEX_LABEL;
1401 BAD_TX_SW_IF_INDEX_LABEL;
1403 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1407 vl_api_sw_interface_set_l2_bridge_t_handler (
1408 vl_api_sw_interface_set_l2_bridge_t *mp)
1410 bd_main_t * bdm = &bd_main;
1411 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1413 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1414 u32 bd_id = ntohl(mp->bd_id);
1418 vlib_main_t *vm = vlib_get_main();
1419 vnet_main_t *vnm = vnet_get_main();
1421 VALIDATE_RX_SW_IF_INDEX(mp);
1423 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1426 //VALIDATE_TX_SW_IF_INDEX(mp);
1427 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1428 rx_sw_if_index, bd_index, bvi, shg, 0);
1430 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1433 BAD_RX_SW_IF_INDEX_LABEL;
1435 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1439 vl_api_bridge_domain_add_del_t_handler (
1440 vl_api_bridge_domain_add_del_t *mp)
1442 vlib_main_t * vm = vlib_get_main ();
1443 bd_main_t * bdm = &bd_main;
1444 vl_api_bridge_domain_add_del_reply_t * rmp;
1446 u32 enable_flags = 0, disable_flags = 0;
1447 u32 bd_id = ntohl(mp->bd_id);
1451 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1454 enable_flags |= L2_FLOOD;
1456 disable_flags |= L2_FLOOD;
1459 enable_flags |= L2_UU_FLOOD;
1461 disable_flags |= L2_UU_FLOOD;
1464 enable_flags |= L2_FWD;
1466 disable_flags |= L2_FWD;
1469 enable_flags |= L2_ARP_TERM;
1471 disable_flags |= L2_ARP_TERM;
1474 enable_flags |= L2_LEARN;
1476 disable_flags |= L2_LEARN;
1479 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1482 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1485 rv = bd_delete_bd_index(bdm, bd_id);
1487 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1490 static void vl_api_bridge_domain_details_t_handler (
1491 vl_api_bridge_domain_details_t * mp)
1493 clib_warning ("BUG");
1496 static void vl_api_bridge_domain_sw_if_details_t_handler (
1497 vl_api_bridge_domain_sw_if_details_t * mp)
1499 clib_warning ("BUG");
1502 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1503 l2_bridge_domain_t * bd_config,
1507 vl_api_bridge_domain_details_t * mp;
1509 mp = vl_msg_api_alloc (sizeof (*mp));
1510 memset (mp, 0, sizeof (*mp));
1511 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1512 mp->bd_id = ntohl (bd_config->bd_id);
1513 mp->flood = bd_feature_flood (bd_config);
1514 mp->uu_flood = bd_feature_uu_flood (bd_config);
1515 mp->forward = bd_feature_forward (bd_config);
1516 mp->learn = bd_feature_learn (bd_config);
1517 mp->arp_term = bd_feature_arp_term (bd_config);
1518 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1519 mp->n_sw_ifs = ntohl (n_sw_ifs);
1520 mp->context = context;
1522 vl_msg_api_send_shmem (q, (u8 *)&mp);
1525 static void send_bd_sw_if_details (l2input_main_t * l2im,
1526 unix_shared_memory_queue_t *q,
1527 l2_flood_member_t * member, u32 bd_id,
1530 vl_api_bridge_domain_sw_if_details_t * mp;
1531 l2_input_config_t * input_cfg;
1533 mp = vl_msg_api_alloc (sizeof (*mp));
1534 memset (mp, 0, sizeof (*mp));
1535 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1536 mp->bd_id = ntohl (bd_id);
1537 mp->sw_if_index = ntohl (member->sw_if_index);
1538 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1539 mp->shg = input_cfg->shg;
1540 mp->context = context;
1542 vl_msg_api_send_shmem (q, (u8 *)&mp);
1545 static void vl_api_bridge_domain_dump_t_handler (
1546 vl_api_bridge_domain_dump_t *mp)
1548 bd_main_t * bdm = &bd_main;
1549 l2input_main_t * l2im = &l2input_main;
1550 unix_shared_memory_queue_t * q;
1551 l2_bridge_domain_t * bd_config;
1552 u32 bd_id, bd_index;
1555 q = vl_api_client_index_to_input_queue (mp->client_index);
1560 bd_id = ntohl(mp->bd_id);
1562 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1563 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1564 for (; bd_index < end; bd_index++) {
1565 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1566 /* skip dummy bd_id 0 */
1567 if (bd_config && (bd_config->bd_id > 0)) {
1569 l2_flood_member_t * m;
1571 n_sw_ifs = vec_len (bd_config->members);
1572 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1574 vec_foreach (m, bd_config->members) {
1575 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1582 vl_api_l2fib_add_del_t_handler (
1583 vl_api_l2fib_add_del_t *mp)
1585 bd_main_t * bdm = &bd_main;
1586 l2input_main_t * l2im = &l2input_main;
1587 vl_api_l2fib_add_del_reply_t * rmp;
1590 u32 sw_if_index = ntohl(mp->sw_if_index);
1591 u32 bd_id = ntohl(mp->bd_id);
1599 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1601 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1602 goto bad_sw_if_index;
1607 VALIDATE_SW_IF_INDEX(mp);
1608 if (vec_len(l2im->configs) <= sw_if_index) {
1609 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1610 goto bad_sw_if_index;
1612 l2_input_config_t * config;
1613 config = vec_elt_at_index(l2im->configs, sw_if_index);
1614 if (config->bridge == 0) {
1615 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1616 goto bad_sw_if_index;
1619 static_mac = mp->static_mac ? 1 : 0;
1620 filter_mac = mp->filter_mac ? 1 : 0;
1621 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1624 l2fib_del_entry(mac, bd_index);
1627 BAD_SW_IF_INDEX_LABEL;
1629 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1633 vl_api_l2_flags_t_handler (
1634 vl_api_l2_flags_t *mp)
1636 vl_api_l2_flags_reply_t * rmp;
1638 u32 sw_if_index = ntohl(mp->sw_if_index);
1639 u32 flags = ntohl(mp->feature_bitmap);
1642 VALIDATE_SW_IF_INDEX(mp);
1645 if (flags & L2INPUT_FEAT_ ## a) \
1646 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1647 foreach_l2input_feat;
1650 BAD_SW_IF_INDEX_LABEL;
1652 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1656 vl_api_bridge_flags_t_handler (
1657 vl_api_bridge_flags_t *mp)
1659 vlib_main_t *vm = vlib_get_main();
1660 bd_main_t * bdm = &bd_main;
1661 vl_api_bridge_flags_reply_t * rmp;
1663 u32 bd_id = ntohl(mp->bd_id);
1665 u32 flags = ntohl(mp->feature_bitmap);
1668 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1670 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1676 bd_set_flags(vm, bd_index, flags, mp->is_set);
1679 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1680 rmp->resulting_feature_bitmap = ntohl(flags));
1684 vl_api_bd_ip_mac_add_del_t_handler (
1685 vl_api_bd_ip_mac_add_del_t *mp)
1687 bd_main_t * bdm = &bd_main;
1688 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1690 u32 bd_id = ntohl(mp->bd_id);
1694 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1696 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1701 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1702 mp->mac_address, mp->is_ipv6, mp->is_add))
1703 rv = VNET_API_ERROR_UNSPECIFIED;
1706 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1710 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1713 vl_api_tap_connect_reply_t * rmp;
1714 unix_shared_memory_queue_t * q;
1715 u32 sw_if_index = (u32)~0;
1717 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1718 mp->use_random_mac ? 0 : mp->mac_address,
1719 &sw_if_index, mp->renumber,
1720 ntohl(mp->custom_dev_instance));
1722 q = vl_api_client_index_to_input_queue (mp->client_index);
1726 rmp = vl_msg_api_alloc (sizeof (*rmp));
1727 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1728 rmp->context = mp->context;
1729 rmp->retval = ntohl(rv);
1730 rmp->sw_if_index = ntohl(sw_if_index);
1732 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1736 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1739 vl_api_tap_modify_reply_t * rmp;
1740 unix_shared_memory_queue_t * q;
1741 u32 sw_if_index = (u32)~0;
1743 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1744 mp->use_random_mac ? 0 : mp->mac_address,
1745 &sw_if_index, mp->renumber,
1746 ntohl(mp->custom_dev_instance));
1748 q = vl_api_client_index_to_input_queue (mp->client_index);
1752 rmp = vl_msg_api_alloc (sizeof (*rmp));
1753 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1754 rmp->context = mp->context;
1755 rmp->retval = ntohl(rv);
1756 rmp->sw_if_index = ntohl(sw_if_index);
1758 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1762 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1765 vpe_api_main_t * vam = &vpe_api_main;
1766 vl_api_tap_delete_reply_t * rmp;
1767 unix_shared_memory_queue_t * q;
1768 u32 sw_if_index = ntohl(mp->sw_if_index);
1770 rv = vnet_tap_delete (vm, sw_if_index);
1772 q = vl_api_client_index_to_input_queue (mp->client_index);
1776 rmp = vl_msg_api_alloc (sizeof (*rmp));
1777 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1778 rmp->context = mp->context;
1779 rmp->retval = ntohl(rv);
1781 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1784 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1788 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1790 vl_api_create_vlan_subif_reply_t * rmp;
1791 vnet_main_t * vnm = vnet_get_main();
1792 u32 hw_if_index, sw_if_index = (u32)~0;
1793 vnet_hw_interface_t * hi;
1796 vnet_sw_interface_t template;
1798 vnet_interface_main_t * im = &vnm->interface_main;
1799 u64 sup_and_sub_key;
1801 unix_shared_memory_queue_t * q;
1802 clib_error_t * error;
1804 VALIDATE_SW_IF_INDEX(mp);
1806 hw_if_index = ntohl(mp->sw_if_index);
1807 hi = vnet_get_hw_interface (vnm, hw_if_index);
1809 id = ntohl(mp->vlan_id);
1810 if (id == 0 || id > 4095) {
1811 rv = VNET_API_ERROR_INVALID_VLAN;
1815 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1817 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1819 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1823 kp = clib_mem_alloc (sizeof (*kp));
1824 *kp = sup_and_sub_key;
1826 memset (&template, 0, sizeof (template));
1827 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1828 template.sup_sw_if_index = hi->sw_if_index;
1829 template.sub.id = id;
1830 template.sub.eth.raw_flags = 0;
1831 template.sub.eth.flags.one_tag = 1;
1832 template.sub.eth.outer_vlan_id = id;
1833 template.sub.eth.flags.exact_match = 1;
1835 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1837 clib_error_report(error);
1838 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1841 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1842 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1844 BAD_SW_IF_INDEX_LABEL;
1847 q = vl_api_client_index_to_input_queue (mp->client_index);
1851 rmp = vl_msg_api_alloc (sizeof (*rmp));
1852 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1853 rmp->context = mp->context;
1854 rmp->retval = ntohl(rv);
1855 rmp->sw_if_index = ntohl(sw_if_index);
1856 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1860 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1862 vl_api_create_subif_reply_t * rmp;
1863 vnet_main_t * vnm = vnet_get_main();
1864 u32 sw_if_index = ~0;
1867 vnet_sw_interface_t *si;
1868 vnet_hw_interface_t *hi;
1869 vnet_sw_interface_t template;
1871 vnet_interface_main_t * im = &vnm->interface_main;
1872 u64 sup_and_sub_key;
1874 clib_error_t * error;
1876 VALIDATE_SW_IF_INDEX(mp);
1878 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1879 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1881 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1882 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1886 sw_if_index = si->sw_if_index;
1887 sub_id = ntohl(mp->sub_id);
1889 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1891 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1894 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1895 sw_if_index, sub_id);
1896 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1900 kp = clib_mem_alloc (sizeof (*kp));
1901 *kp = sup_and_sub_key;
1903 memset (&template, 0, sizeof (template));
1904 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1905 template.sup_sw_if_index = sw_if_index;
1906 template.sub.id = sub_id;
1907 template.sub.eth.flags.no_tags = mp->no_tags;
1908 template.sub.eth.flags.one_tag = mp->one_tag;
1909 template.sub.eth.flags.two_tags = mp->two_tags;
1910 template.sub.eth.flags.dot1ad = mp->dot1ad;
1911 template.sub.eth.flags.exact_match = mp->exact_match;
1912 template.sub.eth.flags.default_sub = mp->default_sub;
1913 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1914 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1915 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1916 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1918 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1920 clib_error_report (error);
1921 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1925 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1926 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1928 BAD_SW_IF_INDEX_LABEL;
1932 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1934 rmp->sw_if_index = ntohl(sw_if_index);
1939 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1941 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1943 stats_main_t * sm = &stats_main;
1944 u32 tunnel_sw_if_index = ~0;
1946 dslock (sm, 1 /* release hint */, 5 /* tag */);
1948 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1949 (ip4_address_t *)(mp->dst_address),
1950 (ip4_address_t *)(mp->intfc_address),
1951 (u32)(mp->intfc_address_length),
1952 ntohl(mp->inner_vrf_id),
1953 ntohl(mp->outer_vrf_id),
1954 &tunnel_sw_if_index,
1959 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1961 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1966 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1967 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1969 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1971 stats_main_t * sm = &stats_main;
1972 u32 tunnel_sw_if_index;
1974 dslock (sm, 1 /* release hint */, 5 /* tag */);
1976 rv = vnet_mpls_ethernet_add_del_tunnel
1977 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1978 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1979 ntohl(mp->tx_sw_if_index),
1980 &tunnel_sw_if_index,
1986 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1988 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1993 * This piece of misery brought to you because the control-plane
1994 * can't figure out the tx interface + dst-mac address all by itself
1996 static int mpls_ethernet_add_del_tunnel_2_t_handler
1997 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
1999 pending_route_t * pr;
2000 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2001 vnet_main_t * vnm = vnet_get_main();
2002 vlib_main_t * vm = vlib_get_main();
2003 stats_main_t * sm = &stats_main;
2004 vpe_api_main_t * vam = &vpe_api_main;
2005 u32 inner_fib_index, outer_fib_index;
2006 ip4_main_t * im = &ip4_main;
2007 ip_lookup_main_t * lm = &im->lookup_main;
2008 ip_adjacency_t * adj = 0;
2011 u8 * dst_mac_address;
2015 u32 tunnel_sw_if_index;
2017 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2019 return VNET_API_ERROR_NO_SUCH_FIB;
2021 outer_fib_index = p[0];
2024 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2026 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2028 inner_fib_index = p[0];
2030 if (inner_fib_index == outer_fib_index)
2031 return VNET_API_ERROR_INVALID_VALUE;
2033 lookup_result = ip4_fib_lookup_with_table
2034 (im, outer_fib_index,
2035 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2036 1 /* disable default route */);
2038 adj = ip_get_adjacency (lm, lookup_result);
2039 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2041 if (mp->is_add && mp->resolve_if_needed) {
2042 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2043 pool_get (vam->pending_routes, pr);
2044 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2046 clib_memcpy (pme, mp, sizeof (*pme));
2047 /* recursion block, "just in case" */
2048 pme->resolve_if_needed = 0;
2049 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2050 pme->resolve_opaque = tx_sw_if_index;
2051 vnet_register_ip4_arp_resolution_event
2053 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2054 vpe_resolver_process_node.index,
2055 RESOLUTION_EVENT, pr - vam->pending_routes);
2057 vlib_process_signal_event
2058 (vm, vpe_resolver_process_node.index,
2059 RESOLUTION_PENDING_EVENT, 0 /* data */);
2061 /* The interface may be down, etc. */
2062 e = ip4_probe_neighbor
2063 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2067 clib_error_report(e);
2069 return VNET_API_ERROR_IN_PROGRESS;
2073 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2074 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2077 vnet_rewrite_get_data_internal
2078 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2080 dslock (sm, 1 /* release hint */, 10 /* tag */);
2082 rv = vnet_mpls_ethernet_add_del_tunnel
2083 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2084 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2085 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2093 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2094 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2096 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2099 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2101 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2106 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2108 vl_api_mpls_add_del_encap_reply_t * rmp;
2110 static u32 * labels;
2113 vec_reset_length (labels);
2115 for (i = 0; i < mp->nlabels; i++)
2116 vec_add1 (labels, ntohl(mp->labels[i]));
2119 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2120 ntohl(mp->vrf_id), labels,
2121 ~0 /* policy_tunnel_index */,
2122 0 /* no_dst_hash */,
2126 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2130 vl_api_mpls_add_del_decap_t_handler
2131 (vl_api_mpls_add_del_decap_t *mp)
2133 vl_api_mpls_add_del_decap_reply_t * rmp;
2136 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2137 ntohl(mp->label), ntohl(mp->next_index),
2138 mp->s_bit, mp->is_add);
2140 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2144 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2146 vl_api_proxy_arp_add_del_reply_t * rmp;
2149 ip4_main_t * im = &ip4_main;
2150 stats_main_t * sm = &stats_main;
2151 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2152 ip4_address_t *hi_addr,
2153 u32 fib_index, int is_del);
2156 dslock (sm, 1 /* release hint */, 6 /* tag */);
2158 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2161 rv = VNET_API_ERROR_NO_SUCH_FIB;
2167 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2168 (ip4_address_t *)mp->hi_address,
2169 fib_index, mp->is_add == 0);
2173 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2177 vl_api_proxy_arp_intfc_enable_disable_t_handler
2178 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2181 vnet_main_t * vnm = vnet_get_main();
2182 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2183 vnet_sw_interface_t * si;
2186 VALIDATE_SW_IF_INDEX(mp);
2188 sw_if_index = ntohl(mp->sw_if_index);
2190 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2192 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2196 si = vnet_get_sw_interface (vnm, sw_if_index);
2200 if (mp->enable_disable)
2201 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2203 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2205 BAD_SW_IF_INDEX_LABEL;
2208 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2212 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2214 vl_api_ip_neighbor_add_del_reply_t * rmp;
2215 vnet_main_t * vnm = vnet_get_main();
2218 stats_main_t * sm = &stats_main;
2220 VALIDATE_SW_IF_INDEX(mp);
2222 dslock (sm, 1 /* release hint */, 7 /* tag */);
2226 rv = vnet_set_ip6_ethernet_neighbor
2227 (vm, ntohl(mp->sw_if_index),
2228 (ip6_address_t *)(mp->dst_address),
2229 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2231 rv = vnet_unset_ip6_ethernet_neighbor
2232 (vm, ntohl(mp->sw_if_index),
2233 (ip6_address_t *)(mp->dst_address),
2234 mp->mac_address, sizeof(mp->mac_address));
2236 ip4_main_t * im = &ip4_main;
2237 ip_lookup_main_t * lm = &im->lookup_main;
2238 ethernet_arp_ip4_over_ethernet_address_t a;
2240 ip_adjacency_t *nh_adj;
2242 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2244 rv = VNET_API_ERROR_NO_SUCH_FIB;
2250 * Unfortunately, folks have a penchant for
2251 * adding interface addresses to the ARP cache, and
2252 * wondering why the forwarder eventually ASSERTs...
2254 ai = ip4_fib_lookup_with_table
2255 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2256 1 /* disable default route */);
2259 nh_adj = ip_get_adjacency (lm, ai);
2260 /* Never allow manipulation of a local adj! */
2261 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2262 clib_warning("%U matches local adj",
2264 (ip4_address_t *)(mp->dst_address));
2265 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2270 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2271 clib_memcpy (&a.ip4, mp->dst_address, 4);
2274 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2275 fib_index, &a, mp->is_static);
2277 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2281 BAD_SW_IF_INDEX_LABEL;
2284 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2288 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2291 vpe_main_t *rm = &vpe_main;
2292 ip4_main_t *im4 = &ip4_main;
2293 ip6_main_t *im6 = &ip6_main;
2294 ip_lookup_main_t * lm;
2299 u32 adj_index, sw_if_index;
2300 vl_api_is_address_reachable_t *rmp;
2301 ip_adjacency_t * adj;
2302 unix_shared_memory_queue_t *q;
2304 q = vl_api_client_index_to_input_queue (mp->client_index);
2306 increment_missing_api_client_counter (rm->vlib_main);
2310 rmp = vl_msg_api_alloc (sizeof (*rmp));
2311 clib_memcpy (rmp, mp, sizeof (*rmp));
2313 sw_if_index = mp->next_hop_sw_if_index;
2314 clib_memcpy (&addr, mp->address, sizeof (addr));
2316 lm = &im6->lookup_main;
2318 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2320 lm = &im4->lookup_main;
2322 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2324 if (adj_index == ~0) {
2328 adj = ip_get_adjacency (lm, adj_index);
2330 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2331 && adj->rewrite_header.sw_if_index == sw_if_index) {
2334 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2335 && adj->rewrite_header.sw_if_index == sw_if_index) {
2337 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2339 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2340 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2348 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2352 static void vl_api_sw_interface_details_t_handler (
2353 vl_api_sw_interface_details_t * mp)
2355 clib_warning ("BUG");
2358 static void vl_api_sw_interface_set_flags_t_handler (
2359 vl_api_sw_interface_set_flags_t * mp)
2361 vl_api_sw_interface_set_flags_reply_t *rmp;
2362 vnet_main_t * vnm = vnet_get_main();
2364 clib_error_t * error;
2367 VALIDATE_SW_IF_INDEX(mp);
2369 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2371 error = vnet_sw_interface_set_flags (vnm,
2372 ntohl(mp->sw_if_index),
2376 clib_error_report (error);
2379 BAD_SW_IF_INDEX_LABEL;
2380 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2383 static void vl_api_sw_interface_clear_stats_t_handler (
2384 vl_api_sw_interface_clear_stats_t * mp)
2386 vl_api_sw_interface_clear_stats_reply_t *rmp;
2388 vnet_main_t * vnm = vnet_get_main();
2389 vnet_interface_main_t * im = &vnm->interface_main;
2390 vlib_simple_counter_main_t * sm;
2391 vlib_combined_counter_main_t * cm;
2392 static vnet_main_t ** my_vnet_mains;
2393 int i, j, n_counters;
2397 vec_reset_length (my_vnet_mains);
2399 for (i = 0; i < vec_len (vnet_mains); i++)
2402 vec_add1 (my_vnet_mains, vnet_mains[i]);
2405 if (vec_len (vnet_mains) == 0)
2406 vec_add1 (my_vnet_mains, vnm);
2408 n_counters = vec_len (im->combined_sw_if_counters);
2410 for (j = 0; j < n_counters; j++)
2412 for (i = 0; i < vec_len(my_vnet_mains); i++)
2414 im = &my_vnet_mains[i]->interface_main;
2415 cm = im->combined_sw_if_counters + j;
2416 if (mp->sw_if_index == (u32)~0)
2417 vlib_clear_combined_counters (cm);
2419 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2423 n_counters = vec_len (im->sw_if_counters);
2425 for (j = 0; j < n_counters; j++)
2427 for (i = 0; i < vec_len(my_vnet_mains); i++)
2429 im = &my_vnet_mains[i]->interface_main;
2430 sm = im->sw_if_counters + j;
2431 if (mp->sw_if_index == (u32)~0)
2432 vlib_clear_simple_counters (sm);
2434 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2438 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2441 static void send_sw_interface_details (vpe_api_main_t * am,
2442 unix_shared_memory_queue_t *q,
2443 vnet_sw_interface_t * swif,
2444 u8 * interface_name,
2447 vl_api_sw_interface_details_t * mp;
2448 vnet_hw_interface_t * hi;
2450 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2452 mp = vl_msg_api_alloc (sizeof (*mp));
2453 memset (mp, 0, sizeof (*mp));
2454 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2455 mp->sw_if_index = ntohl(swif->sw_if_index);
2456 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2457 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2459 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2461 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2462 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2463 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2464 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2465 mp->link_mtu = ntohs(hi->max_packet_bytes);
2466 mp->context = context;
2468 strncpy ((char *) mp->interface_name,
2469 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2471 /* Send the L2 address for ethernet physical intfcs */
2472 if (swif->sup_sw_if_index == swif->sw_if_index
2473 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2474 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2475 ethernet_interface_t *ei;
2477 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2478 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2479 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2480 mp->l2_address_length = ntohl(sizeof (ei->address));
2481 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2482 vnet_sub_interface_t *sub = &swif->sub;
2483 mp->sub_id = ntohl(sub->id);
2484 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2485 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2486 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2487 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2488 mp->sub_exact_match = sub->eth.flags.exact_match;
2489 mp->sub_default = sub->eth.flags.default_sub;
2490 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2491 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2493 /* vlan tag rewrite data */
2494 u32 vtr_op = L2_VTR_DISABLED;
2495 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2497 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2498 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2499 // error - default to disabled
2500 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2501 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2504 mp->vtr_op = ntohl(vtr_op);
2505 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2506 mp->vtr_tag1 = ntohl(vtr_tag1);
2507 mp->vtr_tag2 = ntohl(vtr_tag2);
2511 vl_msg_api_send_shmem (q, (u8 *)&mp);
2514 static void send_sw_interface_flags (vpe_api_main_t * am,
2515 unix_shared_memory_queue_t *q,
2516 vnet_sw_interface_t * swif)
2518 vl_api_sw_interface_set_flags_t *mp;
2519 vnet_main_t * vnm = am->vnet_main;
2521 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2523 mp = vl_msg_api_alloc (sizeof (*mp));
2524 memset (mp, 0, sizeof (*mp));
2525 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2526 mp->sw_if_index = ntohl(swif->sw_if_index);
2528 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2530 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2532 vl_msg_api_send_shmem (q, (u8 *)&mp);
2535 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2536 unix_shared_memory_queue_t *q,
2538 __attribute__((unused));
2540 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2541 unix_shared_memory_queue_t *q,
2544 vl_api_sw_interface_set_flags_t *mp;
2546 mp = vl_msg_api_alloc (sizeof (*mp));
2547 memset (mp, 0, sizeof (*mp));
2548 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2549 mp->sw_if_index = ntohl(sw_if_index);
2551 mp->admin_up_down = 0;
2552 mp->link_up_down = 0;
2554 vl_msg_api_send_shmem (q, (u8 *)&mp);
2557 static void vl_api_sw_interface_dump_t_handler (
2558 vl_api_sw_interface_dump_t *mp)
2560 vpe_api_main_t * am = &vpe_api_main;
2561 vnet_sw_interface_t * swif;
2562 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2563 u8 * filter_string = 0, * name_string = 0;
2564 unix_shared_memory_queue_t * q;
2565 char * strcasestr (char *, char *); /* lnx hdr file botch */
2567 q = vl_api_client_index_to_input_queue (mp->client_index);
2572 if (mp->name_filter_valid) {
2573 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2574 filter_string = format (0, "%s%c", mp->name_filter, 0);
2577 pool_foreach (swif, im->sw_interfaces,
2579 name_string = format (name_string, "%U%c",
2580 format_vnet_sw_interface_name,
2581 am->vnet_main, swif, 0);
2583 if (mp->name_filter_valid == 0 ||
2584 strcasestr((char *) name_string, (char *) filter_string)) {
2586 send_sw_interface_details (am, q, swif, name_string, mp->context);
2587 send_sw_interface_flags (am, q, swif);
2589 _vec_len (name_string) = 0;
2592 vec_free (name_string);
2593 vec_free (filter_string);
2596 void send_oam_event (oam_target_t * t)
2598 vpe_api_main_t * vam = &vpe_api_main;
2599 unix_shared_memory_queue_t * q;
2600 vpe_client_registration_t *reg;
2601 vl_api_oam_event_t * mp;
2603 pool_foreach(reg, vam->oam_events_registrations,
2605 q = vl_api_client_index_to_input_queue (reg->client_index);
2607 mp = vl_msg_api_alloc (sizeof (*mp));
2608 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2609 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2610 mp->state = t->state;
2611 vl_msg_api_send_shmem (q, (u8 *)&mp);
2617 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2619 vl_api_oam_add_del_reply_t * rmp;
2622 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2623 (ip4_address_t *)mp->dst_address,
2627 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2631 vl_api_vnet_get_summary_stats_t_handler (
2632 vl_api_vnet_get_summary_stats_t *mp)
2634 stats_main_t * sm = &stats_main;
2635 vnet_interface_main_t * im = sm->interface_main;
2636 vl_api_vnet_summary_stats_reply_t *rmp;
2637 vlib_combined_counter_main_t * cm;
2640 u64 total_pkts[VLIB_N_RX_TX];
2641 u64 total_bytes[VLIB_N_RX_TX];
2643 unix_shared_memory_queue_t * q =
2644 vl_api_client_index_to_input_queue (mp->client_index);
2649 rmp = vl_msg_api_alloc (sizeof (*rmp));
2650 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2651 rmp->context = mp->context;
2654 memset (total_pkts, 0, sizeof (total_pkts));
2655 memset (total_bytes, 0, sizeof (total_bytes));
2657 vnet_interface_counter_lock (im);
2659 vec_foreach (cm, im->combined_sw_if_counters) {
2660 which = cm - im->combined_sw_if_counters;
2662 for (i = 0; i < vec_len (cm->maxi); i++) {
2663 vlib_get_combined_counter (cm, i, &v);
2664 total_pkts[which] += v.packets;
2665 total_bytes[which] += v.bytes;
2668 vnet_interface_counter_unlock (im);
2670 /* Note: in HOST byte order! */
2671 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2672 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2673 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2674 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2675 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2677 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2680 typedef CLIB_PACKED (struct {
2681 ip4_address_t address;
2683 u32 address_length : 6;
2688 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2690 vnet_main_t * vnm = vnet_get_main();
2691 vnet_interface_main_t * im = &vnm->interface_main;
2692 ip4_main_t * im4 = &ip4_main;
2693 static ip4_route_t * routes;
2694 static u32 * sw_if_indices_to_shut;
2695 stats_main_t * sm = &stats_main;
2700 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2701 u32 target_fib_id = ntohl(mp->vrf_id);
2703 dslock (sm, 1 /* release hint */, 8 /* tag */);
2705 vec_foreach (fib, im4->fibs) {
2706 vnet_sw_interface_t * si;
2708 if (fib->table_id != target_fib_id)
2711 /* remove any mpls/gre tunnels in this fib */
2712 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2714 /* remove any mpls encap/decap labels */
2715 mpls_fib_reset_labels (fib->table_id);
2717 /* remove any proxy arps in this fib */
2718 vnet_proxy_arp_fib_reset (fib->table_id);
2720 /* Set the flow hash for this fib to the default */
2721 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2723 vec_reset_length (sw_if_indices_to_shut);
2725 /* Shut down interfaces in this FIB / clean out intfc routes */
2726 pool_foreach (si, im->sw_interfaces,
2728 u32 sw_if_index = si->sw_if_index;
2730 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2731 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2733 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2736 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2737 sw_if_index = sw_if_indices_to_shut[i];
2738 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2740 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2741 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2742 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2745 vec_reset_length (routes);
2747 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2748 uword * hash = fib->adj_index_by_dst_address[i];
2752 x.address_length = i;
2754 hash_foreach_pair (p, hash,
2756 x.address.data_u32 = p->key;
2757 vec_add1 (routes, x);
2761 vec_foreach (r, routes) {
2762 ip4_add_del_route_args_t a;
2764 memset (&a, 0, sizeof (a));
2765 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2766 a.table_index_or_table_id = fib - im4->fibs;
2767 a.dst_address = r->address;
2768 a.dst_address_length = r->address_length;
2771 ip4_add_del_route (im4, &a);
2772 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2773 IP4_ROUTE_FLAG_FIB_INDEX);
2777 } /* vec_foreach (fib) */
2784 ip6_address_t address;
2791 ip6_route_t ** routep;
2792 } add_routes_in_fib_arg_t;
2794 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2796 add_routes_in_fib_arg_t * ap = arg;
2798 if (kvp->key[2]>>32 == ap->fib_index)
2800 ip6_address_t *addr;
2802 addr = (ip6_address_t *) kvp;
2803 vec_add2 (*ap->routep, r, 1);
2804 r->address = addr[0];
2805 r->address_length = kvp->key[2] & 0xFF;
2806 r->index = kvp->value;
2810 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2812 vnet_main_t * vnm = vnet_get_main();
2813 vnet_interface_main_t * im = &vnm->interface_main;
2814 ip6_main_t * im6 = &ip6_main;
2815 stats_main_t * sm = &stats_main;
2816 static ip6_route_t * routes;
2817 static u32 * sw_if_indices_to_shut;
2822 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2823 u32 target_fib_id = ntohl(mp->vrf_id);
2824 add_routes_in_fib_arg_t _a, *a=&_a;
2825 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2827 dslock (sm, 1 /* release hint */, 9 /* tag */);
2829 vec_foreach (fib, im6->fibs) {
2830 vnet_sw_interface_t * si;
2832 if (fib->table_id != target_fib_id)
2835 vec_reset_length (sw_if_indices_to_shut);
2837 /* Shut down interfaces in this FIB / clean out intfc routes */
2838 pool_foreach (si, im->sw_interfaces,
2840 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2842 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2845 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2846 sw_if_index = sw_if_indices_to_shut[i];
2847 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2849 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2850 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2851 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2854 vec_reset_length (routes);
2856 a->fib_index = fib - im6->fibs;
2857 a->routep = &routes;
2859 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2861 vec_foreach (r, routes) {
2862 ip6_add_del_route_args_t a;
2864 memset (&a, 0, sizeof (a));
2865 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2866 a.table_index_or_table_id = fib - im6->fibs;
2867 a.dst_address = r->address;
2868 a.dst_address_length = r->address_length;
2871 ip6_add_del_route (im6, &a);
2872 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2873 IP6_ROUTE_FLAG_FIB_INDEX);
2876 /* Reinstall the neighbor / router discovery routes */
2877 vnet_ip6_fib_init (im6, fib - im6->fibs);
2879 } /* vec_foreach (fib) */
2885 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2888 vl_api_reset_fib_reply_t * rmp;
2891 rv = ip6_reset_fib_t_handler (mp);
2893 rv = ip4_reset_fib_t_handler (mp);
2895 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2900 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2902 vl_api_dhcp_proxy_config_reply_t * rmp;
2905 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2906 (ip4_address_t *)(&mp->dhcp_src_address),
2907 (u32) ntohl(mp->vrf_id),
2908 (int) mp->insert_circuit_id,
2909 (int) (mp->is_add == 0));
2911 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2916 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2918 vl_api_dhcp_proxy_config_reply_t * rmp;
2921 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2922 (ip6_address_t *)(&mp->dhcp_src_address),
2923 (u32) ntohl(mp->vrf_id),
2924 (int) mp->insert_circuit_id,
2925 (int) (mp->is_add == 0));
2927 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2931 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2933 vl_api_dhcp_proxy_config_reply_t * rmp;
2936 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2937 (ip4_address_t *)(&mp->dhcp_src_address),
2938 (u32) ntohl(mp->rx_vrf_id),
2939 (u32) ntohl(mp->server_vrf_id),
2940 (int) mp->insert_circuit_id,
2941 (int) (mp->is_add == 0));
2943 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2948 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2950 vl_api_dhcp_proxy_config_reply_t * rmp;
2954 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2955 (ip6_address_t *)(&mp->dhcp_src_address),
2956 (u32) ntohl(mp->rx_vrf_id),
2957 (u32) ntohl(mp->server_vrf_id),
2958 (int) mp->insert_circuit_id,
2959 (int) (mp->is_add == 0));
2961 rv = VNET_API_ERROR_UNIMPLEMENTED;
2964 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2969 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2971 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2974 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2977 (int)mp->is_add == 0);
2979 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2982 (int)mp->is_add == 0);
2984 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2988 static void vl_api_dhcp_proxy_config_t_handler
2989 (vl_api_dhcp_proxy_config_t *mp)
2991 if (mp->is_ipv6 == 0)
2992 dhcpv4_proxy_config (mp);
2994 dhcpv6_proxy_config (mp);
2997 static void vl_api_dhcp_proxy_config_2_t_handler
2998 (vl_api_dhcp_proxy_config_2_t *mp)
3000 if (mp->is_ipv6 == 0)
3001 dhcpv4_proxy_config_2 (mp);
3003 dhcpv6_proxy_config_2 (mp);
3006 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3007 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3009 unix_shared_memory_queue_t * q;
3010 vl_api_dhcp_compl_event_t * mp;
3012 q = vl_api_client_index_to_input_queue (client_index);
3016 mp = vl_msg_api_alloc (sizeof (*mp));
3017 mp->client_index = client_index;
3019 mp->is_ipv6 = is_ipv6;
3020 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3021 mp->hostname[vec_len(hostname) + 1] = '\n';
3022 clib_memcpy (&mp->host_address[0], host_address, 16);
3023 clib_memcpy (&mp->router_address[0], router_address, 16);
3024 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3026 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3028 vl_msg_api_send_shmem (q, (u8 *)&mp);
3031 static void vl_api_dhcp_client_config_t_handler
3032 (vl_api_dhcp_client_config_t *mp)
3034 vlib_main_t *vm = vlib_get_main();
3035 vl_api_dhcp_client_config_reply_t * rmp;
3038 VALIDATE_SW_IF_INDEX(mp);
3040 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3041 mp->hostname, mp->is_add, mp->client_index,
3042 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3045 BAD_SW_IF_INDEX_LABEL;
3047 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3051 vl_api_sw_interface_ip6nd_ra_config_t_handler
3052 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3054 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3056 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3058 is_no = mp->is_no == 1;
3059 surpress = mp->surpress == 1;
3060 managed = mp->managed == 1;
3061 other = mp->other == 1;
3062 ll_option = mp->ll_option == 1;
3063 send_unicast = mp->send_unicast == 1;
3064 cease = mp->cease == 1;
3065 default_router = mp->default_router == 1;
3067 VALIDATE_SW_IF_INDEX(mp);
3069 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3070 surpress, managed, other,
3071 ll_option, send_unicast, cease,
3072 default_router, ntohl (mp->lifetime),
3073 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3074 ntohl(mp->max_interval), ntohl( mp->min_interval),
3077 BAD_SW_IF_INDEX_LABEL;
3079 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3083 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3084 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3086 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3088 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3090 VALIDATE_SW_IF_INDEX(mp);
3092 is_no = mp->is_no == 1;
3093 use_default = mp->use_default == 1;
3094 no_advertise = mp->no_advertise == 1;
3095 off_link = mp->off_link == 1;
3096 no_autoconfig = mp->no_autoconfig == 1;
3097 no_onlink = mp->no_onlink == 1;
3099 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3100 (ip6_address_t *)mp->address, mp->address_length,
3101 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3102 no_advertise, off_link, no_autoconfig, no_onlink,
3105 BAD_SW_IF_INDEX_LABEL;
3106 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3110 vl_api_sw_interface_ip6_enable_disable_t_handler
3111 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3113 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3114 vnet_main_t * vnm = vnet_get_main();
3116 clib_error_t * error;
3120 VALIDATE_SW_IF_INDEX(mp);
3122 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3123 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3126 clib_error_report(error);
3127 rv = VNET_API_ERROR_UNSPECIFIED;
3129 rv = vnm->api_errno;
3132 BAD_SW_IF_INDEX_LABEL;
3134 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3138 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3139 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3141 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3143 clib_error_t * error;
3144 vnet_main_t * vnm = vnet_get_main();
3148 VALIDATE_SW_IF_INDEX(mp);
3150 error = set_ip6_link_local_address(vm,
3151 ntohl(mp->sw_if_index),
3152 (ip6_address_t *)mp->address,
3153 mp->address_length);
3155 clib_error_report(error);
3156 rv = VNET_API_ERROR_UNSPECIFIED;
3158 rv = vnm->api_errno;
3161 BAD_SW_IF_INDEX_LABEL;
3163 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3166 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3168 vl_api_set_ip_flow_hash_reply_t *rmp;
3169 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3171 clib_warning ("unimplemented...");
3173 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3176 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3178 vl_api_set_ip_flow_hash_reply_t *rmp;
3181 u32 flow_hash_config = 0;
3183 table_id = ntohl(mp->vrf_id);
3185 #define _(a,b) if (mp->a) flow_hash_config |= b;
3186 foreach_flow_hash_bit;
3189 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3191 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3195 static void vl_api_set_ip_flow_hash_t_handler
3196 (vl_api_set_ip_flow_hash_t *mp)
3198 if (mp->is_ipv6 == 0)
3199 set_ip4_flow_hash (mp);
3201 set_ip6_flow_hash (mp);
3204 static void vl_api_sw_interface_set_unnumbered_t_handler
3205 (vl_api_sw_interface_set_unnumbered_t *mp)
3207 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3209 vnet_sw_interface_t * si;
3210 vnet_main_t *vnm = vnet_get_main();
3211 u32 sw_if_index, unnumbered_sw_if_index;
3213 sw_if_index = ntohl(mp->sw_if_index);
3214 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3217 * The API message field names are backwards from
3218 * the underlying data structure names.
3219 * It's not worth changing them now.
3221 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3222 unnumbered_sw_if_index)) {
3223 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3227 /* Only check the "use loop0" field when setting the binding */
3229 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3230 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3234 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3237 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3238 si->unnumbered_sw_if_index = sw_if_index;
3240 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3241 si->unnumbered_sw_if_index = (u32)~0;
3245 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3248 static void vl_api_create_loopback_t_handler
3249 (vl_api_create_loopback_t *mp)
3251 vl_api_create_loopback_reply_t * rmp;
3255 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3257 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3259 rmp->sw_if_index = ntohl (sw_if_index);
3263 static void vl_api_delete_loopback_t_handler
3264 (vl_api_delete_loopback_t *mp)
3266 vl_api_delete_loopback_reply_t * rmp;
3270 sw_if_index = ntohl (mp->sw_if_index);
3271 rv = vnet_delete_loopback_interface (sw_if_index);
3273 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3276 static void vl_api_control_ping_t_handler
3277 (vl_api_control_ping_t *mp)
3279 vl_api_control_ping_reply_t * rmp;
3282 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3284 rmp->vpe_pid = ntohl (getpid());
3288 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3290 u8 **shmem_vecp = (u8 **)arg;
3293 api_main_t * am = &api_main;
3296 shmem_vec = *shmem_vecp;
3298 offset = vec_len (shmem_vec);
3300 pthread_mutex_lock (&am->vlib_rp->mutex);
3301 oldheap = svm_push_data_heap (am->vlib_rp);
3303 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3305 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3307 svm_pop_heap (oldheap);
3308 pthread_mutex_unlock (&am->vlib_rp->mutex);
3310 *shmem_vecp = shmem_vec;
3314 static void vl_api_cli_request_t_handler
3315 (vl_api_cli_request_t *mp)
3317 vl_api_cli_reply_t *rp;
3318 unix_shared_memory_queue_t *q;
3319 vlib_main_t * vm = vlib_get_main();
3320 api_main_t * am = &api_main;
3321 unformat_input_t input;
3325 q = vl_api_client_index_to_input_queue (mp->client_index);
3329 rp = vl_msg_api_alloc (sizeof (*rp));
3330 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3331 rp->context = mp->context;
3333 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3335 vlib_cli_input (vm, &input, shmem_cli_output,
3338 pthread_mutex_lock (&am->vlib_rp->mutex);
3339 oldheap = svm_push_data_heap (am->vlib_rp);
3341 vec_add1(shmem_vec, 0);
3343 svm_pop_heap (oldheap);
3344 pthread_mutex_unlock (&am->vlib_rp->mutex);
3346 rp->reply_in_shmem = (uword)shmem_vec;
3348 vl_msg_api_send_shmem (q, (u8 *)&rp);
3351 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3354 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3355 vnet_main_t *vnm = vnet_get_main();
3356 clib_error_t * error;
3361 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3363 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3366 clib_error_report(error);
3367 rv = VNET_API_ERROR_UNSPECIFIED;
3369 rv = vnm->api_errno;
3372 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3375 static void vl_api_sr_tunnel_add_del_t_handler
3376 (vl_api_sr_tunnel_add_del_t *mp)
3379 clib_warning ("unimplemented");
3381 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3383 vl_api_sr_tunnel_add_del_reply_t * rmp;
3384 ip6_address_t * segments = 0, * seg;
3385 ip6_address_t * tags = 0, *tag;
3386 ip6_address_t * this_address;
3389 if (mp->n_segments == 0) {
3394 memset (a, 0, sizeof (*a));
3395 a->src_address = (ip6_address_t *)&mp->src_address;
3396 a->dst_address = (ip6_address_t *)&mp->dst_address;
3397 a->dst_mask_width = mp->dst_mask_width;
3398 a->flags_net_byte_order = mp->flags_net_byte_order;
3399 a->is_del = (mp->is_add == 0);
3400 a->rx_table_id = ntohl(mp->outer_vrf_id);
3401 a->tx_table_id = ntohl(mp->inner_vrf_id);
3403 a->name = format(0, "%s", mp->name);
3404 if (!(vec_len(a->name)))
3407 a->policy_name = format(0, "%s", mp->policy_name);
3408 if (!(vec_len(a->policy_name)))
3411 /* Yank segments and tags out of the API message */
3412 this_address = (ip6_address_t *)mp->segs_and_tags;
3413 for (i = 0; i < mp->n_segments; i++) {
3414 vec_add2 (segments, seg, 1);
3415 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3418 for (i = 0; i < mp->n_tags; i++) {
3419 vec_add2 (tags, tag, 1);
3420 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3424 a->segments = segments;
3427 rv = ip6_sr_add_del_tunnel (a);
3431 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3435 static void vl_api_sr_policy_add_del_t_handler
3436 (vl_api_sr_policy_add_del_t *mp)
3439 clib_warning ("unimplemented");
3441 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3443 vl_api_sr_policy_add_del_reply_t * rmp;
3446 memset (a, 0, sizeof (*a));
3447 a->is_del = (mp->is_add == 0);
3449 a->name = format(0, "%s", mp->name);
3450 if (!(vec_len(a->name)))
3452 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3456 if (!(mp->tunnel_names[0]))
3458 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3462 // start deserializing tunnel_names
3463 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3464 u8 * deser_tun_names = mp->tunnel_names;
3465 deser_tun_names += 1; //moving along
3468 int tun_name_len = 0;
3470 for (i=0; i < num_tunnels; i++)
3472 tun_name_len= *deser_tun_names;
3473 deser_tun_names += 1;
3474 vec_resize (tun_name, tun_name_len);
3475 memcpy(tun_name, deser_tun_names, tun_name_len);
3476 vec_add1 (a->tunnel_names, tun_name);
3477 deser_tun_names += tun_name_len;
3481 rv = ip6_sr_add_del_policy (a);
3485 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3489 static void vl_api_sr_multicast_map_add_del_t_handler
3490 (vl_api_sr_multicast_map_add_del_t *mp)
3493 clib_warning ("unimplemented");
3495 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3497 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3499 memset (a, 0, sizeof (*a));
3500 a->is_del = (mp->is_add == 0);
3502 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3503 a->policy_name = format(0, "%s", mp->policy_name);
3505 if (a->multicast_address == 0)
3511 if (!(a->policy_name))
3517 #if DPDK > 0 /* Cannot call replicate without DPDK */
3518 rv = ip6_sr_add_del_multicastmap (a);
3520 clib_warning ("multicast replication without DPDK not implemented");
3521 rv = VNET_API_ERROR_UNIMPLEMENTED;
3526 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3530 #define foreach_classify_add_del_table_field \
3535 _(match_n_vectors) \
3536 _(next_table_index) \
3539 static void vl_api_classify_add_del_table_t_handler
3540 (vl_api_classify_add_del_table_t * mp)
3542 vl_api_classify_add_del_table_reply_t * rmp;
3543 vnet_classify_main_t * cm = &vnet_classify_main;
3544 vnet_classify_table_t * t;
3548 foreach_classify_add_del_table_field;
3551 #define _(a) a = ntohl(mp->a);
3552 foreach_classify_add_del_table_field;
3555 /* The underlying API fails silently, on purpose, so check here */
3556 if (mp->is_add == 0)
3557 if (pool_is_free_index (cm->tables, table_index)) {
3558 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3562 rv = vnet_classify_add_del_table
3563 (cm, mp->mask, nbuckets, memory_size,
3564 skip_n_vectors, match_n_vectors,
3565 next_table_index, miss_next_index,
3566 &table_index, mp->is_add);
3569 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3571 if (rv == 0 && mp->is_add) {
3572 t = pool_elt_at_index (cm->tables, table_index);
3573 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3574 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3575 rmp->new_table_index = ntohl(table_index);
3577 rmp->skip_n_vectors = ~0;
3578 rmp->match_n_vectors = ~0;
3579 rmp->new_table_index = ~0;
3584 static void vl_api_classify_add_del_session_t_handler
3585 (vl_api_classify_add_del_session_t * mp)
3587 vnet_classify_main_t * cm = &vnet_classify_main;
3588 vl_api_classify_add_del_session_reply_t * rmp;
3590 u32 table_index, hit_next_index, opaque_index;
3593 table_index = ntohl (mp->table_index);
3594 hit_next_index = ntohl (mp->hit_next_index);
3595 opaque_index = ntohl (mp->opaque_index);
3596 advance = ntohl (mp->advance);
3598 rv = vnet_classify_add_del_session
3599 (cm, table_index, mp->match, hit_next_index, opaque_index,
3600 advance, mp->is_add);
3602 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3605 static void vl_api_classify_set_interface_ip_table_t_handler
3606 (vl_api_classify_set_interface_ip_table_t * mp)
3608 vlib_main_t * vm = vlib_get_main();
3609 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3611 u32 table_index, sw_if_index;
3613 table_index = ntohl (mp->table_index);
3614 sw_if_index = ntohl (mp->sw_if_index);
3616 VALIDATE_SW_IF_INDEX(mp);
3619 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3621 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3623 BAD_SW_IF_INDEX_LABEL;
3625 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3628 static void vl_api_classify_set_interface_l2_tables_t_handler
3629 (vl_api_classify_set_interface_l2_tables_t * mp)
3631 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3633 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3636 ip4_table_index = ntohl(mp->ip4_table_index);
3637 ip6_table_index = ntohl(mp->ip6_table_index);
3638 other_table_index = ntohl(mp->other_table_index);
3639 sw_if_index = ntohl(mp->sw_if_index);
3641 VALIDATE_SW_IF_INDEX(mp);
3643 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3644 ip6_table_index, other_table_index);
3647 if (ip4_table_index != ~0 || ip6_table_index != ~0
3648 || other_table_index != ~0)
3653 vnet_l2_classify_enable_disable (sw_if_index, enable);
3656 BAD_SW_IF_INDEX_LABEL;
3658 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3662 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3665 vl_api_l2_fib_clear_table_reply_t * rmp;
3667 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3668 * that is not currently implemented. When that TODO is fixed
3669 * this call should be changed to pass 1 instead of 0.
3671 l2fib_clear_table (0);
3673 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3676 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3681 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3684 vl_api_l2_interface_efp_filter_reply_t * rmp;
3685 vnet_main_t *vnm = vnet_get_main();
3687 // enable/disable the feature
3688 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3689 rv = vnm->api_errno;
3691 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3695 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3698 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3699 vnet_main_t * vnm = vnet_get_main();
3700 vlib_main_t * vm = vlib_get_main();
3703 VALIDATE_SW_IF_INDEX(mp);
3705 vtr_op = ntohl(mp->vtr_op);
3707 /* The L2 code is unsuspicious */
3709 case L2_VTR_DISABLED:
3714 case L2_VTR_TRANSLATE_1_1:
3715 case L2_VTR_TRANSLATE_1_2:
3716 case L2_VTR_TRANSLATE_2_1:
3717 case L2_VTR_TRANSLATE_2_2:
3721 rv = VNET_API_ERROR_INVALID_VALUE;
3722 goto bad_sw_if_index;
3725 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3726 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3729 BAD_SW_IF_INDEX_LABEL;
3731 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3735 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3739 vl_api_create_vhost_user_if_reply_t * rmp;
3740 u32 sw_if_index = (u32)~0;
3742 vnet_main_t * vnm = vnet_get_main();
3743 vlib_main_t * vm = vlib_get_main();
3745 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3746 mp->is_server, &sw_if_index, (u64)~0,
3747 mp->renumber, ntohl(mp->custom_dev_instance),
3748 (mp->use_custom_mac)?mp->mac_address:NULL);
3750 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3752 rmp->sw_if_index = ntohl (sw_if_index);
3758 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3762 vl_api_modify_vhost_user_if_reply_t * rmp;
3763 u32 sw_if_index = ntohl(mp->sw_if_index);
3765 vnet_main_t * vnm = vnet_get_main();
3766 vlib_main_t * vm = vlib_get_main();
3768 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3769 mp->is_server, sw_if_index, (u64)~0,
3770 mp->renumber, ntohl(mp->custom_dev_instance));
3772 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3777 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3781 vpe_api_main_t * vam = &vpe_api_main;
3782 vl_api_delete_vhost_user_if_reply_t * rmp;
3783 u32 sw_if_index = ntohl(mp->sw_if_index);
3785 vnet_main_t * vnm = vnet_get_main();
3786 vlib_main_t * vm = vlib_get_main();
3788 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3790 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3792 unix_shared_memory_queue_t * q =
3793 vl_api_client_index_to_input_queue (mp->client_index);
3797 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3802 static void vl_api_sw_interface_vhost_user_details_t_handler (
3803 vl_api_sw_interface_vhost_user_details_t * mp)
3805 clib_warning ("BUG");
3809 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3810 unix_shared_memory_queue_t *q,
3811 vhost_user_intf_details_t * vui,
3814 vl_api_sw_interface_vhost_user_details_t * mp;
3816 mp = vl_msg_api_alloc (sizeof (*mp));
3817 memset (mp, 0, sizeof (*mp));
3818 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3819 mp->sw_if_index = ntohl(vui->sw_if_index);
3820 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3821 mp->features = clib_net_to_host_u64 (vui->features);
3822 mp->is_server = vui->is_server;
3823 mp->num_regions = ntohl(vui->num_regions);
3824 mp->sock_errno = ntohl(vui->sock_errno);
3825 mp->context = context;
3827 strncpy ((char *) mp->sock_filename,
3828 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3829 strncpy ((char *) mp->interface_name,
3830 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3832 vl_msg_api_send_shmem (q, (u8 *)&mp);
3837 vl_api_sw_interface_vhost_user_dump_t_handler (
3838 vl_api_sw_interface_vhost_user_dump_t *mp)
3842 vpe_api_main_t * am = &vpe_api_main;
3843 vnet_main_t * vnm = vnet_get_main();
3844 vlib_main_t * vm = vlib_get_main();
3845 vhost_user_intf_details_t *ifaces = NULL;
3846 vhost_user_intf_details_t *vuid = NULL;
3847 unix_shared_memory_queue_t * q;
3849 q = vl_api_client_index_to_input_queue (mp->client_index);
3853 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3857 vec_foreach (vuid, ifaces) {
3858 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3864 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3865 unix_shared_memory_queue_t *q,
3870 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3871 u8 * if_name = NULL;
3872 vnet_sw_interface_t * si = NULL;
3874 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3876 if_name = format(if_name, "%U",
3877 format_vnet_sw_interface_name, lm->vnet_main, si);
3879 mp = vl_msg_api_alloc (sizeof (*mp));
3880 memset (mp, 0, sizeof (*mp));
3881 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3882 strncpy((char *)mp->interface_name,
3883 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3884 mp->sw_if_index = ntohl(si->sw_if_index);
3885 mp->local_session_id = s->local_session_id;
3886 mp->remote_session_id = s->remote_session_id;
3887 mp->local_cookie[0] = s->local_cookie[0];
3888 mp->local_cookie[1] = s->local_cookie[1];
3889 mp->remote_cookie = s->remote_cookie;
3890 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3891 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3892 mp->l2_sublayer_present = s->l2_sublayer_present;
3893 mp->context = context;
3895 vl_msg_api_send_shmem (q, (u8 *)&mp);
3898 static void send_ip_address_details (vpe_api_main_t * am,
3899 unix_shared_memory_queue_t * q,
3905 vl_api_ip_address_details_t * mp;
3907 mp = vl_msg_api_alloc (sizeof (*mp));
3908 memset (mp, 0, sizeof (*mp));
3909 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3912 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3914 u32 * tp = (u32 *)mp->ip;
3915 *tp = ntohl(*(u32*)ip);
3917 mp->prefix_length = prefix_length;
3918 mp->context = context;
3920 vl_msg_api_send_shmem (q, (u8 *)&mp);
3924 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3926 vpe_api_main_t * am = &vpe_api_main;
3927 unix_shared_memory_queue_t * q;
3930 ip6_main_t * im6 = &ip6_main;
3931 ip4_main_t * im4 = &ip4_main;
3932 ip_lookup_main_t * lm6 = &im6->lookup_main;
3933 ip_lookup_main_t * lm4 = &im4->lookup_main;
3934 ip_interface_address_t * ia = 0;
3935 u32 sw_if_index = ~0;
3936 int rv __attribute__ ((unused)) = 0;
3938 VALIDATE_SW_IF_INDEX(mp);
3940 sw_if_index = ntohl(mp->sw_if_index);
3942 q = vl_api_client_index_to_input_queue (mp->client_index);
3948 foreach_ip_interface_address (lm6, ia, sw_if_index,
3949 1 /* honor unnumbered */,
3951 r6 = ip_interface_address_get_address (lm6, ia);
3952 u16 prefix_length = ia->address_length;
3953 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
3956 foreach_ip_interface_address (lm4, ia, sw_if_index,
3957 1 /* honor unnumbered */,
3959 r4 = ip_interface_address_get_address (lm4, ia);
3960 u16 prefix_length = ia->address_length;
3961 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
3964 BAD_SW_IF_INDEX_LABEL;
3967 static void send_ip_details (vpe_api_main_t * am,
3968 unix_shared_memory_queue_t *q,
3972 vl_api_ip_details_t * mp;
3974 mp = vl_msg_api_alloc (sizeof (*mp));
3975 memset (mp, 0, sizeof (*mp));
3976 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3978 mp->sw_if_index = ntohl(sw_if_index);
3979 mp->context = context;
3981 vl_msg_api_send_shmem (q, (u8 *)&mp);
3985 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3986 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3988 vpe_api_main_t * am = &vpe_api_main;
3989 l2t_main_t * lm = &l2t_main;
3990 unix_shared_memory_queue_t * q;
3991 l2t_session_t *session;
3993 q = vl_api_client_index_to_input_queue (mp->client_index);
3997 pool_foreach (session, lm->sessions,
3999 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4004 static void send_sw_interface_tap_details (vpe_api_main_t * am,
4005 unix_shared_memory_queue_t *q,
4006 tapcli_interface_details_t *tap_if,
4009 vl_api_sw_interface_tap_details_t * mp;
4010 mp = vl_msg_api_alloc (sizeof (*mp));
4011 memset (mp, 0, sizeof (*mp));
4012 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4013 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4014 strncpy((char *)mp->dev_name,
4015 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4016 mp->context = context;
4018 vl_msg_api_send_shmem (q, (u8 *)&mp);
4022 vl_api_sw_interface_tap_dump_t_handler (
4023 vl_api_sw_interface_tap_dump_t *mp)
4026 vpe_api_main_t * am = &vpe_api_main;
4027 unix_shared_memory_queue_t * q;
4028 tapcli_interface_details_t *tapifs = NULL;
4029 tapcli_interface_details_t *tap_if = NULL;
4031 q = vl_api_client_index_to_input_queue (mp->client_index);
4035 rv = vnet_tap_dump_ifs(&tapifs);
4039 vec_foreach(tap_if, tapifs) {
4040 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4047 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4049 vpe_api_main_t * am = &vpe_api_main;
4050 vnet_main_t * vnm = vnet_get_main();
4051 vlib_main_t * vm = vlib_get_main();
4052 vnet_interface_main_t * im = &vnm->interface_main;
4053 unix_shared_memory_queue_t * q;
4054 vnet_sw_interface_t * si, * sorted_sis;
4055 u32 sw_if_index = ~0;
4057 q = vl_api_client_index_to_input_queue (mp->client_index);
4062 /* Gather interfaces. */
4063 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4064 _vec_len (sorted_sis) = 0;
4065 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4067 vec_foreach (si, sorted_sis) {
4068 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4069 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4072 sw_if_index = si->sw_if_index;
4073 send_ip_details(am, q, sw_if_index, mp->context);
4078 static void vl_api_l2_fib_table_entry_t_handler (
4079 vl_api_l2_fib_table_entry_t * mp)
4081 clib_warning ("BUG");
4084 static void send_l2fib_table_entry (vpe_api_main_t * am,
4085 unix_shared_memory_queue_t *q,
4086 l2fib_entry_key_t * l2fe_key,
4087 l2fib_entry_result_t * l2fe_res,
4090 vl_api_l2_fib_table_entry_t * mp;
4092 mp = vl_msg_api_alloc (sizeof (*mp));
4093 memset (mp, 0, sizeof (*mp));
4094 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4096 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4098 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4099 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4100 mp->static_mac = l2fe_res->fields.static_mac;
4101 mp->filter_mac = l2fe_res->fields.filter;
4102 mp->bvi_mac = l2fe_res->fields.bvi;
4103 mp->context = context;
4105 vl_msg_api_send_shmem (q, (u8 *)&mp);
4109 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4111 vpe_api_main_t * am = &vpe_api_main;
4112 bd_main_t * bdm = &bd_main;
4113 l2fib_entry_key_t *l2fe_key = NULL;
4114 l2fib_entry_result_t *l2fe_res = NULL;
4115 u32 ni, bd_id = ntohl (mp->bd_id);
4117 unix_shared_memory_queue_t * q;
4120 q = vl_api_client_index_to_input_queue (mp->client_index);
4124 /* see l2fib_table_dump: ~0 means "any" */
4128 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4135 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4137 vec_foreach_index (ni, l2fe_key) {
4138 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4139 vec_elt_at_index(l2fe_res, ni), mp->context);
4146 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4148 vl_api_show_version_reply_t *rmp;
4150 char * vpe_api_get_build_directory(void);
4151 char * vpe_api_get_version(void);
4152 char * vpe_api_get_build_date(void);
4154 unix_shared_memory_queue_t * q =
4155 vl_api_client_index_to_input_queue (mp->client_index);
4160 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4162 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4163 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4164 ARRAY_LEN(rmp->build_directory)-1);
4165 strncpy ((char *) rmp->version, vpe_api_get_version(),
4166 ARRAY_LEN(rmp->version)-1);
4167 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4168 ARRAY_LEN(rmp->build_date)-1);
4172 static void vl_api_get_node_index_t_handler
4173 (vl_api_get_node_index_t * mp)
4175 vlib_main_t * vm = vlib_get_main();
4176 vl_api_get_node_index_reply_t * rmp;
4179 u32 node_index = ~0;
4181 n = vlib_get_node_by_name (vm, mp->node_name);
4184 rv = VNET_API_ERROR_NO_SUCH_NODE;
4186 node_index = n->index;
4188 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4190 rmp->node_index = ntohl(node_index);
4194 static void vl_api_add_node_next_t_handler
4195 (vl_api_add_node_next_t * mp)
4197 vlib_main_t * vm = vlib_get_main();
4198 vl_api_add_node_next_reply_t * rmp;
4199 vlib_node_t * n, * next;
4201 u32 next_index = ~0;
4203 n = vlib_get_node_by_name (vm, mp->node_name);
4206 rv = VNET_API_ERROR_NO_SUCH_NODE;
4210 next = vlib_get_node_by_name (vm, mp->next_name);
4213 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4215 next_index = vlib_node_add_next (vm, n->index, next->index);
4218 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4220 rmp->next_index = ntohl(next_index);
4224 static void vl_api_l2tpv3_create_tunnel_t_handler
4225 (vl_api_l2tpv3_create_tunnel_t *mp)
4227 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4228 l2t_main_t *lm = &l2t_main;
4229 u32 sw_if_index = (u32)~0;
4232 if (mp->is_ipv6 != 1) {
4233 rv = VNET_API_ERROR_UNIMPLEMENTED;
4237 rv = create_l2tpv3_ipv6_tunnel (lm,
4238 (ip6_address_t *) mp->client_address,
4239 (ip6_address_t *) mp->our_address,
4240 ntohl(mp->local_session_id),
4241 ntohl(mp->remote_session_id),
4242 clib_net_to_host_u64(mp->local_cookie),
4243 clib_net_to_host_u64(mp->remote_cookie),
4244 mp->l2_sublayer_present,
4248 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4250 rmp->sw_if_index = ntohl (sw_if_index);
4254 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4255 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4257 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4258 l2t_main_t *lm = &l2t_main;
4261 VALIDATE_SW_IF_INDEX(mp);
4263 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4264 clib_net_to_host_u64(mp->new_local_cookie),
4265 clib_net_to_host_u64(mp->new_remote_cookie));
4267 BAD_SW_IF_INDEX_LABEL;
4269 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4272 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4273 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4276 vnet_main_t * vnm = vnet_get_main();
4277 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4279 VALIDATE_SW_IF_INDEX(mp);
4281 rv = l2tpv3_interface_enable_disable
4282 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4284 BAD_SW_IF_INDEX_LABEL;
4286 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4289 static void vl_api_l2tpv3_set_lookup_key_t_handler
4290 (vl_api_l2tpv3_set_lookup_key_t * mp)
4293 l2t_main_t *lm = &l2t_main;
4294 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4296 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4297 rv = VNET_API_ERROR_INVALID_VALUE;
4301 lm->lookup_type = mp->key;
4304 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4307 static void vl_api_vxlan_add_del_tunnel_t_handler
4308 (vl_api_vxlan_add_del_tunnel_t * mp)
4310 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4312 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4313 u32 encap_fib_index;
4315 ip4_main_t * im = &ip4_main;
4316 u32 sw_if_index = ~0;
4318 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4320 rv = VNET_API_ERROR_NO_SUCH_FIB;
4323 encap_fib_index = p[0];
4325 /* Check src & dst are different */
4326 if ((a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4327 (!a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4328 rv = VNET_API_ERROR_SAME_SRC_DST;
4331 memset (a, 0, sizeof (*a));
4333 a->is_add = mp->is_add;
4334 a->is_ip6 = mp->is_ipv6;
4336 /* ip addresses sent in network byte order */
4338 memcpy(&(a->src.ip6), mp->src_address, 16);
4339 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4341 memcpy(&(a->src.ip4), mp->src_address, 4);
4342 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4345 a->encap_fib_index = encap_fib_index;
4346 a->decap_next_index = ntohl(mp->decap_next_index);
4347 a->vni = ntohl(mp->vni);
4348 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4351 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4353 rmp->sw_if_index = ntohl (sw_if_index);
4357 static void send_vxlan_tunnel_details
4358 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4360 vl_api_vxlan_tunnel_details_t * rmp;
4361 ip4_main_t * im4 = &ip4_main;
4362 ip6_main_t * im6 = &ip6_main;
4363 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4365 rmp = vl_msg_api_alloc (sizeof (*rmp));
4366 memset (rmp, 0, sizeof (*rmp));
4367 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4369 memcpy(rmp->src_address, &(t->src.ip6), 16);
4370 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4371 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4373 memcpy(rmp->src_address, &(t->src.ip4), 4);
4374 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4375 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4377 rmp->vni = htonl(t->vni);
4378 rmp->decap_next_index = htonl(t->decap_next_index);
4379 rmp->sw_if_index = htonl(t->sw_if_index);
4380 rmp->is_ipv6 = is_ipv6;
4381 rmp->context = context;
4383 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4386 static void vl_api_vxlan_tunnel_dump_t_handler
4387 (vl_api_vxlan_tunnel_dump_t * mp)
4389 unix_shared_memory_queue_t * q;
4390 vxlan_main_t * vxm = &vxlan_main;
4394 q = vl_api_client_index_to_input_queue (mp->client_index);
4399 sw_if_index = ntohl(mp->sw_if_index);
4401 if (~0 == sw_if_index) {
4402 pool_foreach (t, vxm->tunnels,
4404 send_vxlan_tunnel_details(t, q, mp->context);
4407 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4408 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4411 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4412 send_vxlan_tunnel_details(t, q, mp->context);
4416 static void vl_api_gre_add_del_tunnel_t_handler
4417 (vl_api_gre_add_del_tunnel_t * mp)
4419 vl_api_gre_add_del_tunnel_reply_t * rmp;
4421 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4424 ip4_main_t * im = &ip4_main;
4425 u32 sw_if_index = ~0;
4427 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_table_id));
4429 rv = VNET_API_ERROR_NO_SUCH_FIB;
4432 outer_table_id = p[0];
4434 /* Check src & dst are different */
4435 if (memcmp(&mp->src_address, &mp->dst_address, 4) == 0) {
4436 rv = VNET_API_ERROR_SAME_SRC_DST;
4440 memset (a, 0, sizeof (*a));
4442 a->is_add = mp->is_add;
4444 /* ip addresses sent in network byte order */
4445 a->src.as_u32 = mp->src_address;
4446 a->dst.as_u32 = mp->dst_address;
4448 a->outer_table_id = outer_table_id;
4449 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4452 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4454 rmp->sw_if_index = ntohl (sw_if_index);
4458 static void send_gre_tunnel_details
4459 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4461 vl_api_gre_tunnel_details_t * rmp;
4462 ip4_main_t * im = &ip4_main;
4464 rmp = vl_msg_api_alloc (sizeof (*rmp));
4465 memset (rmp, 0, sizeof (*rmp));
4466 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4467 rmp->src_address = t->tunnel_src.data_u32;
4468 rmp->dst_address = t->tunnel_dst.data_u32;
4469 rmp->outer_table_id = htonl(im->fibs[t->outer_fib_index].table_id);
4470 rmp->sw_if_index = htonl(t->sw_if_index);
4471 rmp->context = context;
4473 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4476 static void vl_api_gre_tunnel_dump_t_handler
4477 (vl_api_gre_tunnel_dump_t * mp)
4479 unix_shared_memory_queue_t * q;
4480 gre_main_t * gm = &gre_main;
4484 q = vl_api_client_index_to_input_queue (mp->client_index);
4489 sw_if_index = ntohl(mp->sw_if_index);
4491 if (~0 == sw_if_index) {
4492 pool_foreach (t, gm->tunnels,
4494 send_gre_tunnel_details(t, q, mp->context);
4497 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4498 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4501 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4502 send_gre_tunnel_details(t, q, mp->context);
4507 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4509 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4511 vl_api_l2_patch_add_del_reply_t * rmp;
4512 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4516 VALIDATE_RX_SW_IF_INDEX(mp);
4517 VALIDATE_TX_SW_IF_INDEX(mp);
4519 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4520 ntohl(mp->tx_sw_if_index),
4521 (int)(mp->is_add != 0));
4523 BAD_RX_SW_IF_INDEX_LABEL;
4524 BAD_TX_SW_IF_INDEX_LABEL;
4526 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4530 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4531 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4533 vl_api_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4535 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4536 u32 encap_fib_index, decap_fib_index;
4539 ip4_main_t * im = &ip4_main;
4540 u32 sw_if_index = ~0;
4543 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4545 rv = VNET_API_ERROR_NO_SUCH_FIB;
4548 encap_fib_index = p[0];
4550 protocol = ntohl(mp->protocol);
4552 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4553 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT) {
4554 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4556 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4559 decap_fib_index = p[0];
4561 decap_fib_index = ntohl(mp->decap_vrf_id);
4564 memset (a, 0, sizeof (*a));
4566 a->is_add = mp->is_add;
4567 /* ip addresses sent in network byte order */
4568 a->local.as_u32 = ntohl(mp->local);
4569 a->remote.as_u32 = ntohl(mp->remote);
4570 a->encap_fib_index = encap_fib_index;
4571 a->decap_fib_index = decap_fib_index;
4572 a->protocol = protocol;
4573 a->vni = ntohl(mp->vni);
4574 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4577 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4579 rmp->sw_if_index = ntohl (sw_if_index);
4584 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4586 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4588 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4590 u8 *locator_name = NULL;
4592 memset(a, 0, sizeof(a[0]));
4594 locator_name = format(0, "%s", mp->locator_set_name);
4596 a->name = locator_name;
4598 a->is_add = mp->is_add;
4601 rv = vnet_lisp_add_del_locator_set_name(a, &ls_index);
4603 vec_free(locator_name);
4605 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4609 vl_api_lisp_add_del_locator_t_handler(
4610 vl_api_lisp_add_del_locator_t *mp)
4612 vl_api_lisp_add_del_locator_reply_t *rmp;
4614 locator_t locator, *locators = NULL;
4615 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4617 u8 *locator_name = NULL;
4619 memset(&locator, 0, sizeof(locator));
4620 memset(a, 0, sizeof(a[0]));
4622 locator.sw_if_index = ntohl(mp->sw_if_index);
4623 locator.priority = mp->priority;
4624 locator.weight = mp->weight;
4626 vec_add1(locators, locator);
4628 locator_name = format(0, "%s", mp->locator_set_name);
4630 a->name = locator_name;
4631 a->locators = locators;
4632 a->is_add = mp->is_add;
4635 rv = vnet_lisp_add_del_locator(a, &ls_index);
4638 vec_free(locator_name);
4640 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4644 vl_api_lisp_add_del_local_eid_t_handler(
4645 vl_api_lisp_add_del_local_eid_t *mp)
4647 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4648 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4650 ip_prefix_t *prefp = NULL;
4651 ip_address_t *ip_eid = NULL;
4654 u32 locator_set_index = ~0, map_index = ~0;
4655 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4658 prefp = &gid_address_ippref(&eid);
4659 ip_eid = &ip_prefix_addr(prefp);
4660 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4663 clib_memcpy(&ip_addr_v6(ip_eid), mp->ip_address,
4664 sizeof(ip_addr_v6(ip_eid)));
4665 ip_addr_version(ip_eid) = IP6;
4667 clib_memcpy(&ip_addr_v4(ip_eid), mp->ip_address,
4668 sizeof(ip_addr_v4(ip_eid)));
4669 ip_addr_version(ip_eid) = IP4;
4671 ip_prefix_len(prefp) = mp->prefix_len;
4673 name = format(0, "%s", mp->locator_set_name);
4674 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4676 rv = VNET_API_ERROR_INVALID_VALUE;
4679 locator_set_index = p[0];
4681 /* XXX treat batch configuration */
4682 a->is_add = mp->is_add;
4684 a->locator_set_index = locator_set_index;
4687 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4692 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4696 lisp_gpe_add_del_fwd_entry_set_address(
4697 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4698 ip_address_t *slocator,
4699 ip_address_t *dlocator,
4702 ip_address_t *ip_eid = NULL;
4703 ip_prefix_t *prefp = NULL;
4705 prefp = &gid_address_ippref(eid);
4706 ip_eid = &ip_prefix_addr(prefp);
4708 if (mp->eid_is_ipv6) {
4709 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4710 sizeof(ip_addr_v6(ip_eid)));
4711 ip_addr_version(ip_eid) = IP6;
4713 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4714 sizeof(ip_addr_v4(ip_eid)));
4715 ip_addr_version(ip_eid) = IP4;
4717 ip_prefix_len(prefp) = mp->eid_prefix_len;
4719 if (mp->address_is_ipv6) {
4720 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4721 sizeof(ip_addr_v6(slocator)));
4722 ip_addr_version(slocator) = IP6;
4723 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4724 sizeof(ip_addr_v6(dlocator)));
4725 ip_addr_version(dlocator) = IP6;
4727 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4728 sizeof(ip_addr_v4(slocator)));
4729 ip_addr_version(slocator) = IP4;
4730 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4731 sizeof(ip_addr_v4(dlocator)));
4732 ip_addr_version(dlocator) = IP4;
4737 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4738 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4740 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4742 ip_address_t slocator, dlocator;
4744 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4746 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4748 memset (&a, 0, sizeof(a));
4750 a.is_add = mp->is_add;
4752 a.slocator = slocator;
4753 a.dlocator = dlocator;
4754 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4756 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4760 vl_api_lisp_add_del_map_resolver_t_handler(
4761 vl_api_lisp_add_del_map_resolver_t *mp)
4763 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4765 ip_address_t *ip_addr = NULL;
4766 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4768 a->is_add = mp->is_add;
4769 ip_addr = &a->address;
4772 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4773 sizeof(ip_addr_v6(ip_addr)));
4774 ip_addr_version(ip_addr) = IP6;
4776 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4777 sizeof(ip_addr_v4(ip_addr)));
4778 ip_addr_version(ip_addr) = IP4;
4781 rv = vnet_lisp_add_del_map_resolver (a);
4783 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4787 vl_api_lisp_gpe_enable_disable_t_handler(
4788 vl_api_lisp_gpe_enable_disable_t *mp)
4790 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4792 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
4794 a->is_en = mp->is_en;
4795 vnet_lisp_gpe_enable_disable (a);
4797 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4801 vl_api_lisp_enable_disable_t_handler(
4802 vl_api_lisp_enable_disable_t *mp)
4804 vl_api_lisp_enable_disable_reply_t *rmp;
4807 vnet_lisp_enable_disable (mp->is_en);
4808 REPLY_MACRO(VL_API_LISP_ENABLE_DISABLE_REPLY);
4812 vl_api_lisp_gpe_add_del_iface_t_handler(
4813 vl_api_lisp_gpe_add_del_iface_t *mp)
4815 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4817 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4819 a->is_add = mp->is_add;
4820 a->table_id = mp->table_id;
4822 vnet_lisp_gpe_add_del_iface (a, 0);
4824 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4827 /** Used for transferring locators via VPP API */
4828 typedef CLIB_PACKED(struct
4830 u8 is_ip4; /**< is locator an IPv4 address */
4831 u8 addr[16]; /**< IPv4/IPv6 address */
4835 send_lisp_locator_set_details_set_address
4836 (vl_api_lisp_locator_set_details_t *rmp,
4837 gid_address_t *gid_address)
4839 ip_prefix_t *ip_addr;
4841 if (gid_address_type(gid_address) != GID_ADDR_IP_PREFIX) {
4845 ip_addr = &gid_address_ippref(gid_address);
4846 rmp->prefix_len = ip_prefix_len(ip_addr);
4847 rmp->is_ipv6 = ip_prefix_version(ip_addr);
4848 ip_address_copy_addr(rmp->ip_address, &ip_prefix_addr(ip_addr));
4852 vl_api_lisp_add_del_remote_mapping_t_handler (
4853 vl_api_lisp_add_del_remote_mapping_t *mp)
4856 ip_address_t rloc, * rlocs = 0;
4857 vl_api_lisp_add_del_remote_mapping_reply_t * rmp;
4859 gid_address_t _seid, * seid = &_seid;
4860 gid_address_t _deid, * deid = &_deid;
4861 ip_prefix_t * seid_pref = &gid_address_ippref(seid);
4862 ip_prefix_t * deid_pref = &gid_address_ippref(deid);
4864 gid_address_type(seid) = GID_ADDR_IP_PREFIX;
4865 gid_address_type(deid) = GID_ADDR_IP_PREFIX;
4866 ip_address_t * seid_addr = &ip_prefix_addr(seid_pref);
4867 ip_address_t * deid_addr = &ip_prefix_addr(deid_pref);
4868 ip_prefix_len(seid_pref) = mp->seid_len;
4869 ip_prefix_len(deid_pref) = mp->deid_len;
4870 gid_address_set_vni (seid, ntohl (mp->vni));
4871 gid_address_set_vni (deid, ntohl (mp->vni));
4873 if (mp->eid_is_ip4) {
4874 ip_prefix_version(seid_pref) = IP4;
4875 ip_prefix_version(deid_pref) = IP4;
4876 clib_memcpy (&ip_addr_v4(seid_addr),
4877 mp->seid, sizeof (ip_addr_v4(seid_addr)));
4878 clib_memcpy (&ip_addr_v4(deid_addr),
4879 mp->deid, sizeof (ip_addr_v4(deid_addr)));
4881 ip_prefix_version(seid_pref) = IP6;
4882 ip_prefix_version(deid_pref) = IP6;
4883 clib_memcpy (&ip_addr_v6(seid_addr),
4884 mp->seid, sizeof (ip_addr_v6(seid_addr)));
4885 clib_memcpy (&ip_addr_v6(deid_addr),
4886 mp->deid, sizeof (ip_addr_v6(deid_addr)));
4889 for (i = 0; i < mp->rloc_num; i++) {
4890 rloc_t * r = &((rloc_t *) mp->rlocs)[i];
4892 clib_memcpy (&ip_addr_v4(&rloc), &r->addr, sizeof (rloc_t));
4893 ip_addr_version (&rloc) = IP4;
4895 clib_memcpy (&ip_addr_v6(&rloc), &r->addr, sizeof (rloc_t));
4896 ip_addr_version (&rloc) = IP6;
4898 vec_add1 (rlocs, rloc);
4901 rv = vnet_lisp_add_del_remote_mapping (deid, seid, rlocs,
4902 mp->action, mp->is_add);
4904 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4908 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
4909 locator_set_t *lsit,
4910 unix_shared_memory_queue_t *q,
4914 vl_api_lisp_locator_set_details_t *rmp;
4915 locator_t *loc = NULL;
4919 vec_foreach (locit, lsit->locator_indices) {
4920 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4921 rmp = vl_msg_api_alloc (sizeof (*rmp));
4922 memset (rmp, 0, sizeof (*rmp));
4923 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
4924 rmp->local = lsit->local;
4926 ASSERT(lsit->name != NULL);
4927 strncpy((char *) rmp->locator_set_name,
4928 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4929 rmp->sw_if_index = htonl(loc->sw_if_index);
4931 str = format(0, "remote-%d", index);
4932 strncpy((char *) rmp->locator_set_name, (char *) str,
4933 ARRAY_LEN(rmp->locator_set_name) - 1);
4934 send_lisp_locator_set_details_set_address(rmp, &loc->address);
4938 rmp->priority = loc->priority;
4939 rmp->weight = loc->weight;
4940 rmp->context = context;
4942 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4947 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
4949 unix_shared_memory_queue_t * q = NULL;
4950 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4951 locator_set_t * lsit = NULL;
4954 q = vl_api_client_index_to_input_queue (mp->client_index);
4960 pool_foreach (lsit, lcm->locator_set_pool,
4962 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
4967 send_lisp_local_eid_table_details (mapping_t *mapit,
4968 unix_shared_memory_queue_t *q,
4971 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
4972 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4973 locator_set_t *ls = NULL;
4974 gid_address_t *gid = NULL;
4975 ip_prefix_t *ip_prefix = NULL;
4979 ls = pool_elt_at_index (lcm->locator_set_pool,
4980 mapit->locator_set_index);
4983 type = gid_address_type(gid);
4985 if (type != GID_ADDR_IP_PREFIX) {
4989 ip_prefix = &gid_address_ippref(gid);
4991 rmp = vl_msg_api_alloc (sizeof (*rmp));
4992 memset (rmp, 0, sizeof (*rmp));
4993 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
4995 ASSERT(ls->name != NULL);
4996 strncpy((char *) rmp->locator_set_name,
4997 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4999 str = format(0, "remote-%d", mapit->locator_set_index);
5000 strncpy((char *) rmp->locator_set_name, (char *) str,
5001 ARRAY_LEN(rmp->locator_set_name) - 1);
5005 switch (ip_prefix_version(ip_prefix)) {
5007 rmp->eid_is_ipv6 = 0;
5008 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v4(ip_prefix),
5009 sizeof(ip_prefix_v4(ip_prefix)));
5013 rmp->eid_is_ipv6 = 1;
5014 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v6(ip_prefix),
5015 sizeof(ip_prefix_v6(ip_prefix)));
5021 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
5022 rmp->context = context;
5024 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5028 vl_api_lisp_local_eid_table_dump_t_handler (
5029 vl_api_lisp_local_eid_table_dump_t *mp)
5031 unix_shared_memory_queue_t * q = NULL;
5032 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5033 mapping_t * mapit = NULL;
5035 q = vl_api_client_index_to_input_queue (mp->client_index);
5040 pool_foreach (mapit, lcm->mapping_pool,
5042 send_lisp_local_eid_table_details(mapit, q, mp->context);
5047 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5048 unix_shared_memory_queue_t *q,
5051 vl_api_lisp_gpe_tunnel_details_t *rmp;
5052 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5054 rmp = vl_msg_api_alloc (sizeof (*rmp));
5055 memset (rmp, 0, sizeof (*rmp));
5056 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5058 rmp->tunnels = tunnel - lgm->tunnels;
5060 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5061 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5062 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5064 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5065 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5066 rmp->dcap_next = htonl(tunnel->decap_next_index);
5067 rmp->lisp_ver = tunnel->ver_res;
5068 rmp->next_protocol = tunnel->next_protocol;
5069 rmp->flags = tunnel->flags;
5070 rmp->ver_res = tunnel->ver_res;
5071 rmp->res = tunnel->res;
5072 rmp->iid = htonl(tunnel->vni);
5073 rmp->context = context;
5075 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5079 vl_api_lisp_gpe_tunnel_dump_t_handler (
5080 vl_api_lisp_local_eid_table_dump_t *mp)
5082 unix_shared_memory_queue_t * q = NULL;
5083 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5084 lisp_gpe_tunnel_t * tunnel = NULL;
5086 if (pool_elts(lgm->tunnels) == 0) {
5090 q = vl_api_client_index_to_input_queue (mp->client_index);
5095 pool_foreach(tunnel, lgm->tunnels,
5097 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5102 send_lisp_map_resolver_details (ip_address_t *ip,
5103 unix_shared_memory_queue_t *q,
5106 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5108 rmp = vl_msg_api_alloc (sizeof (*rmp));
5109 memset (rmp, 0, sizeof (*rmp));
5110 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5112 switch (ip_addr_version(ip)) {
5115 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5120 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5126 rmp->context = context;
5128 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5132 vl_api_lisp_map_resolver_dump_t_handler (
5133 vl_api_lisp_local_eid_table_dump_t *mp)
5135 unix_shared_memory_queue_t * q = NULL;
5136 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5137 ip_address_t *ip = NULL;
5139 q = vl_api_client_index_to_input_queue (mp->client_index);
5144 vec_foreach(ip, lcm->map_resolvers) {
5145 send_lisp_map_resolver_details(ip, q, mp->context);
5151 send_lisp_enable_disable_details (unix_shared_memory_queue_t *q,
5154 vl_api_lisp_enable_disable_status_details_t *rmp = NULL;
5156 rmp = vl_msg_api_alloc (sizeof (*rmp));
5157 memset (rmp, 0, sizeof (*rmp));
5158 rmp->_vl_msg_id = ntohs(VL_API_LISP_ENABLE_DISABLE_STATUS_DETAILS);
5160 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5161 rmp->feature_status = vnet_lisp_enable_disable_status ();
5162 rmp->context = context;
5164 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5168 vl_api_lisp_enable_disable_status_dump_t_handler
5169 (vl_api_lisp_enable_disable_status_dump_t *mp)
5171 unix_shared_memory_queue_t * q = NULL;
5173 q = vl_api_client_index_to_input_queue (mp->client_index);
5178 send_lisp_enable_disable_details(q, mp->context);
5182 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5184 vl_api_interface_name_renumber_reply_t * rmp;
5187 VALIDATE_SW_IF_INDEX(mp);
5189 rv = vnet_interface_name_renumber
5190 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5192 BAD_SW_IF_INDEX_LABEL;
5194 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5197 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5198 u32 sw_if_index, u32 address)
5200 vpe_api_main_t * am = &vpe_api_main;
5201 vlib_main_t * vm = am->vlib_main;
5202 vl_api_ip4_arp_event_t * event;
5203 static f64 arp_event_last_time;
5204 f64 now = vlib_time_now (vm);
5206 if (pool_is_free_index (am->arp_events, pool_index))
5209 event = pool_elt_at_index (am->arp_events, pool_index);
5210 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5211 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5212 } else { /* same mac */
5213 if ((sw_if_index == event->sw_if_index) &&
5215 /* for BD case, also check IP address with 10 sec timeout */
5216 ((address == event->address) &&
5217 ((now - arp_event_last_time) < 10.0))))
5221 arp_event_last_time = now;
5222 event->sw_if_index = sw_if_index;
5223 if (address) event->address = address;
5227 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5229 vpe_api_main_t * am = &vpe_api_main;
5231 if (pool_is_free_index (am->arp_events, pool_index))
5234 pool_put_index (am->arp_events, pool_index);
5239 vl_api_want_ip4_arp_events_t_handler
5240 (vl_api_want_ip4_arp_events_t * mp)
5242 vpe_api_main_t * am = &vpe_api_main;
5243 vnet_main_t * vnm = vnet_get_main();
5244 vl_api_want_ip4_arp_events_reply_t *rmp;
5245 vl_api_ip4_arp_event_t * event;
5248 if (mp->enable_disable) {
5249 pool_get (am->arp_events, event);
5250 memset (event, 0, sizeof (*event));
5252 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5253 event->client_index = mp->client_index;
5254 event->context = mp->context;
5255 event->address = mp->address;
5256 event->pid = mp->pid;
5258 rv = vnet_add_del_ip4_arp_change_event
5259 (vnm, arp_change_data_callback,
5261 &mp->address /* addr, in net byte order */,
5262 vpe_resolver_process_node.index,
5263 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5265 rv = vnet_add_del_ip4_arp_change_event
5266 (vnm, arp_change_delete_callback,
5268 &mp->address /* addr, in net byte order */,
5269 vpe_resolver_process_node.index,
5270 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5272 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5275 static void vl_api_input_acl_set_interface_t_handler
5276 (vl_api_input_acl_set_interface_t * mp)
5278 vlib_main_t *vm = vlib_get_main();
5279 vl_api_input_acl_set_interface_reply_t * rmp;
5281 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5283 ip4_table_index = ntohl(mp->ip4_table_index);
5284 ip6_table_index = ntohl(mp->ip6_table_index);
5285 l2_table_index = ntohl(mp->l2_table_index);
5286 sw_if_index = ntohl(mp->sw_if_index);
5288 VALIDATE_SW_IF_INDEX(mp);
5290 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5291 ip6_table_index, l2_table_index,
5294 BAD_SW_IF_INDEX_LABEL;
5296 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5299 static void vl_api_ipsec_spd_add_del_t_handler
5300 (vl_api_ipsec_spd_add_del_t * mp)
5303 clib_warning ("unimplemented");
5306 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5307 vl_api_ipsec_spd_add_del_reply_t * rmp;
5311 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5313 rv = VNET_API_ERROR_UNIMPLEMENTED;
5316 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5320 static void vl_api_ipsec_interface_add_del_spd_t_handler
5321 (vl_api_ipsec_interface_add_del_spd_t * mp)
5323 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5324 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5326 u32 sw_if_index __attribute__((unused));
5327 u32 spd_id __attribute__((unused));
5329 sw_if_index = ntohl(mp->sw_if_index);
5330 spd_id = ntohl(mp->spd_id);
5332 VALIDATE_SW_IF_INDEX(mp);
5335 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5337 rv = VNET_API_ERROR_UNIMPLEMENTED;
5340 BAD_SW_IF_INDEX_LABEL;
5342 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5345 static void vl_api_ipsec_spd_add_del_entry_t_handler
5346 (vl_api_ipsec_spd_add_del_entry_t * mp)
5348 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5349 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5355 memset(&p, 0, sizeof(p));
5357 p.id = ntohl(mp->spd_id);
5358 p.priority = ntohl(mp->priority);
5359 p.is_outbound = mp->is_outbound;
5360 p.is_ipv6 = mp->is_ipv6;
5362 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5363 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5364 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5365 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5367 p.protocol = mp->protocol;
5368 p.rport.start = ntohs(mp->remote_port_start);
5369 p.rport.stop = ntohs(mp->remote_port_stop);
5370 p.lport.start = ntohs(mp->local_port_start);
5371 p.lport.stop = ntohs(mp->local_port_stop);
5372 /* policy action resolve unsupported */
5373 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5374 clib_warning("unsupported action: 'resolve'");
5375 rv = VNET_API_ERROR_UNIMPLEMENTED;
5378 p.policy = mp->policy;
5379 p.sa_id = ntohl(mp->sa_id);
5381 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5385 if (mp->is_ip_any) {
5387 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5390 rv = VNET_API_ERROR_UNIMPLEMENTED;
5395 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5398 static void vl_api_ipsec_sad_add_del_entry_t_handler
5399 (vl_api_ipsec_sad_add_del_entry_t * mp)
5401 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5402 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5407 memset(&sa, 0, sizeof(sa));
5409 sa.id = ntohl(mp->sad_id);
5410 sa.spi = ntohl(mp->spi);
5411 /* security protocol AH unsupported */
5412 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5413 clib_warning("unsupported security protocol 'AH'");
5414 rv = VNET_API_ERROR_UNIMPLEMENTED;
5417 sa.protocol = mp->protocol;
5418 /* check for unsupported crypto-alg */
5419 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5420 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5421 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5422 mp->crypto_algorithm);
5423 rv = VNET_API_ERROR_UNIMPLEMENTED;
5426 sa.crypto_alg = mp->crypto_algorithm;
5427 sa.crypto_key_len = mp->crypto_key_length;
5428 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5429 /* check for unsupported integ-alg */
5430 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5431 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5432 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5433 mp->integrity_algorithm);
5434 rv = VNET_API_ERROR_UNIMPLEMENTED;
5437 sa.integ_alg = mp->integrity_algorithm;
5438 sa.integ_key_len = mp->integrity_key_length;
5439 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5440 sa.use_esn = mp->use_extended_sequence_number;
5441 sa.is_tunnel = mp->is_tunnel;
5442 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5443 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5444 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5446 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5448 rv = VNET_API_ERROR_UNIMPLEMENTED;
5453 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5457 vl_api_ikev2_profile_add_del_t_handler
5458 (vl_api_ikev2_profile_add_del_t * mp)
5460 vl_api_ikev2_profile_add_del_reply_t * rmp;
5464 vlib_main_t * vm = vlib_get_main();
5465 clib_error_t * error;
5466 u8 * tmp = format(0, "%s", mp->name);
5467 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5470 rv = VNET_API_ERROR_UNSPECIFIED;
5472 rv = VNET_API_ERROR_UNIMPLEMENTED;
5475 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5479 vl_api_ikev2_profile_set_auth_t_handler
5480 (vl_api_ikev2_profile_set_auth_t * mp)
5482 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5486 vlib_main_t * vm = vlib_get_main();
5487 clib_error_t * error;
5488 u8 * tmp = format(0, "%s", mp->name);
5489 u8 * data = vec_new (u8, mp->data_len);
5490 clib_memcpy(data, mp->data, mp->data_len);
5491 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5495 rv = VNET_API_ERROR_UNSPECIFIED;
5497 rv = VNET_API_ERROR_UNIMPLEMENTED;
5500 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5504 vl_api_ikev2_profile_set_id_t_handler
5505 (vl_api_ikev2_profile_set_id_t * mp)
5507 vl_api_ikev2_profile_add_del_reply_t * rmp;
5511 vlib_main_t * vm = vlib_get_main();
5512 clib_error_t * error;
5513 u8 * tmp = format(0, "%s", mp->name);
5514 u8 * data = vec_new (u8, mp->data_len);
5515 clib_memcpy(data, mp->data, mp->data_len);
5516 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
5520 rv = VNET_API_ERROR_UNSPECIFIED;
5522 rv = VNET_API_ERROR_UNIMPLEMENTED;
5525 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5529 vl_api_ikev2_profile_set_ts_t_handler
5530 (vl_api_ikev2_profile_set_ts_t * mp)
5532 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5536 vlib_main_t * vm = vlib_get_main();
5537 clib_error_t * error;
5538 u8 * tmp = format(0, "%s", mp->name);
5539 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
5540 mp->end_port, (ip4_address_t) mp->start_addr,
5541 (ip4_address_t) mp->end_addr, mp->is_local);
5544 rv = VNET_API_ERROR_UNSPECIFIED;
5546 rv = VNET_API_ERROR_UNIMPLEMENTED;
5549 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5553 vl_api_ikev2_set_local_key_t_handler
5554 (vl_api_ikev2_set_local_key_t * mp)
5556 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5560 vlib_main_t * vm = vlib_get_main();
5561 clib_error_t * error;
5563 error = ikev2_set_local_key(vm, mp->key_file);
5565 rv = VNET_API_ERROR_UNSPECIFIED;
5567 rv = VNET_API_ERROR_UNIMPLEMENTED;
5570 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5574 vl_api_map_add_domain_t_handler
5575 (vl_api_map_add_domain_t * mp)
5577 vl_api_map_add_domain_reply_t * rmp;
5580 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
5581 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
5582 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
5583 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
5584 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
5586 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
5588 rmp->index = ntohl(index);
5593 vl_api_map_del_domain_t_handler
5594 (vl_api_map_del_domain_t * mp)
5596 vl_api_map_del_domain_reply_t * rmp;
5599 rv = map_delete_domain(ntohl(mp->index));
5601 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
5605 vl_api_map_add_del_rule_t_handler
5606 (vl_api_map_add_del_rule_t * mp)
5608 vl_api_map_del_domain_reply_t * rmp;
5611 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
5613 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
5617 vl_api_map_domain_dump_t_handler
5618 (vl_api_map_domain_dump_t * mp)
5620 vl_api_map_domain_details_t * rmp;
5621 map_main_t *mm = &map_main;
5623 unix_shared_memory_queue_t * q;
5625 if (pool_elts (mm->domains) == 0)
5628 q = vl_api_client_index_to_input_queue (mp->client_index);
5633 pool_foreach(d, mm->domains, ({
5634 /* Make sure every field is initiated (or don't skip the memset()) */
5635 rmp = vl_msg_api_alloc (sizeof (*rmp));
5636 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
5637 rmp->domain_index = htonl(d - mm->domains);
5638 rmp->ea_bits_len = d->ea_bits_len;
5639 rmp->psid_offset = d->psid_offset;
5640 rmp->psid_length = d->psid_length;
5641 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
5642 rmp->ip4_prefix_len = d->ip4_prefix_len;
5643 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
5644 rmp->ip6_prefix_len = d->ip6_prefix_len;
5645 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
5646 rmp->ip6_src_len = d->ip6_src_len;
5647 rmp->mtu = htons(d->mtu);
5648 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
5649 rmp->context = mp->context;
5651 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5656 vl_api_map_rule_dump_t_handler
5657 (vl_api_map_rule_dump_t * mp)
5659 unix_shared_memory_queue_t * q;
5662 vl_api_map_rule_details_t * rmp;
5663 map_main_t *mm = &map_main;
5664 u32 domain_index = ntohl(mp->domain_index);
5667 if (pool_elts (mm->domains) == 0)
5670 d = pool_elt_at_index(mm->domains, domain_index);
5671 if (!d || !d->rules) {
5675 q = vl_api_client_index_to_input_queue (mp->client_index);
5680 for (i = 0; i < (0x1 << d->psid_length); i++) {
5682 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
5685 rmp = vl_msg_api_alloc(sizeof(*rmp));
5686 memset(rmp, 0, sizeof(*rmp));
5687 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
5688 rmp->psid = htons(i);
5689 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
5690 rmp->context = mp->context;
5691 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5696 vl_api_map_summary_stats_t_handler (
5697 vl_api_map_summary_stats_t *mp)
5699 vl_api_map_summary_stats_reply_t *rmp;
5700 vlib_combined_counter_main_t *cm;
5703 u64 total_pkts[VLIB_N_RX_TX];
5704 u64 total_bytes[VLIB_N_RX_TX];
5705 map_main_t *mm = &map_main;
5706 unix_shared_memory_queue_t *q =
5707 vl_api_client_index_to_input_queue(mp->client_index);
5712 rmp = vl_msg_api_alloc (sizeof (*rmp));
5713 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
5714 rmp->context = mp->context;
5717 memset (total_pkts, 0, sizeof (total_pkts));
5718 memset (total_bytes, 0, sizeof (total_bytes));
5720 map_domain_counter_lock (mm);
5721 vec_foreach(cm, mm->domain_counters) {
5722 which = cm - mm->domain_counters;
5724 for (i = 0; i < vec_len(cm->maxi); i++) {
5725 vlib_get_combined_counter (cm, i, &v);
5726 total_pkts[which] += v.packets;
5727 total_bytes[which] += v.bytes;
5731 map_domain_counter_unlock (mm);
5733 /* Note: in network byte order! */
5734 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
5735 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
5736 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
5737 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
5738 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
5739 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
5740 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));
5741 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));
5743 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5746 static void vl_api_ipsec_sa_set_key_t_handler
5747 (vl_api_ipsec_sa_set_key_t * mp)
5749 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5750 vl_api_ipsec_sa_set_key_reply_t *rmp;
5754 sa.id = ntohl(mp->sa_id);
5755 sa.crypto_key_len = mp->crypto_key_length;
5756 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5757 sa.integ_key_len = mp->integrity_key_length;
5758 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5760 rv = ipsec_set_sa_key(vm, &sa);
5762 rv = VNET_API_ERROR_UNIMPLEMENTED;
5765 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
5768 static void vl_api_cop_interface_enable_disable_t_handler
5769 (vl_api_cop_interface_enable_disable_t * mp)
5771 vl_api_cop_interface_enable_disable_reply_t * rmp;
5773 u32 sw_if_index = ntohl(mp->sw_if_index);
5776 VALIDATE_SW_IF_INDEX(mp);
5778 enable_disable = (int) mp->enable_disable;
5780 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5782 BAD_SW_IF_INDEX_LABEL;
5784 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5787 static void vl_api_cop_whitelist_enable_disable_t_handler
5788 (vl_api_cop_whitelist_enable_disable_t * mp)
5790 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
5791 cop_whitelist_enable_disable_args_t _a, *a=&_a;
5792 u32 sw_if_index = ntohl(mp->sw_if_index);
5795 VALIDATE_SW_IF_INDEX(mp);
5797 a->sw_if_index = sw_if_index;
5800 a->default_cop = mp->default_cop;
5801 a->fib_id = ntohl(mp->fib_id);
5803 rv = cop_whitelist_enable_disable (a);
5805 BAD_SW_IF_INDEX_LABEL;
5807 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5810 static void vl_api_get_node_graph_t_handler
5811 (vl_api_get_node_graph_t * mp)
5815 api_main_t * am = &api_main;
5816 vlib_main_t * vm = vlib_get_main();
5818 vl_api_get_node_graph_reply_t * rmp;
5820 pthread_mutex_lock (&am->vlib_rp->mutex);
5821 oldheap = svm_push_data_heap (am->vlib_rp);
5824 * Keep the number of memcpy ops to a minimum (e.g. 1).
5825 * The current size of the serialized vector is
5826 * slightly under 4K.
5828 vec_validate (vector, 4095);
5829 vec_reset_length (vector);
5831 vector = vlib_node_serialize (&vm->node_main, vector);
5833 svm_pop_heap (oldheap);
5834 pthread_mutex_unlock (&am->vlib_rp->mutex);
5836 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5837 rmp->reply_in_shmem = (uword) vector);
5840 static void vl_api_trace_profile_add_t_handler
5841 (vl_api_trace_profile_add_t *mp)
5844 vl_api_trace_profile_add_reply_t * rmp;
5845 clib_error_t *error;
5847 /* Ignoring the profile id as currently a single profile
5849 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5850 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5851 mp->pow_enable, mp->trace_tsp,
5854 clib_error_report(error);
5855 rv = clib_error_get_code(error);
5858 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5861 static void vl_api_trace_profile_apply_t_handler
5862 (vl_api_trace_profile_apply_t *mp)
5865 vl_api_trace_profile_apply_reply_t * rmp;
5867 if (mp->enable != 0) {
5868 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5869 ntohl(mp->prefix_length),
5871 mp->trace_op == IOAM_HBYH_ADD,
5872 mp->trace_op == IOAM_HBYH_POP,
5873 mp->trace_op == IOAM_HBYH_MOD);
5875 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5877 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5880 static void vl_api_trace_profile_del_t_handler
5881 (vl_api_trace_profile_del_t *mp)
5884 vl_api_trace_profile_del_reply_t * rmp;
5885 clib_error_t *error;
5887 error = clear_ioam_rewrite_fn();
5889 clib_error_report(error);
5890 rv = clib_error_get_code(error);
5893 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5897 vl_api_af_packet_create_t_handler
5898 (vl_api_af_packet_create_t *mp)
5900 vlib_main_t *vm = vlib_get_main();
5901 vl_api_af_packet_create_reply_t *rmp;
5903 u8 *host_if_name = NULL;
5905 host_if_name = format(0, "%s", mp->host_if_name);
5906 vec_add1 (host_if_name, 0);
5908 rv = af_packet_create_if(vm, host_if_name,
5909 mp->use_random_hw_addr ? 0 : mp->hw_addr);
5911 vec_free(host_if_name);
5913 REPLY_MACRO(VL_API_AF_PACKET_CREATE_REPLY);
5917 vl_api_af_packet_delete_t_handler
5918 (vl_api_af_packet_delete_t *mp)
5920 vlib_main_t * vm = vlib_get_main();
5921 vl_api_af_packet_delete_reply_t *rmp;
5923 u8 *host_if_name = NULL;
5925 host_if_name = format(0, "%s", mp->host_if_name);
5926 vec_add1 (host_if_name, 0);
5928 rv = af_packet_delete_if(vm, host_if_name);
5930 vec_free(host_if_name);
5932 REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY);
5935 #define BOUNCE_HANDLER(nn) \
5936 static void vl_api_##nn##_t_handler ( \
5937 vl_api_##nn##_t *mp) \
5939 vpe_client_registration_t *reg; \
5940 vpe_api_main_t * vam = &vpe_api_main; \
5941 unix_shared_memory_queue_t * q; \
5943 /* One registration only... */ \
5944 pool_foreach(reg, vam->nn##_registrations, \
5946 q = vl_api_client_index_to_input_queue (reg->client_index); \
5949 * If the queue is stuffed, turf the msg and complain \
5950 * It's unlikely that the intended recipient is \
5951 * alive; avoid deadlock at all costs. \
5953 if (q->cursize == q->maxsize) { \
5954 clib_warning ("ERROR: receiver queue full, drop msg"); \
5955 vl_msg_api_free (mp); \
5958 vl_msg_api_send_shmem (q, (u8 *)&mp); \
5962 vl_msg_api_free (mp); \
5967 * Add vpe's API message handlers to the table.
5968 * vlib has alread mapped shared memory and
5969 * added the client registration handlers.
5970 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
5973 static clib_error_t *
5974 vpe_api_hookup (vlib_main_t *vm)
5976 api_main_t * am = &api_main;
5979 vl_msg_api_set_handlers(VL_API_##N, #n, \
5980 vl_api_##n##_t_handler, \
5982 vl_api_##n##_t_endian, \
5983 vl_api_##n##_t_print, \
5984 sizeof(vl_api_##n##_t), 1);
5985 foreach_vpe_api_msg;
5989 * Manually register the sr tunnel add del msg, so we trace
5990 * enough bytes to capture a typical segment list
5992 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
5993 "sr_tunnel_add_del",
5994 vl_api_sr_tunnel_add_del_t_handler,
5996 vl_api_sr_tunnel_add_del_t_endian,
5997 vl_api_sr_tunnel_add_del_t_print,
6002 * Manually register the sr policy add del msg, so we trace
6003 * enough bytes to capture a typical tunnel name list
6005 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
6006 "sr_policy_add_del",
6007 vl_api_sr_policy_add_del_t_handler,
6009 vl_api_sr_policy_add_del_t_endian,
6010 vl_api_sr_policy_add_del_t_print,
6014 * Trace space for 8 MPLS encap labels, classifier mask+match
6016 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
6017 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
6018 += 5 * sizeof (u32x4);
6019 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
6020 += 5 * sizeof (u32x4);
6021 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
6022 += 16 * sizeof (u32);
6025 * Thread-safe API messages
6027 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
6032 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
6034 static clib_error_t *
6035 vpe_api_init (vlib_main_t *vm)
6037 vpe_api_main_t *am = &vpe_api_main;
6040 am->vnet_main = vnet_get_main();
6041 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
6042 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6043 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6044 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6045 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6046 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
6049 vl_set_memory_region_name ("/vpe-api");
6050 vl_enable_disable_memory_api (vm, 1 /* enable it */);
6055 VLIB_INIT_FUNCTION(vpe_api_init);
6057 static clib_error_t *
6058 chroot_config (vlib_main_t * vm, unformat_input_t * input)
6062 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6064 if (unformat (input, "prefix %s", &chroot_path))
6066 vec_add1 (chroot_path, 0);
6067 vl_set_memory_root_path ((char *)chroot_path);
6070 return clib_error_return (0, "unknown input `%U'",
6071 format_unformat_error, input);
6075 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
6077 void * get_unformat_vnet_sw_interface (void)
6079 return (void *) &unformat_vnet_sw_interface;
6082 #undef vl_api_version
6083 #define vl_api_version(n,v) static u32 vpe_api_version = v;
6084 #include <api/vpe.api.h>
6085 #undef vl_api_version
6087 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
6089 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
6090 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
6091 clib_host_to_net_u32 (mp->api_versions[0]),
6098 static u8 * format_arp_event (u8 * s, va_list * args)
6100 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
6102 s = format (s, "pid %d: %U", event->pid,
6103 format_ip4_address, &event->address);
6107 static clib_error_t *
6108 show_ip4_arp_events_fn (vlib_main_t * vm,
6109 unformat_input_t * input,
6110 vlib_cli_command_t * cmd)
6112 vpe_api_main_t * am = &vpe_api_main;
6113 vl_api_ip4_arp_event_t * event;
6115 if (pool_elts (am->arp_events) == 0) {
6116 vlib_cli_output (vm, "No active arp event registrations");
6120 pool_foreach (event, am->arp_events,
6122 vlib_cli_output (vm, "%U", format_arp_event, event);
6128 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
6129 .path = "show arp event registrations",
6130 .function = show_ip4_arp_events_fn,
6131 .short_help = "Show arp event registrations",