2 *------------------------------------------------------------------
3 * api.c - message handler registration
5 * Copyright (c) 2010 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
23 #include <sys/types.h>
26 #include <netinet/in.h>
33 #include <vppinfra/clib.h>
34 #include <vppinfra/vec.h>
35 #include <vppinfra/hash.h>
36 #include <vppinfra/bitmap.h>
37 #include <vppinfra/fifo.h>
38 #include <vppinfra/time.h>
39 #include <vppinfra/mheap.h>
40 #include <vppinfra/heap.h>
41 #include <vppinfra/pool.h>
42 #include <vppinfra/format.h>
43 #include <vppinfra/error.h>
45 #include <vnet/vnet.h>
46 #include <vnet/l2/l2_input.h>
47 #include <vnet/l2/l2_bd.h>
48 #include <vnet/l2tp/l2tp.h>
49 #include <vnet/ip/ip.h>
50 #include <vnet/unix/tuntap.h>
51 #include <vnet/unix/tapcli.h>
52 #include <vnet/mpls-gre/mpls.h>
53 #include <vnet/dhcp/proxy.h>
54 #include <vnet/dhcp/client.h>
56 #include <vnet/sr/sr.h>
58 #include <vnet/dhcpv6/proxy.h>
59 #include <vlib/vlib.h>
60 #include <vlib/unix/unix.h>
61 #include <vlibapi/api.h>
62 #include <vlibmemory/api.h>
63 #include <vnet/classify/vnet_classify.h>
64 #include <vnet/classify/input_acl.h>
65 #include <vnet/l2/l2_classify.h>
66 #include <vnet/vxlan/vxlan.h>
67 #include <vnet/l2/l2_vtr.h>
68 #include <vnet/nsh-gre/nsh_gre.h>
69 #include <vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.h>
70 #include <vnet/lisp-gpe/lisp_gpe.h>
71 #include <vnet/map/map.h>
72 #include <vnet/cop/cop.h>
73 #include <vnet/ip/ip6_hop_by_hop.h>
76 #undef __included_bihash_template_h__
77 #include <vnet/l2/l2_fib.h>
80 #include <vnet/ipsec/ipsec.h>
81 #include <vnet/ipsec/ikev2.h>
84 #include <vnet/devices/virtio/vhost-user.h>
87 #include <stats/stats.h>
90 #include <vnet/ethernet/ethernet.h>
91 #include <vnet/ethernet/arp_packet.h>
92 #include <vnet/interface.h>
94 #include <vnet/l2/l2_fib.h>
95 #include <vnet/l2/l2_bd.h>
96 #include <api/vpe_msg_enum.h>
99 #define f64_print(a,b)
101 #define vl_typedefs /* define message structures */
102 #include <api/vpe_all_api_h.h>
105 #define vl_endianfun /* define message structures */
106 #include <api/vpe_all_api_h.h>
109 /* instantiate all the print functions we know about */
110 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
112 #include <api/vpe_all_api_h.h>
115 #define REPLY_MACRO(t) \
117 unix_shared_memory_queue_t * q; \
118 rv = vl_msg_api_pd_handler (mp, rv); \
119 q = vl_api_client_index_to_input_queue (mp->client_index); \
123 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
124 rmp->_vl_msg_id = ntohs((t)); \
125 rmp->context = mp->context; \
126 rmp->retval = ntohl(rv); \
128 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
131 #define REPLY_MACRO2(t, body) \
133 unix_shared_memory_queue_t * q; \
134 rv = vl_msg_api_pd_handler (mp, rv); \
135 q = vl_api_client_index_to_input_queue (mp->client_index); \
139 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
140 rmp->_vl_msg_id = ntohs((t)); \
141 rmp->context = mp->context; \
142 rmp->retval = ntohl(rv); \
143 do {body;} while (0); \
144 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
147 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
149 #define VALIDATE_SW_IF_INDEX(mp) \
150 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
151 vnet_main_t *__vnm = vnet_get_main(); \
152 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
154 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
155 goto bad_sw_if_index; \
159 #define BAD_SW_IF_INDEX_LABEL \
165 #define VALIDATE_RX_SW_IF_INDEX(mp) \
166 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
167 vnet_main_t *__vnm = vnet_get_main(); \
168 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
169 __rx_sw_if_index)) { \
170 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
171 goto bad_rx_sw_if_index; \
175 #define BAD_RX_SW_IF_INDEX_LABEL \
177 bad_rx_sw_if_index: \
181 #define VALIDATE_TX_SW_IF_INDEX(mp) \
182 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
183 vnet_main_t *__vnm = vnet_get_main(); \
184 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
185 __tx_sw_if_index)) { \
186 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
187 goto bad_tx_sw_if_index; \
191 #define BAD_TX_SW_IF_INDEX_LABEL \
193 bad_tx_sw_if_index: \
199 #define VALIDATE_SW_IF_INDEX(mp)
200 #define BAD_SW_IF_INDEX_LABEL
201 #define VALIDATE_RX_SW_IF_INDEX(mp)
202 #define BAD_RX_SW_IF_INDEX_LABEL
203 #define VALIDATE_TX_SW_IF_INDEX(mp)
204 #define BAD_TX_SW_IF_INDEX_LABEL
206 #endif /* CLIB_DEBUG > 0 */
208 #define foreach_vpe_api_msg \
209 _(WANT_INTERFACE_EVENTS, want_interface_events) \
210 _(WANT_FROM_NETCONF_SERVER, want_from_netconf_server) \
211 _(WANT_TO_NETCONF_SERVER, want_to_netconf_server) \
212 _(WANT_FROM_NETCONF_CLIENT, want_from_netconf_client) \
213 _(WANT_TO_NETCONF_CLIENT, want_to_netconf_client) \
214 _(FROM_NETCONF_SERVER, from_netconf_server) \
215 _(TO_NETCONF_SERVER, to_netconf_server) \
216 _(FROM_NETCONF_CLIENT, from_netconf_client) \
217 _(TO_NETCONF_CLIENT, to_netconf_client) \
218 _(WANT_OAM_EVENTS, want_oam_events) \
219 _(OAM_ADD_DEL, oam_add_del) \
220 _(SW_INTERFACE_DUMP, sw_interface_dump) \
221 _(SW_INTERFACE_DETAILS, sw_interface_details) \
222 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
223 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
224 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
225 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
226 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
227 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
228 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
229 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
230 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
231 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
232 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
233 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
234 _(L2FIB_ADD_DEL, l2fib_add_del) \
235 _(L2_FLAGS, l2_flags) \
236 _(BRIDGE_FLAGS, bridge_flags) \
237 _(TAP_CONNECT, tap_connect) \
238 _(TAP_MODIFY, tap_modify) \
239 _(TAP_DELETE, tap_delete) \
240 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
241 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
242 _(CREATE_SUBIF, create_subif) \
243 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
244 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
245 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
246 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
247 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
248 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
249 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
250 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
251 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
252 _(RESET_FIB, reset_fib) \
253 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
254 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
255 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
256 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
257 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
258 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
259 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
260 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
261 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
262 sw_interface_ip6_set_link_local_address) \
263 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
264 _(CREATE_LOOPBACK, create_loopback) \
265 _(CONTROL_PING, control_ping) \
266 _(CLI_REQUEST, cli_request) \
267 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
268 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
269 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
270 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
271 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
272 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
273 _(GET_NODE_INDEX, get_node_index) \
274 _(ADD_NODE_NEXT, add_node_next) \
275 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
276 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
277 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
278 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
279 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
280 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
281 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
282 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
283 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
284 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
285 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
286 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
287 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
288 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
289 _(IP_ADDRESS_DUMP, ip_address_dump) \
290 _(IP_DUMP, ip_dump) \
291 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
292 _(SHOW_VERSION, show_version) \
293 _(NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel) \
294 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
295 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
296 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel) \
297 _(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel) \
298 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
299 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
300 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
301 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
302 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
303 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
304 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
305 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
306 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
307 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
308 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
309 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
310 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
311 _(DELETE_LOOPBACK, delete_loopback) \
312 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
313 _(MAP_ADD_DOMAIN, map_add_domain) \
314 _(MAP_DEL_DOMAIN, map_del_domain) \
315 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
316 _(MAP_DOMAIN_DUMP, map_domain_dump) \
317 _(MAP_RULE_DUMP, map_rule_dump) \
318 _(MAP_SUMMARY_STATS, map_summary_stats) \
319 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
320 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
321 _(GET_NODE_GRAPH, get_node_graph) \
322 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
323 _(TRACE_PROFILE_ADD, trace_profile_add) \
324 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
325 _(TRACE_PROFILE_DEL, trace_profile_del)
328 #define QUOTE(x) QUOTE_(x)
330 #define foreach_registration_hash \
331 _(interface_events) \
332 _(to_netconf_server) \
333 _(from_netconf_server) \
334 _(to_netconf_client) \
335 _(from_netconf_client) \
339 RESOLVE_IP4_ADD_DEL_ROUTE=1,
340 RESOLVE_IP6_ADD_DEL_ROUTE,
341 RESOLVE_MPLS_ETHERNET_ADD_DEL,
347 vl_api_ip_add_del_route_t r;
348 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
354 #define _(a) uword *a##_registration_hash; \
355 vpe_client_registration_t * a##_registrations;
356 foreach_registration_hash
359 /* notifications happen really early in the game */
360 u8 link_state_process_up;
362 /* ip4 pending route adds */
363 pending_route_t * pending_routes;
365 /* ip4 arp event registration pool */
366 vl_api_ip4_arp_event_t * arp_events;
369 vlib_main_t * vlib_main;
370 vnet_main_t * vnet_main;
373 static vlib_node_registration_t vpe_resolver_process_node;
374 static vpe_api_main_t vpe_api_main;
376 static void send_sw_interface_flags (vpe_api_main_t * am,
377 unix_shared_memory_queue_t *q,
378 vnet_sw_interface_t * swif);
379 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
380 unix_shared_memory_queue_t *q,
383 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
386 /* Clean up all registrations belonging to the indicated client */
387 int vl_api_memclnt_delete_callback (u32 client_index)
389 vpe_api_main_t * vam = &vpe_api_main;
390 vpe_client_registration_t *rp;
392 int stats_memclnt_delete_callback (u32 client_index);
394 stats_memclnt_delete_callback (client_index);
397 p = hash_get (vam->a##_registration_hash, client_index); \
399 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
400 pool_put (vam->a##_registrations, rp); \
401 hash_unset (vam->a##_registration_hash, client_index); \
403 foreach_registration_hash;
408 #define API_LINK_STATE_EVENT 1
409 #define API_ADMIN_UP_DOWN_EVENT 2
412 event_data_cmp (void * a1, void * a2)
417 return (word) e1[0] - (word) e2[0];
421 link_state_process (vlib_main_t * vm,
422 vlib_node_runtime_t * rt,
425 vpe_api_main_t * vam = &vpe_api_main;
426 vnet_main_t * vnm = vam->vnet_main;
427 vnet_sw_interface_t * swif;
428 uword * event_data = 0;
429 vpe_client_registration_t *reg;
431 u32 prev_sw_if_index;
432 unix_shared_memory_queue_t * q;
434 vam->link_state_process_up = 1;
437 vlib_process_wait_for_event (vm);
439 /* Unified list of changed link or admin state sw_if_indices */
440 vlib_process_get_events_with_type
441 (vm, &event_data, API_LINK_STATE_EVENT);
442 vlib_process_get_events_with_type
443 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
445 /* Sort, so we can eliminate duplicates */
446 vec_sort_with_function (event_data, event_data_cmp);
448 prev_sw_if_index = ~0;
450 for (i = 0; i < vec_len(event_data); i++) {
451 /* Only one message per swif */
452 if (prev_sw_if_index == event_data[i])
454 prev_sw_if_index = event_data[i];
456 pool_foreach(reg, vam->interface_events_registrations,
458 q = vl_api_client_index_to_input_queue (reg->client_index);
460 // sw_interface may be deleted already
461 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
464 swif = vnet_get_sw_interface (vnm, event_data[i]);
465 send_sw_interface_flags (vam, q, swif);
470 vec_reset_length (event_data);
476 static clib_error_t *
477 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
478 static clib_error_t *
479 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
481 VLIB_REGISTER_NODE (link_state_process_node,static) = {
482 .function = link_state_process,
483 .type = VLIB_NODE_TYPE_PROCESS,
484 .name = "vpe-link-state-process",
487 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
488 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
490 static clib_error_t *
491 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
493 vpe_api_main_t * vam = &vpe_api_main;
494 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
496 if (vam->link_state_process_up)
497 vlib_process_signal_event (vam->vlib_main,
498 link_state_process_node.index,
499 API_LINK_STATE_EVENT,
504 static clib_error_t *
505 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
507 vpe_api_main_t * vam = &vpe_api_main;
510 * Note: it's perfectly fair to set a subif admin up / admin down.
511 * Note the subtle distinction between this routine and the previous
514 if (vam->link_state_process_up)
515 vlib_process_signal_event (vam->vlib_main,
516 link_state_process_node.index,
517 API_ADMIN_UP_DOWN_EVENT,
522 #define pub_sub_handler(lca,UCA) \
523 static void vl_api_want_##lca##_t_handler ( \
524 vl_api_want_##lca##_t *mp) \
526 vpe_api_main_t *vam = &vpe_api_main; \
527 vpe_client_registration_t *rp; \
528 vl_api_want_##lca##_reply_t *rmp; \
532 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
534 if (mp->enable_disable) { \
535 clib_warning ("pid %d: already enabled...", mp->pid); \
536 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
539 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
540 pool_put (vam->lca##_registrations, rp); \
541 hash_unset (vam->lca##_registration_hash, \
546 if (mp->enable_disable == 0) { \
547 clib_warning ("pid %d: already disabled...", mp->pid); \
548 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
551 pool_get (vam->lca##_registrations, rp); \
552 rp->client_index = mp->client_index; \
553 rp->client_pid = mp->pid; \
554 hash_set (vam->lca##_registration_hash, rp->client_index, \
555 rp - vam->lca##_registrations); \
558 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
561 pub_sub_handler (interface_events,INTERFACE_EVENTS)
562 pub_sub_handler (from_netconf_server,FROM_NETCONF_SERVER)
563 pub_sub_handler (to_netconf_server,TO_NETCONF_SERVER)
564 pub_sub_handler (from_netconf_client,FROM_NETCONF_CLIENT)
565 pub_sub_handler (to_netconf_client,TO_NETCONF_CLIENT)
566 pub_sub_handler (oam_events,OAM_EVENTS)
568 #define RESOLUTION_EVENT 1
569 #define RESOLUTION_PENDING_EVENT 2
570 #define IP4_ARP_EVENT 3
572 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
573 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
574 static int mpls_ethernet_add_del_tunnel_2_t_handler
575 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
577 void handle_ip4_arp_event (u32 pool_index)
579 vpe_api_main_t * vam = &vpe_api_main;
580 vnet_main_t * vnm = vam->vnet_main;
581 vlib_main_t * vm = vam->vlib_main;
582 vl_api_ip4_arp_event_t * event;
583 vl_api_ip4_arp_event_t * mp;
584 unix_shared_memory_queue_t * q;
586 /* Client can cancel, die, etc. */
587 if (pool_is_free_index (vam->arp_events, pool_index))
590 event = pool_elt_at_index (vam->arp_events, pool_index);
592 q = vl_api_client_index_to_input_queue (event->client_index);
594 (void) vnet_add_del_ip4_arp_change_event
595 (vnm, arp_change_delete_callback,
596 event->pid, &event->address,
597 vpe_resolver_process_node.index, IP4_ARP_EVENT,
598 ~0 /* pool index, notused */, 0 /* is_add */);
602 if (q->cursize < q->maxsize) {
603 mp = vl_msg_api_alloc (sizeof (*mp));
604 memcpy (mp, event, sizeof (*mp));
605 vl_msg_api_send_shmem (q, (u8 *)&mp);
607 static f64 last_time;
609 * Throttle syslog msgs.
610 * It's pretty tempting to just revoke the registration...
612 if (vlib_time_now (vm) > last_time + 10.0) {
613 clib_warning ("arp event for %U to pid %d: queue stuffed!",
614 format_ip4_address, &event->address, event->pid);
615 last_time = vlib_time_now(vm);
621 resolver_process (vlib_main_t * vm,
622 vlib_node_runtime_t * rt,
626 uword *event_data = 0;
628 vpe_api_main_t * vam = &vpe_api_main;
629 pending_route_t * pr;
630 vl_api_ip_add_del_route_t * adr;
631 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
632 u32 * resolution_failures = 0;
637 vlib_process_wait_for_event_or_clock (vm, timeout);
639 event_type = vlib_process_get_events (vm, &event_data);
641 switch (event_type) {
642 case RESOLUTION_PENDING_EVENT:
646 case RESOLUTION_EVENT:
647 for (i = 0; i < vec_len(event_data); i++) {
649 * Resolution events can occur long after the
650 * original request has timed out. $$$ add a cancel
653 if (pool_is_free_index (vam->pending_routes, event_data[i]))
656 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
660 switch (pr->resolve_type) {
661 case RESOLVE_IP4_ADD_DEL_ROUTE:
662 rv = ip4_add_del_route_t_handler (adr);
663 clib_warning ("resolver: add %U/%d via %U %s",
665 (ip4_address_t *)&(adr->dst_address),
666 adr->dst_address_length,
668 (ip4_address_t *)&(adr->next_hop_address),
669 (rv >= 0) ? "succeeded" : "failed");
672 case RESOLVE_IP6_ADD_DEL_ROUTE:
673 rv = ip6_add_del_route_t_handler (adr);
674 clib_warning ("resolver: add %U/%d via %U %s",
676 (ip6_address_t *)&(adr->dst_address),
677 adr->dst_address_length,
679 (ip6_address_t *)&(adr->next_hop_address),
680 (rv >= 0) ? "succeeded" : "failed");
683 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
684 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
685 clib_warning ("resolver: add mpls-o-e via %U %s",
687 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
688 (rv >= 0) ? "succeeded" : "failed");
692 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
694 pool_put (vam->pending_routes, pr);
699 for (i = 0; i < vec_len(event_data); i++)
700 handle_ip4_arp_event (event_data[i]);
703 case ~0: /* timeout, retry pending resolutions */
704 pool_foreach (pr, vam->pending_routes,
710 /* May fail, e.g. due to interface down */
711 switch (pr->resolve_type) {
712 case RESOLVE_IP4_ADD_DEL_ROUTE:
713 e = ip4_probe_neighbor
714 (vm, (ip4_address_t *)&(adr->next_hop_address),
715 ntohl(adr->next_hop_sw_if_index));
718 case RESOLVE_IP6_ADD_DEL_ROUTE:
719 e = ip6_probe_neighbor
720 (vm, (ip6_address_t *)&(adr->next_hop_address),
721 ntohl(adr->next_hop_sw_if_index));
724 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
726 e = ip4_probe_neighbor
728 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
729 pme->resolve_opaque);
733 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
737 clib_error_report (e);
739 adr->resolve_attempts = 1;
741 pme->resolve_attempts = 1;
745 adr->resolve_attempts -= 1;
746 if (adr->resolve_attempts == 0)
747 vec_add1 (resolution_failures,
748 pr - vam->pending_routes);
750 pme->resolve_attempts -= 1;
751 if (pme->resolve_attempts == 0)
752 vec_add1 (resolution_failures,
753 pr - vam->pending_routes);
757 for (i = 0; i < vec_len (resolution_failures); i++) {
758 pr = pool_elt_at_index (vam->pending_routes,
759 resolution_failures[i]);
763 switch (pr->resolve_type) {
764 case RESOLVE_IP4_ADD_DEL_ROUTE:
765 clib_warning ("resolver: add %U/%d via %U retry failure",
767 (ip4_address_t *)&(adr->dst_address),
768 adr->dst_address_length,
770 (ip4_address_t *)&(adr->next_hop_address));
773 case RESOLVE_IP6_ADD_DEL_ROUTE:
774 clib_warning ("resolver: add %U/%d via %U retry failure",
776 (ip6_address_t *)&(adr->dst_address),
777 adr->dst_address_length,
779 (ip6_address_t *)&(adr->next_hop_address));
782 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
783 clib_warning ("resolver: add mpls-o-e via %U retry failure",
785 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
789 clib_warning ("BUG");
791 pool_put(vam->pending_routes, pr);
793 vec_reset_length (resolution_failures);
796 if (pool_elts (vam->pending_routes) == 0)
798 vec_reset_length (event_data);
800 return 0; /* or not */
803 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
804 .function = resolver_process,
805 .type = VLIB_NODE_TYPE_PROCESS,
806 .name = "vpe-route-resolver-process",
809 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
811 ip4_main_t * im = &ip4_main;
812 ip_lookup_main_t * lm = &im->lookup_main;
813 vnet_classify_main_t * cm = &vnet_classify_main;
814 stats_main_t * sm = &stats_main;
815 ip4_add_del_route_args_t a;
816 ip4_address_t next_hop_address;
818 vpe_api_main_t * vam = &vpe_api_main;
819 vnet_main_t * vnm = vam->vnet_main;
820 vlib_main_t * vm = vlib_get_main();
821 pending_route_t * pr;
822 vl_api_ip_add_del_route_t * adr;
826 ip_adjacency_t *nh_adj, *add_adj = 0;
828 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
830 if (mp->create_vrf_if_needed) {
832 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
834 fib_index = f->index;
836 /* No such VRF, and we weren't asked to create one */
837 return VNET_API_ERROR_NO_SUCH_FIB;
843 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
844 ntohl(mp->next_hop_sw_if_index)))
845 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
847 memcpy (next_hop_address.data, mp->next_hop_address,
848 sizeof (next_hop_address.data));
850 /* Arp for the next_hop if necessary */
851 if (mp->is_add && mp->resolve_if_needed) {
853 ip_adjacency_t * adj;
855 lookup_result = ip4_fib_lookup_with_table
856 (im, fib_index, &next_hop_address, 1 /* disable default route */);
858 adj = ip_get_adjacency (lm, lookup_result);
860 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
861 pool_get (vam->pending_routes, pr);
862 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
864 memcpy (adr, mp, sizeof (*adr));
865 /* recursion block, "just in case" */
866 adr->resolve_if_needed = 0;
867 adr->resolve_attempts = ntohl(mp->resolve_attempts);
868 vnet_register_ip4_arp_resolution_event
869 (vnm, &next_hop_address, vpe_resolver_process_node.index,
870 RESOLUTION_EVENT, pr - vam->pending_routes);
872 vlib_process_signal_event
873 (vm, vpe_resolver_process_node.index,
874 RESOLUTION_PENDING_EVENT, 0 /* data */);
876 /* The interface may be down, etc. */
877 e = ip4_probe_neighbor
878 (vm, (ip4_address_t *)&(mp->next_hop_address),
879 ntohl(mp->next_hop_sw_if_index));
882 clib_error_report(e);
884 return VNET_API_ERROR_IN_PROGRESS;
888 if (mp->is_multipath) {
891 dslock (sm, 1 /* release hint */, 10 /* tag */);
894 flags = IP4_ROUTE_FLAG_ADD;
896 flags = IP4_ROUTE_FLAG_DEL;
899 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
901 ip4_add_del_route_next_hop (im, flags,
902 (ip4_address_t *) mp->dst_address,
903 (u32) mp->dst_address_length,
904 (ip4_address_t *) mp->next_hop_address,
905 ntohl(mp->next_hop_sw_if_index),
906 (u32) mp->next_hop_weight,
913 memset (&a, 0, sizeof (a));
914 memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
916 a.dst_address_length = mp->dst_address_length;
918 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
919 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
920 a.table_index_or_table_id = fib_index;
925 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
927 dslock (sm, 1 /* release hint */, 2 /* tag */);
931 ai = lm->drop_adj_index;
932 else if (mp->is_local)
933 ai = lm->local_adj_index;
934 else if (mp->is_classify) {
936 memset(&cadj, 0, sizeof(cadj));
937 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
938 cadj.classify.table_index = ntohl(mp->classify_table_index);
939 if (pool_is_free_index (cm->tables, cadj.classify.table_index)) {
941 return VNET_API_ERROR_NO_SUCH_TABLE;
943 vec_add1 (add_adj, cadj);
947 ai = ip4_fib_lookup_with_table
948 (im, fib_index, &next_hop_address,
949 1 /* disable default route */);
950 if (ai == lm->miss_adj_index) {
952 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
956 nh_adj = ip_get_adjacency (lm, ai);
957 vec_add1 (add_adj, nh_adj[0]);
958 if (mp->lookup_in_vrf) {
959 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
961 add_adj[0].explicit_fib_index = p[0];
965 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
969 ip_adjacency_t * adj;
970 int disable_default_route = 1;
972 /* Trying to delete the default route? */
973 if (a.dst_address.as_u32 == 0 &&
974 a.dst_address_length == 0)
975 disable_default_route = 0;
977 ai = ip4_fib_lookup_with_table
978 (im, fib_index, &a.dst_address, disable_default_route);
979 if (ai == lm->miss_adj_index) {
981 return VNET_API_ERROR_UNKNOWN_DESTINATION;
984 adj = ip_get_adjacency (lm, ai);
985 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
987 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
994 a.n_add_adj = vec_len(add_adj);
995 ip4_add_del_route (im, &a);
1003 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1005 ip6_main_t * im = &ip6_main;
1006 ip_lookup_main_t * lm = &im->lookup_main;
1007 vnet_main_t * vnm = vnet_get_main();
1008 vlib_main_t * vm = vlib_get_main();
1009 vpe_api_main_t * vam = &vpe_api_main;
1010 stats_main_t * sm = &stats_main;
1011 ip6_add_del_route_args_t a;
1012 ip6_address_t next_hop_address;
1013 pending_route_t * pr;
1014 vl_api_ip_add_del_route_t * adr;
1019 ip_adjacency_t * nh_adj, * add_adj = 0;
1022 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1025 if (mp->create_vrf_if_needed) {
1027 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1029 fib_index = f->index;
1031 /* No such VRF, and we weren't asked to create one */
1032 return VNET_API_ERROR_NO_SUCH_FIB;
1038 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1039 ntohl(mp->next_hop_sw_if_index)))
1040 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1042 memcpy (next_hop_address.as_u8, mp->next_hop_address,
1043 sizeof (next_hop_address.as_u8));
1045 /* Arp for the next_hop if necessary */
1046 if (mp->is_add && mp->resolve_if_needed) {
1048 ip_adjacency_t * adj;
1050 lookup_result = ip6_fib_lookup_with_table
1051 (im, fib_index, &next_hop_address);
1053 adj = ip_get_adjacency (lm, lookup_result);
1055 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1056 pool_get (vam->pending_routes, pr);
1058 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1059 memcpy (adr, mp, sizeof (*adr));
1060 /* recursion block, "just in case" */
1061 adr->resolve_if_needed = 0;
1062 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1063 vnet_register_ip6_neighbor_resolution_event
1064 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1065 RESOLUTION_EVENT, pr - vam->pending_routes);
1067 vlib_process_signal_event
1068 (vm, vpe_resolver_process_node.index,
1069 RESOLUTION_PENDING_EVENT, 0 /* data */);
1071 /* The interface may be down, etc. */
1072 e = ip6_probe_neighbor
1073 (vm, (ip6_address_t *)&(mp->next_hop_address),
1074 ntohl(mp->next_hop_sw_if_index));
1077 clib_error_report(e);
1079 return VNET_API_ERROR_IN_PROGRESS;
1083 if (mp->is_multipath) {
1086 dslock (sm, 1 /* release hint */, 11 /* tag */);
1089 flags = IP6_ROUTE_FLAG_ADD;
1091 flags = IP6_ROUTE_FLAG_DEL;
1094 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1096 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1097 (u32) mp->dst_address_length,
1098 (ip6_address_t *)mp->next_hop_address,
1099 ntohl(mp->next_hop_sw_if_index),
1100 (u32) mp->next_hop_weight,
1107 memset (&a, 0, sizeof (a));
1108 memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1110 a.dst_address_length = mp->dst_address_length;
1112 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1113 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1114 a.table_index_or_table_id = fib_index;
1119 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1121 dslock (sm, 1 /* release hint */, 3 /* tag */);
1125 ai = lm->drop_adj_index;
1126 else if (mp->is_local)
1127 ai = lm->local_adj_index;
1129 ai = ip6_fib_lookup_with_table
1130 (im, fib_index, &next_hop_address);
1131 if (ai == lm->miss_adj_index) {
1133 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1137 nh_adj = ip_get_adjacency (lm, ai);
1138 vec_add1 (add_adj, nh_adj[0]);
1139 if (mp->lookup_in_vrf) {
1140 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1142 add_adj[0].explicit_fib_index = p[0];
1146 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1150 ip_adjacency_t * adj;
1152 ai = ip6_fib_lookup_with_table
1153 (im, fib_index, &a.dst_address);
1154 if (ai == lm->miss_adj_index) {
1156 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1158 adj = ip_get_adjacency (lm, ai);
1159 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1161 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1166 a.add_adj = add_adj;
1167 a.n_add_adj = vec_len(add_adj);
1168 ip6_add_del_route (im, &a);
1176 void vl_api_ip_add_del_route_t_handler (
1177 vl_api_ip_add_del_route_t *mp)
1179 vl_api_ip_add_del_route_reply_t * rmp;
1181 vnet_main_t * vnm = vnet_get_main();
1186 rv = ip6_add_del_route_t_handler (mp);
1188 rv = ip4_add_del_route_t_handler (mp);
1190 rv = (rv == 0) ? vnm->api_errno : rv;
1192 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1195 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1196 u32 sw_if_index, u8 *next_hop_addr)
1198 vl_api_ip_add_del_route_t mp;
1201 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1204 * Configure default IP route:
1205 * - ip route add 0.0.0.0/1 via <GW IP>
1206 * - ip route add 128.0.0.0/1 via <GW IP>
1208 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1210 mp.resolve_attempts = ~0;
1211 mp.resolve_if_needed = 1;
1213 mp.is_ipv6 = is_ipv6;
1214 mp.next_hop_weight = 1;
1216 memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1219 rv = ip6_add_del_route_t_handler (&mp);
1222 mp.dst_address_length = 1;
1224 mp.dst_address[0] = 0;
1225 rv = ip4_add_del_route_t_handler (&mp);
1227 mp.dst_address[0] = 128;
1228 rv |= ip4_add_del_route_t_handler (&mp);
1232 clib_error_return (0, "failed to config default IP route");
1237 vl_api_sw_interface_add_del_address_t_handler
1238 (vl_api_sw_interface_add_del_address_t *mp)
1240 vlib_main_t *vm = vlib_get_main();
1241 vl_api_sw_interface_add_del_address_reply_t * rmp;
1245 VALIDATE_SW_IF_INDEX(mp);
1247 is_del = mp->is_add == 0;
1250 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1251 else if (mp->is_ipv6)
1252 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1253 (void *)mp->address,
1254 mp->address_length, is_del);
1256 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1257 (void *) mp->address,
1258 mp->address_length, is_del);
1260 BAD_SW_IF_INDEX_LABEL;
1262 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1266 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1269 u32 table_id = ntohl(mp->vrf_id);
1270 u32 sw_if_index = ntohl(mp->sw_if_index);
1271 vl_api_sw_interface_set_table_reply_t * rmp;
1272 stats_main_t * sm = &stats_main;
1274 VALIDATE_SW_IF_INDEX(mp);
1276 dslock (sm, 1 /* release hint */, 4 /* tag */);
1279 ip6_main_t * im = &ip6_main;
1281 find_ip6_fib_by_table_index_or_id (im, table_id,
1282 IP6_ROUTE_FLAG_TABLE_ID);
1284 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1285 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1287 rv = VNET_API_ERROR_NO_SUCH_FIB;
1290 ip4_main_t * im = &ip4_main;
1291 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1292 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1294 /* Truthfully this can't fail */
1296 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1297 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1299 rv = VNET_API_ERROR_NO_SUCH_FIB;
1304 BAD_SW_IF_INDEX_LABEL;
1306 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1310 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1312 vlib_main_t *vm = vlib_get_main();
1313 vl_api_sw_interface_set_vpath_reply_t * rmp;
1316 u32 sw_if_index = ntohl(mp->sw_if_index);
1317 ip4_main_t *ip4m = &ip4_main;
1318 ip6_main_t *ip6m = &ip6_main;
1319 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1320 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1321 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1322 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1323 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1324 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1326 VALIDATE_SW_IF_INDEX(mp);
1328 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1330 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1331 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1332 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1333 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1334 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1335 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1336 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1337 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1338 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1339 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1340 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1341 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1342 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1343 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1344 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1345 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1347 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1348 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1349 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1350 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1351 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1352 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1353 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1354 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1355 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1356 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1357 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1358 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1359 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1360 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1361 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1362 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1365 BAD_SW_IF_INDEX_LABEL;
1367 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1371 vl_api_sw_interface_set_l2_xconnect_t_handler (
1372 vl_api_sw_interface_set_l2_xconnect_t *mp)
1374 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1376 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1377 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1378 vlib_main_t *vm = vlib_get_main();
1379 vnet_main_t *vnm = vnet_get_main();
1381 VALIDATE_RX_SW_IF_INDEX(mp);
1384 VALIDATE_TX_SW_IF_INDEX(mp);
1385 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1386 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1388 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1391 BAD_RX_SW_IF_INDEX_LABEL;
1392 BAD_TX_SW_IF_INDEX_LABEL;
1394 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1398 vl_api_sw_interface_set_l2_bridge_t_handler (
1399 vl_api_sw_interface_set_l2_bridge_t *mp)
1401 bd_main_t * bdm = &bd_main;
1402 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1404 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1405 u32 bd_id = ntohl(mp->bd_id);
1409 vlib_main_t *vm = vlib_get_main();
1410 vnet_main_t *vnm = vnet_get_main();
1412 VALIDATE_RX_SW_IF_INDEX(mp);
1414 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1417 //VALIDATE_TX_SW_IF_INDEX(mp);
1418 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1419 rx_sw_if_index, bd_index, bvi, shg, 0);
1421 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1424 BAD_RX_SW_IF_INDEX_LABEL;
1426 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1430 vl_api_bridge_domain_add_del_t_handler (
1431 vl_api_bridge_domain_add_del_t *mp)
1433 vlib_main_t * vm = vlib_get_main ();
1434 bd_main_t * bdm = &bd_main;
1435 vl_api_bridge_domain_add_del_reply_t * rmp;
1437 u32 enable_flags = 0, disable_flags = 0;
1438 u32 bd_id = ntohl(mp->bd_id);
1442 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1445 enable_flags |= L2_FLOOD;
1447 disable_flags |= L2_FLOOD;
1450 enable_flags |= L2_UU_FLOOD;
1452 disable_flags |= L2_UU_FLOOD;
1455 enable_flags |= L2_FWD;
1457 disable_flags |= L2_FWD;
1460 enable_flags |= L2_ARP_TERM;
1462 disable_flags |= L2_ARP_TERM;
1465 enable_flags |= L2_LEARN;
1467 disable_flags |= L2_LEARN;
1470 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1473 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1476 rv = bd_delete_bd_index(bdm, bd_id);
1478 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1481 static void vl_api_bridge_domain_details_t_handler (
1482 vl_api_bridge_domain_details_t * mp)
1484 clib_warning ("BUG");
1487 static void vl_api_bridge_domain_sw_if_details_t_handler (
1488 vl_api_bridge_domain_sw_if_details_t * mp)
1490 clib_warning ("BUG");
1493 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1494 l2_bridge_domain_t * bd_config,
1497 vl_api_bridge_domain_details_t * mp;
1499 mp = vl_msg_api_alloc (sizeof (*mp));
1500 memset (mp, 0, sizeof (*mp));
1501 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1502 mp->bd_id = ntohl (bd_config->bd_id);
1503 mp->flood = bd_feature_flood (bd_config);
1504 mp->uu_flood = bd_feature_uu_flood (bd_config);
1505 mp->forward = bd_feature_forward (bd_config);
1506 mp->learn = bd_feature_learn (bd_config);
1507 mp->arp_term = bd_feature_arp_term (bd_config);
1508 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1509 mp->n_sw_ifs = ntohl (n_sw_ifs);
1511 vl_msg_api_send_shmem (q, (u8 *)&mp);
1514 static void send_bd_sw_if_details (l2input_main_t * l2im,
1515 unix_shared_memory_queue_t *q,
1516 l2_flood_member_t * member, u32 bd_id)
1518 vl_api_bridge_domain_sw_if_details_t * mp;
1519 l2_input_config_t * input_cfg;
1521 mp = vl_msg_api_alloc (sizeof (*mp));
1522 memset (mp, 0, sizeof (*mp));
1523 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1524 mp->bd_id = ntohl (bd_id);
1525 mp->sw_if_index = ntohl (member->sw_if_index);
1526 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1527 mp->shg = input_cfg->shg;
1529 vl_msg_api_send_shmem (q, (u8 *)&mp);
1532 static void vl_api_bridge_domain_dump_t_handler (
1533 vl_api_bridge_domain_dump_t *mp)
1535 bd_main_t * bdm = &bd_main;
1536 l2input_main_t * l2im = &l2input_main;
1537 unix_shared_memory_queue_t * q;
1538 l2_bridge_domain_t * bd_config;
1539 u32 bd_id, bd_index;
1542 q = vl_api_client_index_to_input_queue (mp->client_index);
1547 bd_id = ntohl(mp->bd_id);
1549 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1550 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1551 for (; bd_index < end; bd_index++) {
1552 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1553 /* skip dummy bd_id 0 */
1554 if (bd_config && (bd_config->bd_id > 0)) {
1556 l2_flood_member_t * m;
1558 n_sw_ifs = vec_len (bd_config->members);
1559 send_bridge_domain_details (q, bd_config, n_sw_ifs);
1561 vec_foreach (m, bd_config->members) {
1562 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id);
1569 vl_api_l2fib_add_del_t_handler (
1570 vl_api_l2fib_add_del_t *mp)
1572 bd_main_t * bdm = &bd_main;
1573 l2input_main_t * l2im = &l2input_main;
1574 vl_api_l2fib_add_del_reply_t * rmp;
1577 u32 sw_if_index = ntohl(mp->sw_if_index);
1578 u32 bd_id = ntohl(mp->bd_id);
1586 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1588 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1589 goto bad_sw_if_index;
1594 VALIDATE_SW_IF_INDEX(mp);
1595 if (vec_len(l2im->configs) <= sw_if_index) {
1596 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1597 goto bad_sw_if_index;
1599 l2_input_config_t * config;
1600 config = vec_elt_at_index(l2im->configs, sw_if_index);
1601 if (config->bridge == 0) {
1602 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1603 goto bad_sw_if_index;
1606 static_mac = mp->static_mac ? 1 : 0;
1607 filter_mac = mp->filter_mac ? 1 : 0;
1608 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1611 l2fib_del_entry(mac, bd_index);
1614 BAD_SW_IF_INDEX_LABEL;
1616 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1620 vl_api_l2_flags_t_handler (
1621 vl_api_l2_flags_t *mp)
1623 vl_api_l2_flags_reply_t * rmp;
1625 u32 sw_if_index = ntohl(mp->sw_if_index);
1626 u32 flags = ntohl(mp->feature_bitmap);
1629 VALIDATE_SW_IF_INDEX(mp);
1632 if (flags & L2INPUT_FEAT_ ## a) \
1633 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1634 foreach_l2input_feat;
1637 BAD_SW_IF_INDEX_LABEL;
1639 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1643 vl_api_bridge_flags_t_handler (
1644 vl_api_bridge_flags_t *mp)
1646 vlib_main_t *vm = vlib_get_main();
1647 bd_main_t * bdm = &bd_main;
1648 vl_api_bridge_flags_reply_t * rmp;
1650 u32 bd_id = ntohl(mp->bd_id);
1652 u32 flags = ntohl(mp->feature_bitmap);
1655 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1657 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1663 bd_set_flags(vm, bd_index, flags, mp->is_set);
1666 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1667 rmp->resulting_feature_bitmap = ntohl(flags));
1671 vl_api_bd_ip_mac_add_del_t_handler (
1672 vl_api_bd_ip_mac_add_del_t *mp)
1674 bd_main_t * bdm = &bd_main;
1675 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1677 u32 bd_id = ntohl(mp->bd_id);
1681 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1683 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1688 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1689 mp->mac_address, mp->is_ipv6, mp->is_add))
1690 rv = VNET_API_ERROR_UNSPECIFIED;
1693 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1697 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1700 vl_api_tap_connect_reply_t * rmp;
1701 unix_shared_memory_queue_t * q;
1702 u32 sw_if_index = (u32)~0;
1704 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1705 mp->use_random_mac ? 0 : mp->mac_address,
1706 &sw_if_index, mp->renumber,
1707 ntohl(mp->custom_dev_instance));
1709 q = vl_api_client_index_to_input_queue (mp->client_index);
1713 rmp = vl_msg_api_alloc (sizeof (*rmp));
1714 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1715 rmp->context = mp->context;
1716 rmp->retval = ntohl(rv);
1717 rmp->sw_if_index = ntohl(sw_if_index);
1719 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1723 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1726 vl_api_tap_modify_reply_t * rmp;
1727 unix_shared_memory_queue_t * q;
1728 u32 sw_if_index = (u32)~0;
1730 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1731 mp->use_random_mac ? 0 : mp->mac_address,
1732 &sw_if_index, mp->renumber,
1733 ntohl(mp->custom_dev_instance));
1735 q = vl_api_client_index_to_input_queue (mp->client_index);
1739 rmp = vl_msg_api_alloc (sizeof (*rmp));
1740 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1741 rmp->context = mp->context;
1742 rmp->retval = ntohl(rv);
1743 rmp->sw_if_index = ntohl(sw_if_index);
1745 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1749 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1752 vpe_api_main_t * vam = &vpe_api_main;
1753 vl_api_tap_delete_reply_t * rmp;
1754 unix_shared_memory_queue_t * q;
1755 u32 sw_if_index = ntohl(mp->sw_if_index);
1757 rv = vnet_tap_delete (vm, sw_if_index);
1759 q = vl_api_client_index_to_input_queue (mp->client_index);
1763 rmp = vl_msg_api_alloc (sizeof (*rmp));
1764 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1765 rmp->context = mp->context;
1766 rmp->retval = ntohl(rv);
1768 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1771 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1775 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1777 vl_api_create_vlan_subif_reply_t * rmp;
1778 vnet_main_t * vnm = vnet_get_main();
1779 u32 hw_if_index, sw_if_index = (u32)~0;
1780 vnet_hw_interface_t * hi;
1783 vnet_sw_interface_t template;
1785 vnet_interface_main_t * im = &vnm->interface_main;
1786 u64 sup_and_sub_key;
1788 unix_shared_memory_queue_t * q;
1789 clib_error_t * error;
1791 VALIDATE_SW_IF_INDEX(mp);
1793 hw_if_index = ntohl(mp->sw_if_index);
1794 hi = vnet_get_hw_interface (vnm, hw_if_index);
1796 id = ntohl(mp->vlan_id);
1797 if (id == 0 || id > 4095) {
1798 rv = VNET_API_ERROR_INVALID_VLAN;
1802 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1804 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1806 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1810 kp = clib_mem_alloc (sizeof (*kp));
1811 *kp = sup_and_sub_key;
1813 memset (&template, 0, sizeof (template));
1814 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1815 template.sup_sw_if_index = hi->sw_if_index;
1816 template.sub.id = id;
1817 template.sub.eth.raw_flags = 0;
1818 template.sub.eth.flags.one_tag = 1;
1819 template.sub.eth.outer_vlan_id = id;
1820 template.sub.eth.flags.exact_match = 1;
1822 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1824 clib_error_report(error);
1825 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1828 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1829 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1831 BAD_SW_IF_INDEX_LABEL;
1834 q = vl_api_client_index_to_input_queue (mp->client_index);
1838 rmp = vl_msg_api_alloc (sizeof (*rmp));
1839 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1840 rmp->context = mp->context;
1841 rmp->retval = ntohl(rv);
1842 rmp->sw_if_index = ntohl(sw_if_index);
1843 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1847 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1849 vl_api_create_subif_reply_t * rmp;
1850 vnet_main_t * vnm = vnet_get_main();
1851 u32 sw_if_index = ~0;
1854 vnet_sw_interface_t *si;
1855 vnet_hw_interface_t *hi;
1856 vnet_sw_interface_t template;
1858 vnet_interface_main_t * im = &vnm->interface_main;
1859 u64 sup_and_sub_key;
1861 clib_error_t * error;
1863 VALIDATE_SW_IF_INDEX(mp);
1865 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1866 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1868 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1869 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1873 sw_if_index = si->sw_if_index;
1874 sub_id = ntohl(mp->sub_id);
1876 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1878 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1881 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1882 sw_if_index, sub_id);
1883 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1887 kp = clib_mem_alloc (sizeof (*kp));
1888 *kp = sup_and_sub_key;
1890 memset (&template, 0, sizeof (template));
1891 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1892 template.sup_sw_if_index = sw_if_index;
1893 template.sub.id = sub_id;
1894 template.sub.eth.flags.no_tags = mp->no_tags;
1895 template.sub.eth.flags.one_tag = mp->one_tag;
1896 template.sub.eth.flags.two_tags = mp->two_tags;
1897 template.sub.eth.flags.dot1ad = mp->dot1ad;
1898 template.sub.eth.flags.exact_match = mp->exact_match;
1899 template.sub.eth.flags.default_sub = mp->default_sub;
1900 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1901 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1902 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1903 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1905 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1907 clib_error_report (error);
1908 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1912 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1913 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1915 BAD_SW_IF_INDEX_LABEL;
1919 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1921 rmp->sw_if_index = ntohl(sw_if_index);
1926 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1928 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1930 stats_main_t * sm = &stats_main;
1931 u32 tunnel_sw_if_index = ~0;
1933 dslock (sm, 1 /* release hint */, 5 /* tag */);
1935 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1936 (ip4_address_t *)(mp->dst_address),
1937 (ip4_address_t *)(mp->intfc_address),
1938 (u32)(mp->intfc_address_length),
1939 ntohl(mp->inner_vrf_id),
1940 ntohl(mp->outer_vrf_id),
1941 &tunnel_sw_if_index,
1946 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1948 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1953 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1954 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1956 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1958 stats_main_t * sm = &stats_main;
1959 u32 tunnel_sw_if_index;
1961 dslock (sm, 1 /* release hint */, 5 /* tag */);
1963 rv = vnet_mpls_ethernet_add_del_tunnel
1964 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1965 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1966 ntohl(mp->tx_sw_if_index),
1967 &tunnel_sw_if_index,
1973 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1975 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1980 * This piece of misery brought to you because the control-plane
1981 * can't figure out the tx interface + dst-mac address all by itself
1983 static int mpls_ethernet_add_del_tunnel_2_t_handler
1984 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
1986 pending_route_t * pr;
1987 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
1988 vnet_main_t * vnm = vnet_get_main();
1989 vlib_main_t * vm = vlib_get_main();
1990 stats_main_t * sm = &stats_main;
1991 vpe_api_main_t * vam = &vpe_api_main;
1992 u32 inner_fib_index, outer_fib_index;
1993 ip4_main_t * im = &ip4_main;
1994 ip_lookup_main_t * lm = &im->lookup_main;
1995 ip_adjacency_t * adj = 0;
1998 u8 * dst_mac_address;
2002 u32 tunnel_sw_if_index;
2004 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2006 return VNET_API_ERROR_NO_SUCH_FIB;
2008 outer_fib_index = p[0];
2011 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2013 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2015 inner_fib_index = p[0];
2017 if (inner_fib_index == outer_fib_index)
2018 return VNET_API_ERROR_INVALID_VALUE;
2020 lookup_result = ip4_fib_lookup_with_table
2021 (im, outer_fib_index,
2022 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2023 1 /* disable default route */);
2025 adj = ip_get_adjacency (lm, lookup_result);
2026 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2028 if (mp->is_add && mp->resolve_if_needed) {
2029 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2030 pool_get (vam->pending_routes, pr);
2031 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2033 memcpy (pme, mp, sizeof (*pme));
2034 /* recursion block, "just in case" */
2035 pme->resolve_if_needed = 0;
2036 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2037 pme->resolve_opaque = tx_sw_if_index;
2038 vnet_register_ip4_arp_resolution_event
2040 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2041 vpe_resolver_process_node.index,
2042 RESOLUTION_EVENT, pr - vam->pending_routes);
2044 vlib_process_signal_event
2045 (vm, vpe_resolver_process_node.index,
2046 RESOLUTION_PENDING_EVENT, 0 /* data */);
2048 /* The interface may be down, etc. */
2049 e = ip4_probe_neighbor
2050 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2054 clib_error_report(e);
2056 return VNET_API_ERROR_IN_PROGRESS;
2060 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2061 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2064 vnet_rewrite_get_data_internal
2065 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2067 dslock (sm, 1 /* release hint */, 10 /* tag */);
2069 rv = vnet_mpls_ethernet_add_del_tunnel
2070 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2071 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2072 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2080 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2081 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2083 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2086 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2088 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2093 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2095 vl_api_mpls_add_del_encap_reply_t * rmp;
2097 static u32 * labels;
2100 vec_reset_length (labels);
2102 for (i = 0; i < mp->nlabels; i++)
2103 vec_add1 (labels, ntohl(mp->labels[i]));
2106 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2107 ntohl(mp->vrf_id), labels,
2108 ~0 /* policy_tunnel_index */,
2109 0 /* no_dst_hash */,
2113 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2117 vl_api_mpls_add_del_decap_t_handler
2118 (vl_api_mpls_add_del_decap_t *mp)
2120 vl_api_mpls_add_del_decap_reply_t * rmp;
2123 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2124 ntohl(mp->label), ntohl(mp->next_index),
2125 mp->s_bit, mp->is_add);
2127 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2131 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2133 vl_api_proxy_arp_add_del_reply_t * rmp;
2136 ip4_main_t * im = &ip4_main;
2137 stats_main_t * sm = &stats_main;
2138 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2139 ip4_address_t *hi_addr,
2140 u32 fib_index, int is_del);
2143 dslock (sm, 1 /* release hint */, 6 /* tag */);
2145 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2148 rv = VNET_API_ERROR_NO_SUCH_FIB;
2154 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2155 (ip4_address_t *)mp->hi_address,
2156 fib_index, mp->is_add == 0);
2160 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2164 vl_api_proxy_arp_intfc_enable_disable_t_handler
2165 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2168 vnet_main_t * vnm = vnet_get_main();
2169 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2170 vnet_sw_interface_t * si;
2173 VALIDATE_SW_IF_INDEX(mp);
2175 sw_if_index = ntohl(mp->sw_if_index);
2177 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2179 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2183 si = vnet_get_sw_interface (vnm, sw_if_index);
2187 if (mp->enable_disable)
2188 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2190 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2192 BAD_SW_IF_INDEX_LABEL;
2195 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2199 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2201 vl_api_ip_neighbor_add_del_reply_t * rmp;
2202 vnet_main_t * vnm = vnet_get_main();
2205 stats_main_t * sm = &stats_main;
2207 VALIDATE_SW_IF_INDEX(mp);
2209 dslock (sm, 1 /* release hint */, 7 /* tag */);
2213 rv = vnet_set_ip6_ethernet_neighbor
2214 (vm, ntohl(mp->sw_if_index),
2215 (ip6_address_t *)(mp->dst_address),
2216 mp->mac_address, sizeof (mp->mac_address));
2218 rv = vnet_unset_ip6_ethernet_neighbor
2219 (vm, ntohl(mp->sw_if_index),
2220 (ip6_address_t *)(mp->dst_address),
2221 mp->mac_address, sizeof(mp->mac_address));
2223 ip4_main_t * im = &ip4_main;
2224 ip_lookup_main_t * lm = &im->lookup_main;
2225 ethernet_arp_ip4_over_ethernet_address_t a;
2227 ip_adjacency_t *nh_adj;
2229 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2231 rv = VNET_API_ERROR_NO_SUCH_FIB;
2237 * Unfortunately, folks have a penchant for
2238 * adding interface addresses to the ARP cache, and
2239 * wondering why the forwarder eventually ASSERTs...
2241 ai = ip4_fib_lookup_with_table
2242 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2243 1 /* disable default route */);
2246 nh_adj = ip_get_adjacency (lm, ai);
2247 /* Never allow manipulation of a local adj! */
2248 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2249 clib_warning("%U matches local adj",
2251 (ip4_address_t *)(mp->dst_address));
2252 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2257 memcpy (&a.ethernet, mp->mac_address, 6);
2258 memcpy (&a.ip4, mp->dst_address, 4);
2261 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2262 fib_index, &a, mp->is_static);
2264 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2268 BAD_SW_IF_INDEX_LABEL;
2271 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2275 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2278 vpe_main_t *rm = &vpe_main;
2279 ip4_main_t *im4 = &ip4_main;
2280 ip6_main_t *im6 = &ip6_main;
2281 ip_lookup_main_t * lm;
2286 u32 adj_index, sw_if_index;
2287 vl_api_is_address_reachable_t *rmp;
2288 ip_adjacency_t * adj;
2289 unix_shared_memory_queue_t *q;
2291 q = vl_api_client_index_to_input_queue (mp->client_index);
2293 increment_missing_api_client_counter (rm->vlib_main);
2297 rmp = vl_msg_api_alloc (sizeof (*rmp));
2298 memcpy (rmp, mp, sizeof (*rmp));
2300 sw_if_index = mp->next_hop_sw_if_index;
2301 memcpy (&addr, mp->address, sizeof (addr));
2303 lm = &im6->lookup_main;
2305 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2307 lm = &im4->lookup_main;
2309 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2311 if (adj_index == ~0) {
2315 adj = ip_get_adjacency (lm, adj_index);
2317 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2318 && adj->rewrite_header.sw_if_index == sw_if_index) {
2321 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2322 && adj->rewrite_header.sw_if_index == sw_if_index) {
2324 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2326 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2327 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2335 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2339 static void vl_api_sw_interface_details_t_handler (
2340 vl_api_sw_interface_details_t * mp)
2342 clib_warning ("BUG");
2345 static void vl_api_sw_interface_set_flags_t_handler (
2346 vl_api_sw_interface_set_flags_t * mp)
2348 vl_api_sw_interface_set_flags_reply_t *rmp;
2349 vnet_main_t * vnm = vnet_get_main();
2351 clib_error_t * error;
2354 VALIDATE_SW_IF_INDEX(mp);
2356 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2358 error = vnet_sw_interface_set_flags (vnm,
2359 ntohl(mp->sw_if_index),
2363 clib_error_report (error);
2366 BAD_SW_IF_INDEX_LABEL;
2367 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2370 static void vl_api_sw_interface_clear_stats_t_handler (
2371 vl_api_sw_interface_clear_stats_t * mp)
2373 vl_api_sw_interface_clear_stats_reply_t *rmp;
2375 vnet_main_t * vnm = vnet_get_main();
2376 vnet_interface_main_t * im = &vnm->interface_main;
2377 vlib_simple_counter_main_t * sm;
2378 vlib_combined_counter_main_t * cm;
2379 static vnet_main_t ** my_vnet_mains;
2380 int i, j, n_counters;
2384 vec_reset_length (my_vnet_mains);
2386 for (i = 0; i < vec_len (vnet_mains); i++)
2389 vec_add1 (my_vnet_mains, vnet_mains[i]);
2392 if (vec_len (vnet_mains) == 0)
2393 vec_add1 (my_vnet_mains, vnm);
2395 n_counters = vec_len (im->combined_sw_if_counters);
2397 for (j = 0; j < n_counters; j++)
2399 for (i = 0; i < vec_len(my_vnet_mains); i++)
2401 im = &my_vnet_mains[i]->interface_main;
2402 cm = im->combined_sw_if_counters + j;
2403 if (mp->sw_if_index == (u32)~0)
2404 vlib_clear_combined_counters (cm);
2406 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2410 n_counters = vec_len (im->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 sm = im->sw_if_counters + j;
2418 if (mp->sw_if_index == (u32)~0)
2419 vlib_clear_simple_counters (sm);
2421 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2425 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2428 static void send_sw_interface_details (vpe_api_main_t * am,
2429 unix_shared_memory_queue_t *q,
2430 vnet_sw_interface_t * swif,
2431 u8 * interface_name)
2433 vl_api_sw_interface_details_t * mp;
2434 vnet_hw_interface_t * hi;
2436 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2438 mp = vl_msg_api_alloc (sizeof (*mp));
2439 memset (mp, 0, sizeof (*mp));
2440 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2441 mp->sw_if_index = ntohl(swif->sw_if_index);
2442 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2443 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2445 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2447 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2448 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2449 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2450 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2451 mp->link_mtu = ntohs(hi->max_packet_bytes);
2453 strncpy ((char *) mp->interface_name,
2454 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2456 /* Send the L2 address for ethernet physical intfcs */
2457 if (swif->sup_sw_if_index == swif->sw_if_index
2458 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2459 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2460 ethernet_interface_t *ei;
2462 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2463 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2464 memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2465 mp->l2_address_length = ntohl(sizeof (ei->address));
2466 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2467 vnet_sub_interface_t *sub = &swif->sub;
2468 mp->sub_id = ntohl(sub->id);
2469 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2470 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2471 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2472 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2473 mp->sub_exact_match = sub->eth.flags.exact_match;
2474 mp->sub_default = sub->eth.flags.default_sub;
2475 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2476 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2478 /* vlan tag rewrite data */
2479 u32 vtr_op = L2_VTR_DISABLED;
2480 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2482 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2483 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2484 // error - default to disabled
2485 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2486 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2489 mp->vtr_op = ntohl(vtr_op);
2490 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2491 mp->vtr_tag1 = ntohl(vtr_tag1);
2492 mp->vtr_tag2 = ntohl(vtr_tag2);
2496 vl_msg_api_send_shmem (q, (u8 *)&mp);
2499 static void send_sw_interface_flags (vpe_api_main_t * am,
2500 unix_shared_memory_queue_t *q,
2501 vnet_sw_interface_t * swif)
2503 vl_api_sw_interface_set_flags_t *mp;
2504 vnet_main_t * vnm = am->vnet_main;
2506 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2508 mp = vl_msg_api_alloc (sizeof (*mp));
2509 memset (mp, 0, sizeof (*mp));
2510 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2511 mp->sw_if_index = ntohl(swif->sw_if_index);
2513 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2515 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2517 vl_msg_api_send_shmem (q, (u8 *)&mp);
2520 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2521 unix_shared_memory_queue_t *q,
2523 __attribute__((unused));
2525 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2526 unix_shared_memory_queue_t *q,
2529 vl_api_sw_interface_set_flags_t *mp;
2531 mp = vl_msg_api_alloc (sizeof (*mp));
2532 memset (mp, 0, sizeof (*mp));
2533 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2534 mp->sw_if_index = ntohl(sw_if_index);
2536 mp->admin_up_down = 0;
2537 mp->link_up_down = 0;
2539 vl_msg_api_send_shmem (q, (u8 *)&mp);
2542 static void vl_api_sw_interface_dump_t_handler (
2543 vl_api_sw_interface_dump_t *mp)
2545 vpe_api_main_t * am = &vpe_api_main;
2546 vnet_sw_interface_t * swif;
2547 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2548 u8 * filter_string = 0, * name_string = 0;
2549 unix_shared_memory_queue_t * q;
2550 char * strcasestr (char *, char *); /* lnx hdr file botch */
2552 q = vl_api_client_index_to_input_queue (mp->client_index);
2557 if (mp->name_filter_valid) {
2558 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2559 filter_string = format (0, "%s%c", mp->name_filter, 0);
2562 pool_foreach (swif, im->sw_interfaces,
2564 name_string = format (name_string, "%U%c",
2565 format_vnet_sw_interface_name,
2566 am->vnet_main, swif, 0);
2568 if (mp->name_filter_valid == 0 ||
2569 strcasestr((char *) name_string, (char *) filter_string)) {
2571 send_sw_interface_details (am, q, swif, name_string);
2572 send_sw_interface_flags (am, q, swif);
2574 _vec_len (name_string) = 0;
2577 vec_free (name_string);
2578 vec_free (filter_string);
2581 void send_oam_event (oam_target_t * t)
2583 vpe_api_main_t * vam = &vpe_api_main;
2584 unix_shared_memory_queue_t * q;
2585 vpe_client_registration_t *reg;
2586 vl_api_oam_event_t * mp;
2588 pool_foreach(reg, vam->oam_events_registrations,
2590 q = vl_api_client_index_to_input_queue (reg->client_index);
2592 mp = vl_msg_api_alloc (sizeof (*mp));
2593 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2594 memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2595 mp->state = t->state;
2596 vl_msg_api_send_shmem (q, (u8 *)&mp);
2602 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2604 vl_api_oam_add_del_reply_t * rmp;
2607 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2608 (ip4_address_t *)mp->dst_address,
2612 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2616 vl_api_vnet_get_summary_stats_t_handler (
2617 vl_api_vnet_get_summary_stats_t *mp)
2619 stats_main_t * sm = &stats_main;
2620 vnet_interface_main_t * im = sm->interface_main;
2621 vl_api_vnet_summary_stats_reply_t *rmp;
2622 vlib_combined_counter_main_t * cm;
2625 u64 total_pkts[VLIB_N_RX_TX];
2626 u64 total_bytes[VLIB_N_RX_TX];
2628 unix_shared_memory_queue_t * q =
2629 vl_api_client_index_to_input_queue (mp->client_index);
2634 rmp = vl_msg_api_alloc (sizeof (*rmp));
2635 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2636 rmp->context = mp->context;
2639 memset (total_pkts, 0, sizeof (total_pkts));
2640 memset (total_bytes, 0, sizeof (total_bytes));
2642 vnet_interface_counter_lock (im);
2644 vec_foreach (cm, im->combined_sw_if_counters) {
2645 which = cm - im->combined_sw_if_counters;
2647 for (i = 0; i < vec_len (cm->maxi); i++) {
2648 vlib_get_combined_counter (cm, i, &v);
2649 total_pkts[which] += v.packets;
2650 total_bytes[which] += v.bytes;
2653 vnet_interface_counter_unlock (im);
2655 /* Note: in HOST byte order! */
2656 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2657 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2658 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2659 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2660 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2662 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2665 typedef CLIB_PACKED (struct {
2666 ip4_address_t address;
2668 u32 address_length : 6;
2673 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2675 vnet_main_t * vnm = vnet_get_main();
2676 vnet_interface_main_t * im = &vnm->interface_main;
2677 ip4_main_t * im4 = &ip4_main;
2678 static ip4_route_t * routes;
2679 static u32 * sw_if_indices_to_shut;
2680 stats_main_t * sm = &stats_main;
2685 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2686 u32 target_fib_id = ntohl(mp->vrf_id);
2688 dslock (sm, 1 /* release hint */, 8 /* tag */);
2690 vec_foreach (fib, im4->fibs) {
2691 vnet_sw_interface_t * si;
2693 if (fib->table_id != target_fib_id)
2696 /* remove any mpls/gre tunnels in this fib */
2697 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2699 /* remove any mpls encap/decap labels */
2700 mpls_fib_reset_labels (fib->table_id);
2702 /* remove any proxy arps in this fib */
2703 vnet_proxy_arp_fib_reset (fib->table_id);
2705 /* Set the flow hash for this fib to the default */
2706 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2708 vec_reset_length (sw_if_indices_to_shut);
2710 /* Shut down interfaces in this FIB / clean out intfc routes */
2711 pool_foreach (si, im->sw_interfaces,
2713 u32 sw_if_index = si->sw_if_index;
2715 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2716 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2718 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2721 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2722 sw_if_index = sw_if_indices_to_shut[i];
2723 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2725 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2726 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2727 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2730 vec_reset_length (routes);
2732 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2733 uword * hash = fib->adj_index_by_dst_address[i];
2737 x.address_length = i;
2739 hash_foreach_pair (p, hash,
2741 x.address.data_u32 = p->key;
2742 vec_add1 (routes, x);
2746 vec_foreach (r, routes) {
2747 ip4_add_del_route_args_t a;
2749 memset (&a, 0, sizeof (a));
2750 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2751 a.table_index_or_table_id = fib - im4->fibs;
2752 a.dst_address = r->address;
2753 a.dst_address_length = r->address_length;
2756 ip4_add_del_route (im4, &a);
2757 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2758 IP4_ROUTE_FLAG_FIB_INDEX);
2762 } /* vec_foreach (fib) */
2769 ip6_address_t address;
2776 ip6_route_t ** routep;
2777 } add_routes_in_fib_arg_t;
2779 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2781 add_routes_in_fib_arg_t * ap = arg;
2783 if (kvp->key[2]>>32 == ap->fib_index)
2785 ip6_address_t *addr;
2787 addr = (ip6_address_t *) kvp;
2788 vec_add2 (*ap->routep, r, 1);
2789 r->address = addr[0];
2790 r->address_length = kvp->key[2] & 0xFF;
2791 r->index = kvp->value;
2795 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2797 vnet_main_t * vnm = vnet_get_main();
2798 vnet_interface_main_t * im = &vnm->interface_main;
2799 ip6_main_t * im6 = &ip6_main;
2800 stats_main_t * sm = &stats_main;
2801 static ip6_route_t * routes;
2802 static u32 * sw_if_indices_to_shut;
2807 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2808 u32 target_fib_id = ntohl(mp->vrf_id);
2809 add_routes_in_fib_arg_t _a, *a=&_a;
2810 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2812 dslock (sm, 1 /* release hint */, 9 /* tag */);
2814 vec_foreach (fib, im6->fibs) {
2815 vnet_sw_interface_t * si;
2817 if (fib->table_id != target_fib_id)
2820 vec_reset_length (sw_if_indices_to_shut);
2822 /* Shut down interfaces in this FIB / clean out intfc routes */
2823 pool_foreach (si, im->sw_interfaces,
2825 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2827 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2830 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2831 sw_if_index = sw_if_indices_to_shut[i];
2832 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2834 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2835 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2836 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2839 vec_reset_length (routes);
2841 a->fib_index = fib - im6->fibs;
2842 a->routep = &routes;
2844 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2846 vec_foreach (r, routes) {
2847 ip6_add_del_route_args_t a;
2849 memset (&a, 0, sizeof (a));
2850 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2851 a.table_index_or_table_id = fib - im6->fibs;
2852 a.dst_address = r->address;
2853 a.dst_address_length = r->address_length;
2856 ip6_add_del_route (im6, &a);
2857 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2858 IP6_ROUTE_FLAG_FIB_INDEX);
2861 /* Reinstall the neighbor / router discovery routes */
2862 vnet_ip6_fib_init (im6, fib - im6->fibs);
2864 } /* vec_foreach (fib) */
2870 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2873 vl_api_reset_fib_reply_t * rmp;
2876 rv = ip6_reset_fib_t_handler (mp);
2878 rv = ip4_reset_fib_t_handler (mp);
2880 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2885 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2887 vl_api_dhcp_proxy_config_reply_t * rmp;
2890 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2891 (ip4_address_t *)(&mp->dhcp_src_address),
2892 (u32) ntohl(mp->vrf_id),
2893 (int) mp->insert_circuit_id,
2894 (int) (mp->is_add == 0));
2896 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2901 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2903 vl_api_dhcp_proxy_config_reply_t * rmp;
2906 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2907 (ip6_address_t *)(&mp->dhcp_src_address),
2908 (u32) ntohl(mp->vrf_id),
2909 (int) mp->insert_circuit_id,
2910 (int) (mp->is_add == 0));
2912 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2916 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2918 vl_api_dhcp_proxy_config_reply_t * rmp;
2921 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2922 (ip4_address_t *)(&mp->dhcp_src_address),
2923 (u32) ntohl(mp->rx_vrf_id),
2924 (u32) ntohl(mp->server_vrf_id),
2925 (int) mp->insert_circuit_id,
2926 (int) (mp->is_add == 0));
2928 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2933 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2935 vl_api_dhcp_proxy_config_reply_t * rmp;
2939 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2940 (ip6_address_t *)(&mp->dhcp_src_address),
2941 (u32) ntohl(mp->rx_vrf_id),
2942 (u32) ntohl(mp->server_vrf_id),
2943 (int) mp->insert_circuit_id,
2944 (int) (mp->is_add == 0));
2946 rv = VNET_API_ERROR_UNIMPLEMENTED;
2949 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2954 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2956 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2959 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2962 (int)mp->is_add == 0);
2964 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2967 (int)mp->is_add == 0);
2969 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2973 static void vl_api_dhcp_proxy_config_t_handler
2974 (vl_api_dhcp_proxy_config_t *mp)
2976 if (mp->is_ipv6 == 0)
2977 dhcpv4_proxy_config (mp);
2979 dhcpv6_proxy_config (mp);
2982 static void vl_api_dhcp_proxy_config_2_t_handler
2983 (vl_api_dhcp_proxy_config_2_t *mp)
2985 if (mp->is_ipv6 == 0)
2986 dhcpv4_proxy_config_2 (mp);
2988 dhcpv6_proxy_config_2 (mp);
2991 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
2992 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
2994 unix_shared_memory_queue_t * q;
2995 vl_api_dhcp_compl_event_t * mp;
2997 q = vl_api_client_index_to_input_queue (client_index);
3001 mp = vl_msg_api_alloc (sizeof (*mp));
3002 mp->client_index = client_index;
3004 mp->is_ipv6 = is_ipv6;
3005 memcpy (&mp->hostname, hostname, vec_len(hostname));
3006 mp->hostname[vec_len(hostname) + 1] = '\n';
3007 memcpy (&mp->host_address[0], host_address, 16);
3008 memcpy (&mp->router_address[0], router_address, 16);
3009 memcpy (&mp->host_mac[0], host_mac, 6);
3011 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3013 vl_msg_api_send_shmem (q, (u8 *)&mp);
3016 static void vl_api_dhcp_client_config_t_handler
3017 (vl_api_dhcp_client_config_t *mp)
3019 vlib_main_t *vm = vlib_get_main();
3020 vl_api_dhcp_client_config_reply_t * rmp;
3023 VALIDATE_SW_IF_INDEX(mp);
3025 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3026 mp->hostname, mp->is_add, mp->client_index,
3027 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3030 BAD_SW_IF_INDEX_LABEL;
3032 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3036 vl_api_sw_interface_ip6nd_ra_config_t_handler
3037 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3039 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3041 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3043 is_no = mp->is_no == 1;
3044 surpress = mp->surpress == 1;
3045 managed = mp->managed == 1;
3046 other = mp->other == 1;
3047 ll_option = mp->ll_option == 1;
3048 send_unicast = mp->send_unicast == 1;
3049 cease = mp->cease == 1;
3050 default_router = mp->default_router == 1;
3052 VALIDATE_SW_IF_INDEX(mp);
3054 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3055 surpress, managed, other,
3056 ll_option, send_unicast, cease,
3057 default_router, ntohl (mp->lifetime),
3058 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3059 ntohl(mp->max_interval), ntohl( mp->min_interval),
3062 BAD_SW_IF_INDEX_LABEL;
3064 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3068 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3069 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3071 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3073 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3075 VALIDATE_SW_IF_INDEX(mp);
3077 is_no = mp->is_no == 1;
3078 use_default = mp->use_default == 1;
3079 no_advertise = mp->no_advertise == 1;
3080 off_link = mp->off_link == 1;
3081 no_autoconfig = mp->no_autoconfig == 1;
3082 no_onlink = mp->no_onlink == 1;
3084 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3085 (ip6_address_t *)mp->address, mp->address_length,
3086 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3087 no_advertise, off_link, no_autoconfig, no_onlink,
3090 BAD_SW_IF_INDEX_LABEL;
3091 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3095 vl_api_sw_interface_ip6_enable_disable_t_handler
3096 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3098 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3099 vnet_main_t * vnm = vnet_get_main();
3101 clib_error_t * error;
3105 VALIDATE_SW_IF_INDEX(mp);
3107 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3108 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3111 clib_error_report(error);
3112 rv = VNET_API_ERROR_UNSPECIFIED;
3114 rv = vnm->api_errno;
3117 BAD_SW_IF_INDEX_LABEL;
3119 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3123 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3124 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3126 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3128 clib_error_t * error;
3129 vnet_main_t * vnm = vnet_get_main();
3133 VALIDATE_SW_IF_INDEX(mp);
3135 error = set_ip6_link_local_address(vm,
3136 ntohl(mp->sw_if_index),
3137 (ip6_address_t *)mp->address,
3138 mp->address_length);
3140 clib_error_report(error);
3141 rv = VNET_API_ERROR_UNSPECIFIED;
3143 rv = vnm->api_errno;
3146 BAD_SW_IF_INDEX_LABEL;
3148 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3151 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3153 vl_api_set_ip_flow_hash_reply_t *rmp;
3154 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3156 clib_warning ("unimplemented...");
3158 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3161 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3163 vl_api_set_ip_flow_hash_reply_t *rmp;
3166 u32 flow_hash_config = 0;
3168 table_id = ntohl(mp->vrf_id);
3170 #define _(a,b) if (mp->a) flow_hash_config |= b;
3171 foreach_flow_hash_bit;
3174 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3176 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3180 static void vl_api_set_ip_flow_hash_t_handler
3181 (vl_api_set_ip_flow_hash_t *mp)
3183 if (mp->is_ipv6 == 0)
3184 set_ip4_flow_hash (mp);
3186 set_ip6_flow_hash (mp);
3189 static void vl_api_sw_interface_set_unnumbered_t_handler
3190 (vl_api_sw_interface_set_unnumbered_t *mp)
3192 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3194 vnet_sw_interface_t * si;
3195 vnet_main_t *vnm = vnet_get_main();
3196 u32 sw_if_index, unnumbered_sw_if_index;
3198 sw_if_index = ntohl(mp->sw_if_index);
3199 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3202 * The API message field names are backwards from
3203 * the underlying data structure names.
3204 * It's not worth changing them now.
3206 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3207 unnumbered_sw_if_index)) {
3208 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3212 /* Only check the "use loop0" field when setting the binding */
3214 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3215 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3219 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3222 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3223 si->unnumbered_sw_if_index = sw_if_index;
3225 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3226 si->unnumbered_sw_if_index = (u32)~0;
3230 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3233 static void vl_api_create_loopback_t_handler
3234 (vl_api_create_loopback_t *mp)
3236 vl_api_create_loopback_reply_t * rmp;
3240 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3242 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3244 rmp->sw_if_index = ntohl (sw_if_index);
3248 static void vl_api_delete_loopback_t_handler
3249 (vl_api_delete_loopback_t *mp)
3251 vl_api_delete_loopback_reply_t * rmp;
3255 sw_if_index = ntohl (mp->sw_if_index);
3256 rv = vnet_delete_loopback_interface (sw_if_index);
3258 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3261 static void vl_api_control_ping_t_handler
3262 (vl_api_control_ping_t *mp)
3264 vl_api_control_ping_reply_t * rmp;
3267 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3269 rmp->vpe_pid = ntohl (getpid());
3273 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3275 u8 **shmem_vecp = (u8 **)arg;
3278 api_main_t * am = &api_main;
3281 shmem_vec = *shmem_vecp;
3283 offset = vec_len (shmem_vec);
3285 pthread_mutex_lock (&am->vlib_rp->mutex);
3286 oldheap = svm_push_data_heap (am->vlib_rp);
3288 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3290 memcpy (shmem_vec + offset, buffer, buffer_bytes);
3292 svm_pop_heap (oldheap);
3293 pthread_mutex_unlock (&am->vlib_rp->mutex);
3295 *shmem_vecp = shmem_vec;
3299 static void vl_api_cli_request_t_handler
3300 (vl_api_cli_request_t *mp)
3302 vl_api_cli_reply_t *rp;
3303 unix_shared_memory_queue_t *q;
3304 vlib_main_t * vm = vlib_get_main();
3305 api_main_t * am = &api_main;
3306 unformat_input_t input;
3310 q = vl_api_client_index_to_input_queue (mp->client_index);
3314 rp = vl_msg_api_alloc (sizeof (*rp));
3315 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3316 rp->context = mp->context;
3318 unformat_init_vector (&input, (u8 *)mp->cmd_in_shmem);
3320 vlib_cli_input (vm, &input, shmem_cli_output,
3323 pthread_mutex_lock (&am->vlib_rp->mutex);
3324 oldheap = svm_push_data_heap (am->vlib_rp);
3326 vec_add1(shmem_vec, 0);
3328 svm_pop_heap (oldheap);
3329 pthread_mutex_unlock (&am->vlib_rp->mutex);
3331 rp->reply_in_shmem = (uword)shmem_vec;
3333 vl_msg_api_send_shmem (q, (u8 *)&rp);
3336 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3339 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3340 vnet_main_t *vnm = vnet_get_main();
3341 clib_error_t * error;
3346 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3348 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3351 clib_error_report(error);
3352 rv = VNET_API_ERROR_UNSPECIFIED;
3354 rv = vnm->api_errno;
3357 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3360 static void vl_api_sr_tunnel_add_del_t_handler
3361 (vl_api_sr_tunnel_add_del_t *mp)
3364 clib_warning ("unimplemented");
3366 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3368 vl_api_sr_tunnel_add_del_reply_t * rmp;
3369 ip6_address_t * segments = 0, * seg;
3370 ip6_address_t * tags = 0, *tag;
3371 ip6_address_t * this_address;
3374 if (mp->n_segments == 0) {
3379 memset (a, 0, sizeof (*a));
3380 a->src_address = (ip6_address_t *)&mp->src_address;
3381 a->dst_address = (ip6_address_t *)&mp->dst_address;
3382 a->dst_mask_width = mp->dst_mask_width;
3383 a->flags_net_byte_order = mp->flags_net_byte_order;
3384 a->is_del = (mp->is_add == 0);
3385 a->rx_table_id = ntohl(mp->outer_vrf_id);
3386 a->tx_table_id = ntohl(mp->inner_vrf_id);
3388 /* Yank segments and tags out of the API message */
3389 this_address = (ip6_address_t *)mp->segs_and_tags;
3390 for (i = 0; i < mp->n_segments; i++) {
3391 vec_add2 (segments, seg, 1);
3392 memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3395 for (i = 0; i < mp->n_tags; i++) {
3396 vec_add2 (tags, tag, 1);
3397 memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3401 a->segments = segments;
3404 rv = ip6_sr_add_del_tunnel (a);
3408 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3412 #define foreach_classify_add_del_table_field \
3417 _(match_n_vectors) \
3418 _(next_table_index) \
3421 static void vl_api_classify_add_del_table_t_handler
3422 (vl_api_classify_add_del_table_t * mp)
3424 vl_api_classify_add_del_table_reply_t * rmp;
3425 vnet_classify_main_t * cm = &vnet_classify_main;
3426 vnet_classify_table_t * t;
3430 foreach_classify_add_del_table_field;
3433 #define _(a) a = ntohl(mp->a);
3434 foreach_classify_add_del_table_field;
3437 /* The underlying API fails silently, on purpose, so check here */
3438 if (mp->is_add == 0)
3439 if (pool_is_free_index (cm->tables, table_index)) {
3440 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3444 rv = vnet_classify_add_del_table
3445 (cm, mp->mask, nbuckets, memory_size,
3446 skip_n_vectors, match_n_vectors,
3447 next_table_index, miss_next_index,
3448 &table_index, mp->is_add);
3451 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3453 if (rv == 0 && mp->is_add) {
3454 t = pool_elt_at_index (cm->tables, table_index);
3455 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3456 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3457 rmp->new_table_index = ntohl(table_index);
3459 rmp->skip_n_vectors = ~0;
3460 rmp->match_n_vectors = ~0;
3461 rmp->new_table_index = ~0;
3466 static void vl_api_classify_add_del_session_t_handler
3467 (vl_api_classify_add_del_session_t * mp)
3469 vnet_classify_main_t * cm = &vnet_classify_main;
3470 vl_api_classify_add_del_session_reply_t * rmp;
3472 u32 table_index, hit_next_index, opaque_index;
3475 table_index = ntohl (mp->table_index);
3476 hit_next_index = ntohl (mp->hit_next_index);
3477 opaque_index = ntohl (mp->opaque_index);
3478 advance = ntohl (mp->advance);
3480 rv = vnet_classify_add_del_session
3481 (cm, table_index, mp->match, hit_next_index, opaque_index,
3482 advance, mp->is_add);
3484 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3487 static void vl_api_classify_set_interface_ip_table_t_handler
3488 (vl_api_classify_set_interface_ip_table_t * mp)
3490 vlib_main_t * vm = vlib_get_main();
3491 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3493 u32 table_index, sw_if_index;
3495 table_index = ntohl (mp->table_index);
3496 sw_if_index = ntohl (mp->sw_if_index);
3498 VALIDATE_SW_IF_INDEX(mp);
3501 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3503 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3505 BAD_SW_IF_INDEX_LABEL;
3507 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3510 static void vl_api_classify_set_interface_l2_tables_t_handler
3511 (vl_api_classify_set_interface_l2_tables_t * mp)
3513 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3515 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3518 ip4_table_index = ntohl(mp->ip4_table_index);
3519 ip6_table_index = ntohl(mp->ip6_table_index);
3520 other_table_index = ntohl(mp->other_table_index);
3521 sw_if_index = ntohl(mp->sw_if_index);
3523 VALIDATE_SW_IF_INDEX(mp);
3525 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3526 ip6_table_index, other_table_index);
3529 if (ip4_table_index != ~0 || ip6_table_index != ~0
3530 || other_table_index != ~0)
3535 vnet_l2_classify_enable_disable (sw_if_index, enable);
3538 BAD_SW_IF_INDEX_LABEL;
3540 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3544 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3547 vl_api_l2_fib_clear_table_reply_t * rmp;
3549 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3550 * that is not currently implemented. When that TODO is fixed
3551 * this call should be changed to pass 1 instead of 0.
3553 l2fib_clear_table (0);
3555 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3558 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3563 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3566 vl_api_l2_interface_efp_filter_reply_t * rmp;
3567 vnet_main_t *vnm = vnet_get_main();
3569 // enable/disable the feature
3570 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3571 rv = vnm->api_errno;
3573 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3577 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3580 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3581 vnet_main_t * vnm = vnet_get_main();
3582 vlib_main_t * vm = vlib_get_main();
3585 VALIDATE_SW_IF_INDEX(mp);
3587 vtr_op = ntohl(mp->vtr_op);
3589 /* The L2 code is unsuspicious */
3591 case L2_VTR_DISABLED:
3596 case L2_VTR_TRANSLATE_1_1:
3597 case L2_VTR_TRANSLATE_1_2:
3598 case L2_VTR_TRANSLATE_2_1:
3599 case L2_VTR_TRANSLATE_2_2:
3603 rv = VNET_API_ERROR_INVALID_VALUE;
3604 goto bad_sw_if_index;
3607 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3608 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3611 BAD_SW_IF_INDEX_LABEL;
3613 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3617 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3621 vl_api_create_vhost_user_if_reply_t * rmp;
3622 u32 sw_if_index = (u32)~0;
3624 vnet_main_t * vnm = vnet_get_main();
3625 vlib_main_t * vm = vlib_get_main();
3627 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3628 mp->is_server, &sw_if_index, (u64)~0,
3629 mp->renumber, ntohl(mp->custom_dev_instance),
3630 (mp->use_custom_mac)?mp->mac_address:NULL);
3632 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3634 rmp->sw_if_index = ntohl (sw_if_index);
3640 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3644 vl_api_modify_vhost_user_if_reply_t * rmp;
3645 u32 sw_if_index = ntohl(mp->sw_if_index);
3647 vnet_main_t * vnm = vnet_get_main();
3648 vlib_main_t * vm = vlib_get_main();
3650 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3651 mp->is_server, sw_if_index, (u64)~0,
3652 mp->renumber, ntohl(mp->custom_dev_instance));
3654 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3659 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3663 vpe_api_main_t * vam = &vpe_api_main;
3664 vl_api_delete_vhost_user_if_reply_t * rmp;
3665 u32 sw_if_index = ntohl(mp->sw_if_index);
3667 vnet_main_t * vnm = vnet_get_main();
3668 vlib_main_t * vm = vlib_get_main();
3670 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3672 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3674 unix_shared_memory_queue_t * q =
3675 vl_api_client_index_to_input_queue (mp->client_index);
3679 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3684 static void vl_api_sw_interface_vhost_user_details_t_handler (
3685 vl_api_sw_interface_vhost_user_details_t * mp)
3687 clib_warning ("BUG");
3691 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3692 unix_shared_memory_queue_t *q,
3693 vhost_user_intf_details_t * vui)
3695 vl_api_sw_interface_vhost_user_details_t * mp;
3697 mp = vl_msg_api_alloc (sizeof (*mp));
3698 memset (mp, 0, sizeof (*mp));
3699 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3700 mp->sw_if_index = ntohl(vui->sw_if_index);
3701 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3702 mp->features = clib_net_to_host_u64 (vui->features);
3703 mp->is_server = vui->is_server;
3704 mp->num_regions = ntohl(vui->num_regions);
3705 mp->sock_errno = ntohl(vui->sock_errno);
3707 strncpy ((char *) mp->sock_filename,
3708 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3709 strncpy ((char *) mp->interface_name,
3710 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3712 vl_msg_api_send_shmem (q, (u8 *)&mp);
3717 vl_api_sw_interface_vhost_user_dump_t_handler (
3718 vl_api_sw_interface_vhost_user_dump_t *mp)
3722 vpe_api_main_t * am = &vpe_api_main;
3723 vnet_main_t * vnm = vnet_get_main();
3724 vlib_main_t * vm = vlib_get_main();
3725 vhost_user_intf_details_t *ifaces = NULL;
3726 vhost_user_intf_details_t *vuid = NULL;
3727 unix_shared_memory_queue_t * q;
3729 q = vl_api_client_index_to_input_queue (mp->client_index);
3733 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3737 vec_foreach (vuid, ifaces) {
3738 send_sw_interface_vhost_user_details (am, q, vuid);
3744 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3745 unix_shared_memory_queue_t *q,
3749 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3750 u8 * if_name = NULL;
3751 vnet_sw_interface_t * si = NULL;
3753 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3755 if_name = format(if_name, "%U",
3756 format_vnet_sw_interface_name, lm->vnet_main, si);
3758 mp = vl_msg_api_alloc (sizeof (*mp));
3759 memset (mp, 0, sizeof (*mp));
3760 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3761 strncpy((char *)mp->interface_name,
3762 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3763 mp->sw_if_index = ntohl(si->sw_if_index);
3764 mp->local_session_id = s->local_session_id;
3765 mp->remote_session_id = s->remote_session_id;
3766 mp->local_cookie[0] = s->local_cookie[0];
3767 mp->local_cookie[1] = s->local_cookie[1];
3768 mp->remote_cookie = s->remote_cookie;
3769 memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3770 memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3771 mp->l2_sublayer_present = s->l2_sublayer_present;
3773 vl_msg_api_send_shmem (q, (u8 *)&mp);
3776 static void send_ip_address_details (vpe_api_main_t * am,
3777 unix_shared_memory_queue_t * q,
3782 vl_api_ip_address_details_t * mp;
3784 mp = vl_msg_api_alloc (sizeof (*mp));
3785 memset (mp, 0, sizeof (*mp));
3786 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3789 memcpy(&mp->ip, ip, sizeof(mp->ip));
3791 u32 * tp = (u32 *)mp->ip;
3792 *tp = ntohl(*(u32*)ip);
3794 mp->prefix_length = prefix_length;
3796 vl_msg_api_send_shmem (q, (u8 *)&mp);
3800 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3802 vpe_api_main_t * am = &vpe_api_main;
3803 unix_shared_memory_queue_t * q;
3806 ip6_main_t * im6 = &ip6_main;
3807 ip4_main_t * im4 = &ip4_main;
3808 ip_lookup_main_t * lm6 = &im6->lookup_main;
3809 ip_lookup_main_t * lm4 = &im4->lookup_main;
3810 ip_interface_address_t * ia = 0;
3811 u32 sw_if_index = ~0;
3813 sw_if_index = ntohl(mp->sw_if_index);
3815 q = vl_api_client_index_to_input_queue (mp->client_index);
3821 foreach_ip_interface_address (lm6, ia, sw_if_index,
3822 1 /* honor unnumbered */,
3824 r6 = ip_interface_address_get_address (lm6, ia);
3825 u16 prefix_length = ia->address_length;
3826 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1);
3829 foreach_ip_interface_address (lm4, ia, sw_if_index,
3830 1 /* honor unnumbered */,
3832 r4 = ip_interface_address_get_address (lm4, ia);
3833 u16 prefix_length = ia->address_length;
3834 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0);
3839 static void send_ip_details (vpe_api_main_t * am,
3840 unix_shared_memory_queue_t *q,
3843 vl_api_ip_details_t * mp;
3845 mp = vl_msg_api_alloc (sizeof (*mp));
3846 memset (mp, 0, sizeof (*mp));
3847 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3849 mp->sw_if_index = ntohl(sw_if_index);
3851 vl_msg_api_send_shmem (q, (u8 *)&mp);
3855 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3856 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3858 vpe_api_main_t * am = &vpe_api_main;
3859 l2t_main_t * lm = &l2t_main;
3860 unix_shared_memory_queue_t * q;
3861 l2t_session_t *session;
3863 q = vl_api_client_index_to_input_queue (mp->client_index);
3867 pool_foreach (session, lm->sessions,
3869 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm);
3874 static void send_sw_interface_tap_details (vpe_api_main_t * am,
3875 unix_shared_memory_queue_t *q,
3876 tapcli_interface_details_t *tap_if)
3878 vl_api_sw_interface_tap_details_t * mp;
3879 mp = vl_msg_api_alloc (sizeof (*mp));
3880 memset (mp, 0, sizeof (*mp));
3881 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
3882 mp->sw_if_index = ntohl(tap_if->sw_if_index);
3883 strncpy((char *)mp->dev_name,
3884 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
3886 vl_msg_api_send_shmem (q, (u8 *)&mp);
3890 vl_api_sw_interface_tap_dump_t_handler (
3891 vl_api_sw_interface_tap_dump_t *mp)
3894 vpe_api_main_t * am = &vpe_api_main;
3895 unix_shared_memory_queue_t * q;
3896 tapcli_interface_details_t *tapifs = NULL;
3897 tapcli_interface_details_t *tap_if = NULL;
3899 q = vl_api_client_index_to_input_queue (mp->client_index);
3903 rv = vnet_tap_dump_ifs(&tapifs);
3907 vec_foreach(tap_if, tapifs) {
3908 send_sw_interface_tap_details(am, q, tap_if);
3915 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
3917 vpe_api_main_t * am = &vpe_api_main;
3918 vnet_main_t * vnm = vnet_get_main();
3919 vlib_main_t * vm = vlib_get_main();
3920 vnet_interface_main_t * im = &vnm->interface_main;
3921 unix_shared_memory_queue_t * q;
3922 vnet_sw_interface_t * si, * sorted_sis;
3923 u32 sw_if_index = ~0;
3925 q = vl_api_client_index_to_input_queue (mp->client_index);
3930 /* Gather interfaces. */
3931 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
3932 _vec_len (sorted_sis) = 0;
3933 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
3935 vec_foreach (si, sorted_sis) {
3936 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
3937 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
3940 sw_if_index = si->sw_if_index;
3941 send_ip_details(am, q, sw_if_index);
3946 static void vl_api_l2_fib_table_entry_t_handler (
3947 vl_api_l2_fib_table_entry_t * mp)
3949 clib_warning ("BUG");
3952 static void send_l2fib_table_entry (vpe_api_main_t * am,
3953 unix_shared_memory_queue_t *q,
3954 l2fib_entry_key_t * l2fe_key,
3955 l2fib_entry_result_t * l2fe_res)
3957 vl_api_l2_fib_table_entry_t * mp;
3959 mp = vl_msg_api_alloc (sizeof (*mp));
3960 memset (mp, 0, sizeof (*mp));
3961 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
3963 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
3965 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
3966 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
3967 mp->static_mac = l2fe_res->fields.static_mac;
3968 mp->filter_mac = l2fe_res->fields.filter;
3969 mp->bvi_mac = l2fe_res->fields.bvi;
3971 vl_msg_api_send_shmem (q, (u8 *)&mp);
3975 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
3977 vpe_api_main_t * am = &vpe_api_main;
3978 bd_main_t * bdm = &bd_main;
3979 l2fib_entry_key_t *l2fe_key = NULL;
3980 l2fib_entry_result_t *l2fe_res = NULL;
3981 u32 ni, bd_id = ntohl (mp->bd_id);
3983 unix_shared_memory_queue_t * q;
3986 q = vl_api_client_index_to_input_queue (mp->client_index);
3990 /* see l2fib_table_dump: ~0 means "any" */
3994 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4001 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4003 vec_foreach_index (ni, l2fe_key) {
4004 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4005 vec_elt_at_index(l2fe_res, ni));
4012 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4014 vl_api_show_version_reply_t *rmp;
4016 char * vpe_api_get_build_directory(void);
4017 char * vpe_api_get_version(void);
4018 char * vpe_api_get_build_date(void);
4020 unix_shared_memory_queue_t * q =
4021 vl_api_client_index_to_input_queue (mp->client_index);
4026 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4028 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4029 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4030 ARRAY_LEN(rmp->build_directory)-1);
4031 strncpy ((char *) rmp->version, vpe_api_get_version(),
4032 ARRAY_LEN(rmp->version)-1);
4033 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4034 ARRAY_LEN(rmp->build_date)-1);
4038 static void vl_api_get_node_index_t_handler
4039 (vl_api_get_node_index_t * mp)
4041 vlib_main_t * vm = vlib_get_main();
4042 vl_api_get_node_index_reply_t * rmp;
4045 u32 node_index = ~0;
4047 n = vlib_get_node_by_name (vm, mp->node_name);
4050 rv = VNET_API_ERROR_NO_SUCH_NODE;
4052 node_index = n->index;
4054 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4056 rmp->node_index = ntohl(node_index);
4060 static void vl_api_add_node_next_t_handler
4061 (vl_api_add_node_next_t * mp)
4063 vlib_main_t * vm = vlib_get_main();
4064 vl_api_add_node_next_reply_t * rmp;
4065 vlib_node_t * n, * next;
4067 u32 next_index = ~0;
4069 n = vlib_get_node_by_name (vm, mp->node_name);
4072 rv = VNET_API_ERROR_NO_SUCH_NODE;
4076 next = vlib_get_node_by_name (vm, mp->next_name);
4079 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4081 next_index = vlib_node_add_next (vm, n->index, next->index);
4084 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4086 rmp->next_index = ntohl(next_index);
4090 static void vl_api_l2tpv3_create_tunnel_t_handler
4091 (vl_api_l2tpv3_create_tunnel_t *mp)
4093 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4094 l2t_main_t *lm = &l2t_main;
4095 u32 sw_if_index = (u32)~0;
4098 if (mp->is_ipv6 != 1) {
4099 rv = VNET_API_ERROR_UNIMPLEMENTED;
4103 rv = create_l2tpv3_ipv6_tunnel (lm,
4104 (ip6_address_t *) mp->client_address,
4105 (ip6_address_t *) mp->our_address,
4106 ntohl(mp->local_session_id),
4107 ntohl(mp->remote_session_id),
4108 clib_net_to_host_u64(mp->local_cookie),
4109 clib_net_to_host_u64(mp->remote_cookie),
4110 mp->l2_sublayer_present,
4114 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4116 rmp->sw_if_index = ntohl (sw_if_index);
4120 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4121 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4123 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4124 l2t_main_t *lm = &l2t_main;
4127 VALIDATE_SW_IF_INDEX(mp);
4129 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4130 clib_net_to_host_u64(mp->new_local_cookie),
4131 clib_net_to_host_u64(mp->new_remote_cookie));
4133 BAD_SW_IF_INDEX_LABEL;
4135 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4138 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4139 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4142 vnet_main_t * vnm = vnet_get_main();
4143 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4145 VALIDATE_SW_IF_INDEX(mp);
4147 rv = l2tpv3_interface_enable_disable
4148 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4150 BAD_SW_IF_INDEX_LABEL;
4152 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4155 static void vl_api_l2tpv3_set_lookup_key_t_handler
4156 (vl_api_l2tpv3_set_lookup_key_t * mp)
4159 l2t_main_t *lm = &l2t_main;
4160 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4162 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4163 rv = VNET_API_ERROR_INVALID_VALUE;
4167 lm->lookup_type = mp->key;
4170 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4173 static void vl_api_vxlan_add_del_tunnel_t_handler
4174 (vl_api_vxlan_add_del_tunnel_t * mp)
4176 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4178 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4179 u32 encap_fib_index;
4181 ip4_main_t * im = &ip4_main;
4182 u32 sw_if_index = ~0;
4184 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4186 rv = VNET_API_ERROR_NO_SUCH_FIB;
4189 encap_fib_index = p[0];
4191 memset (a, 0, sizeof (*a));
4193 a->is_add = mp->is_add;
4195 /* ip addresses sent in network byte order */
4196 a->src.as_u32 = mp->src_address;
4197 a->dst.as_u32 = mp->dst_address;
4199 a->encap_fib_index = encap_fib_index;
4200 a->decap_next_index = ntohl(mp->decap_next_index);
4201 a->vni = ntohl(mp->vni);
4202 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4205 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4207 rmp->sw_if_index = ntohl (sw_if_index);
4211 static void send_vxlan_tunnel_details
4212 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q)
4214 vl_api_vxlan_tunnel_details_t * rmp;
4215 ip4_main_t * im = &ip4_main;
4217 rmp = vl_msg_api_alloc (sizeof (*rmp));
4218 memset (rmp, 0, sizeof (*rmp));
4219 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4220 rmp->src_address = t->src.data_u32;
4221 rmp->dst_address = t->dst.data_u32;
4222 rmp->encap_vrf_id = htonl(im->fibs[t->encap_fib_index].table_id);
4223 rmp->vni = htonl(t->vni);
4224 rmp->decap_next_index = htonl(t->decap_next_index);
4225 rmp->sw_if_index = htonl(t->sw_if_index);
4227 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4230 static void vl_api_vxlan_tunnel_dump_t_handler
4231 (vl_api_vxlan_tunnel_dump_t * mp)
4233 unix_shared_memory_queue_t * q;
4234 vxlan_main_t * vxm = &vxlan_main;
4238 q = vl_api_client_index_to_input_queue (mp->client_index);
4243 sw_if_index = ntohl(mp->sw_if_index);
4245 if (~0 == sw_if_index) {
4246 pool_foreach (t, vxm->tunnels,
4248 send_vxlan_tunnel_details(t, q);
4251 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4252 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4255 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4256 send_vxlan_tunnel_details(t, q);
4261 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4263 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4265 vl_api_l2_patch_add_del_reply_t * rmp;
4266 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4270 VALIDATE_RX_SW_IF_INDEX(mp);
4271 VALIDATE_TX_SW_IF_INDEX(mp);
4273 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4274 ntohl(mp->tx_sw_if_index),
4275 (int)(mp->is_add != 0));
4277 BAD_RX_SW_IF_INDEX_LABEL;
4278 BAD_TX_SW_IF_INDEX_LABEL;
4280 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4284 vl_api_nsh_gre_add_del_tunnel_t_handler
4285 (vl_api_nsh_gre_add_del_tunnel_t * mp)
4287 vl_api_nsh_gre_add_del_tunnel_reply_t * rmp;
4289 vnet_nsh_gre_add_del_tunnel_args_t _a, *a = &_a;
4290 u32 encap_fib_index, decap_fib_index;
4291 u32 decap_next_index;
4293 ip4_main_t * im = &ip4_main;
4295 u32 sw_if_index = ~0;
4298 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4300 rv = VNET_API_ERROR_NO_SUCH_FIB;
4303 encap_fib_index = p[0];
4305 decap_next_index = ntohl(mp->decap_next_index);
4307 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4308 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4309 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4311 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4314 decap_fib_index = p[0];
4316 decap_fib_index = ntohl(mp->decap_vrf_id);
4319 memset (a, 0, sizeof (*a));
4321 a->is_add = mp->is_add;
4322 /* ip addresses sent in network byte order */
4323 a->src.as_u32 = ntohl(mp->src);
4324 a->dst.as_u32 = ntohl(mp->dst);
4325 a->encap_fib_index = encap_fib_index;
4326 a->decap_fib_index = decap_fib_index;
4327 a->decap_next_index = decap_next_index;
4328 a->ver_o_c = mp->ver_o_c;
4329 a->length = mp->length;
4330 a->md_type = mp->md_type;
4331 a->next_protocol = mp->next_protocol;
4332 a->spi_si = ntohl(mp->spi_si);
4333 a->c1 = ntohl(mp->c1);
4334 a->c2 = ntohl(mp->c2);
4335 a->c3 = ntohl(mp->c3);
4336 a->c4 = ntohl(mp->c4);
4338 for (i = 0; i < mp->tlv_len_in_words; i++)
4339 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4343 rv = vnet_nsh_gre_add_del_tunnel (a, &sw_if_index);
4346 REPLY_MACRO2(VL_API_NSH_GRE_ADD_DEL_TUNNEL_REPLY,
4348 rmp->sw_if_index = ntohl (sw_if_index);
4353 vl_api_nsh_vxlan_gpe_add_del_tunnel_t_handler
4354 (vl_api_nsh_vxlan_gpe_add_del_tunnel_t * mp)
4356 vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4358 vnet_nsh_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4359 u32 encap_fib_index, decap_fib_index;
4360 u32 decap_next_index;
4362 ip4_main_t * im = &ip4_main;
4364 u32 sw_if_index = ~0;
4367 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4369 rv = VNET_API_ERROR_NO_SUCH_FIB;
4372 encap_fib_index = p[0];
4374 decap_next_index = ntohl(mp->decap_next_index);
4376 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4377 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4378 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4380 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4383 decap_fib_index = p[0];
4385 decap_fib_index = ntohl(mp->decap_vrf_id);
4388 memset (a, 0, sizeof (*a));
4390 a->is_add = mp->is_add;
4391 /* ip addresses sent in network byte order */
4392 a->src.as_u32 = ntohl(mp->src);
4393 a->dst.as_u32 = ntohl(mp->dst);
4394 a->encap_fib_index = encap_fib_index;
4395 a->decap_fib_index = decap_fib_index;
4396 a->decap_next_index = decap_next_index;
4397 a->vni = ntohl(mp->vni);
4398 a->ver_o_c = mp->ver_o_c;
4399 a->length = mp->length;
4400 a->md_type = mp->md_type;
4401 a->next_protocol = mp->next_protocol;
4402 a->spi_si = ntohl(mp->spi_si);
4403 a->c1 = ntohl(mp->c1);
4404 a->c2 = ntohl(mp->c2);
4405 a->c3 = ntohl(mp->c3);
4406 a->c4 = ntohl(mp->c4);
4408 for (i = 0; i < mp->tlv_len_in_words; i++)
4409 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4413 rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4416 REPLY_MACRO2(VL_API_NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4418 rmp->sw_if_index = ntohl (sw_if_index);
4423 vl_api_lisp_gpe_add_del_tunnel_t_handler
4424 (vl_api_lisp_gpe_add_del_tunnel_t * mp)
4426 vl_api_lisp_gpe_add_del_tunnel_reply_t * rmp;
4428 vnet_lisp_gpe_add_del_tunnel_args_t _a, *a = &_a;
4429 u32 encap_fib_index, decap_fib_index;
4430 u32 decap_next_index;
4432 ip4_main_t * im = &ip4_main;
4433 u32 sw_if_index = ~0;
4435 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4437 rv = VNET_API_ERROR_NO_SUCH_FIB;
4440 encap_fib_index = p[0];
4442 decap_next_index = ntohl(mp->decap_next_index);
4444 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4445 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4446 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4448 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4451 decap_fib_index = p[0];
4453 decap_fib_index = ntohl(mp->decap_vrf_id);
4456 memset (a, 0, sizeof (*a));
4458 a->is_add = mp->is_add;
4459 /* ip addresses sent in network byte order */
4460 a->src.as_u32 = mp->src;
4461 a->dst.as_u32 = mp->dst;
4462 a->encap_fib_index = encap_fib_index;
4463 a->decap_fib_index = decap_fib_index;
4464 a->decap_next_index = decap_next_index;
4465 a->flags = mp->flags;
4466 a->ver_res = mp->ver_res;
4468 a->next_protocol = mp->next_protocol;
4469 a->iid = clib_net_to_host_u32 (mp->iid);
4471 rv = vnet_lisp_gpe_add_del_tunnel (a, &sw_if_index);
4474 REPLY_MACRO2(VL_API_LISP_GPE_ADD_DEL_TUNNEL_REPLY,
4476 rmp->sw_if_index = ntohl (sw_if_index);
4481 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
4483 vl_api_interface_name_renumber_reply_t * rmp;
4486 VALIDATE_SW_IF_INDEX(mp);
4488 rv = vnet_interface_name_renumber
4489 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
4491 BAD_SW_IF_INDEX_LABEL;
4493 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
4496 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
4497 u32 sw_if_index, u32 address)
4499 vpe_api_main_t * am = &vpe_api_main;
4500 vlib_main_t * vm = am->vlib_main;
4501 vl_api_ip4_arp_event_t * event;
4502 static f64 arp_event_last_time;
4503 f64 now = vlib_time_now (vm);
4505 if (pool_is_free_index (am->arp_events, pool_index))
4508 event = pool_elt_at_index (am->arp_events, pool_index);
4509 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
4510 memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
4511 } else { /* same mac */
4512 if ((sw_if_index == event->sw_if_index) &&
4514 /* for BD case, also check IP address with 10 sec timeout */
4515 ((address == event->address) &&
4516 ((now - arp_event_last_time) < 10.0))))
4520 arp_event_last_time = now;
4521 event->sw_if_index = sw_if_index;
4522 if (address) event->address = address;
4526 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
4528 vpe_api_main_t * am = &vpe_api_main;
4530 if (pool_is_free_index (am->arp_events, pool_index))
4533 pool_put_index (am->arp_events, pool_index);
4538 vl_api_want_ip4_arp_events_t_handler
4539 (vl_api_want_ip4_arp_events_t * mp)
4541 vpe_api_main_t * am = &vpe_api_main;
4542 vnet_main_t * vnm = vnet_get_main();
4543 vl_api_want_ip4_arp_events_reply_t *rmp;
4544 vl_api_ip4_arp_event_t * event;
4547 if (mp->enable_disable) {
4548 pool_get (am->arp_events, event);
4549 memset (event, 0, sizeof (*event));
4551 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
4552 event->client_index = mp->client_index;
4553 event->context = mp->context;
4554 event->address = mp->address;
4555 event->pid = mp->pid;
4557 rv = vnet_add_del_ip4_arp_change_event
4558 (vnm, arp_change_data_callback,
4560 &mp->address /* addr, in net byte order */,
4561 vpe_resolver_process_node.index,
4562 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
4564 rv = vnet_add_del_ip4_arp_change_event
4565 (vnm, arp_change_delete_callback,
4567 &mp->address /* addr, in net byte order */,
4568 vpe_resolver_process_node.index,
4569 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
4571 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
4574 static void vl_api_input_acl_set_interface_t_handler
4575 (vl_api_input_acl_set_interface_t * mp)
4577 vlib_main_t *vm = vlib_get_main();
4578 vl_api_input_acl_set_interface_reply_t * rmp;
4580 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
4582 ip4_table_index = ntohl(mp->ip4_table_index);
4583 ip6_table_index = ntohl(mp->ip6_table_index);
4584 l2_table_index = ntohl(mp->l2_table_index);
4585 sw_if_index = ntohl(mp->sw_if_index);
4587 VALIDATE_SW_IF_INDEX(mp);
4589 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
4590 ip6_table_index, l2_table_index,
4593 BAD_SW_IF_INDEX_LABEL;
4595 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
4598 static void vl_api_ipsec_spd_add_del_t_handler
4599 (vl_api_ipsec_spd_add_del_t * mp)
4602 clib_warning ("unimplemented");
4605 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4606 vl_api_ipsec_spd_add_del_reply_t * rmp;
4610 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
4612 rv = VNET_API_ERROR_UNIMPLEMENTED;
4615 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
4619 static void vl_api_ipsec_interface_add_del_spd_t_handler
4620 (vl_api_ipsec_interface_add_del_spd_t * mp)
4622 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4623 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
4625 u32 sw_if_index __attribute__((unused));
4626 u32 spd_id __attribute__((unused));
4628 sw_if_index = ntohl(mp->sw_if_index);
4629 spd_id = ntohl(mp->spd_id);
4631 VALIDATE_SW_IF_INDEX(mp);
4634 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
4636 rv = VNET_API_ERROR_UNIMPLEMENTED;
4639 BAD_SW_IF_INDEX_LABEL;
4641 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
4644 static void vl_api_ipsec_spd_add_del_entry_t_handler
4645 (vl_api_ipsec_spd_add_del_entry_t * mp)
4647 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4648 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
4654 memset(&p, 0, sizeof(p));
4656 p.id = ntohl(mp->spd_id);
4657 p.priority = ntohl(mp->priority);
4658 p.is_outbound = mp->is_outbound;
4659 p.is_ipv6 = mp->is_ipv6;
4661 memcpy(&p.raddr.start, mp->remote_address_start, 16);
4662 memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
4663 memcpy(&p.laddr.start, mp->local_address_start, 16);
4664 memcpy(&p.laddr.stop, mp->local_address_stop, 16);
4666 p.protocol = mp->protocol;
4667 p.rport.start = ntohs(mp->remote_port_start);
4668 p.rport.stop = ntohs(mp->remote_port_stop);
4669 p.lport.start = ntohs(mp->local_port_start);
4670 p.lport.stop = ntohs(mp->local_port_stop);
4671 /* policy action resolve unsupported */
4672 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
4673 clib_warning("unsupported action: 'resolve'");
4674 rv = VNET_API_ERROR_UNIMPLEMENTED;
4677 p.policy = mp->policy;
4678 p.sa_id = ntohl(mp->sa_id);
4680 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4684 if (mp->is_ip_any) {
4686 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4689 rv = VNET_API_ERROR_UNIMPLEMENTED;
4694 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
4697 static void vl_api_ipsec_sad_add_del_entry_t_handler
4698 (vl_api_ipsec_sad_add_del_entry_t * mp)
4700 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4701 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
4706 memset(&sa, 0, sizeof(sa));
4708 sa.id = ntohl(mp->sad_id);
4709 sa.spi = ntohl(mp->spi);
4710 /* security protocol AH unsupported */
4711 if (mp->protocol == IPSEC_PROTOCOL_AH) {
4712 clib_warning("unsupported security protocol 'AH'");
4713 rv = VNET_API_ERROR_UNIMPLEMENTED;
4716 sa.protocol = mp->protocol;
4717 /* check for unsupported crypto-alg */
4718 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
4719 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
4720 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
4721 mp->crypto_algorithm);
4722 rv = VNET_API_ERROR_UNIMPLEMENTED;
4725 sa.crypto_alg = mp->crypto_algorithm;
4726 sa.crypto_key_len = mp->crypto_key_length;
4727 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
4728 /* check for unsupported integ-alg */
4729 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
4730 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
4731 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
4732 mp->integrity_algorithm);
4733 rv = VNET_API_ERROR_UNIMPLEMENTED;
4736 sa.integ_alg = mp->integrity_algorithm;
4737 sa.integ_key_len = mp->integrity_key_length;
4738 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
4739 sa.use_esn = mp->use_extended_sequence_number;
4740 sa.is_tunnel = mp->is_tunnel;
4741 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
4742 memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
4743 memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
4745 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
4747 rv = VNET_API_ERROR_UNIMPLEMENTED;
4752 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
4756 vl_api_ikev2_profile_add_del_t_handler
4757 (vl_api_ikev2_profile_add_del_t * mp)
4759 vlib_main_t * vm = vlib_get_main();
4760 vl_api_ikev2_profile_add_del_reply_t * rmp;
4764 clib_error_t * error;
4765 u8 * tmp = format(0, "%s", mp->name);
4766 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
4769 rv = VNET_API_ERROR_UNSPECIFIED;
4771 rv = VNET_API_ERROR_UNIMPLEMENTED;
4774 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
4778 vl_api_ikev2_profile_set_auth_t_handler
4779 (vl_api_ikev2_profile_set_auth_t * mp)
4781 vlib_main_t * vm = vlib_get_main();
4782 vl_api_ikev2_profile_set_auth_reply_t * rmp;
4786 clib_error_t * error;
4787 u8 * tmp = format(0, "%s", mp->name);
4788 u8 * data = vec_new (u8, mp->data_len);
4789 memcpy(data, mp->data, mp->data_len);
4790 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
4794 rv = VNET_API_ERROR_UNSPECIFIED;
4796 rv = VNET_API_ERROR_UNIMPLEMENTED;
4799 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
4803 vl_api_ikev2_profile_set_id_t_handler
4804 (vl_api_ikev2_profile_set_id_t * mp)
4806 vlib_main_t * vm = vlib_get_main();
4807 vl_api_ikev2_profile_set_id_reply_t * rmp;
4811 clib_error_t * error;
4812 u8 * tmp = format(0, "%s", mp->name);
4813 u8 * data = vec_new (u8, mp->data_len);
4814 memcpy(data, mp->data, mp->data_len);
4815 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
4819 rv = VNET_API_ERROR_UNSPECIFIED;
4821 rv = VNET_API_ERROR_UNIMPLEMENTED;
4824 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
4828 vl_api_ikev2_profile_set_ts_t_handler
4829 (vl_api_ikev2_profile_set_ts_t * mp)
4831 vlib_main_t * vm = vlib_get_main();
4832 vl_api_ikev2_profile_set_ts_reply_t * rmp;
4836 clib_error_t * error;
4837 u8 * tmp = format(0, "%s", mp->name);
4838 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
4839 mp->end_port, (ip4_address_t) mp->start_addr,
4840 (ip4_address_t) mp->end_addr, mp->is_local);
4843 rv = VNET_API_ERROR_UNSPECIFIED;
4845 rv = VNET_API_ERROR_UNIMPLEMENTED;
4848 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
4852 vl_api_ikev2_set_local_key_t_handler
4853 (vl_api_ikev2_set_local_key_t * mp)
4855 vlib_main_t * vm = vlib_get_main();
4856 vl_api_ikev2_set_local_key_reply_t * rmp;
4860 clib_error_t * error;
4862 error = ikev2_set_local_key(vm, mp->key_file);
4864 rv = VNET_API_ERROR_UNSPECIFIED;
4866 rv = VNET_API_ERROR_UNIMPLEMENTED;
4869 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
4873 vl_api_map_add_domain_t_handler
4874 (vl_api_map_add_domain_t * mp)
4876 vl_api_map_add_domain_reply_t * rmp;
4879 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
4880 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
4881 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
4882 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
4883 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
4885 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
4887 rmp->index = ntohl(index);
4892 vl_api_map_del_domain_t_handler
4893 (vl_api_map_del_domain_t * mp)
4895 vl_api_map_del_domain_reply_t * rmp;
4898 rv = map_delete_domain(ntohl(mp->index));
4900 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
4904 vl_api_map_add_del_rule_t_handler
4905 (vl_api_map_add_del_rule_t * mp)
4907 vl_api_map_del_domain_reply_t * rmp;
4910 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
4912 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
4916 vl_api_map_domain_dump_t_handler
4917 (vl_api_map_domain_dump_t * mp)
4919 vl_api_map_domain_details_t * rmp;
4920 map_main_t *mm = &map_main;
4922 unix_shared_memory_queue_t * q;
4924 if (pool_elts (mm->domains) == 0)
4927 q = vl_api_client_index_to_input_queue (mp->client_index);
4932 pool_foreach(d, mm->domains, ({
4933 rmp = vl_msg_api_alloc (sizeof (*rmp));
4934 memset (rmp, 0, sizeof (*rmp));
4935 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
4936 rmp->domain_index = htonl(d - mm->domains);
4937 rmp->ea_bits_len = d->ea_bits_len;
4938 rmp->psid_offset = d->psid_offset;
4939 rmp->psid_length = d->psid_length;
4940 memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
4941 rmp->ip4_prefix_len = d->ip4_prefix_len;
4942 memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
4943 rmp->ip6_prefix_len = d->ip6_prefix_len;
4944 memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
4945 rmp->ip6_src_len = d->ip6_src_len;
4946 rmp->mtu = htons(d->mtu);
4947 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
4949 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4954 vl_api_map_rule_dump_t_handler
4955 (vl_api_map_rule_dump_t * mp)
4957 unix_shared_memory_queue_t * q;
4960 vl_api_map_rule_details_t * rmp;
4961 map_main_t *mm = &map_main;
4962 u32 domain_index = ntohl(mp->domain_index);
4965 if (pool_elts (mm->domains) == 0)
4968 d = pool_elt_at_index(mm->domains, domain_index);
4969 if (!d || !d->rules) {
4973 q = vl_api_client_index_to_input_queue (mp->client_index);
4978 for (i = 0; i < (0x1 << d->psid_length); i++) {
4980 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
4983 rmp = vl_msg_api_alloc(sizeof(*rmp));
4984 memset(rmp, 0, sizeof(*rmp));
4985 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
4986 rmp->psid = htons(i);
4987 memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
4988 vl_msg_api_send_shmem(q, (u8 *)&rmp);
4993 vl_api_map_summary_stats_t_handler (
4994 vl_api_map_summary_stats_t *mp)
4996 vl_api_map_summary_stats_reply_t *rmp;
4997 vlib_combined_counter_main_t *cm;
5000 u64 total_pkts[VLIB_N_RX_TX];
5001 u64 total_bytes[VLIB_N_RX_TX];
5002 map_main_t *mm = &map_main;
5003 unix_shared_memory_queue_t *q =
5004 vl_api_client_index_to_input_queue(mp->client_index);
5009 rmp = vl_msg_api_alloc (sizeof (*rmp));
5010 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
5011 rmp->context = mp->context;
5014 memset (total_pkts, 0, sizeof (total_pkts));
5015 memset (total_bytes, 0, sizeof (total_bytes));
5017 map_domain_counter_lock (mm);
5018 vec_foreach(cm, mm->domain_counters) {
5019 which = cm - mm->domain_counters;
5021 for (i = 0; i < vec_len(cm->maxi); i++) {
5022 vlib_get_combined_counter (cm, i, &v);
5023 total_pkts[which] += v.packets;
5024 total_bytes[which] += v.bytes;
5028 map_domain_counter_unlock (mm);
5030 /* Note: in HOST byte order! */
5031 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = total_pkts[MAP_DOMAIN_COUNTER_RX];
5032 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = total_bytes[MAP_DOMAIN_COUNTER_RX];
5033 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = total_pkts[MAP_DOMAIN_COUNTER_TX];
5034 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = total_bytes[MAP_DOMAIN_COUNTER_TX];
5035 rmp->total_bindings = pool_elts(mm->domains);
5036 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
5037 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK);
5038 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK);
5040 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5043 static void vl_api_ipsec_sa_set_key_t_handler
5044 (vl_api_ipsec_sa_set_key_t * mp)
5046 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5047 vl_api_ipsec_sa_set_key_reply_t *rmp;
5051 sa.id = ntohl(mp->sa_id);
5052 sa.crypto_key_len = mp->crypto_key_length;
5053 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5054 sa.integ_key_len = mp->integrity_key_length;
5055 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5057 rv = ipsec_set_sa_key(vm, &sa);
5059 rv = VNET_API_ERROR_UNIMPLEMENTED;
5062 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
5065 static void vl_api_cop_interface_enable_disable_t_handler
5066 (vl_api_cop_interface_enable_disable_t * mp)
5068 vl_api_cop_interface_enable_disable_reply_t * rmp;
5070 u32 sw_if_index = ntohl(mp->sw_if_index);
5073 VALIDATE_SW_IF_INDEX(mp);
5075 enable_disable = (int) mp->enable_disable;
5077 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5079 BAD_SW_IF_INDEX_LABEL;
5081 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5084 static void vl_api_cop_whitelist_enable_disable_t_handler
5085 (vl_api_cop_whitelist_enable_disable_t * mp)
5087 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
5088 cop_whitelist_enable_disable_args_t _a, *a=&_a;
5089 u32 sw_if_index = ntohl(mp->sw_if_index);
5092 VALIDATE_SW_IF_INDEX(mp);
5094 a->sw_if_index = sw_if_index;
5097 a->default_cop = mp->default_cop;
5098 a->fib_id = ntohl(mp->fib_id);
5100 rv = cop_whitelist_enable_disable (a);
5102 BAD_SW_IF_INDEX_LABEL;
5104 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5107 static void vl_api_get_node_graph_t_handler
5108 (vl_api_get_node_graph_t * mp)
5112 api_main_t * am = &api_main;
5113 vlib_main_t * vm = vlib_get_main();
5115 vl_api_get_node_graph_reply_t * rmp;
5117 pthread_mutex_lock (&am->vlib_rp->mutex);
5118 oldheap = svm_push_data_heap (am->vlib_rp);
5121 * Keep the number of memcpy ops to a minimum (e.g. 1).
5122 * The current size of the serialized vector is
5123 * slightly under 4K.
5125 vec_validate (vector, 4095);
5126 vec_reset_length (vector);
5128 vector = vlib_node_serialize (&vm->node_main, vector);
5130 svm_pop_heap (oldheap);
5131 pthread_mutex_unlock (&am->vlib_rp->mutex);
5133 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5134 rmp->reply_in_shmem = (uword) vector);
5137 static void vl_api_trace_profile_add_t_handler
5138 (vl_api_trace_profile_add_t *mp)
5141 vl_api_trace_profile_add_reply_t * rmp;
5142 clib_error_t *error;
5144 /* Ignoring the profile id as currently a single profile
5146 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5147 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5148 mp->pow_enable, mp->trace_tsp,
5151 clib_error_report(error);
5152 rv = clib_error_get_code(error);
5155 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5158 static void vl_api_trace_profile_apply_t_handler
5159 (vl_api_trace_profile_apply_t *mp)
5162 vl_api_trace_profile_apply_reply_t * rmp;
5164 if (mp->enable != 0) {
5165 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5166 ntohl(mp->prefix_length),
5168 mp->trace_op == IOAM_HBYH_ADD,
5169 mp->trace_op == IOAM_HBYH_POP,
5170 mp->trace_op == IOAM_HBYH_MOD);
5172 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5174 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5177 static void vl_api_trace_profile_del_t_handler
5178 (vl_api_trace_profile_del_t *mp)
5181 vl_api_trace_profile_del_reply_t * rmp;
5182 clib_error_t *error;
5184 error = clear_ioam_rewrite_fn();
5186 clib_error_report(error);
5187 rv = clib_error_get_code(error);
5190 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5194 #define BOUNCE_HANDLER(nn) \
5195 static void vl_api_##nn##_t_handler ( \
5196 vl_api_##nn##_t *mp) \
5198 vpe_client_registration_t *reg; \
5199 vpe_api_main_t * vam = &vpe_api_main; \
5200 unix_shared_memory_queue_t * q; \
5202 /* One registration only... */ \
5203 pool_foreach(reg, vam->nn##_registrations, \
5205 q = vl_api_client_index_to_input_queue (reg->client_index); \
5208 * If the queue is stuffed, turf the msg and complain \
5209 * It's unlikely that the intended recipient is \
5210 * alive; avoid deadlock at all costs. \
5212 if (q->cursize == q->maxsize) { \
5213 clib_warning ("ERROR: receiver queue full, drop msg"); \
5214 vl_msg_api_free (mp); \
5217 vl_msg_api_send_shmem (q, (u8 *)&mp); \
5221 vl_msg_api_free (mp); \
5224 BOUNCE_HANDLER(to_netconf_server);
5225 BOUNCE_HANDLER(from_netconf_server);
5226 BOUNCE_HANDLER(to_netconf_client);
5227 BOUNCE_HANDLER(from_netconf_client);
5231 * Add vpe's API message handlers to the table.
5232 * vlib has alread mapped shared memory and
5233 * added the client registration handlers.
5234 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
5237 static clib_error_t *
5238 vpe_api_hookup (vlib_main_t *vm)
5240 api_main_t * am = &api_main;
5243 vl_msg_api_set_handlers(VL_API_##N, #n, \
5244 vl_api_##n##_t_handler, \
5246 vl_api_##n##_t_endian, \
5247 vl_api_##n##_t_print, \
5248 sizeof(vl_api_##n##_t), 1);
5249 foreach_vpe_api_msg;
5253 * Manually register the sr tunnel add del msg, so we trace
5254 * enough bytes to capture a typical segment list
5256 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
5257 "sr_tunnel_add_del",
5258 vl_api_sr_tunnel_add_del_t_handler,
5260 vl_api_sr_tunnel_add_del_t_endian,
5261 vl_api_sr_tunnel_add_del_t_print,
5264 am->message_bounce [VL_API_FROM_NETCONF_SERVER] = 1;
5265 am->message_bounce [VL_API_TO_NETCONF_SERVER] = 1;
5266 am->message_bounce [VL_API_FROM_NETCONF_CLIENT] = 1;
5267 am->message_bounce [VL_API_TO_NETCONF_CLIENT] = 1;
5270 * Trace space for 8 MPLS encap labels, classifier mask+match
5272 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
5273 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
5274 += 5 * sizeof (u32x4);
5275 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
5276 += 5 * sizeof (u32x4);
5277 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
5278 += 16 * sizeof (u32);
5281 * trace space for 4 nsh-gre variable TLV words
5283 am->api_trace_cfg [VL_API_NSH_GRE_ADD_DEL_TUNNEL].size
5284 += 4 * sizeof (u32);
5287 * Thread-safe API messages
5289 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
5294 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
5296 static clib_error_t *
5297 vpe_api_init (vlib_main_t *vm)
5299 vpe_api_main_t *am = &vpe_api_main;
5302 am->vnet_main = vnet_get_main();
5303 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
5304 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5305 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5306 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5307 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5308 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
5311 vl_set_memory_region_name ("/vpe-api");
5312 vl_enable_disable_memory_api (vm, 1 /* enable it */);
5317 VLIB_INIT_FUNCTION(vpe_api_init);
5319 static clib_error_t *
5320 chroot_config (vlib_main_t * vm, unformat_input_t * input)
5324 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5326 if (unformat (input, "prefix %s", &chroot_path))
5328 vec_add1 (chroot_path, 0);
5329 vl_set_memory_root_path ((char *)chroot_path);
5332 return clib_error_return (0, "unknown input `%U'",
5333 format_unformat_error, input);
5337 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
5339 void * get_unformat_vnet_sw_interface (void)
5341 return (void *) &unformat_vnet_sw_interface;
5344 #undef vl_api_version
5345 #define vl_api_version(n,v) static u32 vpe_api_version = v;
5346 #include <api/vpe.api.h>
5347 #undef vl_api_version
5349 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
5351 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
5352 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
5353 clib_host_to_net_u32 (mp->api_versions[0]),
5360 static u8 * format_arp_event (u8 * s, va_list * args)
5362 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
5364 s = format (s, "pid %d: %U", event->pid,
5365 format_ip4_address, &event->address);
5369 static clib_error_t *
5370 show_ip4_arp_events_fn (vlib_main_t * vm,
5371 unformat_input_t * input,
5372 vlib_cli_command_t * cmd)
5374 vpe_api_main_t * am = &vpe_api_main;
5375 vl_api_ip4_arp_event_t * event;
5377 if (pool_elts (am->arp_events) == 0) {
5378 vlib_cli_output (vm, "No active arp event registrations");
5382 pool_foreach (event, am->arp_events,
5384 vlib_cli_output (vm, "%U", format_arp_event, event);
5390 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
5391 .path = "show arp event registrations",
5392 .function = show_ip4_arp_events_fn,
5393 .short_help = "Show arp event registrations",