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>
77 #include <vnet/policer/policer.h>
80 #undef __included_bihash_template_h__
81 #include <vnet/l2/l2_fib.h>
84 #include <vnet/ipsec/ipsec.h>
85 #include <vnet/ipsec/ikev2.h>
88 #include <vnet/devices/virtio/vhost-user.h>
91 #include <stats/stats.h>
94 #include <vnet/ethernet/ethernet.h>
95 #include <vnet/ethernet/arp_packet.h>
96 #include <vnet/interface.h>
98 #include <vnet/l2/l2_fib.h>
99 #include <vnet/l2/l2_bd.h>
100 #include <api/vpe_msg_enum.h>
102 #define f64_endian(a)
103 #define f64_print(a,b)
105 #define vl_typedefs /* define message structures */
106 #include <api/vpe_all_api_h.h>
109 #define vl_endianfun /* define message structures */
110 #include <api/vpe_all_api_h.h>
113 /* instantiate all the print functions we know about */
114 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
116 #include <api/vpe_all_api_h.h>
119 #define REPLY_MACRO(t) \
121 unix_shared_memory_queue_t * q; \
122 rv = vl_msg_api_pd_handler (mp, rv); \
123 q = vl_api_client_index_to_input_queue (mp->client_index); \
127 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
128 rmp->_vl_msg_id = ntohs((t)); \
129 rmp->context = mp->context; \
130 rmp->retval = ntohl(rv); \
132 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
135 #define REPLY_MACRO2(t, body) \
137 unix_shared_memory_queue_t * q; \
138 rv = vl_msg_api_pd_handler (mp, rv); \
139 q = vl_api_client_index_to_input_queue (mp->client_index); \
143 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
144 rmp->_vl_msg_id = ntohs((t)); \
145 rmp->context = mp->context; \
146 rmp->retval = ntohl(rv); \
147 do {body;} while (0); \
148 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
151 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
153 #define VALIDATE_SW_IF_INDEX(mp) \
154 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
155 vnet_main_t *__vnm = vnet_get_main(); \
156 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
158 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
159 goto bad_sw_if_index; \
163 #define BAD_SW_IF_INDEX_LABEL \
169 #define VALIDATE_RX_SW_IF_INDEX(mp) \
170 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
171 vnet_main_t *__vnm = vnet_get_main(); \
172 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
173 __rx_sw_if_index)) { \
174 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
175 goto bad_rx_sw_if_index; \
179 #define BAD_RX_SW_IF_INDEX_LABEL \
181 bad_rx_sw_if_index: \
185 #define VALIDATE_TX_SW_IF_INDEX(mp) \
186 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
187 vnet_main_t *__vnm = vnet_get_main(); \
188 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
189 __tx_sw_if_index)) { \
190 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
191 goto bad_tx_sw_if_index; \
195 #define BAD_TX_SW_IF_INDEX_LABEL \
197 bad_tx_sw_if_index: \
203 #define VALIDATE_SW_IF_INDEX(mp)
204 #define BAD_SW_IF_INDEX_LABEL
205 #define VALIDATE_RX_SW_IF_INDEX(mp)
206 #define BAD_RX_SW_IF_INDEX_LABEL
207 #define VALIDATE_TX_SW_IF_INDEX(mp)
208 #define BAD_TX_SW_IF_INDEX_LABEL
210 #endif /* CLIB_DEBUG > 0 */
212 #define foreach_vpe_api_msg \
213 _(WANT_INTERFACE_EVENTS, want_interface_events) \
214 _(WANT_OAM_EVENTS, want_oam_events) \
215 _(OAM_ADD_DEL, oam_add_del) \
216 _(SW_INTERFACE_DUMP, sw_interface_dump) \
217 _(SW_INTERFACE_DETAILS, sw_interface_details) \
218 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
219 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
220 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
221 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
222 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
223 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
224 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
225 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
226 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
227 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
228 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
229 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
230 _(L2FIB_ADD_DEL, l2fib_add_del) \
231 _(L2_FLAGS, l2_flags) \
232 _(BRIDGE_FLAGS, bridge_flags) \
233 _(TAP_CONNECT, tap_connect) \
234 _(TAP_MODIFY, tap_modify) \
235 _(TAP_DELETE, tap_delete) \
236 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
237 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
238 _(CREATE_SUBIF, create_subif) \
239 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
240 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
241 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
242 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
243 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
244 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
245 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
246 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
247 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
248 _(RESET_FIB, reset_fib) \
249 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
250 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
251 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
252 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
253 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
254 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
255 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
256 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
257 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
258 sw_interface_ip6_set_link_local_address) \
259 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
260 _(CREATE_LOOPBACK, create_loopback) \
261 _(CONTROL_PING, control_ping) \
262 _(CLI_REQUEST, cli_request) \
263 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
264 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
265 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
266 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
267 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
268 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
269 _(GET_NODE_INDEX, get_node_index) \
270 _(ADD_NODE_NEXT, add_node_next) \
271 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
272 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
273 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
274 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
275 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
276 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
277 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
278 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
279 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
280 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
281 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
282 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
283 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
284 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
285 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
286 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
287 _(IP_ADDRESS_DUMP, ip_address_dump) \
288 _(IP_DUMP, ip_dump) \
289 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
290 _(SHOW_VERSION, show_version) \
291 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
292 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
293 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
294 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
295 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
296 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
297 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
298 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
299 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
300 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
301 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
302 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
303 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
304 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
305 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
306 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
307 _(DELETE_LOOPBACK, delete_loopback) \
308 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
309 _(MAP_ADD_DOMAIN, map_add_domain) \
310 _(MAP_DEL_DOMAIN, map_del_domain) \
311 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
312 _(MAP_DOMAIN_DUMP, map_domain_dump) \
313 _(MAP_RULE_DUMP, map_rule_dump) \
314 _(MAP_SUMMARY_STATS, map_summary_stats) \
315 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
316 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
317 _(GET_NODE_GRAPH, get_node_graph) \
318 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
319 _(TRACE_PROFILE_ADD, trace_profile_add) \
320 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
321 _(TRACE_PROFILE_DEL, trace_profile_del) \
322 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
323 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
324 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
325 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
326 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
327 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
328 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
329 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
330 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
331 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
332 _(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump) \
333 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
334 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
335 _(LISP_ENABLE_DISABLE_STATUS_DUMP, \
336 lisp_enable_disable_status_dump) \
337 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
338 _(AF_PACKET_CREATE, af_packet_create) \
339 _(AF_PACKET_DELETE, af_packet_delete) \
340 _(POLICER_ADD_DEL, policer_add_del)
343 #define QUOTE(x) QUOTE_(x)
345 #define foreach_registration_hash \
346 _(interface_events) \
347 _(to_netconf_server) \
348 _(from_netconf_server) \
349 _(to_netconf_client) \
350 _(from_netconf_client) \
354 RESOLVE_IP4_ADD_DEL_ROUTE=1,
355 RESOLVE_IP6_ADD_DEL_ROUTE,
356 RESOLVE_MPLS_ETHERNET_ADD_DEL,
362 vl_api_ip_add_del_route_t r;
363 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
369 #define _(a) uword *a##_registration_hash; \
370 vpe_client_registration_t * a##_registrations;
371 foreach_registration_hash
374 /* notifications happen really early in the game */
375 u8 link_state_process_up;
377 /* ip4 pending route adds */
378 pending_route_t * pending_routes;
380 /* ip4 arp event registration pool */
381 vl_api_ip4_arp_event_t * arp_events;
384 vlib_main_t * vlib_main;
385 vnet_main_t * vnet_main;
388 static vlib_node_registration_t vpe_resolver_process_node;
389 static vpe_api_main_t vpe_api_main;
391 static void send_sw_interface_flags (vpe_api_main_t * am,
392 unix_shared_memory_queue_t *q,
393 vnet_sw_interface_t * swif);
394 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
395 unix_shared_memory_queue_t *q,
398 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
401 /* Clean up all registrations belonging to the indicated client */
402 int vl_api_memclnt_delete_callback (u32 client_index)
404 vpe_api_main_t * vam = &vpe_api_main;
405 vpe_client_registration_t *rp;
407 int stats_memclnt_delete_callback (u32 client_index);
409 stats_memclnt_delete_callback (client_index);
412 p = hash_get (vam->a##_registration_hash, client_index); \
414 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
415 pool_put (vam->a##_registrations, rp); \
416 hash_unset (vam->a##_registration_hash, client_index); \
418 foreach_registration_hash;
423 #define API_LINK_STATE_EVENT 1
424 #define API_ADMIN_UP_DOWN_EVENT 2
427 event_data_cmp (void * a1, void * a2)
432 return (word) e1[0] - (word) e2[0];
436 link_state_process (vlib_main_t * vm,
437 vlib_node_runtime_t * rt,
440 vpe_api_main_t * vam = &vpe_api_main;
441 vnet_main_t * vnm = vam->vnet_main;
442 vnet_sw_interface_t * swif;
443 uword * event_data = 0;
444 vpe_client_registration_t *reg;
446 u32 prev_sw_if_index;
447 unix_shared_memory_queue_t * q;
449 vam->link_state_process_up = 1;
452 vlib_process_wait_for_event (vm);
454 /* Unified list of changed link or admin state sw_if_indices */
455 vlib_process_get_events_with_type
456 (vm, &event_data, API_LINK_STATE_EVENT);
457 vlib_process_get_events_with_type
458 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
460 /* Sort, so we can eliminate duplicates */
461 vec_sort_with_function (event_data, event_data_cmp);
463 prev_sw_if_index = ~0;
465 for (i = 0; i < vec_len(event_data); i++) {
466 /* Only one message per swif */
467 if (prev_sw_if_index == event_data[i])
469 prev_sw_if_index = event_data[i];
471 pool_foreach(reg, vam->interface_events_registrations,
473 q = vl_api_client_index_to_input_queue (reg->client_index);
475 // sw_interface may be deleted already
476 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
479 swif = vnet_get_sw_interface (vnm, event_data[i]);
480 send_sw_interface_flags (vam, q, swif);
485 vec_reset_length (event_data);
491 static clib_error_t *
492 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
493 static clib_error_t *
494 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
496 VLIB_REGISTER_NODE (link_state_process_node,static) = {
497 .function = link_state_process,
498 .type = VLIB_NODE_TYPE_PROCESS,
499 .name = "vpe-link-state-process",
502 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
503 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
505 static clib_error_t *
506 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
508 vpe_api_main_t * vam = &vpe_api_main;
509 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
511 if (vam->link_state_process_up)
512 vlib_process_signal_event (vam->vlib_main,
513 link_state_process_node.index,
514 API_LINK_STATE_EVENT,
519 static clib_error_t *
520 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
522 vpe_api_main_t * vam = &vpe_api_main;
525 * Note: it's perfectly fair to set a subif admin up / admin down.
526 * Note the subtle distinction between this routine and the previous
529 if (vam->link_state_process_up)
530 vlib_process_signal_event (vam->vlib_main,
531 link_state_process_node.index,
532 API_ADMIN_UP_DOWN_EVENT,
537 #define pub_sub_handler(lca,UCA) \
538 static void vl_api_want_##lca##_t_handler ( \
539 vl_api_want_##lca##_t *mp) \
541 vpe_api_main_t *vam = &vpe_api_main; \
542 vpe_client_registration_t *rp; \
543 vl_api_want_##lca##_reply_t *rmp; \
547 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
549 if (mp->enable_disable) { \
550 clib_warning ("pid %d: already enabled...", mp->pid); \
551 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
554 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
555 pool_put (vam->lca##_registrations, rp); \
556 hash_unset (vam->lca##_registration_hash, \
561 if (mp->enable_disable == 0) { \
562 clib_warning ("pid %d: already disabled...", mp->pid); \
563 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
566 pool_get (vam->lca##_registrations, rp); \
567 rp->client_index = mp->client_index; \
568 rp->client_pid = mp->pid; \
569 hash_set (vam->lca##_registration_hash, rp->client_index, \
570 rp - vam->lca##_registrations); \
573 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
576 pub_sub_handler (interface_events,INTERFACE_EVENTS)
577 pub_sub_handler (oam_events,OAM_EVENTS)
579 #define RESOLUTION_EVENT 1
580 #define RESOLUTION_PENDING_EVENT 2
581 #define IP4_ARP_EVENT 3
583 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
584 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
585 static int mpls_ethernet_add_del_tunnel_2_t_handler
586 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
588 void handle_ip4_arp_event (u32 pool_index)
590 vpe_api_main_t * vam = &vpe_api_main;
591 vnet_main_t * vnm = vam->vnet_main;
592 vlib_main_t * vm = vam->vlib_main;
593 vl_api_ip4_arp_event_t * event;
594 vl_api_ip4_arp_event_t * mp;
595 unix_shared_memory_queue_t * q;
597 /* Client can cancel, die, etc. */
598 if (pool_is_free_index (vam->arp_events, pool_index))
601 event = pool_elt_at_index (vam->arp_events, pool_index);
603 q = vl_api_client_index_to_input_queue (event->client_index);
605 (void) vnet_add_del_ip4_arp_change_event
606 (vnm, arp_change_delete_callback,
607 event->pid, &event->address,
608 vpe_resolver_process_node.index, IP4_ARP_EVENT,
609 ~0 /* pool index, notused */, 0 /* is_add */);
613 if (q->cursize < q->maxsize) {
614 mp = vl_msg_api_alloc (sizeof (*mp));
615 clib_memcpy (mp, event, sizeof (*mp));
616 vl_msg_api_send_shmem (q, (u8 *)&mp);
618 static f64 last_time;
620 * Throttle syslog msgs.
621 * It's pretty tempting to just revoke the registration...
623 if (vlib_time_now (vm) > last_time + 10.0) {
624 clib_warning ("arp event for %U to pid %d: queue stuffed!",
625 format_ip4_address, &event->address, event->pid);
626 last_time = vlib_time_now(vm);
632 resolver_process (vlib_main_t * vm,
633 vlib_node_runtime_t * rt,
637 uword *event_data = 0;
639 vpe_api_main_t * vam = &vpe_api_main;
640 pending_route_t * pr;
641 vl_api_ip_add_del_route_t * adr;
642 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
643 u32 * resolution_failures = 0;
648 vlib_process_wait_for_event_or_clock (vm, timeout);
650 event_type = vlib_process_get_events (vm, &event_data);
652 switch (event_type) {
653 case RESOLUTION_PENDING_EVENT:
657 case RESOLUTION_EVENT:
658 for (i = 0; i < vec_len(event_data); i++) {
660 * Resolution events can occur long after the
661 * original request has timed out. $$$ add a cancel
664 if (pool_is_free_index (vam->pending_routes, event_data[i]))
667 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
671 switch (pr->resolve_type) {
672 case RESOLVE_IP4_ADD_DEL_ROUTE:
673 rv = ip4_add_del_route_t_handler (adr);
674 clib_warning ("resolver: add %U/%d via %U %s",
676 (ip4_address_t *)&(adr->dst_address),
677 adr->dst_address_length,
679 (ip4_address_t *)&(adr->next_hop_address),
680 (rv >= 0) ? "succeeded" : "failed");
683 case RESOLVE_IP6_ADD_DEL_ROUTE:
684 rv = ip6_add_del_route_t_handler (adr);
685 clib_warning ("resolver: add %U/%d via %U %s",
687 (ip6_address_t *)&(adr->dst_address),
688 adr->dst_address_length,
690 (ip6_address_t *)&(adr->next_hop_address),
691 (rv >= 0) ? "succeeded" : "failed");
694 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
695 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
696 clib_warning ("resolver: add mpls-o-e via %U %s",
698 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
699 (rv >= 0) ? "succeeded" : "failed");
703 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
705 pool_put (vam->pending_routes, pr);
710 for (i = 0; i < vec_len(event_data); i++)
711 handle_ip4_arp_event (event_data[i]);
714 case ~0: /* timeout, retry pending resolutions */
715 pool_foreach (pr, vam->pending_routes,
721 /* May fail, e.g. due to interface down */
722 switch (pr->resolve_type) {
723 case RESOLVE_IP4_ADD_DEL_ROUTE:
724 e = ip4_probe_neighbor
725 (vm, (ip4_address_t *)&(adr->next_hop_address),
726 ntohl(adr->next_hop_sw_if_index));
729 case RESOLVE_IP6_ADD_DEL_ROUTE:
730 e = ip6_probe_neighbor
731 (vm, (ip6_address_t *)&(adr->next_hop_address),
732 ntohl(adr->next_hop_sw_if_index));
735 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
737 e = ip4_probe_neighbor
739 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
740 pme->resolve_opaque);
744 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
748 clib_error_report (e);
750 adr->resolve_attempts = 1;
752 pme->resolve_attempts = 1;
756 adr->resolve_attempts -= 1;
757 if (adr->resolve_attempts == 0)
758 vec_add1 (resolution_failures,
759 pr - vam->pending_routes);
761 pme->resolve_attempts -= 1;
762 if (pme->resolve_attempts == 0)
763 vec_add1 (resolution_failures,
764 pr - vam->pending_routes);
768 for (i = 0; i < vec_len (resolution_failures); i++) {
769 pr = pool_elt_at_index (vam->pending_routes,
770 resolution_failures[i]);
774 switch (pr->resolve_type) {
775 case RESOLVE_IP4_ADD_DEL_ROUTE:
776 clib_warning ("resolver: add %U/%d via %U retry failure",
778 (ip4_address_t *)&(adr->dst_address),
779 adr->dst_address_length,
781 (ip4_address_t *)&(adr->next_hop_address));
784 case RESOLVE_IP6_ADD_DEL_ROUTE:
785 clib_warning ("resolver: add %U/%d via %U retry failure",
787 (ip6_address_t *)&(adr->dst_address),
788 adr->dst_address_length,
790 (ip6_address_t *)&(adr->next_hop_address));
793 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
794 clib_warning ("resolver: add mpls-o-e via %U retry failure",
796 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
800 clib_warning ("BUG");
802 pool_put(vam->pending_routes, pr);
804 vec_reset_length (resolution_failures);
807 if (pool_elts (vam->pending_routes) == 0)
809 vec_reset_length (event_data);
811 return 0; /* or not */
814 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
815 .function = resolver_process,
816 .type = VLIB_NODE_TYPE_PROCESS,
817 .name = "vpe-route-resolver-process",
820 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
822 ip4_main_t * im = &ip4_main;
823 ip_lookup_main_t * lm = &im->lookup_main;
824 vnet_classify_main_t * cm = &vnet_classify_main;
825 stats_main_t * sm = &stats_main;
826 ip4_add_del_route_args_t a;
827 ip4_address_t next_hop_address;
829 vpe_api_main_t * vam = &vpe_api_main;
830 vnet_main_t * vnm = vam->vnet_main;
831 vlib_main_t * vm = vlib_get_main();
832 pending_route_t * pr;
833 vl_api_ip_add_del_route_t * adr;
837 ip_adjacency_t *nh_adj, *add_adj = 0;
839 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
841 if (mp->create_vrf_if_needed) {
843 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
845 fib_index = f->index;
847 /* No such VRF, and we weren't asked to create one */
848 return VNET_API_ERROR_NO_SUCH_FIB;
854 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
855 ntohl(mp->next_hop_sw_if_index)))
856 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
858 clib_memcpy (next_hop_address.data, mp->next_hop_address,
859 sizeof (next_hop_address.data));
861 /* Arp for the next_hop if necessary */
862 if (mp->is_add && mp->resolve_if_needed) {
864 ip_adjacency_t * adj;
866 lookup_result = ip4_fib_lookup_with_table
867 (im, fib_index, &next_hop_address, 1 /* disable default route */);
869 adj = ip_get_adjacency (lm, lookup_result);
871 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
872 pool_get (vam->pending_routes, pr);
873 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
875 clib_memcpy (adr, mp, sizeof (*adr));
876 /* recursion block, "just in case" */
877 adr->resolve_if_needed = 0;
878 adr->resolve_attempts = ntohl(mp->resolve_attempts);
879 vnet_register_ip4_arp_resolution_event
880 (vnm, &next_hop_address, vpe_resolver_process_node.index,
881 RESOLUTION_EVENT, pr - vam->pending_routes);
883 vlib_process_signal_event
884 (vm, vpe_resolver_process_node.index,
885 RESOLUTION_PENDING_EVENT, 0 /* data */);
887 /* The interface may be down, etc. */
888 e = ip4_probe_neighbor
889 (vm, (ip4_address_t *)&(mp->next_hop_address),
890 ntohl(mp->next_hop_sw_if_index));
893 clib_error_report(e);
895 return VNET_API_ERROR_IN_PROGRESS;
899 if (mp->is_multipath) {
902 dslock (sm, 1 /* release hint */, 10 /* tag */);
905 flags = IP4_ROUTE_FLAG_ADD;
907 flags = IP4_ROUTE_FLAG_DEL;
910 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
912 ip4_add_del_route_next_hop (im, flags,
913 (ip4_address_t *) mp->dst_address,
914 (u32) mp->dst_address_length,
915 (ip4_address_t *) mp->next_hop_address,
916 ntohl(mp->next_hop_sw_if_index),
917 (u32) mp->next_hop_weight,
924 memset (&a, 0, sizeof (a));
925 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
927 a.dst_address_length = mp->dst_address_length;
929 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
930 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
931 a.table_index_or_table_id = fib_index;
936 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
938 dslock (sm, 1 /* release hint */, 2 /* tag */);
942 ai = lm->drop_adj_index;
943 else if (mp->is_local)
944 ai = lm->local_adj_index;
945 else if (mp->is_classify) {
947 memset(&cadj, 0, sizeof(cadj));
948 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
949 cadj.classify.table_index = ntohl(mp->classify_table_index);
950 if (pool_is_free_index (cm->tables, cadj.classify.table_index)) {
952 return VNET_API_ERROR_NO_SUCH_TABLE;
954 vec_add1 (add_adj, cadj);
958 ai = ip4_fib_lookup_with_table
959 (im, fib_index, &next_hop_address,
960 1 /* disable default route */);
961 if (ai == lm->miss_adj_index) {
963 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
967 nh_adj = ip_get_adjacency (lm, ai);
968 vec_add1 (add_adj, nh_adj[0]);
969 if (mp->lookup_in_vrf) {
970 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
972 add_adj[0].explicit_fib_index = p[0];
976 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
980 ip_adjacency_t * adj;
981 int disable_default_route = 1;
983 /* Trying to delete the default route? */
984 if (a.dst_address.as_u32 == 0 &&
985 a.dst_address_length == 0)
986 disable_default_route = 0;
988 ai = ip4_fib_lookup_with_table
989 (im, fib_index, &a.dst_address, disable_default_route);
990 if (ai == lm->miss_adj_index) {
992 return VNET_API_ERROR_UNKNOWN_DESTINATION;
995 adj = ip_get_adjacency (lm, ai);
996 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
998 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1004 a.add_adj = add_adj;
1005 a.n_add_adj = vec_len(add_adj);
1006 ip4_add_del_route (im, &a);
1014 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1016 ip6_main_t * im = &ip6_main;
1017 ip_lookup_main_t * lm = &im->lookup_main;
1018 vnet_main_t * vnm = vnet_get_main();
1019 vlib_main_t * vm = vlib_get_main();
1020 vpe_api_main_t * vam = &vpe_api_main;
1021 stats_main_t * sm = &stats_main;
1022 ip6_add_del_route_args_t a;
1023 ip6_address_t next_hop_address;
1024 pending_route_t * pr;
1025 vl_api_ip_add_del_route_t * adr;
1030 ip_adjacency_t * nh_adj, * add_adj = 0;
1033 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1036 if (mp->create_vrf_if_needed) {
1038 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1040 fib_index = f->index;
1042 /* No such VRF, and we weren't asked to create one */
1043 return VNET_API_ERROR_NO_SUCH_FIB;
1049 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1050 ntohl(mp->next_hop_sw_if_index)))
1051 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1053 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1054 sizeof (next_hop_address.as_u8));
1056 /* Arp for the next_hop if necessary */
1057 if (mp->is_add && mp->resolve_if_needed) {
1059 ip_adjacency_t * adj;
1061 lookup_result = ip6_fib_lookup_with_table
1062 (im, fib_index, &next_hop_address);
1064 adj = ip_get_adjacency (lm, lookup_result);
1066 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1067 pool_get (vam->pending_routes, pr);
1069 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1070 clib_memcpy (adr, mp, sizeof (*adr));
1071 /* recursion block, "just in case" */
1072 adr->resolve_if_needed = 0;
1073 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1074 vnet_register_ip6_neighbor_resolution_event
1075 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1076 RESOLUTION_EVENT, pr - vam->pending_routes);
1078 vlib_process_signal_event
1079 (vm, vpe_resolver_process_node.index,
1080 RESOLUTION_PENDING_EVENT, 0 /* data */);
1082 /* The interface may be down, etc. */
1083 e = ip6_probe_neighbor
1084 (vm, (ip6_address_t *)&(mp->next_hop_address),
1085 ntohl(mp->next_hop_sw_if_index));
1088 clib_error_report(e);
1090 return VNET_API_ERROR_IN_PROGRESS;
1094 if (mp->is_multipath) {
1097 dslock (sm, 1 /* release hint */, 11 /* tag */);
1100 flags = IP6_ROUTE_FLAG_ADD;
1102 flags = IP6_ROUTE_FLAG_DEL;
1105 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1107 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1108 (u32) mp->dst_address_length,
1109 (ip6_address_t *)mp->next_hop_address,
1110 ntohl(mp->next_hop_sw_if_index),
1111 (u32) mp->next_hop_weight,
1118 memset (&a, 0, sizeof (a));
1119 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1121 a.dst_address_length = mp->dst_address_length;
1123 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1124 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1125 a.table_index_or_table_id = fib_index;
1130 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1132 dslock (sm, 1 /* release hint */, 3 /* tag */);
1136 ai = lm->drop_adj_index;
1137 else if (mp->is_local)
1138 ai = lm->local_adj_index;
1140 ai = ip6_fib_lookup_with_table
1141 (im, fib_index, &next_hop_address);
1142 if (ai == lm->miss_adj_index) {
1144 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1148 nh_adj = ip_get_adjacency (lm, ai);
1149 vec_add1 (add_adj, nh_adj[0]);
1150 if (mp->lookup_in_vrf) {
1151 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1153 add_adj[0].explicit_fib_index = p[0];
1157 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1161 ip_adjacency_t * adj;
1163 ai = ip6_fib_lookup_with_table
1164 (im, fib_index, &a.dst_address);
1165 if (ai == lm->miss_adj_index) {
1167 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1169 adj = ip_get_adjacency (lm, ai);
1170 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1172 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1177 a.add_adj = add_adj;
1178 a.n_add_adj = vec_len(add_adj);
1179 ip6_add_del_route (im, &a);
1187 void vl_api_ip_add_del_route_t_handler (
1188 vl_api_ip_add_del_route_t *mp)
1190 vl_api_ip_add_del_route_reply_t * rmp;
1192 vnet_main_t * vnm = vnet_get_main();
1197 rv = ip6_add_del_route_t_handler (mp);
1199 rv = ip4_add_del_route_t_handler (mp);
1201 rv = (rv == 0) ? vnm->api_errno : rv;
1203 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1206 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1207 u32 sw_if_index, u8 *next_hop_addr)
1209 vl_api_ip_add_del_route_t mp;
1212 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1215 * Configure default IP route:
1216 * - ip route add 0.0.0.0/1 via <GW IP>
1217 * - ip route add 128.0.0.0/1 via <GW IP>
1219 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1221 mp.resolve_attempts = ~0;
1222 mp.resolve_if_needed = 1;
1224 mp.is_ipv6 = is_ipv6;
1225 mp.next_hop_weight = 1;
1227 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1230 rv = ip6_add_del_route_t_handler (&mp);
1233 mp.dst_address_length = 1;
1235 mp.dst_address[0] = 0;
1236 rv = ip4_add_del_route_t_handler (&mp);
1238 mp.dst_address[0] = 128;
1239 rv |= ip4_add_del_route_t_handler (&mp);
1243 clib_error_return (0, "failed to config default IP route");
1248 vl_api_sw_interface_add_del_address_t_handler
1249 (vl_api_sw_interface_add_del_address_t *mp)
1251 vlib_main_t *vm = vlib_get_main();
1252 vl_api_sw_interface_add_del_address_reply_t * rmp;
1256 VALIDATE_SW_IF_INDEX(mp);
1258 is_del = mp->is_add == 0;
1261 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1262 else if (mp->is_ipv6)
1263 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1264 (void *)mp->address,
1265 mp->address_length, is_del);
1267 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1268 (void *) mp->address,
1269 mp->address_length, is_del);
1271 BAD_SW_IF_INDEX_LABEL;
1273 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1277 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1280 u32 table_id = ntohl(mp->vrf_id);
1281 u32 sw_if_index = ntohl(mp->sw_if_index);
1282 vl_api_sw_interface_set_table_reply_t * rmp;
1283 stats_main_t * sm = &stats_main;
1285 VALIDATE_SW_IF_INDEX(mp);
1287 dslock (sm, 1 /* release hint */, 4 /* tag */);
1290 ip6_main_t * im = &ip6_main;
1292 find_ip6_fib_by_table_index_or_id (im, table_id,
1293 IP6_ROUTE_FLAG_TABLE_ID);
1295 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1296 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1298 rv = VNET_API_ERROR_NO_SUCH_FIB;
1301 ip4_main_t * im = &ip4_main;
1302 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1303 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1305 /* Truthfully this can't fail */
1307 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1308 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1310 rv = VNET_API_ERROR_NO_SUCH_FIB;
1315 BAD_SW_IF_INDEX_LABEL;
1317 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1321 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1323 vlib_main_t *vm = vlib_get_main();
1324 vl_api_sw_interface_set_vpath_reply_t * rmp;
1327 u32 sw_if_index = ntohl(mp->sw_if_index);
1328 ip4_main_t *ip4m = &ip4_main;
1329 ip6_main_t *ip6m = &ip6_main;
1330 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1331 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1332 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1333 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1334 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1335 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1337 VALIDATE_SW_IF_INDEX(mp);
1339 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1341 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1342 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1343 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1344 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1345 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1346 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1347 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1348 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1349 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1350 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1351 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1352 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1353 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1354 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1355 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1356 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1358 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1359 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1360 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1361 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1362 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1363 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1364 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1365 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1366 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1367 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1368 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1369 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1370 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1371 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1372 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1373 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1376 BAD_SW_IF_INDEX_LABEL;
1378 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1382 vl_api_sw_interface_set_l2_xconnect_t_handler (
1383 vl_api_sw_interface_set_l2_xconnect_t *mp)
1385 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1387 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1388 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1389 vlib_main_t *vm = vlib_get_main();
1390 vnet_main_t *vnm = vnet_get_main();
1392 VALIDATE_RX_SW_IF_INDEX(mp);
1395 VALIDATE_TX_SW_IF_INDEX(mp);
1396 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1397 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1399 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1402 BAD_RX_SW_IF_INDEX_LABEL;
1403 BAD_TX_SW_IF_INDEX_LABEL;
1405 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1409 vl_api_sw_interface_set_l2_bridge_t_handler (
1410 vl_api_sw_interface_set_l2_bridge_t *mp)
1412 bd_main_t * bdm = &bd_main;
1413 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1415 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1416 u32 bd_id = ntohl(mp->bd_id);
1420 vlib_main_t *vm = vlib_get_main();
1421 vnet_main_t *vnm = vnet_get_main();
1423 VALIDATE_RX_SW_IF_INDEX(mp);
1425 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1428 //VALIDATE_TX_SW_IF_INDEX(mp);
1429 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1430 rx_sw_if_index, bd_index, bvi, shg, 0);
1432 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1435 BAD_RX_SW_IF_INDEX_LABEL;
1437 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1441 vl_api_bridge_domain_add_del_t_handler (
1442 vl_api_bridge_domain_add_del_t *mp)
1444 vlib_main_t * vm = vlib_get_main ();
1445 bd_main_t * bdm = &bd_main;
1446 vl_api_bridge_domain_add_del_reply_t * rmp;
1448 u32 enable_flags = 0, disable_flags = 0;
1449 u32 bd_id = ntohl(mp->bd_id);
1453 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1456 enable_flags |= L2_FLOOD;
1458 disable_flags |= L2_FLOOD;
1461 enable_flags |= L2_UU_FLOOD;
1463 disable_flags |= L2_UU_FLOOD;
1466 enable_flags |= L2_FWD;
1468 disable_flags |= L2_FWD;
1471 enable_flags |= L2_ARP_TERM;
1473 disable_flags |= L2_ARP_TERM;
1476 enable_flags |= L2_LEARN;
1478 disable_flags |= L2_LEARN;
1481 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1484 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1487 rv = bd_delete_bd_index(bdm, bd_id);
1489 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1492 static void vl_api_bridge_domain_details_t_handler (
1493 vl_api_bridge_domain_details_t * mp)
1495 clib_warning ("BUG");
1498 static void vl_api_bridge_domain_sw_if_details_t_handler (
1499 vl_api_bridge_domain_sw_if_details_t * mp)
1501 clib_warning ("BUG");
1504 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1505 l2_bridge_domain_t * bd_config,
1509 vl_api_bridge_domain_details_t * mp;
1511 mp = vl_msg_api_alloc (sizeof (*mp));
1512 memset (mp, 0, sizeof (*mp));
1513 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1514 mp->bd_id = ntohl (bd_config->bd_id);
1515 mp->flood = bd_feature_flood (bd_config);
1516 mp->uu_flood = bd_feature_uu_flood (bd_config);
1517 mp->forward = bd_feature_forward (bd_config);
1518 mp->learn = bd_feature_learn (bd_config);
1519 mp->arp_term = bd_feature_arp_term (bd_config);
1520 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1521 mp->n_sw_ifs = ntohl (n_sw_ifs);
1522 mp->context = context;
1524 vl_msg_api_send_shmem (q, (u8 *)&mp);
1527 static void send_bd_sw_if_details (l2input_main_t * l2im,
1528 unix_shared_memory_queue_t *q,
1529 l2_flood_member_t * member, u32 bd_id,
1532 vl_api_bridge_domain_sw_if_details_t * mp;
1533 l2_input_config_t * input_cfg;
1535 mp = vl_msg_api_alloc (sizeof (*mp));
1536 memset (mp, 0, sizeof (*mp));
1537 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1538 mp->bd_id = ntohl (bd_id);
1539 mp->sw_if_index = ntohl (member->sw_if_index);
1540 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1541 mp->shg = input_cfg->shg;
1542 mp->context = context;
1544 vl_msg_api_send_shmem (q, (u8 *)&mp);
1547 static void vl_api_bridge_domain_dump_t_handler (
1548 vl_api_bridge_domain_dump_t *mp)
1550 bd_main_t * bdm = &bd_main;
1551 l2input_main_t * l2im = &l2input_main;
1552 unix_shared_memory_queue_t * q;
1553 l2_bridge_domain_t * bd_config;
1554 u32 bd_id, bd_index;
1557 q = vl_api_client_index_to_input_queue (mp->client_index);
1562 bd_id = ntohl(mp->bd_id);
1564 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1565 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1566 for (; bd_index < end; bd_index++) {
1567 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1568 /* skip dummy bd_id 0 */
1569 if (bd_config && (bd_config->bd_id > 0)) {
1571 l2_flood_member_t * m;
1573 n_sw_ifs = vec_len (bd_config->members);
1574 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1576 vec_foreach (m, bd_config->members) {
1577 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1584 vl_api_l2fib_add_del_t_handler (
1585 vl_api_l2fib_add_del_t *mp)
1587 bd_main_t * bdm = &bd_main;
1588 l2input_main_t * l2im = &l2input_main;
1589 vl_api_l2fib_add_del_reply_t * rmp;
1592 u32 sw_if_index = ntohl(mp->sw_if_index);
1593 u32 bd_id = ntohl(mp->bd_id);
1601 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1603 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1604 goto bad_sw_if_index;
1609 VALIDATE_SW_IF_INDEX(mp);
1610 if (vec_len(l2im->configs) <= sw_if_index) {
1611 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1612 goto bad_sw_if_index;
1614 l2_input_config_t * config;
1615 config = vec_elt_at_index(l2im->configs, sw_if_index);
1616 if (config->bridge == 0) {
1617 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1618 goto bad_sw_if_index;
1621 static_mac = mp->static_mac ? 1 : 0;
1622 filter_mac = mp->filter_mac ? 1 : 0;
1623 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1626 l2fib_del_entry(mac, bd_index);
1629 BAD_SW_IF_INDEX_LABEL;
1631 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1635 vl_api_l2_flags_t_handler (
1636 vl_api_l2_flags_t *mp)
1638 vl_api_l2_flags_reply_t * rmp;
1640 u32 sw_if_index = ntohl(mp->sw_if_index);
1641 u32 flags = ntohl(mp->feature_bitmap);
1644 VALIDATE_SW_IF_INDEX(mp);
1647 if (flags & L2INPUT_FEAT_ ## a) \
1648 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1649 foreach_l2input_feat;
1652 BAD_SW_IF_INDEX_LABEL;
1654 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1658 vl_api_bridge_flags_t_handler (
1659 vl_api_bridge_flags_t *mp)
1661 vlib_main_t *vm = vlib_get_main();
1662 bd_main_t * bdm = &bd_main;
1663 vl_api_bridge_flags_reply_t * rmp;
1665 u32 bd_id = ntohl(mp->bd_id);
1667 u32 flags = ntohl(mp->feature_bitmap);
1670 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1672 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1678 bd_set_flags(vm, bd_index, flags, mp->is_set);
1681 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1682 rmp->resulting_feature_bitmap = ntohl(flags));
1686 vl_api_bd_ip_mac_add_del_t_handler (
1687 vl_api_bd_ip_mac_add_del_t *mp)
1689 bd_main_t * bdm = &bd_main;
1690 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1692 u32 bd_id = ntohl(mp->bd_id);
1696 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1698 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1703 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1704 mp->mac_address, mp->is_ipv6, mp->is_add))
1705 rv = VNET_API_ERROR_UNSPECIFIED;
1708 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1712 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1715 vl_api_tap_connect_reply_t * rmp;
1716 unix_shared_memory_queue_t * q;
1717 u32 sw_if_index = (u32)~0;
1719 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1720 mp->use_random_mac ? 0 : mp->mac_address,
1721 &sw_if_index, mp->renumber,
1722 ntohl(mp->custom_dev_instance));
1724 q = vl_api_client_index_to_input_queue (mp->client_index);
1728 rmp = vl_msg_api_alloc (sizeof (*rmp));
1729 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1730 rmp->context = mp->context;
1731 rmp->retval = ntohl(rv);
1732 rmp->sw_if_index = ntohl(sw_if_index);
1734 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1738 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1741 vl_api_tap_modify_reply_t * rmp;
1742 unix_shared_memory_queue_t * q;
1743 u32 sw_if_index = (u32)~0;
1745 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1746 mp->use_random_mac ? 0 : mp->mac_address,
1747 &sw_if_index, mp->renumber,
1748 ntohl(mp->custom_dev_instance));
1750 q = vl_api_client_index_to_input_queue (mp->client_index);
1754 rmp = vl_msg_api_alloc (sizeof (*rmp));
1755 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1756 rmp->context = mp->context;
1757 rmp->retval = ntohl(rv);
1758 rmp->sw_if_index = ntohl(sw_if_index);
1760 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1764 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1767 vpe_api_main_t * vam = &vpe_api_main;
1768 vl_api_tap_delete_reply_t * rmp;
1769 unix_shared_memory_queue_t * q;
1770 u32 sw_if_index = ntohl(mp->sw_if_index);
1772 rv = vnet_tap_delete (vm, sw_if_index);
1774 q = vl_api_client_index_to_input_queue (mp->client_index);
1778 rmp = vl_msg_api_alloc (sizeof (*rmp));
1779 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1780 rmp->context = mp->context;
1781 rmp->retval = ntohl(rv);
1783 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1786 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1790 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1792 vl_api_create_vlan_subif_reply_t * rmp;
1793 vnet_main_t * vnm = vnet_get_main();
1794 u32 hw_if_index, sw_if_index = (u32)~0;
1795 vnet_hw_interface_t * hi;
1798 vnet_sw_interface_t template;
1800 vnet_interface_main_t * im = &vnm->interface_main;
1801 u64 sup_and_sub_key;
1803 unix_shared_memory_queue_t * q;
1804 clib_error_t * error;
1806 VALIDATE_SW_IF_INDEX(mp);
1808 hw_if_index = ntohl(mp->sw_if_index);
1809 hi = vnet_get_hw_interface (vnm, hw_if_index);
1811 id = ntohl(mp->vlan_id);
1812 if (id == 0 || id > 4095) {
1813 rv = VNET_API_ERROR_INVALID_VLAN;
1817 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1819 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1821 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1825 kp = clib_mem_alloc (sizeof (*kp));
1826 *kp = sup_and_sub_key;
1828 memset (&template, 0, sizeof (template));
1829 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1830 template.sup_sw_if_index = hi->sw_if_index;
1831 template.sub.id = id;
1832 template.sub.eth.raw_flags = 0;
1833 template.sub.eth.flags.one_tag = 1;
1834 template.sub.eth.outer_vlan_id = id;
1835 template.sub.eth.flags.exact_match = 1;
1837 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1839 clib_error_report(error);
1840 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1843 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1844 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1846 BAD_SW_IF_INDEX_LABEL;
1849 q = vl_api_client_index_to_input_queue (mp->client_index);
1853 rmp = vl_msg_api_alloc (sizeof (*rmp));
1854 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1855 rmp->context = mp->context;
1856 rmp->retval = ntohl(rv);
1857 rmp->sw_if_index = ntohl(sw_if_index);
1858 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1862 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1864 vl_api_create_subif_reply_t * rmp;
1865 vnet_main_t * vnm = vnet_get_main();
1866 u32 sw_if_index = ~0;
1869 vnet_sw_interface_t *si;
1870 vnet_hw_interface_t *hi;
1871 vnet_sw_interface_t template;
1873 vnet_interface_main_t * im = &vnm->interface_main;
1874 u64 sup_and_sub_key;
1876 clib_error_t * error;
1878 VALIDATE_SW_IF_INDEX(mp);
1880 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1881 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1883 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1884 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1888 sw_if_index = si->sw_if_index;
1889 sub_id = ntohl(mp->sub_id);
1891 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1893 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1896 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1897 sw_if_index, sub_id);
1898 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1902 kp = clib_mem_alloc (sizeof (*kp));
1903 *kp = sup_and_sub_key;
1905 memset (&template, 0, sizeof (template));
1906 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1907 template.sup_sw_if_index = sw_if_index;
1908 template.sub.id = sub_id;
1909 template.sub.eth.flags.no_tags = mp->no_tags;
1910 template.sub.eth.flags.one_tag = mp->one_tag;
1911 template.sub.eth.flags.two_tags = mp->two_tags;
1912 template.sub.eth.flags.dot1ad = mp->dot1ad;
1913 template.sub.eth.flags.exact_match = mp->exact_match;
1914 template.sub.eth.flags.default_sub = mp->default_sub;
1915 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1916 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1917 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1918 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1920 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1922 clib_error_report (error);
1923 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1927 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1928 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1930 BAD_SW_IF_INDEX_LABEL;
1934 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1936 rmp->sw_if_index = ntohl(sw_if_index);
1941 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1943 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1945 stats_main_t * sm = &stats_main;
1946 u32 tunnel_sw_if_index = ~0;
1948 dslock (sm, 1 /* release hint */, 5 /* tag */);
1950 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1951 (ip4_address_t *)(mp->dst_address),
1952 (ip4_address_t *)(mp->intfc_address),
1953 (u32)(mp->intfc_address_length),
1954 ntohl(mp->inner_vrf_id),
1955 ntohl(mp->outer_vrf_id),
1956 &tunnel_sw_if_index,
1961 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1963 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1968 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1969 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1971 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1973 stats_main_t * sm = &stats_main;
1974 u32 tunnel_sw_if_index;
1976 dslock (sm, 1 /* release hint */, 5 /* tag */);
1978 rv = vnet_mpls_ethernet_add_del_tunnel
1979 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1980 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1981 ntohl(mp->tx_sw_if_index),
1982 &tunnel_sw_if_index,
1988 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1990 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1995 * This piece of misery brought to you because the control-plane
1996 * can't figure out the tx interface + dst-mac address all by itself
1998 static int mpls_ethernet_add_del_tunnel_2_t_handler
1999 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2001 pending_route_t * pr;
2002 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2003 vnet_main_t * vnm = vnet_get_main();
2004 vlib_main_t * vm = vlib_get_main();
2005 stats_main_t * sm = &stats_main;
2006 vpe_api_main_t * vam = &vpe_api_main;
2007 u32 inner_fib_index, outer_fib_index;
2008 ip4_main_t * im = &ip4_main;
2009 ip_lookup_main_t * lm = &im->lookup_main;
2010 ip_adjacency_t * adj = 0;
2013 u8 * dst_mac_address;
2017 u32 tunnel_sw_if_index;
2019 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2021 return VNET_API_ERROR_NO_SUCH_FIB;
2023 outer_fib_index = p[0];
2026 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2028 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2030 inner_fib_index = p[0];
2032 if (inner_fib_index == outer_fib_index)
2033 return VNET_API_ERROR_INVALID_VALUE;
2035 lookup_result = ip4_fib_lookup_with_table
2036 (im, outer_fib_index,
2037 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2038 1 /* disable default route */);
2040 adj = ip_get_adjacency (lm, lookup_result);
2041 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2043 if (mp->is_add && mp->resolve_if_needed) {
2044 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2045 pool_get (vam->pending_routes, pr);
2046 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2048 clib_memcpy (pme, mp, sizeof (*pme));
2049 /* recursion block, "just in case" */
2050 pme->resolve_if_needed = 0;
2051 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2052 pme->resolve_opaque = tx_sw_if_index;
2053 vnet_register_ip4_arp_resolution_event
2055 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2056 vpe_resolver_process_node.index,
2057 RESOLUTION_EVENT, pr - vam->pending_routes);
2059 vlib_process_signal_event
2060 (vm, vpe_resolver_process_node.index,
2061 RESOLUTION_PENDING_EVENT, 0 /* data */);
2063 /* The interface may be down, etc. */
2064 e = ip4_probe_neighbor
2065 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2069 clib_error_report(e);
2071 return VNET_API_ERROR_IN_PROGRESS;
2075 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2076 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2079 vnet_rewrite_get_data_internal
2080 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2082 dslock (sm, 1 /* release hint */, 10 /* tag */);
2084 rv = vnet_mpls_ethernet_add_del_tunnel
2085 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2086 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2087 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2095 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2096 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2098 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2101 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2103 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2108 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2110 vl_api_mpls_add_del_encap_reply_t * rmp;
2112 static u32 * labels;
2115 vec_reset_length (labels);
2117 for (i = 0; i < mp->nlabels; i++)
2118 vec_add1 (labels, ntohl(mp->labels[i]));
2121 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2122 ntohl(mp->vrf_id), labels,
2123 ~0 /* policy_tunnel_index */,
2124 0 /* no_dst_hash */,
2128 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2132 vl_api_mpls_add_del_decap_t_handler
2133 (vl_api_mpls_add_del_decap_t *mp)
2135 vl_api_mpls_add_del_decap_reply_t * rmp;
2138 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2139 ntohl(mp->label), ntohl(mp->next_index),
2140 mp->s_bit, mp->is_add);
2142 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2146 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2148 vl_api_proxy_arp_add_del_reply_t * rmp;
2151 ip4_main_t * im = &ip4_main;
2152 stats_main_t * sm = &stats_main;
2153 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2154 ip4_address_t *hi_addr,
2155 u32 fib_index, int is_del);
2158 dslock (sm, 1 /* release hint */, 6 /* tag */);
2160 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2163 rv = VNET_API_ERROR_NO_SUCH_FIB;
2169 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2170 (ip4_address_t *)mp->hi_address,
2171 fib_index, mp->is_add == 0);
2175 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2179 vl_api_proxy_arp_intfc_enable_disable_t_handler
2180 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2183 vnet_main_t * vnm = vnet_get_main();
2184 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2185 vnet_sw_interface_t * si;
2188 VALIDATE_SW_IF_INDEX(mp);
2190 sw_if_index = ntohl(mp->sw_if_index);
2192 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2194 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2198 si = vnet_get_sw_interface (vnm, sw_if_index);
2202 if (mp->enable_disable)
2203 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2205 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2207 BAD_SW_IF_INDEX_LABEL;
2210 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2214 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2216 vl_api_ip_neighbor_add_del_reply_t * rmp;
2217 vnet_main_t * vnm = vnet_get_main();
2220 stats_main_t * sm = &stats_main;
2222 VALIDATE_SW_IF_INDEX(mp);
2224 dslock (sm, 1 /* release hint */, 7 /* tag */);
2228 rv = vnet_set_ip6_ethernet_neighbor
2229 (vm, ntohl(mp->sw_if_index),
2230 (ip6_address_t *)(mp->dst_address),
2231 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2233 rv = vnet_unset_ip6_ethernet_neighbor
2234 (vm, ntohl(mp->sw_if_index),
2235 (ip6_address_t *)(mp->dst_address),
2236 mp->mac_address, sizeof(mp->mac_address));
2238 ip4_main_t * im = &ip4_main;
2239 ip_lookup_main_t * lm = &im->lookup_main;
2240 ethernet_arp_ip4_over_ethernet_address_t a;
2242 ip_adjacency_t *nh_adj;
2244 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2246 rv = VNET_API_ERROR_NO_SUCH_FIB;
2252 * Unfortunately, folks have a penchant for
2253 * adding interface addresses to the ARP cache, and
2254 * wondering why the forwarder eventually ASSERTs...
2256 ai = ip4_fib_lookup_with_table
2257 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2258 1 /* disable default route */);
2261 nh_adj = ip_get_adjacency (lm, ai);
2262 /* Never allow manipulation of a local adj! */
2263 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2264 clib_warning("%U matches local adj",
2266 (ip4_address_t *)(mp->dst_address));
2267 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2272 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2273 clib_memcpy (&a.ip4, mp->dst_address, 4);
2276 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2277 fib_index, &a, mp->is_static);
2279 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2283 BAD_SW_IF_INDEX_LABEL;
2286 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2290 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2293 vpe_main_t *rm = &vpe_main;
2294 ip4_main_t *im4 = &ip4_main;
2295 ip6_main_t *im6 = &ip6_main;
2296 ip_lookup_main_t * lm;
2301 u32 adj_index, sw_if_index;
2302 vl_api_is_address_reachable_t *rmp;
2303 ip_adjacency_t * adj;
2304 unix_shared_memory_queue_t *q;
2306 q = vl_api_client_index_to_input_queue (mp->client_index);
2308 increment_missing_api_client_counter (rm->vlib_main);
2312 rmp = vl_msg_api_alloc (sizeof (*rmp));
2313 clib_memcpy (rmp, mp, sizeof (*rmp));
2315 sw_if_index = mp->next_hop_sw_if_index;
2316 clib_memcpy (&addr, mp->address, sizeof (addr));
2318 lm = &im6->lookup_main;
2320 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2322 lm = &im4->lookup_main;
2324 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2326 if (adj_index == ~0) {
2330 adj = ip_get_adjacency (lm, adj_index);
2332 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2333 && adj->rewrite_header.sw_if_index == sw_if_index) {
2336 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2337 && adj->rewrite_header.sw_if_index == sw_if_index) {
2339 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2341 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2342 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2350 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2354 static void vl_api_sw_interface_details_t_handler (
2355 vl_api_sw_interface_details_t * mp)
2357 clib_warning ("BUG");
2360 static void vl_api_sw_interface_set_flags_t_handler (
2361 vl_api_sw_interface_set_flags_t * mp)
2363 vl_api_sw_interface_set_flags_reply_t *rmp;
2364 vnet_main_t * vnm = vnet_get_main();
2366 clib_error_t * error;
2369 VALIDATE_SW_IF_INDEX(mp);
2371 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2373 error = vnet_sw_interface_set_flags (vnm,
2374 ntohl(mp->sw_if_index),
2378 clib_error_report (error);
2381 BAD_SW_IF_INDEX_LABEL;
2382 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2385 static void vl_api_sw_interface_clear_stats_t_handler (
2386 vl_api_sw_interface_clear_stats_t * mp)
2388 vl_api_sw_interface_clear_stats_reply_t *rmp;
2390 vnet_main_t * vnm = vnet_get_main();
2391 vnet_interface_main_t * im = &vnm->interface_main;
2392 vlib_simple_counter_main_t * sm;
2393 vlib_combined_counter_main_t * cm;
2394 static vnet_main_t ** my_vnet_mains;
2395 int i, j, n_counters;
2399 vec_reset_length (my_vnet_mains);
2401 for (i = 0; i < vec_len (vnet_mains); i++)
2404 vec_add1 (my_vnet_mains, vnet_mains[i]);
2407 if (vec_len (vnet_mains) == 0)
2408 vec_add1 (my_vnet_mains, vnm);
2410 n_counters = vec_len (im->combined_sw_if_counters);
2412 for (j = 0; j < n_counters; j++)
2414 for (i = 0; i < vec_len(my_vnet_mains); i++)
2416 im = &my_vnet_mains[i]->interface_main;
2417 cm = im->combined_sw_if_counters + j;
2418 if (mp->sw_if_index == (u32)~0)
2419 vlib_clear_combined_counters (cm);
2421 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2425 n_counters = vec_len (im->sw_if_counters);
2427 for (j = 0; j < n_counters; j++)
2429 for (i = 0; i < vec_len(my_vnet_mains); i++)
2431 im = &my_vnet_mains[i]->interface_main;
2432 sm = im->sw_if_counters + j;
2433 if (mp->sw_if_index == (u32)~0)
2434 vlib_clear_simple_counters (sm);
2436 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2440 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2443 static void send_sw_interface_details (vpe_api_main_t * am,
2444 unix_shared_memory_queue_t *q,
2445 vnet_sw_interface_t * swif,
2446 u8 * interface_name,
2449 vl_api_sw_interface_details_t * mp;
2450 vnet_hw_interface_t * hi;
2452 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2454 mp = vl_msg_api_alloc (sizeof (*mp));
2455 memset (mp, 0, sizeof (*mp));
2456 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2457 mp->sw_if_index = ntohl(swif->sw_if_index);
2458 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2459 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2461 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2463 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2464 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2465 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2466 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2467 mp->link_mtu = ntohs(hi->max_packet_bytes);
2468 mp->context = context;
2470 strncpy ((char *) mp->interface_name,
2471 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2473 /* Send the L2 address for ethernet physical intfcs */
2474 if (swif->sup_sw_if_index == swif->sw_if_index
2475 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2476 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2477 ethernet_interface_t *ei;
2479 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2480 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2481 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2482 mp->l2_address_length = ntohl(sizeof (ei->address));
2483 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2484 vnet_sub_interface_t *sub = &swif->sub;
2485 mp->sub_id = ntohl(sub->id);
2486 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2487 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2488 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2489 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2490 mp->sub_exact_match = sub->eth.flags.exact_match;
2491 mp->sub_default = sub->eth.flags.default_sub;
2492 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2493 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2495 /* vlan tag rewrite data */
2496 u32 vtr_op = L2_VTR_DISABLED;
2497 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2499 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2500 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2501 // error - default to disabled
2502 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2503 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2506 mp->vtr_op = ntohl(vtr_op);
2507 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2508 mp->vtr_tag1 = ntohl(vtr_tag1);
2509 mp->vtr_tag2 = ntohl(vtr_tag2);
2513 vl_msg_api_send_shmem (q, (u8 *)&mp);
2516 static void send_sw_interface_flags (vpe_api_main_t * am,
2517 unix_shared_memory_queue_t *q,
2518 vnet_sw_interface_t * swif)
2520 vl_api_sw_interface_set_flags_t *mp;
2521 vnet_main_t * vnm = am->vnet_main;
2523 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2525 mp = vl_msg_api_alloc (sizeof (*mp));
2526 memset (mp, 0, sizeof (*mp));
2527 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2528 mp->sw_if_index = ntohl(swif->sw_if_index);
2530 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2532 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2534 vl_msg_api_send_shmem (q, (u8 *)&mp);
2537 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2538 unix_shared_memory_queue_t *q,
2540 __attribute__((unused));
2542 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2543 unix_shared_memory_queue_t *q,
2546 vl_api_sw_interface_set_flags_t *mp;
2548 mp = vl_msg_api_alloc (sizeof (*mp));
2549 memset (mp, 0, sizeof (*mp));
2550 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2551 mp->sw_if_index = ntohl(sw_if_index);
2553 mp->admin_up_down = 0;
2554 mp->link_up_down = 0;
2556 vl_msg_api_send_shmem (q, (u8 *)&mp);
2559 static void vl_api_sw_interface_dump_t_handler (
2560 vl_api_sw_interface_dump_t *mp)
2562 vpe_api_main_t * am = &vpe_api_main;
2563 vnet_sw_interface_t * swif;
2564 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2565 u8 * filter_string = 0, * name_string = 0;
2566 unix_shared_memory_queue_t * q;
2567 char * strcasestr (char *, char *); /* lnx hdr file botch */
2569 q = vl_api_client_index_to_input_queue (mp->client_index);
2574 if (mp->name_filter_valid) {
2575 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2576 filter_string = format (0, "%s%c", mp->name_filter, 0);
2579 pool_foreach (swif, im->sw_interfaces,
2581 name_string = format (name_string, "%U%c",
2582 format_vnet_sw_interface_name,
2583 am->vnet_main, swif, 0);
2585 if (mp->name_filter_valid == 0 ||
2586 strcasestr((char *) name_string, (char *) filter_string)) {
2588 send_sw_interface_details (am, q, swif, name_string, mp->context);
2589 send_sw_interface_flags (am, q, swif);
2591 _vec_len (name_string) = 0;
2594 vec_free (name_string);
2595 vec_free (filter_string);
2598 void send_oam_event (oam_target_t * t)
2600 vpe_api_main_t * vam = &vpe_api_main;
2601 unix_shared_memory_queue_t * q;
2602 vpe_client_registration_t *reg;
2603 vl_api_oam_event_t * mp;
2605 pool_foreach(reg, vam->oam_events_registrations,
2607 q = vl_api_client_index_to_input_queue (reg->client_index);
2609 mp = vl_msg_api_alloc (sizeof (*mp));
2610 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2611 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2612 mp->state = t->state;
2613 vl_msg_api_send_shmem (q, (u8 *)&mp);
2619 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2621 vl_api_oam_add_del_reply_t * rmp;
2624 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2625 (ip4_address_t *)mp->dst_address,
2629 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2633 vl_api_vnet_get_summary_stats_t_handler (
2634 vl_api_vnet_get_summary_stats_t *mp)
2636 stats_main_t * sm = &stats_main;
2637 vnet_interface_main_t * im = sm->interface_main;
2638 vl_api_vnet_summary_stats_reply_t *rmp;
2639 vlib_combined_counter_main_t * cm;
2642 u64 total_pkts[VLIB_N_RX_TX];
2643 u64 total_bytes[VLIB_N_RX_TX];
2645 unix_shared_memory_queue_t * q =
2646 vl_api_client_index_to_input_queue (mp->client_index);
2651 rmp = vl_msg_api_alloc (sizeof (*rmp));
2652 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2653 rmp->context = mp->context;
2656 memset (total_pkts, 0, sizeof (total_pkts));
2657 memset (total_bytes, 0, sizeof (total_bytes));
2659 vnet_interface_counter_lock (im);
2661 vec_foreach (cm, im->combined_sw_if_counters) {
2662 which = cm - im->combined_sw_if_counters;
2664 for (i = 0; i < vec_len (cm->maxi); i++) {
2665 vlib_get_combined_counter (cm, i, &v);
2666 total_pkts[which] += v.packets;
2667 total_bytes[which] += v.bytes;
2670 vnet_interface_counter_unlock (im);
2672 /* Note: in HOST byte order! */
2673 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2674 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2675 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2676 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2677 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2679 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2682 typedef CLIB_PACKED (struct {
2683 ip4_address_t address;
2685 u32 address_length : 6;
2690 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2692 vnet_main_t * vnm = vnet_get_main();
2693 vnet_interface_main_t * im = &vnm->interface_main;
2694 ip4_main_t * im4 = &ip4_main;
2695 static ip4_route_t * routes;
2696 static u32 * sw_if_indices_to_shut;
2697 stats_main_t * sm = &stats_main;
2702 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2703 u32 target_fib_id = ntohl(mp->vrf_id);
2705 dslock (sm, 1 /* release hint */, 8 /* tag */);
2707 vec_foreach (fib, im4->fibs) {
2708 vnet_sw_interface_t * si;
2710 if (fib->table_id != target_fib_id)
2713 /* remove any mpls/gre tunnels in this fib */
2714 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2716 /* remove any mpls encap/decap labels */
2717 mpls_fib_reset_labels (fib->table_id);
2719 /* remove any proxy arps in this fib */
2720 vnet_proxy_arp_fib_reset (fib->table_id);
2722 /* Set the flow hash for this fib to the default */
2723 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2725 vec_reset_length (sw_if_indices_to_shut);
2727 /* Shut down interfaces in this FIB / clean out intfc routes */
2728 pool_foreach (si, im->sw_interfaces,
2730 u32 sw_if_index = si->sw_if_index;
2732 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2733 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2735 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2738 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2739 sw_if_index = sw_if_indices_to_shut[i];
2740 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2742 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2743 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2744 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2747 vec_reset_length (routes);
2749 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2750 uword * hash = fib->adj_index_by_dst_address[i];
2754 x.address_length = i;
2756 hash_foreach_pair (p, hash,
2758 x.address.data_u32 = p->key;
2759 vec_add1 (routes, x);
2763 vec_foreach (r, routes) {
2764 ip4_add_del_route_args_t a;
2766 memset (&a, 0, sizeof (a));
2767 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2768 a.table_index_or_table_id = fib - im4->fibs;
2769 a.dst_address = r->address;
2770 a.dst_address_length = r->address_length;
2773 ip4_add_del_route (im4, &a);
2774 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2775 IP4_ROUTE_FLAG_FIB_INDEX);
2779 } /* vec_foreach (fib) */
2786 ip6_address_t address;
2793 ip6_route_t ** routep;
2794 } add_routes_in_fib_arg_t;
2796 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2798 add_routes_in_fib_arg_t * ap = arg;
2800 if (kvp->key[2]>>32 == ap->fib_index)
2802 ip6_address_t *addr;
2804 addr = (ip6_address_t *) kvp;
2805 vec_add2 (*ap->routep, r, 1);
2806 r->address = addr[0];
2807 r->address_length = kvp->key[2] & 0xFF;
2808 r->index = kvp->value;
2812 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2814 vnet_main_t * vnm = vnet_get_main();
2815 vnet_interface_main_t * im = &vnm->interface_main;
2816 ip6_main_t * im6 = &ip6_main;
2817 stats_main_t * sm = &stats_main;
2818 static ip6_route_t * routes;
2819 static u32 * sw_if_indices_to_shut;
2824 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2825 u32 target_fib_id = ntohl(mp->vrf_id);
2826 add_routes_in_fib_arg_t _a, *a=&_a;
2827 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2829 dslock (sm, 1 /* release hint */, 9 /* tag */);
2831 vec_foreach (fib, im6->fibs) {
2832 vnet_sw_interface_t * si;
2834 if (fib->table_id != target_fib_id)
2837 vec_reset_length (sw_if_indices_to_shut);
2839 /* Shut down interfaces in this FIB / clean out intfc routes */
2840 pool_foreach (si, im->sw_interfaces,
2842 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2844 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2847 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2848 sw_if_index = sw_if_indices_to_shut[i];
2849 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2851 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2852 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2853 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2856 vec_reset_length (routes);
2858 a->fib_index = fib - im6->fibs;
2859 a->routep = &routes;
2861 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2863 vec_foreach (r, routes) {
2864 ip6_add_del_route_args_t a;
2866 memset (&a, 0, sizeof (a));
2867 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2868 a.table_index_or_table_id = fib - im6->fibs;
2869 a.dst_address = r->address;
2870 a.dst_address_length = r->address_length;
2873 ip6_add_del_route (im6, &a);
2874 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2875 IP6_ROUTE_FLAG_FIB_INDEX);
2878 /* Reinstall the neighbor / router discovery routes */
2879 vnet_ip6_fib_init (im6, fib - im6->fibs);
2881 } /* vec_foreach (fib) */
2887 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2890 vl_api_reset_fib_reply_t * rmp;
2893 rv = ip6_reset_fib_t_handler (mp);
2895 rv = ip4_reset_fib_t_handler (mp);
2897 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2902 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2904 vl_api_dhcp_proxy_config_reply_t * rmp;
2907 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2908 (ip4_address_t *)(&mp->dhcp_src_address),
2909 (u32) ntohl(mp->vrf_id),
2910 (int) mp->insert_circuit_id,
2911 (int) (mp->is_add == 0));
2913 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2918 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2920 vl_api_dhcp_proxy_config_reply_t * rmp;
2923 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2924 (ip6_address_t *)(&mp->dhcp_src_address),
2925 (u32) ntohl(mp->vrf_id),
2926 (int) mp->insert_circuit_id,
2927 (int) (mp->is_add == 0));
2929 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2933 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2935 vl_api_dhcp_proxy_config_reply_t * rmp;
2938 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2939 (ip4_address_t *)(&mp->dhcp_src_address),
2940 (u32) ntohl(mp->rx_vrf_id),
2941 (u32) ntohl(mp->server_vrf_id),
2942 (int) mp->insert_circuit_id,
2943 (int) (mp->is_add == 0));
2945 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2950 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2952 vl_api_dhcp_proxy_config_reply_t * rmp;
2956 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2957 (ip6_address_t *)(&mp->dhcp_src_address),
2958 (u32) ntohl(mp->rx_vrf_id),
2959 (u32) ntohl(mp->server_vrf_id),
2960 (int) mp->insert_circuit_id,
2961 (int) (mp->is_add == 0));
2963 rv = VNET_API_ERROR_UNIMPLEMENTED;
2966 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2971 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2973 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2976 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2979 (int)mp->is_add == 0);
2981 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2984 (int)mp->is_add == 0);
2986 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2990 static void vl_api_dhcp_proxy_config_t_handler
2991 (vl_api_dhcp_proxy_config_t *mp)
2993 if (mp->is_ipv6 == 0)
2994 dhcpv4_proxy_config (mp);
2996 dhcpv6_proxy_config (mp);
2999 static void vl_api_dhcp_proxy_config_2_t_handler
3000 (vl_api_dhcp_proxy_config_2_t *mp)
3002 if (mp->is_ipv6 == 0)
3003 dhcpv4_proxy_config_2 (mp);
3005 dhcpv6_proxy_config_2 (mp);
3008 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3009 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3011 unix_shared_memory_queue_t * q;
3012 vl_api_dhcp_compl_event_t * mp;
3014 q = vl_api_client_index_to_input_queue (client_index);
3018 mp = vl_msg_api_alloc (sizeof (*mp));
3019 mp->client_index = client_index;
3021 mp->is_ipv6 = is_ipv6;
3022 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3023 mp->hostname[vec_len(hostname) + 1] = '\n';
3024 clib_memcpy (&mp->host_address[0], host_address, 16);
3025 clib_memcpy (&mp->router_address[0], router_address, 16);
3026 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3028 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3030 vl_msg_api_send_shmem (q, (u8 *)&mp);
3033 static void vl_api_dhcp_client_config_t_handler
3034 (vl_api_dhcp_client_config_t *mp)
3036 vlib_main_t *vm = vlib_get_main();
3037 vl_api_dhcp_client_config_reply_t * rmp;
3040 VALIDATE_SW_IF_INDEX(mp);
3042 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3043 mp->hostname, mp->is_add, mp->client_index,
3044 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3047 BAD_SW_IF_INDEX_LABEL;
3049 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3053 vl_api_sw_interface_ip6nd_ra_config_t_handler
3054 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3056 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3058 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3060 is_no = mp->is_no == 1;
3061 surpress = mp->surpress == 1;
3062 managed = mp->managed == 1;
3063 other = mp->other == 1;
3064 ll_option = mp->ll_option == 1;
3065 send_unicast = mp->send_unicast == 1;
3066 cease = mp->cease == 1;
3067 default_router = mp->default_router == 1;
3069 VALIDATE_SW_IF_INDEX(mp);
3071 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3072 surpress, managed, other,
3073 ll_option, send_unicast, cease,
3074 default_router, ntohl (mp->lifetime),
3075 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3076 ntohl(mp->max_interval), ntohl( mp->min_interval),
3079 BAD_SW_IF_INDEX_LABEL;
3081 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3085 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3086 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3088 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3090 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3092 VALIDATE_SW_IF_INDEX(mp);
3094 is_no = mp->is_no == 1;
3095 use_default = mp->use_default == 1;
3096 no_advertise = mp->no_advertise == 1;
3097 off_link = mp->off_link == 1;
3098 no_autoconfig = mp->no_autoconfig == 1;
3099 no_onlink = mp->no_onlink == 1;
3101 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3102 (ip6_address_t *)mp->address, mp->address_length,
3103 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3104 no_advertise, off_link, no_autoconfig, no_onlink,
3107 BAD_SW_IF_INDEX_LABEL;
3108 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3112 vl_api_sw_interface_ip6_enable_disable_t_handler
3113 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3115 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3116 vnet_main_t * vnm = vnet_get_main();
3118 clib_error_t * error;
3122 VALIDATE_SW_IF_INDEX(mp);
3124 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3125 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3128 clib_error_report(error);
3129 rv = VNET_API_ERROR_UNSPECIFIED;
3131 rv = vnm->api_errno;
3134 BAD_SW_IF_INDEX_LABEL;
3136 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3140 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3141 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3143 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3145 clib_error_t * error;
3146 vnet_main_t * vnm = vnet_get_main();
3150 VALIDATE_SW_IF_INDEX(mp);
3152 error = set_ip6_link_local_address(vm,
3153 ntohl(mp->sw_if_index),
3154 (ip6_address_t *)mp->address,
3155 mp->address_length);
3157 clib_error_report(error);
3158 rv = VNET_API_ERROR_UNSPECIFIED;
3160 rv = vnm->api_errno;
3163 BAD_SW_IF_INDEX_LABEL;
3165 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3168 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3170 vl_api_set_ip_flow_hash_reply_t *rmp;
3171 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3173 clib_warning ("unimplemented...");
3175 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3178 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3180 vl_api_set_ip_flow_hash_reply_t *rmp;
3183 u32 flow_hash_config = 0;
3185 table_id = ntohl(mp->vrf_id);
3187 #define _(a,b) if (mp->a) flow_hash_config |= b;
3188 foreach_flow_hash_bit;
3191 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3193 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3197 static void vl_api_set_ip_flow_hash_t_handler
3198 (vl_api_set_ip_flow_hash_t *mp)
3200 if (mp->is_ipv6 == 0)
3201 set_ip4_flow_hash (mp);
3203 set_ip6_flow_hash (mp);
3206 static void vl_api_sw_interface_set_unnumbered_t_handler
3207 (vl_api_sw_interface_set_unnumbered_t *mp)
3209 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3211 vnet_sw_interface_t * si;
3212 vnet_main_t *vnm = vnet_get_main();
3213 u32 sw_if_index, unnumbered_sw_if_index;
3215 sw_if_index = ntohl(mp->sw_if_index);
3216 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3219 * The API message field names are backwards from
3220 * the underlying data structure names.
3221 * It's not worth changing them now.
3223 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3224 unnumbered_sw_if_index)) {
3225 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3229 /* Only check the "use loop0" field when setting the binding */
3231 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3232 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3236 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3239 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3240 si->unnumbered_sw_if_index = sw_if_index;
3242 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3243 si->unnumbered_sw_if_index = (u32)~0;
3247 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3250 static void vl_api_create_loopback_t_handler
3251 (vl_api_create_loopback_t *mp)
3253 vl_api_create_loopback_reply_t * rmp;
3257 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3259 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3261 rmp->sw_if_index = ntohl (sw_if_index);
3265 static void vl_api_delete_loopback_t_handler
3266 (vl_api_delete_loopback_t *mp)
3268 vl_api_delete_loopback_reply_t * rmp;
3272 sw_if_index = ntohl (mp->sw_if_index);
3273 rv = vnet_delete_loopback_interface (sw_if_index);
3275 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3278 static void vl_api_control_ping_t_handler
3279 (vl_api_control_ping_t *mp)
3281 vl_api_control_ping_reply_t * rmp;
3284 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3286 rmp->vpe_pid = ntohl (getpid());
3290 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3292 u8 **shmem_vecp = (u8 **)arg;
3295 api_main_t * am = &api_main;
3298 shmem_vec = *shmem_vecp;
3300 offset = vec_len (shmem_vec);
3302 pthread_mutex_lock (&am->vlib_rp->mutex);
3303 oldheap = svm_push_data_heap (am->vlib_rp);
3305 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3307 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3309 svm_pop_heap (oldheap);
3310 pthread_mutex_unlock (&am->vlib_rp->mutex);
3312 *shmem_vecp = shmem_vec;
3316 static void vl_api_cli_request_t_handler
3317 (vl_api_cli_request_t *mp)
3319 vl_api_cli_reply_t *rp;
3320 unix_shared_memory_queue_t *q;
3321 vlib_main_t * vm = vlib_get_main();
3322 api_main_t * am = &api_main;
3323 unformat_input_t input;
3327 q = vl_api_client_index_to_input_queue (mp->client_index);
3331 rp = vl_msg_api_alloc (sizeof (*rp));
3332 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3333 rp->context = mp->context;
3335 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3337 vlib_cli_input (vm, &input, shmem_cli_output,
3340 pthread_mutex_lock (&am->vlib_rp->mutex);
3341 oldheap = svm_push_data_heap (am->vlib_rp);
3343 vec_add1(shmem_vec, 0);
3345 svm_pop_heap (oldheap);
3346 pthread_mutex_unlock (&am->vlib_rp->mutex);
3348 rp->reply_in_shmem = (uword)shmem_vec;
3350 vl_msg_api_send_shmem (q, (u8 *)&rp);
3353 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3356 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3357 vnet_main_t *vnm = vnet_get_main();
3358 clib_error_t * error;
3363 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3365 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3368 clib_error_report(error);
3369 rv = VNET_API_ERROR_UNSPECIFIED;
3371 rv = vnm->api_errno;
3374 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3377 static void vl_api_sr_tunnel_add_del_t_handler
3378 (vl_api_sr_tunnel_add_del_t *mp)
3381 clib_warning ("unimplemented");
3383 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3385 vl_api_sr_tunnel_add_del_reply_t * rmp;
3386 ip6_address_t * segments = 0, * seg;
3387 ip6_address_t * tags = 0, *tag;
3388 ip6_address_t * this_address;
3391 if (mp->n_segments == 0) {
3396 memset (a, 0, sizeof (*a));
3397 a->src_address = (ip6_address_t *)&mp->src_address;
3398 a->dst_address = (ip6_address_t *)&mp->dst_address;
3399 a->dst_mask_width = mp->dst_mask_width;
3400 a->flags_net_byte_order = mp->flags_net_byte_order;
3401 a->is_del = (mp->is_add == 0);
3402 a->rx_table_id = ntohl(mp->outer_vrf_id);
3403 a->tx_table_id = ntohl(mp->inner_vrf_id);
3405 a->name = format(0, "%s", mp->name);
3406 if (!(vec_len(a->name)))
3409 a->policy_name = format(0, "%s", mp->policy_name);
3410 if (!(vec_len(a->policy_name)))
3413 /* Yank segments and tags out of the API message */
3414 this_address = (ip6_address_t *)mp->segs_and_tags;
3415 for (i = 0; i < mp->n_segments; i++) {
3416 vec_add2 (segments, seg, 1);
3417 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3420 for (i = 0; i < mp->n_tags; i++) {
3421 vec_add2 (tags, tag, 1);
3422 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3426 a->segments = segments;
3429 rv = ip6_sr_add_del_tunnel (a);
3433 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3437 static void vl_api_sr_policy_add_del_t_handler
3438 (vl_api_sr_policy_add_del_t *mp)
3441 clib_warning ("unimplemented");
3443 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3445 vl_api_sr_policy_add_del_reply_t * rmp;
3448 memset (a, 0, sizeof (*a));
3449 a->is_del = (mp->is_add == 0);
3451 a->name = format(0, "%s", mp->name);
3452 if (!(vec_len(a->name)))
3454 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3458 if (!(mp->tunnel_names[0]))
3460 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3464 // start deserializing tunnel_names
3465 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3466 u8 * deser_tun_names = mp->tunnel_names;
3467 deser_tun_names += 1; //moving along
3470 int tun_name_len = 0;
3472 for (i=0; i < num_tunnels; i++)
3474 tun_name_len= *deser_tun_names;
3475 deser_tun_names += 1;
3476 vec_resize (tun_name, tun_name_len);
3477 memcpy(tun_name, deser_tun_names, tun_name_len);
3478 vec_add1 (a->tunnel_names, tun_name);
3479 deser_tun_names += tun_name_len;
3483 rv = ip6_sr_add_del_policy (a);
3487 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3491 static void vl_api_sr_multicast_map_add_del_t_handler
3492 (vl_api_sr_multicast_map_add_del_t *mp)
3495 clib_warning ("unimplemented");
3497 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3499 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3501 memset (a, 0, sizeof (*a));
3502 a->is_del = (mp->is_add == 0);
3504 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3505 a->policy_name = format(0, "%s", mp->policy_name);
3507 if (a->multicast_address == 0)
3513 if (!(a->policy_name))
3519 #if DPDK > 0 /* Cannot call replicate without DPDK */
3520 rv = ip6_sr_add_del_multicastmap (a);
3522 clib_warning ("multicast replication without DPDK not implemented");
3523 rv = VNET_API_ERROR_UNIMPLEMENTED;
3528 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3532 #define foreach_classify_add_del_table_field \
3537 _(match_n_vectors) \
3538 _(next_table_index) \
3541 static void vl_api_classify_add_del_table_t_handler
3542 (vl_api_classify_add_del_table_t * mp)
3544 vl_api_classify_add_del_table_reply_t * rmp;
3545 vnet_classify_main_t * cm = &vnet_classify_main;
3546 vnet_classify_table_t * t;
3550 foreach_classify_add_del_table_field;
3553 #define _(a) a = ntohl(mp->a);
3554 foreach_classify_add_del_table_field;
3557 /* The underlying API fails silently, on purpose, so check here */
3558 if (mp->is_add == 0)
3559 if (pool_is_free_index (cm->tables, table_index)) {
3560 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3564 rv = vnet_classify_add_del_table
3565 (cm, mp->mask, nbuckets, memory_size,
3566 skip_n_vectors, match_n_vectors,
3567 next_table_index, miss_next_index,
3568 &table_index, mp->is_add);
3571 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3573 if (rv == 0 && mp->is_add) {
3574 t = pool_elt_at_index (cm->tables, table_index);
3575 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3576 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3577 rmp->new_table_index = ntohl(table_index);
3579 rmp->skip_n_vectors = ~0;
3580 rmp->match_n_vectors = ~0;
3581 rmp->new_table_index = ~0;
3586 static void vl_api_classify_add_del_session_t_handler
3587 (vl_api_classify_add_del_session_t * mp)
3589 vnet_classify_main_t * cm = &vnet_classify_main;
3590 vl_api_classify_add_del_session_reply_t * rmp;
3592 u32 table_index, hit_next_index, opaque_index;
3595 table_index = ntohl (mp->table_index);
3596 hit_next_index = ntohl (mp->hit_next_index);
3597 opaque_index = ntohl (mp->opaque_index);
3598 advance = ntohl (mp->advance);
3600 rv = vnet_classify_add_del_session
3601 (cm, table_index, mp->match, hit_next_index, opaque_index,
3602 advance, mp->is_add);
3604 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3607 static void vl_api_classify_set_interface_ip_table_t_handler
3608 (vl_api_classify_set_interface_ip_table_t * mp)
3610 vlib_main_t * vm = vlib_get_main();
3611 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3613 u32 table_index, sw_if_index;
3615 table_index = ntohl (mp->table_index);
3616 sw_if_index = ntohl (mp->sw_if_index);
3618 VALIDATE_SW_IF_INDEX(mp);
3621 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3623 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3625 BAD_SW_IF_INDEX_LABEL;
3627 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3630 static void vl_api_classify_set_interface_l2_tables_t_handler
3631 (vl_api_classify_set_interface_l2_tables_t * mp)
3633 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3635 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3638 ip4_table_index = ntohl(mp->ip4_table_index);
3639 ip6_table_index = ntohl(mp->ip6_table_index);
3640 other_table_index = ntohl(mp->other_table_index);
3641 sw_if_index = ntohl(mp->sw_if_index);
3643 VALIDATE_SW_IF_INDEX(mp);
3645 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3646 ip6_table_index, other_table_index);
3649 if (ip4_table_index != ~0 || ip6_table_index != ~0
3650 || other_table_index != ~0)
3655 vnet_l2_classify_enable_disable (sw_if_index, enable);
3658 BAD_SW_IF_INDEX_LABEL;
3660 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3664 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3667 vl_api_l2_fib_clear_table_reply_t * rmp;
3669 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3670 * that is not currently implemented. When that TODO is fixed
3671 * this call should be changed to pass 1 instead of 0.
3673 l2fib_clear_table (0);
3675 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3678 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3683 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3686 vl_api_l2_interface_efp_filter_reply_t * rmp;
3687 vnet_main_t *vnm = vnet_get_main();
3689 // enable/disable the feature
3690 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3691 rv = vnm->api_errno;
3693 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3697 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3700 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3701 vnet_main_t * vnm = vnet_get_main();
3702 vlib_main_t * vm = vlib_get_main();
3705 VALIDATE_SW_IF_INDEX(mp);
3707 vtr_op = ntohl(mp->vtr_op);
3709 /* The L2 code is unsuspicious */
3711 case L2_VTR_DISABLED:
3716 case L2_VTR_TRANSLATE_1_1:
3717 case L2_VTR_TRANSLATE_1_2:
3718 case L2_VTR_TRANSLATE_2_1:
3719 case L2_VTR_TRANSLATE_2_2:
3723 rv = VNET_API_ERROR_INVALID_VALUE;
3724 goto bad_sw_if_index;
3727 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3728 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3731 BAD_SW_IF_INDEX_LABEL;
3733 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3737 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3741 vl_api_create_vhost_user_if_reply_t * rmp;
3742 u32 sw_if_index = (u32)~0;
3744 vnet_main_t * vnm = vnet_get_main();
3745 vlib_main_t * vm = vlib_get_main();
3747 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3748 mp->is_server, &sw_if_index, (u64)~0,
3749 mp->renumber, ntohl(mp->custom_dev_instance),
3750 (mp->use_custom_mac)?mp->mac_address:NULL);
3752 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3754 rmp->sw_if_index = ntohl (sw_if_index);
3760 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3764 vl_api_modify_vhost_user_if_reply_t * rmp;
3765 u32 sw_if_index = ntohl(mp->sw_if_index);
3767 vnet_main_t * vnm = vnet_get_main();
3768 vlib_main_t * vm = vlib_get_main();
3770 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3771 mp->is_server, sw_if_index, (u64)~0,
3772 mp->renumber, ntohl(mp->custom_dev_instance));
3774 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3779 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3783 vpe_api_main_t * vam = &vpe_api_main;
3784 vl_api_delete_vhost_user_if_reply_t * rmp;
3785 u32 sw_if_index = ntohl(mp->sw_if_index);
3787 vnet_main_t * vnm = vnet_get_main();
3788 vlib_main_t * vm = vlib_get_main();
3790 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3792 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3794 unix_shared_memory_queue_t * q =
3795 vl_api_client_index_to_input_queue (mp->client_index);
3799 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3804 static void vl_api_sw_interface_vhost_user_details_t_handler (
3805 vl_api_sw_interface_vhost_user_details_t * mp)
3807 clib_warning ("BUG");
3811 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3812 unix_shared_memory_queue_t *q,
3813 vhost_user_intf_details_t * vui,
3816 vl_api_sw_interface_vhost_user_details_t * mp;
3818 mp = vl_msg_api_alloc (sizeof (*mp));
3819 memset (mp, 0, sizeof (*mp));
3820 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3821 mp->sw_if_index = ntohl(vui->sw_if_index);
3822 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3823 mp->features = clib_net_to_host_u64 (vui->features);
3824 mp->is_server = vui->is_server;
3825 mp->num_regions = ntohl(vui->num_regions);
3826 mp->sock_errno = ntohl(vui->sock_errno);
3827 mp->context = context;
3829 strncpy ((char *) mp->sock_filename,
3830 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3831 strncpy ((char *) mp->interface_name,
3832 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3834 vl_msg_api_send_shmem (q, (u8 *)&mp);
3839 vl_api_sw_interface_vhost_user_dump_t_handler (
3840 vl_api_sw_interface_vhost_user_dump_t *mp)
3844 vpe_api_main_t * am = &vpe_api_main;
3845 vnet_main_t * vnm = vnet_get_main();
3846 vlib_main_t * vm = vlib_get_main();
3847 vhost_user_intf_details_t *ifaces = NULL;
3848 vhost_user_intf_details_t *vuid = NULL;
3849 unix_shared_memory_queue_t * q;
3851 q = vl_api_client_index_to_input_queue (mp->client_index);
3855 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3859 vec_foreach (vuid, ifaces) {
3860 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3866 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3867 unix_shared_memory_queue_t *q,
3872 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3873 u8 * if_name = NULL;
3874 vnet_sw_interface_t * si = NULL;
3876 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3878 if_name = format(if_name, "%U",
3879 format_vnet_sw_interface_name, lm->vnet_main, si);
3881 mp = vl_msg_api_alloc (sizeof (*mp));
3882 memset (mp, 0, sizeof (*mp));
3883 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3884 strncpy((char *)mp->interface_name,
3885 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3886 mp->sw_if_index = ntohl(si->sw_if_index);
3887 mp->local_session_id = s->local_session_id;
3888 mp->remote_session_id = s->remote_session_id;
3889 mp->local_cookie[0] = s->local_cookie[0];
3890 mp->local_cookie[1] = s->local_cookie[1];
3891 mp->remote_cookie = s->remote_cookie;
3892 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3893 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3894 mp->l2_sublayer_present = s->l2_sublayer_present;
3895 mp->context = context;
3897 vl_msg_api_send_shmem (q, (u8 *)&mp);
3900 static void send_ip_address_details (vpe_api_main_t * am,
3901 unix_shared_memory_queue_t * q,
3907 vl_api_ip_address_details_t * mp;
3909 mp = vl_msg_api_alloc (sizeof (*mp));
3910 memset (mp, 0, sizeof (*mp));
3911 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3914 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3916 u32 * tp = (u32 *)mp->ip;
3917 *tp = ntohl(*(u32*)ip);
3919 mp->prefix_length = prefix_length;
3920 mp->context = context;
3922 vl_msg_api_send_shmem (q, (u8 *)&mp);
3926 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3928 vpe_api_main_t * am = &vpe_api_main;
3929 unix_shared_memory_queue_t * q;
3932 ip6_main_t * im6 = &ip6_main;
3933 ip4_main_t * im4 = &ip4_main;
3934 ip_lookup_main_t * lm6 = &im6->lookup_main;
3935 ip_lookup_main_t * lm4 = &im4->lookup_main;
3936 ip_interface_address_t * ia = 0;
3937 u32 sw_if_index = ~0;
3938 int rv __attribute__ ((unused)) = 0;
3940 VALIDATE_SW_IF_INDEX(mp);
3942 sw_if_index = ntohl(mp->sw_if_index);
3944 q = vl_api_client_index_to_input_queue (mp->client_index);
3950 foreach_ip_interface_address (lm6, ia, sw_if_index,
3951 1 /* honor unnumbered */,
3953 r6 = ip_interface_address_get_address (lm6, ia);
3954 u16 prefix_length = ia->address_length;
3955 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
3958 foreach_ip_interface_address (lm4, ia, sw_if_index,
3959 1 /* honor unnumbered */,
3961 r4 = ip_interface_address_get_address (lm4, ia);
3962 u16 prefix_length = ia->address_length;
3963 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
3966 BAD_SW_IF_INDEX_LABEL;
3969 static void send_ip_details (vpe_api_main_t * am,
3970 unix_shared_memory_queue_t *q,
3974 vl_api_ip_details_t * mp;
3976 mp = vl_msg_api_alloc (sizeof (*mp));
3977 memset (mp, 0, sizeof (*mp));
3978 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3980 mp->sw_if_index = ntohl(sw_if_index);
3981 mp->context = context;
3983 vl_msg_api_send_shmem (q, (u8 *)&mp);
3987 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3988 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3990 vpe_api_main_t * am = &vpe_api_main;
3991 l2t_main_t * lm = &l2t_main;
3992 unix_shared_memory_queue_t * q;
3993 l2t_session_t *session;
3995 q = vl_api_client_index_to_input_queue (mp->client_index);
3999 pool_foreach (session, lm->sessions,
4001 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4006 static void send_sw_interface_tap_details (vpe_api_main_t * am,
4007 unix_shared_memory_queue_t *q,
4008 tapcli_interface_details_t *tap_if,
4011 vl_api_sw_interface_tap_details_t * mp;
4012 mp = vl_msg_api_alloc (sizeof (*mp));
4013 memset (mp, 0, sizeof (*mp));
4014 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4015 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4016 strncpy((char *)mp->dev_name,
4017 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4018 mp->context = context;
4020 vl_msg_api_send_shmem (q, (u8 *)&mp);
4024 vl_api_sw_interface_tap_dump_t_handler (
4025 vl_api_sw_interface_tap_dump_t *mp)
4028 vpe_api_main_t * am = &vpe_api_main;
4029 unix_shared_memory_queue_t * q;
4030 tapcli_interface_details_t *tapifs = NULL;
4031 tapcli_interface_details_t *tap_if = NULL;
4033 q = vl_api_client_index_to_input_queue (mp->client_index);
4037 rv = vnet_tap_dump_ifs(&tapifs);
4041 vec_foreach(tap_if, tapifs) {
4042 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4049 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4051 vpe_api_main_t * am = &vpe_api_main;
4052 vnet_main_t * vnm = vnet_get_main();
4053 vlib_main_t * vm = vlib_get_main();
4054 vnet_interface_main_t * im = &vnm->interface_main;
4055 unix_shared_memory_queue_t * q;
4056 vnet_sw_interface_t * si, * sorted_sis;
4057 u32 sw_if_index = ~0;
4059 q = vl_api_client_index_to_input_queue (mp->client_index);
4064 /* Gather interfaces. */
4065 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4066 _vec_len (sorted_sis) = 0;
4067 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4069 vec_foreach (si, sorted_sis) {
4070 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4071 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4074 sw_if_index = si->sw_if_index;
4075 send_ip_details(am, q, sw_if_index, mp->context);
4080 static void vl_api_l2_fib_table_entry_t_handler (
4081 vl_api_l2_fib_table_entry_t * mp)
4083 clib_warning ("BUG");
4086 static void send_l2fib_table_entry (vpe_api_main_t * am,
4087 unix_shared_memory_queue_t *q,
4088 l2fib_entry_key_t * l2fe_key,
4089 l2fib_entry_result_t * l2fe_res,
4092 vl_api_l2_fib_table_entry_t * mp;
4094 mp = vl_msg_api_alloc (sizeof (*mp));
4095 memset (mp, 0, sizeof (*mp));
4096 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4098 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4100 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4101 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4102 mp->static_mac = l2fe_res->fields.static_mac;
4103 mp->filter_mac = l2fe_res->fields.filter;
4104 mp->bvi_mac = l2fe_res->fields.bvi;
4105 mp->context = context;
4107 vl_msg_api_send_shmem (q, (u8 *)&mp);
4111 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4113 vpe_api_main_t * am = &vpe_api_main;
4114 bd_main_t * bdm = &bd_main;
4115 l2fib_entry_key_t *l2fe_key = NULL;
4116 l2fib_entry_result_t *l2fe_res = NULL;
4117 u32 ni, bd_id = ntohl (mp->bd_id);
4119 unix_shared_memory_queue_t * q;
4122 q = vl_api_client_index_to_input_queue (mp->client_index);
4126 /* see l2fib_table_dump: ~0 means "any" */
4130 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4137 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4139 vec_foreach_index (ni, l2fe_key) {
4140 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4141 vec_elt_at_index(l2fe_res, ni), mp->context);
4148 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4150 vl_api_show_version_reply_t *rmp;
4152 char * vpe_api_get_build_directory(void);
4153 char * vpe_api_get_version(void);
4154 char * vpe_api_get_build_date(void);
4156 unix_shared_memory_queue_t * q =
4157 vl_api_client_index_to_input_queue (mp->client_index);
4162 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4164 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4165 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4166 ARRAY_LEN(rmp->build_directory)-1);
4167 strncpy ((char *) rmp->version, vpe_api_get_version(),
4168 ARRAY_LEN(rmp->version)-1);
4169 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4170 ARRAY_LEN(rmp->build_date)-1);
4174 static void vl_api_get_node_index_t_handler
4175 (vl_api_get_node_index_t * mp)
4177 vlib_main_t * vm = vlib_get_main();
4178 vl_api_get_node_index_reply_t * rmp;
4181 u32 node_index = ~0;
4183 n = vlib_get_node_by_name (vm, mp->node_name);
4186 rv = VNET_API_ERROR_NO_SUCH_NODE;
4188 node_index = n->index;
4190 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4192 rmp->node_index = ntohl(node_index);
4196 static void vl_api_add_node_next_t_handler
4197 (vl_api_add_node_next_t * mp)
4199 vlib_main_t * vm = vlib_get_main();
4200 vl_api_add_node_next_reply_t * rmp;
4201 vlib_node_t * n, * next;
4203 u32 next_index = ~0;
4205 n = vlib_get_node_by_name (vm, mp->node_name);
4208 rv = VNET_API_ERROR_NO_SUCH_NODE;
4212 next = vlib_get_node_by_name (vm, mp->next_name);
4215 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4217 next_index = vlib_node_add_next (vm, n->index, next->index);
4220 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4222 rmp->next_index = ntohl(next_index);
4226 static void vl_api_l2tpv3_create_tunnel_t_handler
4227 (vl_api_l2tpv3_create_tunnel_t *mp)
4229 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4230 l2t_main_t *lm = &l2t_main;
4231 u32 sw_if_index = (u32)~0;
4234 if (mp->is_ipv6 != 1) {
4235 rv = VNET_API_ERROR_UNIMPLEMENTED;
4239 rv = create_l2tpv3_ipv6_tunnel (lm,
4240 (ip6_address_t *) mp->client_address,
4241 (ip6_address_t *) mp->our_address,
4242 ntohl(mp->local_session_id),
4243 ntohl(mp->remote_session_id),
4244 clib_net_to_host_u64(mp->local_cookie),
4245 clib_net_to_host_u64(mp->remote_cookie),
4246 mp->l2_sublayer_present,
4250 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4252 rmp->sw_if_index = ntohl (sw_if_index);
4256 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4257 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4259 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4260 l2t_main_t *lm = &l2t_main;
4263 VALIDATE_SW_IF_INDEX(mp);
4265 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4266 clib_net_to_host_u64(mp->new_local_cookie),
4267 clib_net_to_host_u64(mp->new_remote_cookie));
4269 BAD_SW_IF_INDEX_LABEL;
4271 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4274 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4275 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4278 vnet_main_t * vnm = vnet_get_main();
4279 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4281 VALIDATE_SW_IF_INDEX(mp);
4283 rv = l2tpv3_interface_enable_disable
4284 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4286 BAD_SW_IF_INDEX_LABEL;
4288 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4291 static void vl_api_l2tpv3_set_lookup_key_t_handler
4292 (vl_api_l2tpv3_set_lookup_key_t * mp)
4295 l2t_main_t *lm = &l2t_main;
4296 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4298 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4299 rv = VNET_API_ERROR_INVALID_VALUE;
4303 lm->lookup_type = mp->key;
4306 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4309 static void vl_api_vxlan_add_del_tunnel_t_handler
4310 (vl_api_vxlan_add_del_tunnel_t * mp)
4312 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4314 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4315 u32 encap_fib_index;
4317 ip4_main_t * im = &ip4_main;
4318 u32 sw_if_index = ~0;
4320 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4322 rv = VNET_API_ERROR_NO_SUCH_FIB;
4325 encap_fib_index = p[0];
4327 /* Check src & dst are different */
4328 if ((a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4329 (!a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4330 rv = VNET_API_ERROR_SAME_SRC_DST;
4333 memset (a, 0, sizeof (*a));
4335 a->is_add = mp->is_add;
4336 a->is_ip6 = mp->is_ipv6;
4338 /* ip addresses sent in network byte order */
4340 memcpy(&(a->src.ip6), mp->src_address, 16);
4341 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4343 memcpy(&(a->src.ip4), mp->src_address, 4);
4344 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4347 a->encap_fib_index = encap_fib_index;
4348 a->decap_next_index = ntohl(mp->decap_next_index);
4349 a->vni = ntohl(mp->vni);
4350 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4353 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4355 rmp->sw_if_index = ntohl (sw_if_index);
4359 static void send_vxlan_tunnel_details
4360 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4362 vl_api_vxlan_tunnel_details_t * rmp;
4363 ip4_main_t * im4 = &ip4_main;
4364 ip6_main_t * im6 = &ip6_main;
4365 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4367 rmp = vl_msg_api_alloc (sizeof (*rmp));
4368 memset (rmp, 0, sizeof (*rmp));
4369 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4371 memcpy(rmp->src_address, &(t->src.ip6), 16);
4372 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4373 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4375 memcpy(rmp->src_address, &(t->src.ip4), 4);
4376 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4377 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4379 rmp->vni = htonl(t->vni);
4380 rmp->decap_next_index = htonl(t->decap_next_index);
4381 rmp->sw_if_index = htonl(t->sw_if_index);
4382 rmp->is_ipv6 = is_ipv6;
4383 rmp->context = context;
4385 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4388 static void vl_api_vxlan_tunnel_dump_t_handler
4389 (vl_api_vxlan_tunnel_dump_t * mp)
4391 unix_shared_memory_queue_t * q;
4392 vxlan_main_t * vxm = &vxlan_main;
4396 q = vl_api_client_index_to_input_queue (mp->client_index);
4401 sw_if_index = ntohl(mp->sw_if_index);
4403 if (~0 == sw_if_index) {
4404 pool_foreach (t, vxm->tunnels,
4406 send_vxlan_tunnel_details(t, q, mp->context);
4409 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4410 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4413 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4414 send_vxlan_tunnel_details(t, q, mp->context);
4418 static void vl_api_gre_add_del_tunnel_t_handler
4419 (vl_api_gre_add_del_tunnel_t * mp)
4421 vl_api_gre_add_del_tunnel_reply_t * rmp;
4423 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4426 ip4_main_t * im = &ip4_main;
4427 u32 sw_if_index = ~0;
4429 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_table_id));
4431 rv = VNET_API_ERROR_NO_SUCH_FIB;
4434 outer_table_id = p[0];
4436 /* Check src & dst are different */
4437 if (memcmp(&mp->src_address, &mp->dst_address, 4) == 0) {
4438 rv = VNET_API_ERROR_SAME_SRC_DST;
4442 memset (a, 0, sizeof (*a));
4444 a->is_add = mp->is_add;
4446 /* ip addresses sent in network byte order */
4447 a->src.as_u32 = mp->src_address;
4448 a->dst.as_u32 = mp->dst_address;
4450 a->outer_table_id = outer_table_id;
4451 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4454 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4456 rmp->sw_if_index = ntohl (sw_if_index);
4460 static void send_gre_tunnel_details
4461 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4463 vl_api_gre_tunnel_details_t * rmp;
4464 ip4_main_t * im = &ip4_main;
4466 rmp = vl_msg_api_alloc (sizeof (*rmp));
4467 memset (rmp, 0, sizeof (*rmp));
4468 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4469 rmp->src_address = t->tunnel_src.data_u32;
4470 rmp->dst_address = t->tunnel_dst.data_u32;
4471 rmp->outer_table_id = htonl(im->fibs[t->outer_fib_index].table_id);
4472 rmp->sw_if_index = htonl(t->sw_if_index);
4473 rmp->context = context;
4475 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4478 static void vl_api_gre_tunnel_dump_t_handler
4479 (vl_api_gre_tunnel_dump_t * mp)
4481 unix_shared_memory_queue_t * q;
4482 gre_main_t * gm = &gre_main;
4486 q = vl_api_client_index_to_input_queue (mp->client_index);
4491 sw_if_index = ntohl(mp->sw_if_index);
4493 if (~0 == sw_if_index) {
4494 pool_foreach (t, gm->tunnels,
4496 send_gre_tunnel_details(t, q, mp->context);
4499 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4500 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4503 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4504 send_gre_tunnel_details(t, q, mp->context);
4509 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4511 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4513 vl_api_l2_patch_add_del_reply_t * rmp;
4514 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4518 VALIDATE_RX_SW_IF_INDEX(mp);
4519 VALIDATE_TX_SW_IF_INDEX(mp);
4521 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4522 ntohl(mp->tx_sw_if_index),
4523 (int)(mp->is_add != 0));
4525 BAD_RX_SW_IF_INDEX_LABEL;
4526 BAD_TX_SW_IF_INDEX_LABEL;
4528 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4532 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4533 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4535 vl_api_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4537 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4538 u32 encap_fib_index, decap_fib_index;
4541 ip4_main_t * im = &ip4_main;
4542 u32 sw_if_index = ~0;
4545 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4547 rv = VNET_API_ERROR_NO_SUCH_FIB;
4550 encap_fib_index = p[0];
4552 protocol = ntohl(mp->protocol);
4554 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4555 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT) {
4556 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4558 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4561 decap_fib_index = p[0];
4563 decap_fib_index = ntohl(mp->decap_vrf_id);
4566 memset (a, 0, sizeof (*a));
4568 a->is_add = mp->is_add;
4569 /* ip addresses sent in network byte order */
4570 a->local.as_u32 = ntohl(mp->local);
4571 a->remote.as_u32 = ntohl(mp->remote);
4572 a->encap_fib_index = encap_fib_index;
4573 a->decap_fib_index = decap_fib_index;
4574 a->protocol = protocol;
4575 a->vni = ntohl(mp->vni);
4576 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4579 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4581 rmp->sw_if_index = ntohl (sw_if_index);
4586 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4588 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4590 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4592 u8 *locator_name = NULL;
4594 memset(a, 0, sizeof(a[0]));
4596 locator_name = format(0, "%s", mp->locator_set_name);
4598 a->name = locator_name;
4600 a->is_add = mp->is_add;
4603 rv = vnet_lisp_add_del_locator_set_name(a, &ls_index);
4605 vec_free(locator_name);
4607 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4611 vl_api_lisp_add_del_locator_t_handler(
4612 vl_api_lisp_add_del_locator_t *mp)
4614 vl_api_lisp_add_del_locator_reply_t *rmp;
4616 locator_t locator, *locators = NULL;
4617 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4619 u8 *locator_name = NULL;
4621 memset(&locator, 0, sizeof(locator));
4622 memset(a, 0, sizeof(a[0]));
4624 locator.sw_if_index = ntohl(mp->sw_if_index);
4625 locator.priority = mp->priority;
4626 locator.weight = mp->weight;
4628 vec_add1(locators, locator);
4630 locator_name = format(0, "%s", mp->locator_set_name);
4632 a->name = locator_name;
4633 a->locators = locators;
4634 a->is_add = mp->is_add;
4637 rv = vnet_lisp_add_del_locator(a, &ls_index);
4640 vec_free(locator_name);
4642 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4646 vl_api_lisp_add_del_local_eid_t_handler(
4647 vl_api_lisp_add_del_local_eid_t *mp)
4649 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4650 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4652 ip_prefix_t *prefp = NULL;
4653 ip_address_t *ip_eid = NULL;
4656 u32 locator_set_index = ~0, map_index = ~0;
4657 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4660 prefp = &gid_address_ippref(&eid);
4661 ip_eid = &ip_prefix_addr(prefp);
4662 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4665 clib_memcpy(&ip_addr_v6(ip_eid), mp->ip_address,
4666 sizeof(ip_addr_v6(ip_eid)));
4667 ip_addr_version(ip_eid) = IP6;
4669 clib_memcpy(&ip_addr_v4(ip_eid), mp->ip_address,
4670 sizeof(ip_addr_v4(ip_eid)));
4671 ip_addr_version(ip_eid) = IP4;
4673 ip_prefix_len(prefp) = mp->prefix_len;
4675 name = format(0, "%s", mp->locator_set_name);
4676 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4678 rv = VNET_API_ERROR_INVALID_VALUE;
4681 locator_set_index = p[0];
4683 /* XXX treat batch configuration */
4684 a->is_add = mp->is_add;
4686 a->locator_set_index = locator_set_index;
4689 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4694 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4698 lisp_gpe_add_del_fwd_entry_set_address(
4699 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4700 ip_address_t *slocator,
4701 ip_address_t *dlocator,
4704 ip_address_t *ip_eid = NULL;
4705 ip_prefix_t *prefp = NULL;
4707 prefp = &gid_address_ippref(eid);
4708 ip_eid = &ip_prefix_addr(prefp);
4710 if (mp->eid_is_ipv6) {
4711 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4712 sizeof(ip_addr_v6(ip_eid)));
4713 ip_addr_version(ip_eid) = IP6;
4715 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4716 sizeof(ip_addr_v4(ip_eid)));
4717 ip_addr_version(ip_eid) = IP4;
4719 ip_prefix_len(prefp) = mp->eid_prefix_len;
4721 if (mp->address_is_ipv6) {
4722 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4723 sizeof(ip_addr_v6(slocator)));
4724 ip_addr_version(slocator) = IP6;
4725 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4726 sizeof(ip_addr_v6(dlocator)));
4727 ip_addr_version(dlocator) = IP6;
4729 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4730 sizeof(ip_addr_v4(slocator)));
4731 ip_addr_version(slocator) = IP4;
4732 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4733 sizeof(ip_addr_v4(dlocator)));
4734 ip_addr_version(dlocator) = IP4;
4739 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4740 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4742 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4744 ip_address_t slocator, dlocator;
4746 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4748 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4750 memset (&a, 0, sizeof(a));
4752 a.is_add = mp->is_add;
4754 a.slocator = slocator;
4755 a.dlocator = dlocator;
4756 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4758 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4762 vl_api_lisp_add_del_map_resolver_t_handler(
4763 vl_api_lisp_add_del_map_resolver_t *mp)
4765 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4767 ip_address_t *ip_addr = NULL;
4768 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4770 a->is_add = mp->is_add;
4771 ip_addr = &a->address;
4774 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4775 sizeof(ip_addr_v6(ip_addr)));
4776 ip_addr_version(ip_addr) = IP6;
4778 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4779 sizeof(ip_addr_v4(ip_addr)));
4780 ip_addr_version(ip_addr) = IP4;
4783 rv = vnet_lisp_add_del_map_resolver (a);
4785 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4789 vl_api_lisp_gpe_enable_disable_t_handler(
4790 vl_api_lisp_gpe_enable_disable_t *mp)
4792 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4794 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
4796 a->is_en = mp->is_en;
4797 vnet_lisp_gpe_enable_disable (a);
4799 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4803 vl_api_lisp_enable_disable_t_handler(
4804 vl_api_lisp_enable_disable_t *mp)
4806 vl_api_lisp_enable_disable_reply_t *rmp;
4809 vnet_lisp_enable_disable (mp->is_en);
4810 REPLY_MACRO(VL_API_LISP_ENABLE_DISABLE_REPLY);
4814 vl_api_lisp_gpe_add_del_iface_t_handler(
4815 vl_api_lisp_gpe_add_del_iface_t *mp)
4817 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4819 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4821 a->is_add = mp->is_add;
4822 a->table_id = mp->table_id;
4824 vnet_lisp_gpe_add_del_iface (a, 0);
4826 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4829 /** Used for transferring locators via VPP API */
4830 typedef CLIB_PACKED(struct
4832 u8 is_ip4; /**< is locator an IPv4 address */
4833 u8 addr[16]; /**< IPv4/IPv6 address */
4837 send_lisp_locator_set_details_set_address
4838 (vl_api_lisp_locator_set_details_t *rmp,
4839 gid_address_t *gid_address)
4841 ip_prefix_t *ip_addr;
4843 if (gid_address_type(gid_address) != GID_ADDR_IP_PREFIX) {
4847 ip_addr = &gid_address_ippref(gid_address);
4848 rmp->prefix_len = ip_prefix_len(ip_addr);
4849 rmp->is_ipv6 = ip_prefix_version(ip_addr);
4850 ip_address_copy_addr(rmp->ip_address, &ip_prefix_addr(ip_addr));
4854 vl_api_lisp_add_del_remote_mapping_t_handler (
4855 vl_api_lisp_add_del_remote_mapping_t *mp)
4858 ip_address_t rloc, * rlocs = 0;
4859 vl_api_lisp_add_del_remote_mapping_reply_t * rmp;
4861 gid_address_t _seid, * seid = &_seid;
4862 gid_address_t _deid, * deid = &_deid;
4863 ip_prefix_t * seid_pref = &gid_address_ippref(seid);
4864 ip_prefix_t * deid_pref = &gid_address_ippref(deid);
4866 gid_address_type(seid) = GID_ADDR_IP_PREFIX;
4867 gid_address_type(deid) = GID_ADDR_IP_PREFIX;
4868 ip_address_t * seid_addr = &ip_prefix_addr(seid_pref);
4869 ip_address_t * deid_addr = &ip_prefix_addr(deid_pref);
4870 ip_prefix_len(seid_pref) = mp->seid_len;
4871 ip_prefix_len(deid_pref) = mp->deid_len;
4872 gid_address_set_vni (seid, ntohl (mp->vni));
4873 gid_address_set_vni (deid, ntohl (mp->vni));
4875 if (mp->eid_is_ip4) {
4876 ip_prefix_version(seid_pref) = IP4;
4877 ip_prefix_version(deid_pref) = IP4;
4878 clib_memcpy (&ip_addr_v4(seid_addr),
4879 mp->seid, sizeof (ip_addr_v4(seid_addr)));
4880 clib_memcpy (&ip_addr_v4(deid_addr),
4881 mp->deid, sizeof (ip_addr_v4(deid_addr)));
4883 ip_prefix_version(seid_pref) = IP6;
4884 ip_prefix_version(deid_pref) = IP6;
4885 clib_memcpy (&ip_addr_v6(seid_addr),
4886 mp->seid, sizeof (ip_addr_v6(seid_addr)));
4887 clib_memcpy (&ip_addr_v6(deid_addr),
4888 mp->deid, sizeof (ip_addr_v6(deid_addr)));
4891 for (i = 0; i < mp->rloc_num; i++) {
4892 rloc_t * r = &((rloc_t *) mp->rlocs)[i];
4894 clib_memcpy (&ip_addr_v4(&rloc), &r->addr, sizeof (rloc_t));
4895 ip_addr_version (&rloc) = IP4;
4897 clib_memcpy (&ip_addr_v6(&rloc), &r->addr, sizeof (rloc_t));
4898 ip_addr_version (&rloc) = IP6;
4900 vec_add1 (rlocs, rloc);
4903 rv = vnet_lisp_add_del_remote_mapping (deid, seid, rlocs,
4904 mp->action, mp->is_add);
4906 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4910 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
4911 locator_set_t *lsit,
4912 unix_shared_memory_queue_t *q,
4916 vl_api_lisp_locator_set_details_t *rmp;
4917 locator_t *loc = NULL;
4921 vec_foreach (locit, lsit->locator_indices) {
4922 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4923 rmp = vl_msg_api_alloc (sizeof (*rmp));
4924 memset (rmp, 0, sizeof (*rmp));
4925 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
4926 rmp->local = lsit->local;
4928 ASSERT(lsit->name != NULL);
4929 strncpy((char *) rmp->locator_set_name,
4930 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4931 rmp->sw_if_index = htonl(loc->sw_if_index);
4933 str = format(0, "remote-%d", index);
4934 strncpy((char *) rmp->locator_set_name, (char *) str,
4935 ARRAY_LEN(rmp->locator_set_name) - 1);
4936 send_lisp_locator_set_details_set_address(rmp, &loc->address);
4940 rmp->priority = loc->priority;
4941 rmp->weight = loc->weight;
4942 rmp->context = context;
4944 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4949 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
4951 unix_shared_memory_queue_t * q = NULL;
4952 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4953 locator_set_t * lsit = NULL;
4956 q = vl_api_client_index_to_input_queue (mp->client_index);
4962 pool_foreach (lsit, lcm->locator_set_pool,
4964 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
4969 send_lisp_local_eid_table_details (mapping_t *mapit,
4970 unix_shared_memory_queue_t *q,
4973 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
4974 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4975 locator_set_t *ls = NULL;
4976 gid_address_t *gid = NULL;
4977 ip_prefix_t *ip_prefix = NULL;
4981 ls = pool_elt_at_index (lcm->locator_set_pool,
4982 mapit->locator_set_index);
4985 type = gid_address_type(gid);
4987 if (type != GID_ADDR_IP_PREFIX) {
4991 ip_prefix = &gid_address_ippref(gid);
4993 rmp = vl_msg_api_alloc (sizeof (*rmp));
4994 memset (rmp, 0, sizeof (*rmp));
4995 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
4997 ASSERT(ls->name != NULL);
4998 strncpy((char *) rmp->locator_set_name,
4999 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5001 str = format(0, "remote-%d", mapit->locator_set_index);
5002 strncpy((char *) rmp->locator_set_name, (char *) str,
5003 ARRAY_LEN(rmp->locator_set_name) - 1);
5007 switch (ip_prefix_version(ip_prefix)) {
5009 rmp->eid_is_ipv6 = 0;
5010 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v4(ip_prefix),
5011 sizeof(ip_prefix_v4(ip_prefix)));
5015 rmp->eid_is_ipv6 = 1;
5016 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v6(ip_prefix),
5017 sizeof(ip_prefix_v6(ip_prefix)));
5023 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
5024 rmp->context = context;
5026 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5030 vl_api_lisp_local_eid_table_dump_t_handler (
5031 vl_api_lisp_local_eid_table_dump_t *mp)
5033 unix_shared_memory_queue_t * q = NULL;
5034 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5035 mapping_t * mapit = NULL;
5037 q = vl_api_client_index_to_input_queue (mp->client_index);
5042 pool_foreach (mapit, lcm->mapping_pool,
5044 send_lisp_local_eid_table_details(mapit, q, mp->context);
5049 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5050 unix_shared_memory_queue_t *q,
5053 vl_api_lisp_gpe_tunnel_details_t *rmp;
5054 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5056 rmp = vl_msg_api_alloc (sizeof (*rmp));
5057 memset (rmp, 0, sizeof (*rmp));
5058 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5060 rmp->tunnels = tunnel - lgm->tunnels;
5062 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5063 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5064 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5066 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5067 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5068 rmp->dcap_next = htonl(tunnel->decap_next_index);
5069 rmp->lisp_ver = tunnel->ver_res;
5070 rmp->next_protocol = tunnel->next_protocol;
5071 rmp->flags = tunnel->flags;
5072 rmp->ver_res = tunnel->ver_res;
5073 rmp->res = tunnel->res;
5074 rmp->iid = htonl(tunnel->vni);
5075 rmp->context = context;
5077 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5081 vl_api_lisp_gpe_tunnel_dump_t_handler (
5082 vl_api_lisp_local_eid_table_dump_t *mp)
5084 unix_shared_memory_queue_t * q = NULL;
5085 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5086 lisp_gpe_tunnel_t * tunnel = NULL;
5088 if (pool_elts(lgm->tunnels) == 0) {
5092 q = vl_api_client_index_to_input_queue (mp->client_index);
5097 pool_foreach(tunnel, lgm->tunnels,
5099 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5104 send_lisp_map_resolver_details (ip_address_t *ip,
5105 unix_shared_memory_queue_t *q,
5108 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5110 rmp = vl_msg_api_alloc (sizeof (*rmp));
5111 memset (rmp, 0, sizeof (*rmp));
5112 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5114 switch (ip_addr_version(ip)) {
5117 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5122 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5128 rmp->context = context;
5130 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5134 vl_api_lisp_map_resolver_dump_t_handler (
5135 vl_api_lisp_local_eid_table_dump_t *mp)
5137 unix_shared_memory_queue_t * q = NULL;
5138 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5139 ip_address_t *ip = NULL;
5141 q = vl_api_client_index_to_input_queue (mp->client_index);
5146 vec_foreach(ip, lcm->map_resolvers) {
5147 send_lisp_map_resolver_details(ip, q, mp->context);
5153 send_lisp_enable_disable_details (unix_shared_memory_queue_t *q,
5156 vl_api_lisp_enable_disable_status_details_t *rmp = NULL;
5158 rmp = vl_msg_api_alloc (sizeof (*rmp));
5159 memset (rmp, 0, sizeof (*rmp));
5160 rmp->_vl_msg_id = ntohs(VL_API_LISP_ENABLE_DISABLE_STATUS_DETAILS);
5162 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5163 rmp->feature_status = vnet_lisp_enable_disable_status ();
5164 rmp->context = context;
5166 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5170 vl_api_lisp_enable_disable_status_dump_t_handler
5171 (vl_api_lisp_enable_disable_status_dump_t *mp)
5173 unix_shared_memory_queue_t * q = NULL;
5175 q = vl_api_client_index_to_input_queue (mp->client_index);
5180 send_lisp_enable_disable_details(q, mp->context);
5184 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5186 vl_api_interface_name_renumber_reply_t * rmp;
5189 VALIDATE_SW_IF_INDEX(mp);
5191 rv = vnet_interface_name_renumber
5192 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5194 BAD_SW_IF_INDEX_LABEL;
5196 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5199 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5200 u32 sw_if_index, u32 address)
5202 vpe_api_main_t * am = &vpe_api_main;
5203 vlib_main_t * vm = am->vlib_main;
5204 vl_api_ip4_arp_event_t * event;
5205 static f64 arp_event_last_time;
5206 f64 now = vlib_time_now (vm);
5208 if (pool_is_free_index (am->arp_events, pool_index))
5211 event = pool_elt_at_index (am->arp_events, pool_index);
5212 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5213 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5214 } else { /* same mac */
5215 if ((sw_if_index == event->sw_if_index) &&
5217 /* for BD case, also check IP address with 10 sec timeout */
5218 ((address == event->address) &&
5219 ((now - arp_event_last_time) < 10.0))))
5223 arp_event_last_time = now;
5224 event->sw_if_index = sw_if_index;
5225 if (address) event->address = address;
5229 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5231 vpe_api_main_t * am = &vpe_api_main;
5233 if (pool_is_free_index (am->arp_events, pool_index))
5236 pool_put_index (am->arp_events, pool_index);
5241 vl_api_want_ip4_arp_events_t_handler
5242 (vl_api_want_ip4_arp_events_t * mp)
5244 vpe_api_main_t * am = &vpe_api_main;
5245 vnet_main_t * vnm = vnet_get_main();
5246 vl_api_want_ip4_arp_events_reply_t *rmp;
5247 vl_api_ip4_arp_event_t * event;
5250 if (mp->enable_disable) {
5251 pool_get (am->arp_events, event);
5252 memset (event, 0, sizeof (*event));
5254 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5255 event->client_index = mp->client_index;
5256 event->context = mp->context;
5257 event->address = mp->address;
5258 event->pid = mp->pid;
5260 rv = vnet_add_del_ip4_arp_change_event
5261 (vnm, arp_change_data_callback,
5263 &mp->address /* addr, in net byte order */,
5264 vpe_resolver_process_node.index,
5265 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5267 rv = vnet_add_del_ip4_arp_change_event
5268 (vnm, arp_change_delete_callback,
5270 &mp->address /* addr, in net byte order */,
5271 vpe_resolver_process_node.index,
5272 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5274 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5277 static void vl_api_input_acl_set_interface_t_handler
5278 (vl_api_input_acl_set_interface_t * mp)
5280 vlib_main_t *vm = vlib_get_main();
5281 vl_api_input_acl_set_interface_reply_t * rmp;
5283 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5285 ip4_table_index = ntohl(mp->ip4_table_index);
5286 ip6_table_index = ntohl(mp->ip6_table_index);
5287 l2_table_index = ntohl(mp->l2_table_index);
5288 sw_if_index = ntohl(mp->sw_if_index);
5290 VALIDATE_SW_IF_INDEX(mp);
5292 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5293 ip6_table_index, l2_table_index,
5296 BAD_SW_IF_INDEX_LABEL;
5298 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5301 static void vl_api_ipsec_spd_add_del_t_handler
5302 (vl_api_ipsec_spd_add_del_t * mp)
5305 clib_warning ("unimplemented");
5308 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5309 vl_api_ipsec_spd_add_del_reply_t * rmp;
5313 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5315 rv = VNET_API_ERROR_UNIMPLEMENTED;
5318 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5322 static void vl_api_ipsec_interface_add_del_spd_t_handler
5323 (vl_api_ipsec_interface_add_del_spd_t * mp)
5325 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5326 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5328 u32 sw_if_index __attribute__((unused));
5329 u32 spd_id __attribute__((unused));
5331 sw_if_index = ntohl(mp->sw_if_index);
5332 spd_id = ntohl(mp->spd_id);
5334 VALIDATE_SW_IF_INDEX(mp);
5337 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5339 rv = VNET_API_ERROR_UNIMPLEMENTED;
5342 BAD_SW_IF_INDEX_LABEL;
5344 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5347 static void vl_api_ipsec_spd_add_del_entry_t_handler
5348 (vl_api_ipsec_spd_add_del_entry_t * mp)
5350 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5351 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5357 memset(&p, 0, sizeof(p));
5359 p.id = ntohl(mp->spd_id);
5360 p.priority = ntohl(mp->priority);
5361 p.is_outbound = mp->is_outbound;
5362 p.is_ipv6 = mp->is_ipv6;
5364 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5365 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5366 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5367 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5369 p.protocol = mp->protocol;
5370 p.rport.start = ntohs(mp->remote_port_start);
5371 p.rport.stop = ntohs(mp->remote_port_stop);
5372 p.lport.start = ntohs(mp->local_port_start);
5373 p.lport.stop = ntohs(mp->local_port_stop);
5374 /* policy action resolve unsupported */
5375 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5376 clib_warning("unsupported action: 'resolve'");
5377 rv = VNET_API_ERROR_UNIMPLEMENTED;
5380 p.policy = mp->policy;
5381 p.sa_id = ntohl(mp->sa_id);
5383 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5387 if (mp->is_ip_any) {
5389 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5392 rv = VNET_API_ERROR_UNIMPLEMENTED;
5397 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5400 static void vl_api_ipsec_sad_add_del_entry_t_handler
5401 (vl_api_ipsec_sad_add_del_entry_t * mp)
5403 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5404 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5409 memset(&sa, 0, sizeof(sa));
5411 sa.id = ntohl(mp->sad_id);
5412 sa.spi = ntohl(mp->spi);
5413 /* security protocol AH unsupported */
5414 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5415 clib_warning("unsupported security protocol 'AH'");
5416 rv = VNET_API_ERROR_UNIMPLEMENTED;
5419 sa.protocol = mp->protocol;
5420 /* check for unsupported crypto-alg */
5421 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5422 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5423 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5424 mp->crypto_algorithm);
5425 rv = VNET_API_ERROR_UNIMPLEMENTED;
5428 sa.crypto_alg = mp->crypto_algorithm;
5429 sa.crypto_key_len = mp->crypto_key_length;
5430 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5431 /* check for unsupported integ-alg */
5432 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5433 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5434 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5435 mp->integrity_algorithm);
5436 rv = VNET_API_ERROR_UNIMPLEMENTED;
5439 sa.integ_alg = mp->integrity_algorithm;
5440 sa.integ_key_len = mp->integrity_key_length;
5441 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5442 sa.use_esn = mp->use_extended_sequence_number;
5443 sa.is_tunnel = mp->is_tunnel;
5444 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5445 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5446 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5448 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5450 rv = VNET_API_ERROR_UNIMPLEMENTED;
5455 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5459 vl_api_ikev2_profile_add_del_t_handler
5460 (vl_api_ikev2_profile_add_del_t * mp)
5462 vl_api_ikev2_profile_add_del_reply_t * rmp;
5466 vlib_main_t * vm = vlib_get_main();
5467 clib_error_t * error;
5468 u8 * tmp = format(0, "%s", mp->name);
5469 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5472 rv = VNET_API_ERROR_UNSPECIFIED;
5474 rv = VNET_API_ERROR_UNIMPLEMENTED;
5477 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5481 vl_api_ikev2_profile_set_auth_t_handler
5482 (vl_api_ikev2_profile_set_auth_t * mp)
5484 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5488 vlib_main_t * vm = vlib_get_main();
5489 clib_error_t * error;
5490 u8 * tmp = format(0, "%s", mp->name);
5491 u8 * data = vec_new (u8, mp->data_len);
5492 clib_memcpy(data, mp->data, mp->data_len);
5493 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5497 rv = VNET_API_ERROR_UNSPECIFIED;
5499 rv = VNET_API_ERROR_UNIMPLEMENTED;
5502 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5506 vl_api_ikev2_profile_set_id_t_handler
5507 (vl_api_ikev2_profile_set_id_t * mp)
5509 vl_api_ikev2_profile_add_del_reply_t * rmp;
5513 vlib_main_t * vm = vlib_get_main();
5514 clib_error_t * error;
5515 u8 * tmp = format(0, "%s", mp->name);
5516 u8 * data = vec_new (u8, mp->data_len);
5517 clib_memcpy(data, mp->data, mp->data_len);
5518 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
5522 rv = VNET_API_ERROR_UNSPECIFIED;
5524 rv = VNET_API_ERROR_UNIMPLEMENTED;
5527 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5531 vl_api_ikev2_profile_set_ts_t_handler
5532 (vl_api_ikev2_profile_set_ts_t * mp)
5534 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5538 vlib_main_t * vm = vlib_get_main();
5539 clib_error_t * error;
5540 u8 * tmp = format(0, "%s", mp->name);
5541 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
5542 mp->end_port, (ip4_address_t) mp->start_addr,
5543 (ip4_address_t) mp->end_addr, mp->is_local);
5546 rv = VNET_API_ERROR_UNSPECIFIED;
5548 rv = VNET_API_ERROR_UNIMPLEMENTED;
5551 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5555 vl_api_ikev2_set_local_key_t_handler
5556 (vl_api_ikev2_set_local_key_t * mp)
5558 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5562 vlib_main_t * vm = vlib_get_main();
5563 clib_error_t * error;
5565 error = ikev2_set_local_key(vm, mp->key_file);
5567 rv = VNET_API_ERROR_UNSPECIFIED;
5569 rv = VNET_API_ERROR_UNIMPLEMENTED;
5572 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5576 vl_api_map_add_domain_t_handler
5577 (vl_api_map_add_domain_t * mp)
5579 vl_api_map_add_domain_reply_t * rmp;
5582 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
5583 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
5584 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
5585 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
5586 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
5588 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
5590 rmp->index = ntohl(index);
5595 vl_api_map_del_domain_t_handler
5596 (vl_api_map_del_domain_t * mp)
5598 vl_api_map_del_domain_reply_t * rmp;
5601 rv = map_delete_domain(ntohl(mp->index));
5603 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
5607 vl_api_map_add_del_rule_t_handler
5608 (vl_api_map_add_del_rule_t * mp)
5610 vl_api_map_del_domain_reply_t * rmp;
5613 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
5615 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
5619 vl_api_map_domain_dump_t_handler
5620 (vl_api_map_domain_dump_t * mp)
5622 vl_api_map_domain_details_t * rmp;
5623 map_main_t *mm = &map_main;
5625 unix_shared_memory_queue_t * q;
5627 if (pool_elts (mm->domains) == 0)
5630 q = vl_api_client_index_to_input_queue (mp->client_index);
5635 pool_foreach(d, mm->domains, ({
5636 /* Make sure every field is initiated (or don't skip the memset()) */
5637 rmp = vl_msg_api_alloc (sizeof (*rmp));
5638 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
5639 rmp->domain_index = htonl(d - mm->domains);
5640 rmp->ea_bits_len = d->ea_bits_len;
5641 rmp->psid_offset = d->psid_offset;
5642 rmp->psid_length = d->psid_length;
5643 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
5644 rmp->ip4_prefix_len = d->ip4_prefix_len;
5645 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
5646 rmp->ip6_prefix_len = d->ip6_prefix_len;
5647 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
5648 rmp->ip6_src_len = d->ip6_src_len;
5649 rmp->mtu = htons(d->mtu);
5650 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
5651 rmp->context = mp->context;
5653 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5658 vl_api_map_rule_dump_t_handler
5659 (vl_api_map_rule_dump_t * mp)
5661 unix_shared_memory_queue_t * q;
5664 vl_api_map_rule_details_t * rmp;
5665 map_main_t *mm = &map_main;
5666 u32 domain_index = ntohl(mp->domain_index);
5669 if (pool_elts (mm->domains) == 0)
5672 d = pool_elt_at_index(mm->domains, domain_index);
5673 if (!d || !d->rules) {
5677 q = vl_api_client_index_to_input_queue (mp->client_index);
5682 for (i = 0; i < (0x1 << d->psid_length); i++) {
5684 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
5687 rmp = vl_msg_api_alloc(sizeof(*rmp));
5688 memset(rmp, 0, sizeof(*rmp));
5689 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
5690 rmp->psid = htons(i);
5691 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
5692 rmp->context = mp->context;
5693 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5698 vl_api_map_summary_stats_t_handler (
5699 vl_api_map_summary_stats_t *mp)
5701 vl_api_map_summary_stats_reply_t *rmp;
5702 vlib_combined_counter_main_t *cm;
5705 u64 total_pkts[VLIB_N_RX_TX];
5706 u64 total_bytes[VLIB_N_RX_TX];
5707 map_main_t *mm = &map_main;
5708 unix_shared_memory_queue_t *q =
5709 vl_api_client_index_to_input_queue(mp->client_index);
5714 rmp = vl_msg_api_alloc (sizeof (*rmp));
5715 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
5716 rmp->context = mp->context;
5719 memset (total_pkts, 0, sizeof (total_pkts));
5720 memset (total_bytes, 0, sizeof (total_bytes));
5722 map_domain_counter_lock (mm);
5723 vec_foreach(cm, mm->domain_counters) {
5724 which = cm - mm->domain_counters;
5726 for (i = 0; i < vec_len(cm->maxi); i++) {
5727 vlib_get_combined_counter (cm, i, &v);
5728 total_pkts[which] += v.packets;
5729 total_bytes[which] += v.bytes;
5733 map_domain_counter_unlock (mm);
5735 /* Note: in network byte order! */
5736 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
5737 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
5738 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
5739 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
5740 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
5741 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
5742 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));
5743 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));
5745 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5748 static void vl_api_ipsec_sa_set_key_t_handler
5749 (vl_api_ipsec_sa_set_key_t * mp)
5751 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5752 vl_api_ipsec_sa_set_key_reply_t *rmp;
5756 sa.id = ntohl(mp->sa_id);
5757 sa.crypto_key_len = mp->crypto_key_length;
5758 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5759 sa.integ_key_len = mp->integrity_key_length;
5760 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5762 rv = ipsec_set_sa_key(vm, &sa);
5764 rv = VNET_API_ERROR_UNIMPLEMENTED;
5767 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
5770 static void vl_api_cop_interface_enable_disable_t_handler
5771 (vl_api_cop_interface_enable_disable_t * mp)
5773 vl_api_cop_interface_enable_disable_reply_t * rmp;
5775 u32 sw_if_index = ntohl(mp->sw_if_index);
5778 VALIDATE_SW_IF_INDEX(mp);
5780 enable_disable = (int) mp->enable_disable;
5782 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5784 BAD_SW_IF_INDEX_LABEL;
5786 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5789 static void vl_api_cop_whitelist_enable_disable_t_handler
5790 (vl_api_cop_whitelist_enable_disable_t * mp)
5792 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
5793 cop_whitelist_enable_disable_args_t _a, *a=&_a;
5794 u32 sw_if_index = ntohl(mp->sw_if_index);
5797 VALIDATE_SW_IF_INDEX(mp);
5799 a->sw_if_index = sw_if_index;
5802 a->default_cop = mp->default_cop;
5803 a->fib_id = ntohl(mp->fib_id);
5805 rv = cop_whitelist_enable_disable (a);
5807 BAD_SW_IF_INDEX_LABEL;
5809 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5812 static void vl_api_get_node_graph_t_handler
5813 (vl_api_get_node_graph_t * mp)
5817 api_main_t * am = &api_main;
5818 vlib_main_t * vm = vlib_get_main();
5820 vl_api_get_node_graph_reply_t * rmp;
5822 pthread_mutex_lock (&am->vlib_rp->mutex);
5823 oldheap = svm_push_data_heap (am->vlib_rp);
5826 * Keep the number of memcpy ops to a minimum (e.g. 1).
5827 * The current size of the serialized vector is
5828 * slightly under 4K.
5830 vec_validate (vector, 4095);
5831 vec_reset_length (vector);
5833 vector = vlib_node_serialize (&vm->node_main, vector);
5835 svm_pop_heap (oldheap);
5836 pthread_mutex_unlock (&am->vlib_rp->mutex);
5838 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5839 rmp->reply_in_shmem = (uword) vector);
5842 static void vl_api_trace_profile_add_t_handler
5843 (vl_api_trace_profile_add_t *mp)
5846 vl_api_trace_profile_add_reply_t * rmp;
5847 clib_error_t *error;
5849 /* Ignoring the profile id as currently a single profile
5851 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5852 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5853 mp->pow_enable, mp->trace_tsp,
5856 clib_error_report(error);
5857 rv = clib_error_get_code(error);
5860 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5863 static void vl_api_trace_profile_apply_t_handler
5864 (vl_api_trace_profile_apply_t *mp)
5867 vl_api_trace_profile_apply_reply_t * rmp;
5869 if (mp->enable != 0) {
5870 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5871 ntohl(mp->prefix_length),
5873 mp->trace_op == IOAM_HBYH_ADD,
5874 mp->trace_op == IOAM_HBYH_POP,
5875 mp->trace_op == IOAM_HBYH_MOD);
5877 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5879 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5882 static void vl_api_trace_profile_del_t_handler
5883 (vl_api_trace_profile_del_t *mp)
5886 vl_api_trace_profile_del_reply_t * rmp;
5887 clib_error_t *error;
5889 error = clear_ioam_rewrite_fn();
5891 clib_error_report(error);
5892 rv = clib_error_get_code(error);
5895 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5899 vl_api_af_packet_create_t_handler
5900 (vl_api_af_packet_create_t *mp)
5902 vlib_main_t *vm = vlib_get_main();
5903 vl_api_af_packet_create_reply_t *rmp;
5905 u8 *host_if_name = NULL;
5907 host_if_name = format(0, "%s", mp->host_if_name);
5908 vec_add1 (host_if_name, 0);
5910 rv = af_packet_create_if(vm, host_if_name,
5911 mp->use_random_hw_addr ? 0 : mp->hw_addr);
5913 vec_free(host_if_name);
5915 REPLY_MACRO(VL_API_AF_PACKET_CREATE_REPLY);
5919 vl_api_af_packet_delete_t_handler
5920 (vl_api_af_packet_delete_t *mp)
5922 vlib_main_t * vm = vlib_get_main();
5923 vl_api_af_packet_delete_reply_t *rmp;
5925 u8 *host_if_name = NULL;
5927 host_if_name = format(0, "%s", mp->host_if_name);
5928 vec_add1 (host_if_name, 0);
5930 rv = af_packet_delete_if(vm, host_if_name);
5932 vec_free(host_if_name);
5934 REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY);
5938 vl_api_policer_add_del_t_handler
5939 (vl_api_policer_add_del_t *mp)
5941 vlib_main_t * vm = vlib_get_main();
5942 vl_api_policer_add_del_reply_t *rmp;
5945 sse2_qos_pol_cfg_params_st cfg;
5946 clib_error_t * error;
5948 name = format(0, "%s", mp->name);
5950 memset (&cfg, 0, sizeof (cfg));
5952 cfg.rnd_type = mp->round_type;
5953 cfg.rate_type = mp->rate_type;
5954 cfg.rb.kbps.cir_kbps = mp->cir;
5955 cfg.rb.kbps.eir_kbps = mp->eir;
5956 cfg.rb.kbps.cb_bytes = mp->cb;
5957 cfg.rb.kbps.eb_bytes = mp->eb;
5959 error = policer_add_del(vm, name, &cfg, mp->is_add);
5962 rv = VNET_API_ERROR_UNSPECIFIED;
5964 REPLY_MACRO(VL_API_POLICER_ADD_DEL_REPLY);
5967 #define BOUNCE_HANDLER(nn) \
5968 static void vl_api_##nn##_t_handler ( \
5969 vl_api_##nn##_t *mp) \
5971 vpe_client_registration_t *reg; \
5972 vpe_api_main_t * vam = &vpe_api_main; \
5973 unix_shared_memory_queue_t * q; \
5975 /* One registration only... */ \
5976 pool_foreach(reg, vam->nn##_registrations, \
5978 q = vl_api_client_index_to_input_queue (reg->client_index); \
5981 * If the queue is stuffed, turf the msg and complain \
5982 * It's unlikely that the intended recipient is \
5983 * alive; avoid deadlock at all costs. \
5985 if (q->cursize == q->maxsize) { \
5986 clib_warning ("ERROR: receiver queue full, drop msg"); \
5987 vl_msg_api_free (mp); \
5990 vl_msg_api_send_shmem (q, (u8 *)&mp); \
5994 vl_msg_api_free (mp); \
5999 * Add vpe's API message handlers to the table.
6000 * vlib has alread mapped shared memory and
6001 * added the client registration handlers.
6002 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
6005 static clib_error_t *
6006 vpe_api_hookup (vlib_main_t *vm)
6008 api_main_t * am = &api_main;
6011 vl_msg_api_set_handlers(VL_API_##N, #n, \
6012 vl_api_##n##_t_handler, \
6014 vl_api_##n##_t_endian, \
6015 vl_api_##n##_t_print, \
6016 sizeof(vl_api_##n##_t), 1);
6017 foreach_vpe_api_msg;
6021 * Manually register the sr tunnel add del msg, so we trace
6022 * enough bytes to capture a typical segment list
6024 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
6025 "sr_tunnel_add_del",
6026 vl_api_sr_tunnel_add_del_t_handler,
6028 vl_api_sr_tunnel_add_del_t_endian,
6029 vl_api_sr_tunnel_add_del_t_print,
6034 * Manually register the sr policy add del msg, so we trace
6035 * enough bytes to capture a typical tunnel name list
6037 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
6038 "sr_policy_add_del",
6039 vl_api_sr_policy_add_del_t_handler,
6041 vl_api_sr_policy_add_del_t_endian,
6042 vl_api_sr_policy_add_del_t_print,
6046 * Trace space for 8 MPLS encap labels, classifier mask+match
6048 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
6049 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
6050 += 5 * sizeof (u32x4);
6051 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
6052 += 5 * sizeof (u32x4);
6053 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
6054 += 16 * sizeof (u32);
6057 * Thread-safe API messages
6059 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
6064 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
6066 static clib_error_t *
6067 vpe_api_init (vlib_main_t *vm)
6069 vpe_api_main_t *am = &vpe_api_main;
6072 am->vnet_main = vnet_get_main();
6073 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
6074 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6075 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6076 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6077 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6078 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
6081 vl_set_memory_region_name ("/vpe-api");
6082 vl_enable_disable_memory_api (vm, 1 /* enable it */);
6087 VLIB_INIT_FUNCTION(vpe_api_init);
6089 static clib_error_t *
6090 chroot_config (vlib_main_t * vm, unformat_input_t * input)
6094 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6096 if (unformat (input, "prefix %s", &chroot_path))
6098 vec_add1 (chroot_path, 0);
6099 vl_set_memory_root_path ((char *)chroot_path);
6102 return clib_error_return (0, "unknown input `%U'",
6103 format_unformat_error, input);
6107 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
6109 void * get_unformat_vnet_sw_interface (void)
6111 return (void *) &unformat_vnet_sw_interface;
6114 #undef vl_api_version
6115 #define vl_api_version(n,v) static u32 vpe_api_version = v;
6116 #include <api/vpe.api.h>
6117 #undef vl_api_version
6119 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
6121 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
6122 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
6123 clib_host_to_net_u32 (mp->api_versions[0]),
6130 static u8 * format_arp_event (u8 * s, va_list * args)
6132 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
6134 s = format (s, "pid %d: %U", event->pid,
6135 format_ip4_address, &event->address);
6139 static clib_error_t *
6140 show_ip4_arp_events_fn (vlib_main_t * vm,
6141 unformat_input_t * input,
6142 vlib_cli_command_t * cmd)
6144 vpe_api_main_t * am = &vpe_api_main;
6145 vl_api_ip4_arp_event_t * event;
6147 if (pool_elts (am->arp_events) == 0) {
6148 vlib_cli_output (vm, "No active arp event registrations");
6152 pool_foreach (event, am->arp_events,
6154 vlib_cli_output (vm, "%U", format_arp_event, event);
6160 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
6161 .path = "show arp event registrations",
6162 .function = show_ip4_arp_events_fn,
6163 .short_help = "Show arp event registrations",