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>
75 #undef __included_bihash_template_h__
76 #include <vnet/l2/l2_fib.h>
80 #include <vnet/ipsec/ipsec.h>
82 #include <vnet/devices/virtio/vhost-user.h>
85 #include <stats/stats.h>
88 #include <vnet/ethernet/ethernet.h>
89 #include <vnet/ethernet/arp_packet.h>
90 #include <vnet/interface.h>
92 #include <vnet/l2/l2_fib.h>
93 #include <vnet/l2/l2_bd.h>
94 #include <api/vpe_msg_enum.h>
97 #define f64_print(a,b)
99 #define vl_typedefs /* define message structures */
100 #include <api/vpe_all_api_h.h>
103 #define vl_endianfun /* define message structures */
104 #include <api/vpe_all_api_h.h>
107 /* instantiate all the print functions we know about */
108 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
110 #include <api/vpe_all_api_h.h>
113 #define REPLY_MACRO(t) \
115 unix_shared_memory_queue_t * q; \
116 rv = vl_msg_api_pd_handler (mp, rv); \
117 q = vl_api_client_index_to_input_queue (mp->client_index); \
121 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
122 rmp->_vl_msg_id = ntohs((t)); \
123 rmp->context = mp->context; \
124 rmp->retval = ntohl(rv); \
126 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
129 #define REPLY_MACRO2(t, body) \
131 unix_shared_memory_queue_t * q; \
132 rv = vl_msg_api_pd_handler (mp, rv); \
133 q = vl_api_client_index_to_input_queue (mp->client_index); \
137 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
138 rmp->_vl_msg_id = ntohs((t)); \
139 rmp->context = mp->context; \
140 rmp->retval = ntohl(rv); \
141 do {body;} while (0); \
142 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
145 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
147 #define VALIDATE_SW_IF_INDEX(mp) \
148 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
149 vnet_main_t *__vnm = vnet_get_main(); \
150 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
152 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
153 goto bad_sw_if_index; \
157 #define BAD_SW_IF_INDEX_LABEL \
163 #define VALIDATE_RX_SW_IF_INDEX(mp) \
164 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
165 vnet_main_t *__vnm = vnet_get_main(); \
166 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
167 __rx_sw_if_index)) { \
168 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
169 goto bad_rx_sw_if_index; \
173 #define BAD_RX_SW_IF_INDEX_LABEL \
175 bad_rx_sw_if_index: \
179 #define VALIDATE_TX_SW_IF_INDEX(mp) \
180 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
181 vnet_main_t *__vnm = vnet_get_main(); \
182 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
183 __tx_sw_if_index)) { \
184 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
185 goto bad_tx_sw_if_index; \
189 #define BAD_TX_SW_IF_INDEX_LABEL \
191 bad_tx_sw_if_index: \
197 #define VALIDATE_SW_IF_INDEX(mp)
198 #define BAD_SW_IF_INDEX_LABEL
199 #define VALIDATE_RX_SW_IF_INDEX(mp)
200 #define BAD_RX_SW_IF_INDEX_LABEL
201 #define VALIDATE_TX_SW_IF_INDEX(mp)
202 #define BAD_TX_SW_IF_INDEX_LABEL
204 #endif /* CLIB_DEBUG > 0 */
206 #define foreach_vpe_api_msg \
207 _(WANT_INTERFACE_EVENTS, want_interface_events) \
208 _(WANT_FROM_NETCONF_SERVER, want_from_netconf_server) \
209 _(WANT_TO_NETCONF_SERVER, want_to_netconf_server) \
210 _(WANT_FROM_NETCONF_CLIENT, want_from_netconf_client) \
211 _(WANT_TO_NETCONF_CLIENT, want_to_netconf_client) \
212 _(FROM_NETCONF_SERVER, from_netconf_server) \
213 _(TO_NETCONF_SERVER, to_netconf_server) \
214 _(FROM_NETCONF_CLIENT, from_netconf_client) \
215 _(TO_NETCONF_CLIENT, to_netconf_client) \
216 _(WANT_OAM_EVENTS, want_oam_events) \
217 _(OAM_ADD_DEL, oam_add_del) \
218 _(SW_INTERFACE_DUMP, sw_interface_dump) \
219 _(SW_INTERFACE_DETAILS, sw_interface_details) \
220 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
221 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
222 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
223 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
224 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
225 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
226 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
227 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
228 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
229 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
230 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
231 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
232 _(L2FIB_ADD_DEL, l2fib_add_del) \
233 _(L2_FLAGS, l2_flags) \
234 _(BRIDGE_FLAGS, bridge_flags) \
235 _(TAP_CONNECT, tap_connect) \
236 _(TAP_MODIFY, tap_modify) \
237 _(TAP_DELETE, tap_delete) \
238 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
239 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
240 _(CREATE_SUBIF, create_subif) \
241 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
242 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
243 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
244 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
245 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
246 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
247 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
248 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
249 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
250 _(RESET_FIB, reset_fib) \
251 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
252 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
253 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
254 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
255 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
256 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
257 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
258 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
259 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
260 sw_interface_ip6_set_link_local_address) \
261 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
262 _(CREATE_LOOPBACK, create_loopback) \
263 _(CONTROL_PING, control_ping) \
264 _(CLI_REQUEST, cli_request) \
265 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
266 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
267 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
268 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
269 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
270 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
271 _(GET_NODE_INDEX, get_node_index) \
272 _(ADD_NODE_NEXT, add_node_next) \
273 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
274 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
275 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
276 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
277 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
278 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
279 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
280 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
281 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
282 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
283 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
284 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
285 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
286 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
287 _(IP_ADDRESS_DUMP, ip_address_dump) \
288 _(IP_DUMP, ip_dump) \
289 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
290 _(SHOW_VERSION, show_version) \
291 _(NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel) \
292 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
293 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
294 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel) \
295 _(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel) \
296 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
297 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
298 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
299 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
300 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
301 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
302 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
303 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
304 _(DELETE_LOOPBACK, delete_loopback) \
305 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
306 _(MAP_ADD_DOMAIN, map_add_domain) \
307 _(MAP_DEL_DOMAIN, map_del_domain) \
308 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
309 _(MAP_DOMAIN_DUMP, map_domain_dump) \
310 _(MAP_RULE_DUMP, map_rule_dump) \
311 _(MAP_SUMMARY_STATS, map_summary_stats) \
312 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
313 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
314 _(GET_NODE_GRAPH, get_node_graph)
317 #define QUOTE(x) QUOTE_(x)
319 #define foreach_registration_hash \
320 _(interface_events) \
321 _(to_netconf_server) \
322 _(from_netconf_server) \
323 _(to_netconf_client) \
324 _(from_netconf_client) \
328 RESOLVE_IP4_ADD_DEL_ROUTE=1,
329 RESOLVE_IP6_ADD_DEL_ROUTE,
330 RESOLVE_MPLS_ETHERNET_ADD_DEL,
336 vl_api_ip_add_del_route_t r;
337 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
343 #define _(a) uword *a##_registration_hash; \
344 vpe_client_registration_t * a##_registrations;
345 foreach_registration_hash
348 /* notifications happen really early in the game */
349 u8 link_state_process_up;
351 /* ip4 pending route adds */
352 pending_route_t * pending_routes;
354 /* ip4 arp event registration pool */
355 vl_api_ip4_arp_event_t * arp_events;
358 vlib_main_t * vlib_main;
359 vnet_main_t * vnet_main;
362 static vlib_node_registration_t vpe_resolver_process_node;
363 static vpe_api_main_t vpe_api_main;
365 static void send_sw_interface_flags (vpe_api_main_t * am,
366 unix_shared_memory_queue_t *q,
367 vnet_sw_interface_t * swif);
368 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
369 unix_shared_memory_queue_t *q,
372 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
375 /* Clean up all registrations belonging to the indicated client */
376 int vl_api_memclnt_delete_callback (u32 client_index)
378 vpe_api_main_t * vam = &vpe_api_main;
379 vpe_client_registration_t *rp;
381 int stats_memclnt_delete_callback (u32 client_index);
383 stats_memclnt_delete_callback (client_index);
386 p = hash_get (vam->a##_registration_hash, client_index); \
388 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
389 pool_put (vam->a##_registrations, rp); \
390 hash_unset (vam->a##_registration_hash, client_index); \
392 foreach_registration_hash;
397 #define API_LINK_STATE_EVENT 1
398 #define API_ADMIN_UP_DOWN_EVENT 2
401 event_data_cmp (void * a1, void * a2)
406 return (word) e1[0] - (word) e2[0];
410 link_state_process (vlib_main_t * vm,
411 vlib_node_runtime_t * rt,
414 vpe_api_main_t * vam = &vpe_api_main;
415 vnet_main_t * vnm = vam->vnet_main;
416 vnet_sw_interface_t * swif;
417 uword * event_data = 0;
418 vpe_client_registration_t *reg;
420 u32 prev_sw_if_index;
421 unix_shared_memory_queue_t * q;
423 vam->link_state_process_up = 1;
426 vlib_process_wait_for_event (vm);
428 /* Unified list of changed link or admin state sw_if_indices */
429 vlib_process_get_events_with_type
430 (vm, &event_data, API_LINK_STATE_EVENT);
431 vlib_process_get_events_with_type
432 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
434 /* Sort, so we can eliminate duplicates */
435 vec_sort_with_function (event_data, event_data_cmp);
437 prev_sw_if_index = ~0;
439 for (i = 0; i < vec_len(event_data); i++) {
440 /* Only one message per swif */
441 if (prev_sw_if_index == event_data[i])
443 prev_sw_if_index = event_data[i];
445 pool_foreach(reg, vam->interface_events_registrations,
447 q = vl_api_client_index_to_input_queue (reg->client_index);
449 // sw_interface may be deleted already
450 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
453 swif = vnet_get_sw_interface (vnm, event_data[i]);
454 send_sw_interface_flags (vam, q, swif);
459 vec_reset_length (event_data);
465 static clib_error_t *
466 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
467 static clib_error_t *
468 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
470 VLIB_REGISTER_NODE (link_state_process_node,static) = {
471 .function = link_state_process,
472 .type = VLIB_NODE_TYPE_PROCESS,
473 .name = "vpe-link-state-process",
476 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
477 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
479 static clib_error_t *
480 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
482 vpe_api_main_t * vam = &vpe_api_main;
483 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
485 if (vam->link_state_process_up)
486 vlib_process_signal_event (vam->vlib_main,
487 link_state_process_node.index,
488 API_LINK_STATE_EVENT,
493 static clib_error_t *
494 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
496 vpe_api_main_t * vam = &vpe_api_main;
499 * Note: it's perfectly fair to set a subif admin up / admin down.
500 * Note the subtle distinction between this routine and the previous
503 if (vam->link_state_process_up)
504 vlib_process_signal_event (vam->vlib_main,
505 link_state_process_node.index,
506 API_ADMIN_UP_DOWN_EVENT,
511 #define pub_sub_handler(lca,UCA) \
512 static void vl_api_want_##lca##_t_handler ( \
513 vl_api_want_##lca##_t *mp) \
515 vpe_api_main_t *vam = &vpe_api_main; \
516 vpe_client_registration_t *rp; \
517 vl_api_want_##lca##_reply_t *rmp; \
521 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
523 if (mp->enable_disable) { \
524 clib_warning ("pid %d: already enabled...", mp->pid); \
525 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
528 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
529 pool_put (vam->lca##_registrations, rp); \
530 hash_unset (vam->lca##_registration_hash, \
535 if (mp->enable_disable == 0) { \
536 clib_warning ("pid %d: already disabled...", mp->pid); \
537 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
540 pool_get (vam->lca##_registrations, rp); \
541 rp->client_index = mp->client_index; \
542 rp->client_pid = mp->pid; \
543 hash_set (vam->lca##_registration_hash, rp->client_index, \
544 rp - vam->lca##_registrations); \
547 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
550 pub_sub_handler (interface_events,INTERFACE_EVENTS)
551 pub_sub_handler (from_netconf_server,FROM_NETCONF_SERVER)
552 pub_sub_handler (to_netconf_server,TO_NETCONF_SERVER)
553 pub_sub_handler (from_netconf_client,FROM_NETCONF_CLIENT)
554 pub_sub_handler (to_netconf_client,TO_NETCONF_CLIENT)
555 pub_sub_handler (oam_events,OAM_EVENTS)
557 #define RESOLUTION_EVENT 1
558 #define RESOLUTION_PENDING_EVENT 2
559 #define IP4_ARP_EVENT 3
561 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
562 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
563 static int mpls_ethernet_add_del_tunnel_2_t_handler
564 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
566 void handle_ip4_arp_event (u32 pool_index)
568 vpe_api_main_t * vam = &vpe_api_main;
569 vnet_main_t * vnm = vam->vnet_main;
570 vlib_main_t * vm = vam->vlib_main;
571 vl_api_ip4_arp_event_t * event;
572 vl_api_ip4_arp_event_t * mp;
573 unix_shared_memory_queue_t * q;
575 /* Client can cancel, die, etc. */
576 if (pool_is_free_index (vam->arp_events, pool_index))
579 event = pool_elt_at_index (vam->arp_events, pool_index);
581 q = vl_api_client_index_to_input_queue (event->client_index);
583 (void) vnet_add_del_ip4_arp_change_event
584 (vnm, arp_change_delete_callback,
585 event->pid, &event->address,
586 vpe_resolver_process_node.index, IP4_ARP_EVENT,
587 ~0 /* pool index, notused */, 0 /* is_add */);
591 if (q->cursize < q->maxsize) {
592 mp = vl_msg_api_alloc (sizeof (*mp));
593 memcpy (mp, event, sizeof (*mp));
594 vl_msg_api_send_shmem (q, (u8 *)&mp);
596 static f64 last_time;
598 * Throttle syslog msgs.
599 * It's pretty tempting to just revoke the registration...
601 if (vlib_time_now (vm) > last_time + 10.0) {
602 clib_warning ("arp event for %U to pid %d: queue stuffed!",
603 format_ip4_address, &event->address, event->pid);
604 last_time = vlib_time_now(vm);
610 resolver_process (vlib_main_t * vm,
611 vlib_node_runtime_t * rt,
615 uword *event_data = 0;
617 vpe_api_main_t * vam = &vpe_api_main;
618 pending_route_t * pr;
619 vl_api_ip_add_del_route_t * adr;
620 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
621 u32 * resolution_failures = 0;
626 vlib_process_wait_for_event_or_clock (vm, timeout);
628 event_type = vlib_process_get_events (vm, &event_data);
630 switch (event_type) {
631 case RESOLUTION_PENDING_EVENT:
635 case RESOLUTION_EVENT:
636 for (i = 0; i < vec_len(event_data); i++) {
638 * Resolution events can occur long after the
639 * original request has timed out. $$$ add a cancel
642 if (pool_is_free_index (vam->pending_routes, event_data[i]))
645 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
649 switch (pr->resolve_type) {
650 case RESOLVE_IP4_ADD_DEL_ROUTE:
651 rv = ip4_add_del_route_t_handler (adr);
652 clib_warning ("resolver: add %U/%d via %U %s",
654 (ip4_address_t *)&(adr->dst_address),
655 adr->dst_address_length,
657 (ip4_address_t *)&(adr->next_hop_address),
658 (rv >= 0) ? "succeeded" : "failed");
661 case RESOLVE_IP6_ADD_DEL_ROUTE:
662 rv = ip6_add_del_route_t_handler (adr);
663 clib_warning ("resolver: add %U/%d via %U %s",
665 (ip6_address_t *)&(adr->dst_address),
666 adr->dst_address_length,
668 (ip6_address_t *)&(adr->next_hop_address),
669 (rv >= 0) ? "succeeded" : "failed");
672 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
673 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
674 clib_warning ("resolver: add mpls-o-e via %U %s",
676 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
677 (rv >= 0) ? "succeeded" : "failed");
681 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
683 pool_put (vam->pending_routes, pr);
688 for (i = 0; i < vec_len(event_data); i++)
689 handle_ip4_arp_event (event_data[i]);
692 case ~0: /* timeout, retry pending resolutions */
693 pool_foreach (pr, vam->pending_routes,
699 /* May fail, e.g. due to interface down */
700 switch (pr->resolve_type) {
701 case RESOLVE_IP4_ADD_DEL_ROUTE:
702 e = ip4_probe_neighbor
703 (vm, (ip4_address_t *)&(adr->next_hop_address),
704 ntohl(adr->next_hop_sw_if_index));
707 case RESOLVE_IP6_ADD_DEL_ROUTE:
708 e = ip6_probe_neighbor
709 (vm, (ip6_address_t *)&(adr->next_hop_address),
710 ntohl(adr->next_hop_sw_if_index));
713 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
715 e = ip4_probe_neighbor
717 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
718 pme->resolve_opaque);
722 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
726 clib_error_report (e);
728 adr->resolve_attempts = 1;
730 pme->resolve_attempts = 1;
734 adr->resolve_attempts -= 1;
735 if (adr->resolve_attempts == 0)
736 vec_add1 (resolution_failures,
737 pr - vam->pending_routes);
739 pme->resolve_attempts -= 1;
740 if (pme->resolve_attempts == 0)
741 vec_add1 (resolution_failures,
742 pr - vam->pending_routes);
746 for (i = 0; i < vec_len (resolution_failures); i++) {
747 pr = pool_elt_at_index (vam->pending_routes,
748 resolution_failures[i]);
752 switch (pr->resolve_type) {
753 case RESOLVE_IP4_ADD_DEL_ROUTE:
754 clib_warning ("resolver: add %U/%d via %U retry failure",
756 (ip4_address_t *)&(adr->dst_address),
757 adr->dst_address_length,
759 (ip4_address_t *)&(adr->next_hop_address));
762 case RESOLVE_IP6_ADD_DEL_ROUTE:
763 clib_warning ("resolver: add %U/%d via %U retry failure",
765 (ip6_address_t *)&(adr->dst_address),
766 adr->dst_address_length,
768 (ip6_address_t *)&(adr->next_hop_address));
771 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
772 clib_warning ("resolver: add mpls-o-e via %U retry failure",
774 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
778 clib_warning ("BUG");
780 pool_put(vam->pending_routes, pr);
782 vec_reset_length (resolution_failures);
785 if (pool_elts (vam->pending_routes) == 0)
787 vec_reset_length (event_data);
789 return 0; /* or not */
792 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
793 .function = resolver_process,
794 .type = VLIB_NODE_TYPE_PROCESS,
795 .name = "vpe-route-resolver-process",
798 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
800 ip4_main_t * im = &ip4_main;
801 ip_lookup_main_t * lm = &im->lookup_main;
802 vnet_classify_main_t * cm = &vnet_classify_main;
803 stats_main_t * sm = &stats_main;
804 ip4_add_del_route_args_t a;
805 ip4_address_t next_hop_address;
807 vpe_api_main_t * vam = &vpe_api_main;
808 vnet_main_t * vnm = vam->vnet_main;
809 vlib_main_t * vm = vlib_get_main();
810 pending_route_t * pr;
811 vl_api_ip_add_del_route_t * adr;
815 ip_adjacency_t *nh_adj, *add_adj = 0;
817 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
819 if (mp->create_vrf_if_needed) {
821 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
823 fib_index = f->index;
825 /* No such VRF, and we weren't asked to create one */
826 return VNET_API_ERROR_NO_SUCH_FIB;
832 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
833 ntohl(mp->next_hop_sw_if_index)))
834 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
836 memcpy (next_hop_address.data, mp->next_hop_address,
837 sizeof (next_hop_address.data));
839 /* Arp for the next_hop if necessary */
840 if (mp->is_add && mp->resolve_if_needed) {
842 ip_adjacency_t * adj;
844 lookup_result = ip4_fib_lookup_with_table
845 (im, fib_index, &next_hop_address, 1 /* disable default route */);
847 adj = ip_get_adjacency (lm, lookup_result);
849 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
850 pool_get (vam->pending_routes, pr);
851 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
853 memcpy (adr, mp, sizeof (*adr));
854 /* recursion block, "just in case" */
855 adr->resolve_if_needed = 0;
856 adr->resolve_attempts = ntohl(mp->resolve_attempts);
857 vnet_register_ip4_arp_resolution_event
858 (vnm, &next_hop_address, vpe_resolver_process_node.index,
859 RESOLUTION_EVENT, pr - vam->pending_routes);
861 vlib_process_signal_event
862 (vm, vpe_resolver_process_node.index,
863 RESOLUTION_PENDING_EVENT, 0 /* data */);
865 /* The interface may be down, etc. */
866 e = ip4_probe_neighbor
867 (vm, (ip4_address_t *)&(mp->next_hop_address),
868 ntohl(mp->next_hop_sw_if_index));
871 clib_error_report(e);
873 return VNET_API_ERROR_IN_PROGRESS;
877 if (mp->is_multipath) {
880 dslock (sm, 1 /* release hint */, 10 /* tag */);
883 flags = IP4_ROUTE_FLAG_ADD;
885 flags = IP4_ROUTE_FLAG_DEL;
888 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
890 ip4_add_del_route_next_hop (im, flags,
891 (ip4_address_t *) mp->dst_address,
892 (u32) mp->dst_address_length,
893 (ip4_address_t *) mp->next_hop_address,
894 ntohl(mp->next_hop_sw_if_index),
895 (u32) mp->next_hop_weight,
902 memset (&a, 0, sizeof (a));
903 memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
905 a.dst_address_length = mp->dst_address_length;
907 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
908 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
909 a.table_index_or_table_id = fib_index;
914 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
916 dslock (sm, 1 /* release hint */, 2 /* tag */);
920 ai = lm->drop_adj_index;
921 else if (mp->is_local)
922 ai = lm->local_adj_index;
923 else if (mp->is_classify) {
925 memset(&cadj, 0, sizeof(cadj));
926 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
927 cadj.classify_table_index = ntohl(mp->classify_table_index);
928 if (pool_is_free_index (cm->tables, cadj.classify_table_index)) {
930 return VNET_API_ERROR_NO_SUCH_TABLE;
932 vec_add1 (add_adj, cadj);
936 ai = ip4_fib_lookup_with_table
937 (im, fib_index, &next_hop_address,
938 1 /* disable default route */);
939 if (ai == lm->miss_adj_index) {
941 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
945 nh_adj = ip_get_adjacency (lm, ai);
946 vec_add1 (add_adj, nh_adj[0]);
947 if (mp->lookup_in_vrf) {
948 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
950 add_adj[0].explicit_fib_index = p[0];
954 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
958 ip_adjacency_t * adj;
959 int disable_default_route = 1;
961 /* Trying to delete the default route? */
962 if (a.dst_address.as_u32 == 0 &&
963 a.dst_address_length == 0)
964 disable_default_route = 0;
966 ai = ip4_fib_lookup_with_table
967 (im, fib_index, &a.dst_address, disable_default_route);
968 if (ai == lm->miss_adj_index) {
970 return VNET_API_ERROR_UNKNOWN_DESTINATION;
973 adj = ip_get_adjacency (lm, ai);
974 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
976 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
983 a.n_add_adj = vec_len(add_adj);
984 ip4_add_del_route (im, &a);
992 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
994 ip6_main_t * im = &ip6_main;
995 ip_lookup_main_t * lm = &im->lookup_main;
996 vnet_main_t * vnm = vnet_get_main();
997 vlib_main_t * vm = vlib_get_main();
998 vpe_api_main_t * vam = &vpe_api_main;
999 stats_main_t * sm = &stats_main;
1000 ip6_add_del_route_args_t a;
1001 ip6_address_t next_hop_address;
1002 pending_route_t * pr;
1003 vl_api_ip_add_del_route_t * adr;
1008 ip_adjacency_t * nh_adj, * add_adj = 0;
1011 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1014 if (mp->create_vrf_if_needed) {
1016 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1018 fib_index = f->index;
1020 /* No such VRF, and we weren't asked to create one */
1021 return VNET_API_ERROR_NO_SUCH_FIB;
1027 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1028 ntohl(mp->next_hop_sw_if_index)))
1029 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1031 memcpy (next_hop_address.as_u8, mp->next_hop_address,
1032 sizeof (next_hop_address.as_u8));
1034 /* Arp for the next_hop if necessary */
1035 if (mp->is_add && mp->resolve_if_needed) {
1037 ip_adjacency_t * adj;
1039 lookup_result = ip6_fib_lookup_with_table
1040 (im, fib_index, &next_hop_address);
1042 adj = ip_get_adjacency (lm, lookup_result);
1044 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1045 pool_get (vam->pending_routes, pr);
1047 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1048 memcpy (adr, mp, sizeof (*adr));
1049 /* recursion block, "just in case" */
1050 adr->resolve_if_needed = 0;
1051 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1052 vnet_register_ip6_neighbor_resolution_event
1053 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1054 RESOLUTION_EVENT, pr - vam->pending_routes);
1056 vlib_process_signal_event
1057 (vm, vpe_resolver_process_node.index,
1058 RESOLUTION_PENDING_EVENT, 0 /* data */);
1060 /* The interface may be down, etc. */
1061 e = ip6_probe_neighbor
1062 (vm, (ip6_address_t *)&(mp->next_hop_address),
1063 ntohl(mp->next_hop_sw_if_index));
1066 clib_error_report(e);
1068 return VNET_API_ERROR_IN_PROGRESS;
1072 if (mp->is_multipath) {
1075 dslock (sm, 1 /* release hint */, 11 /* tag */);
1078 flags = IP6_ROUTE_FLAG_ADD;
1080 flags = IP6_ROUTE_FLAG_DEL;
1083 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1085 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1086 (u32) mp->dst_address_length,
1087 (ip6_address_t *)mp->next_hop_address,
1088 ntohl(mp->next_hop_sw_if_index),
1089 (u32) mp->next_hop_weight,
1096 memset (&a, 0, sizeof (a));
1097 memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1099 a.dst_address_length = mp->dst_address_length;
1101 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1102 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1103 a.table_index_or_table_id = fib_index;
1108 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1110 dslock (sm, 1 /* release hint */, 3 /* tag */);
1114 ai = lm->drop_adj_index;
1115 else if (mp->is_local)
1116 ai = lm->local_adj_index;
1118 ai = ip6_fib_lookup_with_table
1119 (im, fib_index, &next_hop_address);
1120 if (ai == lm->miss_adj_index) {
1122 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1126 nh_adj = ip_get_adjacency (lm, ai);
1127 vec_add1 (add_adj, nh_adj[0]);
1128 if (mp->lookup_in_vrf) {
1129 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1131 add_adj[0].explicit_fib_index = p[0];
1135 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1139 ip_adjacency_t * adj;
1141 ai = ip6_fib_lookup_with_table
1142 (im, fib_index, &a.dst_address);
1143 if (ai == lm->miss_adj_index) {
1145 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1147 adj = ip_get_adjacency (lm, ai);
1148 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1150 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1155 a.add_adj = add_adj;
1156 a.n_add_adj = vec_len(add_adj);
1157 ip6_add_del_route (im, &a);
1165 void vl_api_ip_add_del_route_t_handler (
1166 vl_api_ip_add_del_route_t *mp)
1168 vl_api_ip_add_del_route_reply_t * rmp;
1170 vnet_main_t * vnm = vnet_get_main();
1175 rv = ip6_add_del_route_t_handler (mp);
1177 rv = ip4_add_del_route_t_handler (mp);
1179 rv = (rv == 0) ? vnm->api_errno : rv;
1181 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1184 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1185 u32 sw_if_index, u8 *next_hop_addr)
1187 vl_api_ip_add_del_route_t mp;
1190 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1193 * Configure default IP route:
1194 * - ip route add 0.0.0.0/1 via <GW IP>
1195 * - ip route add 128.0.0.0/1 via <GW IP>
1197 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1199 mp.resolve_attempts = ~0;
1200 mp.resolve_if_needed = 1;
1202 mp.is_ipv6 = is_ipv6;
1203 mp.next_hop_weight = 1;
1205 memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1208 rv = ip6_add_del_route_t_handler (&mp);
1211 mp.dst_address_length = 1;
1213 mp.dst_address[0] = 0;
1214 rv = ip4_add_del_route_t_handler (&mp);
1216 mp.dst_address[0] = 128;
1217 rv |= ip4_add_del_route_t_handler (&mp);
1221 clib_error_return (0, "failed to config default IP route");
1226 vl_api_sw_interface_add_del_address_t_handler
1227 (vl_api_sw_interface_add_del_address_t *mp)
1229 vlib_main_t *vm = vlib_get_main();
1230 vl_api_sw_interface_add_del_address_reply_t * rmp;
1234 VALIDATE_SW_IF_INDEX(mp);
1236 is_del = mp->is_add == 0;
1239 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1240 else if (mp->is_ipv6)
1241 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1242 (void *)mp->address,
1243 mp->address_length, is_del);
1245 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1246 (void *) mp->address,
1247 mp->address_length, is_del);
1249 BAD_SW_IF_INDEX_LABEL;
1251 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1255 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1258 u32 table_id = ntohl(mp->vrf_id);
1259 u32 sw_if_index = ntohl(mp->sw_if_index);
1260 vl_api_sw_interface_set_table_reply_t * rmp;
1261 stats_main_t * sm = &stats_main;
1263 VALIDATE_SW_IF_INDEX(mp);
1265 dslock (sm, 1 /* release hint */, 4 /* tag */);
1268 ip6_main_t * im = &ip6_main;
1270 find_ip6_fib_by_table_index_or_id (im, table_id,
1271 IP6_ROUTE_FLAG_TABLE_ID);
1273 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1274 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1276 rv = VNET_API_ERROR_NO_SUCH_FIB;
1279 ip4_main_t * im = &ip4_main;
1280 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1281 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1283 /* Truthfully this can't fail */
1285 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1286 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1288 rv = VNET_API_ERROR_NO_SUCH_FIB;
1293 BAD_SW_IF_INDEX_LABEL;
1295 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1299 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1301 vlib_main_t *vm = vlib_get_main();
1302 vl_api_sw_interface_set_vpath_reply_t * rmp;
1305 u32 sw_if_index = ntohl(mp->sw_if_index);
1306 ip4_main_t *ip4m = &ip4_main;
1307 ip6_main_t *ip6m = &ip6_main;
1308 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1309 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1310 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1311 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1312 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1313 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1315 VALIDATE_SW_IF_INDEX(mp);
1317 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1319 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1320 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1321 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1322 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1323 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1324 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1325 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1326 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1327 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1328 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1329 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1330 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1331 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1332 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1333 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1334 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1336 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1337 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1338 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1339 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1340 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1341 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1342 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1343 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1344 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1345 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1346 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1347 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1348 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1349 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1350 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1351 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1354 BAD_SW_IF_INDEX_LABEL;
1356 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1360 vl_api_sw_interface_set_l2_xconnect_t_handler (
1361 vl_api_sw_interface_set_l2_xconnect_t *mp)
1363 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1365 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1366 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1367 vlib_main_t *vm = vlib_get_main();
1368 vnet_main_t *vnm = vnet_get_main();
1370 VALIDATE_RX_SW_IF_INDEX(mp);
1373 VALIDATE_TX_SW_IF_INDEX(mp);
1374 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1375 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1377 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1380 BAD_RX_SW_IF_INDEX_LABEL;
1381 BAD_TX_SW_IF_INDEX_LABEL;
1383 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1387 vl_api_sw_interface_set_l2_bridge_t_handler (
1388 vl_api_sw_interface_set_l2_bridge_t *mp)
1390 bd_main_t * bdm = &bd_main;
1391 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1393 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1394 u32 bd_id = ntohl(mp->bd_id);
1398 vlib_main_t *vm = vlib_get_main();
1399 vnet_main_t *vnm = vnet_get_main();
1401 VALIDATE_RX_SW_IF_INDEX(mp);
1403 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1406 //VALIDATE_TX_SW_IF_INDEX(mp);
1407 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1408 rx_sw_if_index, bd_index, bvi, shg, 0);
1410 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1413 BAD_RX_SW_IF_INDEX_LABEL;
1415 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1419 vl_api_bridge_domain_add_del_t_handler (
1420 vl_api_bridge_domain_add_del_t *mp)
1422 vlib_main_t * vm = vlib_get_main ();
1423 bd_main_t * bdm = &bd_main;
1424 vl_api_bridge_domain_add_del_reply_t * rmp;
1426 u32 enable_flags = 0, disable_flags = 0;
1427 u32 bd_id = ntohl(mp->bd_id);
1431 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1434 enable_flags |= L2_FLOOD;
1436 disable_flags |= L2_FLOOD;
1439 enable_flags |= L2_UU_FLOOD;
1441 disable_flags |= L2_UU_FLOOD;
1444 enable_flags |= L2_FWD;
1446 disable_flags |= L2_FWD;
1449 enable_flags |= L2_ARP_TERM;
1451 disable_flags |= L2_ARP_TERM;
1454 enable_flags |= L2_LEARN;
1456 disable_flags |= L2_LEARN;
1459 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1462 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1465 rv = bd_delete_bd_index(bdm, bd_id);
1467 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1470 static void vl_api_bridge_domain_details_t_handler (
1471 vl_api_bridge_domain_details_t * mp)
1473 clib_warning ("BUG");
1476 static void vl_api_bridge_domain_sw_if_details_t_handler (
1477 vl_api_bridge_domain_sw_if_details_t * mp)
1479 clib_warning ("BUG");
1482 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1483 l2_bridge_domain_t * bd_config,
1486 vl_api_bridge_domain_details_t * mp;
1488 mp = vl_msg_api_alloc (sizeof (*mp));
1489 memset (mp, 0, sizeof (*mp));
1490 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1491 mp->bd_id = ntohl (bd_config->bd_id);
1492 mp->flood = bd_feature_flood (bd_config);
1493 mp->uu_flood = bd_feature_uu_flood (bd_config);
1494 mp->forward = bd_feature_forward (bd_config);
1495 mp->learn = bd_feature_learn (bd_config);
1496 mp->arp_term = bd_feature_arp_term (bd_config);
1497 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1498 mp->n_sw_ifs = ntohl (n_sw_ifs);
1500 vl_msg_api_send_shmem (q, (u8 *)&mp);
1503 static void send_bd_sw_if_details (l2input_main_t * l2im,
1504 unix_shared_memory_queue_t *q,
1505 l2_flood_member_t * member, u32 bd_id)
1507 vl_api_bridge_domain_sw_if_details_t * mp;
1508 l2_input_config_t * input_cfg;
1510 mp = vl_msg_api_alloc (sizeof (*mp));
1511 memset (mp, 0, sizeof (*mp));
1512 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1513 mp->bd_id = ntohl (bd_id);
1514 mp->sw_if_index = ntohl (member->sw_if_index);
1515 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1516 mp->shg = input_cfg->shg;
1518 vl_msg_api_send_shmem (q, (u8 *)&mp);
1521 static void vl_api_bridge_domain_dump_t_handler (
1522 vl_api_bridge_domain_dump_t *mp)
1524 bd_main_t * bdm = &bd_main;
1525 l2input_main_t * l2im = &l2input_main;
1526 unix_shared_memory_queue_t * q;
1527 l2_bridge_domain_t * bd_config;
1528 u32 bd_id, bd_index;
1531 q = vl_api_client_index_to_input_queue (mp->client_index);
1536 bd_id = ntohl(mp->bd_id);
1538 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1539 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1540 for (; bd_index < end; bd_index++) {
1541 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1542 /* skip dummy bd_id 0 */
1543 if (bd_config && (bd_config->bd_id > 0)) {
1545 l2_flood_member_t * m;
1547 n_sw_ifs = vec_len (bd_config->members);
1548 send_bridge_domain_details (q, bd_config, n_sw_ifs);
1550 vec_foreach (m, bd_config->members) {
1551 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id);
1558 vl_api_l2fib_add_del_t_handler (
1559 vl_api_l2fib_add_del_t *mp)
1561 bd_main_t * bdm = &bd_main;
1562 l2input_main_t * l2im = &l2input_main;
1563 vl_api_l2fib_add_del_reply_t * rmp;
1566 u32 sw_if_index = ntohl(mp->sw_if_index);
1567 u32 bd_id = ntohl(mp->bd_id);
1575 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1577 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1578 goto bad_sw_if_index;
1583 VALIDATE_SW_IF_INDEX(mp);
1584 if (vec_len(l2im->configs) <= sw_if_index) {
1585 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1586 goto bad_sw_if_index;
1588 l2_input_config_t * config;
1589 config = vec_elt_at_index(l2im->configs, sw_if_index);
1590 if (config->bridge == 0) {
1591 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1592 goto bad_sw_if_index;
1595 static_mac = mp->static_mac ? 1 : 0;
1596 filter_mac = mp->filter_mac ? 1 : 0;
1597 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1600 l2fib_del_entry(mac, bd_index);
1603 BAD_SW_IF_INDEX_LABEL;
1605 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1609 vl_api_l2_flags_t_handler (
1610 vl_api_l2_flags_t *mp)
1612 vl_api_l2_flags_reply_t * rmp;
1614 u32 sw_if_index = ntohl(mp->sw_if_index);
1615 u32 flags = ntohl(mp->feature_bitmap);
1618 VALIDATE_SW_IF_INDEX(mp);
1621 if (flags & L2INPUT_FEAT_ ## a) \
1622 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1623 foreach_l2input_feat;
1626 BAD_SW_IF_INDEX_LABEL;
1628 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1632 vl_api_bridge_flags_t_handler (
1633 vl_api_bridge_flags_t *mp)
1635 vlib_main_t *vm = vlib_get_main();
1636 bd_main_t * bdm = &bd_main;
1637 vl_api_bridge_flags_reply_t * rmp;
1639 u32 bd_id = ntohl(mp->bd_id);
1641 u32 flags = ntohl(mp->feature_bitmap);
1644 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1646 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1652 bd_set_flags(vm, bd_index, flags, mp->is_set);
1655 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1656 rmp->resulting_feature_bitmap = ntohl(flags));
1660 vl_api_bd_ip_mac_add_del_t_handler (
1661 vl_api_bd_ip_mac_add_del_t *mp)
1663 bd_main_t * bdm = &bd_main;
1664 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1666 u32 bd_id = ntohl(mp->bd_id);
1670 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1672 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1677 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1678 mp->mac_address, mp->is_ipv6, mp->is_add))
1679 rv = VNET_API_ERROR_UNSPECIFIED;
1682 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1686 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1689 vl_api_tap_connect_reply_t * rmp;
1690 unix_shared_memory_queue_t * q;
1691 u32 sw_if_index = (u32)~0;
1693 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1694 mp->use_random_mac ? 0 : mp->mac_address,
1695 &sw_if_index, mp->renumber,
1696 ntohl(mp->custom_dev_instance));
1698 q = vl_api_client_index_to_input_queue (mp->client_index);
1702 rmp = vl_msg_api_alloc (sizeof (*rmp));
1703 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1704 rmp->context = mp->context;
1705 rmp->retval = ntohl(rv);
1706 rmp->sw_if_index = ntohl(sw_if_index);
1708 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1712 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1715 vl_api_tap_modify_reply_t * rmp;
1716 unix_shared_memory_queue_t * q;
1717 u32 sw_if_index = (u32)~0;
1719 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1720 mp->use_random_mac ? 0 : mp->mac_address,
1721 &sw_if_index, mp->renumber,
1722 ntohl(mp->custom_dev_instance));
1724 q = vl_api_client_index_to_input_queue (mp->client_index);
1728 rmp = vl_msg_api_alloc (sizeof (*rmp));
1729 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1730 rmp->context = mp->context;
1731 rmp->retval = ntohl(rv);
1732 rmp->sw_if_index = ntohl(sw_if_index);
1734 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1738 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1741 vpe_api_main_t * vam = &vpe_api_main;
1742 vl_api_tap_delete_reply_t * rmp;
1743 unix_shared_memory_queue_t * q;
1744 u32 sw_if_index = ntohl(mp->sw_if_index);
1746 rv = vnet_tap_delete (vm, sw_if_index);
1748 q = vl_api_client_index_to_input_queue (mp->client_index);
1752 rmp = vl_msg_api_alloc (sizeof (*rmp));
1753 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1754 rmp->context = mp->context;
1755 rmp->retval = ntohl(rv);
1757 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1760 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1764 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1766 vl_api_create_vlan_subif_reply_t * rmp;
1767 vnet_main_t * vnm = vnet_get_main();
1768 u32 hw_if_index, sw_if_index = (u32)~0;
1769 vnet_hw_interface_t * hi;
1772 vnet_sw_interface_t template;
1774 vnet_interface_main_t * im = &vnm->interface_main;
1775 u64 sup_and_sub_key;
1777 unix_shared_memory_queue_t * q;
1778 clib_error_t * error;
1780 VALIDATE_SW_IF_INDEX(mp);
1782 hw_if_index = ntohl(mp->sw_if_index);
1783 hi = vnet_get_hw_interface (vnm, hw_if_index);
1785 id = ntohl(mp->vlan_id);
1786 if (id == 0 || id > 4095) {
1787 rv = VNET_API_ERROR_INVALID_VLAN;
1791 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1793 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1795 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1799 kp = clib_mem_alloc (sizeof (*kp));
1800 *kp = sup_and_sub_key;
1802 memset (&template, 0, sizeof (template));
1803 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1804 template.sup_sw_if_index = hi->sw_if_index;
1805 template.sub.id = id;
1806 template.sub.eth.raw_flags = 0;
1807 template.sub.eth.flags.one_tag = 1;
1808 template.sub.eth.outer_vlan_id = id;
1809 template.sub.eth.flags.exact_match = 1;
1811 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1813 clib_error_report(error);
1814 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1817 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1818 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1820 BAD_SW_IF_INDEX_LABEL;
1823 q = vl_api_client_index_to_input_queue (mp->client_index);
1827 rmp = vl_msg_api_alloc (sizeof (*rmp));
1828 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1829 rmp->context = mp->context;
1830 rmp->retval = ntohl(rv);
1831 rmp->sw_if_index = ntohl(sw_if_index);
1832 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1836 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1838 vl_api_create_subif_reply_t * rmp;
1839 vnet_main_t * vnm = vnet_get_main();
1840 u32 sw_if_index = ~0;
1843 vnet_sw_interface_t *si;
1844 vnet_hw_interface_t *hi;
1845 vnet_sw_interface_t template;
1847 vnet_interface_main_t * im = &vnm->interface_main;
1848 u64 sup_and_sub_key;
1850 clib_error_t * error;
1852 VALIDATE_SW_IF_INDEX(mp);
1854 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1855 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1857 sw_if_index = si->sw_if_index;
1858 sub_id = ntohl(mp->sub_id);
1860 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1862 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1865 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1866 sw_if_index, sub_id);
1867 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1871 kp = clib_mem_alloc (sizeof (*kp));
1872 *kp = sup_and_sub_key;
1874 memset (&template, 0, sizeof (template));
1875 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1876 template.sup_sw_if_index = sw_if_index;
1877 template.sub.id = sub_id;
1878 template.sub.eth.flags.no_tags = mp->no_tags;
1879 template.sub.eth.flags.one_tag = mp->one_tag;
1880 template.sub.eth.flags.two_tags = mp->two_tags;
1881 template.sub.eth.flags.dot1ad = mp->dot1ad;
1882 template.sub.eth.flags.exact_match = mp->exact_match;
1883 template.sub.eth.flags.default_sub = mp->default_sub;
1884 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1885 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1886 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1887 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1889 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1891 clib_error_report (error);
1892 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1896 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1897 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1899 BAD_SW_IF_INDEX_LABEL;
1903 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1905 rmp->sw_if_index = ntohl(sw_if_index);
1910 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1912 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1914 stats_main_t * sm = &stats_main;
1915 u32 tunnel_sw_if_index = ~0;
1917 dslock (sm, 1 /* release hint */, 5 /* tag */);
1919 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1920 (ip4_address_t *)(mp->dst_address),
1921 (ip4_address_t *)(mp->intfc_address),
1922 (u32)(mp->intfc_address_length),
1923 ntohl(mp->inner_vrf_id),
1924 ntohl(mp->outer_vrf_id),
1925 &tunnel_sw_if_index,
1930 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1932 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1937 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1938 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1940 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1942 stats_main_t * sm = &stats_main;
1943 u32 tunnel_sw_if_index;
1945 dslock (sm, 1 /* release hint */, 5 /* tag */);
1947 rv = vnet_mpls_ethernet_add_del_tunnel
1948 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1949 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1950 ntohl(mp->tx_sw_if_index),
1951 &tunnel_sw_if_index,
1957 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1959 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1964 * This piece of misery brought to you because the control-plane
1965 * can't figure out the tx interface + dst-mac address all by itself
1967 static int mpls_ethernet_add_del_tunnel_2_t_handler
1968 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
1970 pending_route_t * pr;
1971 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
1972 vnet_main_t * vnm = vnet_get_main();
1973 vlib_main_t * vm = vlib_get_main();
1974 stats_main_t * sm = &stats_main;
1975 vpe_api_main_t * vam = &vpe_api_main;
1976 u32 inner_fib_index, outer_fib_index;
1977 ip4_main_t * im = &ip4_main;
1978 ip_lookup_main_t * lm = &im->lookup_main;
1979 ip_adjacency_t * adj = 0;
1982 u8 * dst_mac_address;
1986 u32 tunnel_sw_if_index;
1988 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
1990 return VNET_API_ERROR_NO_SUCH_FIB;
1992 outer_fib_index = p[0];
1995 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
1997 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1999 inner_fib_index = p[0];
2001 if (inner_fib_index == outer_fib_index)
2002 return VNET_API_ERROR_INVALID_VALUE;
2004 lookup_result = ip4_fib_lookup_with_table
2005 (im, outer_fib_index,
2006 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2007 1 /* disable default route */);
2009 adj = ip_get_adjacency (lm, lookup_result);
2010 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2012 if (mp->is_add && mp->resolve_if_needed) {
2013 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2014 pool_get (vam->pending_routes, pr);
2015 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2017 memcpy (pme, mp, sizeof (*pme));
2018 /* recursion block, "just in case" */
2019 pme->resolve_if_needed = 0;
2020 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2021 pme->resolve_opaque = tx_sw_if_index;
2022 vnet_register_ip4_arp_resolution_event
2024 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2025 vpe_resolver_process_node.index,
2026 RESOLUTION_EVENT, pr - vam->pending_routes);
2028 vlib_process_signal_event
2029 (vm, vpe_resolver_process_node.index,
2030 RESOLUTION_PENDING_EVENT, 0 /* data */);
2032 /* The interface may be down, etc. */
2033 e = ip4_probe_neighbor
2034 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2038 clib_error_report(e);
2040 return VNET_API_ERROR_IN_PROGRESS;
2044 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2045 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2048 vnet_rewrite_get_data_internal
2049 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2051 dslock (sm, 1 /* release hint */, 10 /* tag */);
2053 rv = vnet_mpls_ethernet_add_del_tunnel
2054 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2055 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2056 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2064 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2065 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2067 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2070 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2072 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2077 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2079 vl_api_mpls_add_del_encap_reply_t * rmp;
2081 static u32 * labels;
2084 vec_reset_length (labels);
2086 for (i = 0; i < mp->nlabels; i++)
2087 vec_add1 (labels, ntohl(mp->labels[i]));
2090 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2091 ntohl(mp->vrf_id), labels,
2092 ~0 /* policy_tunnel_index */,
2093 0 /* no_dst_hash */,
2097 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2101 vl_api_mpls_add_del_decap_t_handler
2102 (vl_api_mpls_add_del_decap_t *mp)
2104 vl_api_mpls_add_del_decap_reply_t * rmp;
2107 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2108 ntohl(mp->label), ntohl(mp->next_index),
2109 mp->s_bit, mp->is_add);
2111 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2115 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2117 vl_api_proxy_arp_add_del_reply_t * rmp;
2120 ip4_main_t * im = &ip4_main;
2121 stats_main_t * sm = &stats_main;
2122 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2123 ip4_address_t *hi_addr,
2124 u32 fib_index, int is_del);
2127 dslock (sm, 1 /* release hint */, 6 /* tag */);
2129 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2132 rv = VNET_API_ERROR_NO_SUCH_FIB;
2138 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2139 (ip4_address_t *)mp->hi_address,
2140 fib_index, mp->is_add == 0);
2144 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2148 vl_api_proxy_arp_intfc_enable_disable_t_handler
2149 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2152 vnet_main_t * vnm = vnet_get_main();
2153 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2154 vnet_sw_interface_t * si;
2157 VALIDATE_SW_IF_INDEX(mp);
2159 sw_if_index = ntohl(mp->sw_if_index);
2161 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2163 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2167 si = vnet_get_sw_interface (vnm, sw_if_index);
2171 if (mp->enable_disable)
2172 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2174 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2176 BAD_SW_IF_INDEX_LABEL;
2179 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2183 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2185 vl_api_ip_neighbor_add_del_reply_t * rmp;
2186 vnet_main_t * vnm = vnet_get_main();
2189 stats_main_t * sm = &stats_main;
2191 VALIDATE_SW_IF_INDEX(mp);
2193 dslock (sm, 1 /* release hint */, 7 /* tag */);
2197 rv = vnet_set_ip6_ethernet_neighbor
2198 (vm, ntohl(mp->sw_if_index),
2199 (ip6_address_t *)(mp->dst_address),
2200 mp->mac_address, sizeof (mp->mac_address));
2202 rv = vnet_unset_ip6_ethernet_neighbor
2203 (vm, ntohl(mp->sw_if_index),
2204 (ip6_address_t *)(mp->dst_address),
2205 mp->mac_address, sizeof(mp->mac_address));
2207 ip4_main_t * im = &ip4_main;
2208 ip_lookup_main_t * lm = &im->lookup_main;
2209 ethernet_arp_ip4_over_ethernet_address_t a;
2211 ip_adjacency_t *nh_adj;
2213 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2215 rv = VNET_API_ERROR_NO_SUCH_FIB;
2221 * Unfortunately, folks have a penchant for
2222 * adding interface addresses to the ARP cache, and
2223 * wondering why the forwarder eventually ASSERTs...
2225 ai = ip4_fib_lookup_with_table
2226 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2227 1 /* disable default route */);
2230 nh_adj = ip_get_adjacency (lm, ai);
2231 /* Never allow manipulation of a local adj! */
2232 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2233 clib_warning("%U matches local adj",
2235 (ip4_address_t *)(mp->dst_address));
2236 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2241 memcpy (&a.ethernet, mp->mac_address, 6);
2242 memcpy (&a.ip4, mp->dst_address, 4);
2245 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2246 fib_index, &a, mp->is_static);
2248 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2252 BAD_SW_IF_INDEX_LABEL;
2255 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2259 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2262 vpe_main_t *rm = &vpe_main;
2263 ip4_main_t *im4 = &ip4_main;
2264 ip6_main_t *im6 = &ip6_main;
2265 ip_lookup_main_t * lm;
2270 u32 adj_index, sw_if_index;
2271 vl_api_is_address_reachable_t *rmp;
2272 ip_adjacency_t * adj;
2273 unix_shared_memory_queue_t *q;
2275 q = vl_api_client_index_to_input_queue (mp->client_index);
2277 increment_missing_api_client_counter (rm->vlib_main);
2281 rmp = vl_msg_api_alloc (sizeof (*rmp));
2282 memcpy (rmp, mp, sizeof (*rmp));
2284 sw_if_index = mp->next_hop_sw_if_index;
2285 memcpy (&addr, mp->address, sizeof (addr));
2287 lm = &im6->lookup_main;
2289 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2291 lm = &im4->lookup_main;
2293 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2295 if (adj_index == ~0) {
2299 adj = ip_get_adjacency (lm, adj_index);
2301 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2302 && adj->rewrite_header.sw_if_index == sw_if_index) {
2305 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2306 && adj->rewrite_header.sw_if_index == sw_if_index) {
2308 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2310 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2311 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2319 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2323 static void vl_api_sw_interface_details_t_handler (
2324 vl_api_sw_interface_details_t * mp)
2326 clib_warning ("BUG");
2329 static void vl_api_sw_interface_set_flags_t_handler (
2330 vl_api_sw_interface_set_flags_t * mp)
2332 vl_api_sw_interface_set_flags_reply_t *rmp;
2333 vnet_main_t * vnm = vnet_get_main();
2335 clib_error_t * error;
2338 VALIDATE_SW_IF_INDEX(mp);
2340 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2342 error = vnet_sw_interface_set_flags (vnm,
2343 ntohl(mp->sw_if_index),
2347 clib_error_report (error);
2350 BAD_SW_IF_INDEX_LABEL;
2351 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2354 static void send_sw_interface_details (vpe_api_main_t * am,
2355 unix_shared_memory_queue_t *q,
2356 vnet_sw_interface_t * swif,
2357 u8 * interface_name)
2359 vl_api_sw_interface_details_t * mp;
2360 vnet_hw_interface_t * hi;
2362 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2364 mp = vl_msg_api_alloc (sizeof (*mp));
2365 memset (mp, 0, sizeof (*mp));
2366 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2367 mp->sw_if_index = ntohl(swif->sw_if_index);
2368 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2369 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2371 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2373 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2374 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2375 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2376 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2377 mp->link_mtu = ntohs(hi->max_packet_bytes);
2379 strncpy ((char *) mp->interface_name,
2380 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2382 /* Send the L2 address for ethernet physical intfcs */
2383 if (swif->sup_sw_if_index == swif->sw_if_index
2384 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2385 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2386 ethernet_interface_t *ei;
2388 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2389 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2390 memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2391 mp->l2_address_length = ntohl(sizeof (ei->address));
2392 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2393 vnet_sub_interface_t *sub = &swif->sub;
2394 mp->sub_id = ntohl(sub->id);
2395 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2396 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2397 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2398 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2399 mp->sub_exact_match = sub->eth.flags.exact_match;
2400 mp->sub_default = sub->eth.flags.default_sub;
2401 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2402 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2404 /* vlan tag rewrite data */
2405 u32 vtr_op = L2_VTR_DISABLED;
2406 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2408 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2409 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2410 // error - default to disabled
2411 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2412 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2415 mp->vtr_op = ntohl(vtr_op);
2416 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2417 mp->vtr_tag1 = ntohl(vtr_tag1);
2418 mp->vtr_tag2 = ntohl(vtr_tag2);
2422 vl_msg_api_send_shmem (q, (u8 *)&mp);
2425 static void send_sw_interface_flags (vpe_api_main_t * am,
2426 unix_shared_memory_queue_t *q,
2427 vnet_sw_interface_t * swif)
2429 vl_api_sw_interface_set_flags_t *mp;
2430 vnet_main_t * vnm = am->vnet_main;
2432 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2434 mp = vl_msg_api_alloc (sizeof (*mp));
2435 memset (mp, 0, sizeof (*mp));
2436 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2437 mp->sw_if_index = ntohl(swif->sw_if_index);
2439 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2441 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2443 vl_msg_api_send_shmem (q, (u8 *)&mp);
2446 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2447 unix_shared_memory_queue_t *q,
2449 __attribute__((unused));
2451 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2452 unix_shared_memory_queue_t *q,
2455 vl_api_sw_interface_set_flags_t *mp;
2457 mp = vl_msg_api_alloc (sizeof (*mp));
2458 memset (mp, 0, sizeof (*mp));
2459 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2460 mp->sw_if_index = ntohl(sw_if_index);
2462 mp->admin_up_down = 0;
2463 mp->link_up_down = 0;
2465 vl_msg_api_send_shmem (q, (u8 *)&mp);
2468 static void vl_api_sw_interface_dump_t_handler (
2469 vl_api_sw_interface_dump_t *mp)
2471 vpe_api_main_t * am = &vpe_api_main;
2472 vnet_sw_interface_t * swif;
2473 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2474 u8 * filter_string = 0, * name_string = 0;
2475 unix_shared_memory_queue_t * q;
2476 char * strcasestr (char *, char *); /* lnx hdr file botch */
2478 q = vl_api_client_index_to_input_queue (mp->client_index);
2483 if (mp->name_filter_valid) {
2484 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2485 filter_string = format (0, "%s%c", mp->name_filter, 0);
2488 pool_foreach (swif, im->sw_interfaces,
2490 name_string = format (name_string, "%U%c",
2491 format_vnet_sw_interface_name,
2492 am->vnet_main, swif, 0);
2494 if (mp->name_filter_valid == 0 ||
2495 strcasestr((char *) name_string, (char *) filter_string)) {
2497 send_sw_interface_details (am, q, swif, name_string);
2498 send_sw_interface_flags (am, q, swif);
2500 _vec_len (name_string) = 0;
2503 vec_free (name_string);
2504 vec_free (filter_string);
2507 void send_oam_event (oam_target_t * t)
2509 vpe_api_main_t * vam = &vpe_api_main;
2510 unix_shared_memory_queue_t * q;
2511 vpe_client_registration_t *reg;
2512 vl_api_oam_event_t * mp;
2514 pool_foreach(reg, vam->oam_events_registrations,
2516 q = vl_api_client_index_to_input_queue (reg->client_index);
2518 mp = vl_msg_api_alloc (sizeof (*mp));
2519 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2520 memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2521 mp->state = t->state;
2522 vl_msg_api_send_shmem (q, (u8 *)&mp);
2528 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2530 vl_api_oam_add_del_reply_t * rmp;
2533 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2534 (ip4_address_t *)mp->dst_address,
2538 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2542 vl_api_vnet_get_summary_stats_t_handler (
2543 vl_api_vnet_get_summary_stats_t *mp)
2545 stats_main_t * sm = &stats_main;
2546 vnet_interface_main_t * im = sm->interface_main;
2547 vl_api_vnet_summary_stats_reply_t *rmp;
2548 vlib_combined_counter_main_t * cm;
2551 u64 total_pkts[VLIB_N_RX_TX];
2552 u64 total_bytes[VLIB_N_RX_TX];
2554 unix_shared_memory_queue_t * q =
2555 vl_api_client_index_to_input_queue (mp->client_index);
2560 rmp = vl_msg_api_alloc (sizeof (*rmp));
2561 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2562 rmp->context = mp->context;
2565 memset (total_pkts, 0, sizeof (total_pkts));
2566 memset (total_bytes, 0, sizeof (total_bytes));
2568 vnet_interface_counter_lock (im);
2570 vec_foreach (cm, im->combined_sw_if_counters) {
2571 which = cm - im->combined_sw_if_counters;
2573 for (i = 0; i < vec_len (cm->maxi); i++) {
2574 vlib_get_combined_counter (cm, i, &v);
2575 total_pkts[which] += v.packets;
2576 total_bytes[which] += v.bytes;
2579 vnet_interface_counter_unlock (im);
2581 /* Note: in HOST byte order! */
2582 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2583 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2584 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2585 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2586 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2588 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2591 typedef CLIB_PACKED (struct {
2592 ip4_address_t address;
2594 u32 address_length : 6;
2599 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2601 vnet_main_t * vnm = vnet_get_main();
2602 vnet_interface_main_t * im = &vnm->interface_main;
2603 ip4_main_t * im4 = &ip4_main;
2604 static ip4_route_t * routes;
2605 static u32 * sw_if_indices_to_shut;
2606 stats_main_t * sm = &stats_main;
2611 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2612 u32 target_fib_id = ntohl(mp->vrf_id);
2614 dslock (sm, 1 /* release hint */, 8 /* tag */);
2616 vec_foreach (fib, im4->fibs) {
2617 vnet_sw_interface_t * si;
2619 if (fib->table_id != target_fib_id)
2622 /* remove any mpls/gre tunnels in this fib */
2623 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2625 /* remove any mpls encap/decap labels */
2626 mpls_fib_reset_labels (fib->table_id);
2628 /* remove any proxy arps in this fib */
2629 vnet_proxy_arp_fib_reset (fib->table_id);
2631 /* Set the flow hash for this fib to the default */
2632 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2634 vec_reset_length (sw_if_indices_to_shut);
2636 /* Shut down interfaces in this FIB / clean out intfc routes */
2637 pool_foreach (si, im->sw_interfaces,
2639 u32 sw_if_index = si->sw_if_index;
2641 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2642 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2644 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2647 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2648 sw_if_index = sw_if_indices_to_shut[i];
2649 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2651 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2652 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2653 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2656 vec_reset_length (routes);
2658 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2659 uword * hash = fib->adj_index_by_dst_address[i];
2663 x.address_length = i;
2665 hash_foreach_pair (p, hash,
2667 x.address.data_u32 = p->key;
2668 vec_add1 (routes, x);
2672 vec_foreach (r, routes) {
2673 ip4_add_del_route_args_t a;
2675 memset (&a, 0, sizeof (a));
2676 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2677 a.table_index_or_table_id = fib - im4->fibs;
2678 a.dst_address = r->address;
2679 a.dst_address_length = r->address_length;
2682 ip4_add_del_route (im4, &a);
2683 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2684 IP4_ROUTE_FLAG_FIB_INDEX);
2688 } /* vec_foreach (fib) */
2695 ip6_address_t address;
2702 ip6_route_t ** routep;
2703 } add_routes_in_fib_arg_t;
2705 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2707 add_routes_in_fib_arg_t * ap = arg;
2709 if (kvp->key[2]>>32 == ap->fib_index)
2711 ip6_address_t *addr;
2713 addr = (ip6_address_t *) kvp;
2714 vec_add2 (*ap->routep, r, 1);
2715 r->address = addr[0];
2716 r->address_length = kvp->key[2] & 0xFF;
2717 r->index = kvp->value;
2721 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2723 vnet_main_t * vnm = vnet_get_main();
2724 vnet_interface_main_t * im = &vnm->interface_main;
2725 ip6_main_t * im6 = &ip6_main;
2726 stats_main_t * sm = &stats_main;
2727 static ip6_route_t * routes;
2728 static u32 * sw_if_indices_to_shut;
2733 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2734 u32 target_fib_id = ntohl(mp->vrf_id);
2735 add_routes_in_fib_arg_t _a, *a=&_a;
2736 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2738 dslock (sm, 1 /* release hint */, 9 /* tag */);
2740 vec_foreach (fib, im6->fibs) {
2741 vnet_sw_interface_t * si;
2743 if (fib->table_id != target_fib_id)
2746 vec_reset_length (sw_if_indices_to_shut);
2748 /* Shut down interfaces in this FIB / clean out intfc routes */
2749 pool_foreach (si, im->sw_interfaces,
2751 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2753 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2756 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2757 sw_if_index = sw_if_indices_to_shut[i];
2758 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2760 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2761 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2762 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2765 vec_reset_length (routes);
2767 a->fib_index = fib - im6->fibs;
2768 a->routep = &routes;
2770 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2772 vec_foreach (r, routes) {
2773 ip6_add_del_route_args_t a;
2775 memset (&a, 0, sizeof (a));
2776 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2777 a.table_index_or_table_id = fib - im6->fibs;
2778 a.dst_address = r->address;
2779 a.dst_address_length = r->address_length;
2782 ip6_add_del_route (im6, &a);
2783 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2784 IP6_ROUTE_FLAG_FIB_INDEX);
2787 /* Reinstall the neighbor / router discovery routes */
2788 vnet_ip6_fib_init (im6, fib - im6->fibs);
2790 } /* vec_foreach (fib) */
2796 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2799 vl_api_reset_fib_reply_t * rmp;
2802 rv = ip6_reset_fib_t_handler (mp);
2804 rv = ip4_reset_fib_t_handler (mp);
2806 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2811 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2813 vl_api_dhcp_proxy_config_reply_t * rmp;
2816 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2817 (ip4_address_t *)(&mp->dhcp_src_address),
2818 (u32) ntohl(mp->vrf_id),
2819 (int) mp->insert_circuit_id,
2820 (int) (mp->is_add == 0));
2822 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2827 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2829 vl_api_dhcp_proxy_config_reply_t * rmp;
2832 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2833 (ip6_address_t *)(&mp->dhcp_src_address),
2834 (u32) ntohl(mp->vrf_id),
2835 (int) mp->insert_circuit_id,
2836 (int) (mp->is_add == 0));
2838 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2842 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2844 vl_api_dhcp_proxy_config_reply_t * rmp;
2847 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2848 (ip4_address_t *)(&mp->dhcp_src_address),
2849 (u32) ntohl(mp->rx_vrf_id),
2850 (u32) ntohl(mp->server_vrf_id),
2851 (int) mp->insert_circuit_id,
2852 (int) (mp->is_add == 0));
2854 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2859 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2861 vl_api_dhcp_proxy_config_reply_t * rmp;
2865 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2866 (ip6_address_t *)(&mp->dhcp_src_address),
2867 (u32) ntohl(mp->rx_vrf_id),
2868 (u32) ntohl(mp->server_vrf_id),
2869 (int) mp->insert_circuit_id,
2870 (int) (mp->is_add == 0));
2872 rv = VNET_API_ERROR_UNIMPLEMENTED;
2875 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2880 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2882 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2885 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2888 (int)mp->is_add == 0);
2890 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2893 (int)mp->is_add == 0);
2895 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2899 static void vl_api_dhcp_proxy_config_t_handler
2900 (vl_api_dhcp_proxy_config_t *mp)
2902 if (mp->is_ipv6 == 0)
2903 dhcpv4_proxy_config (mp);
2905 dhcpv6_proxy_config (mp);
2908 static void vl_api_dhcp_proxy_config_2_t_handler
2909 (vl_api_dhcp_proxy_config_2_t *mp)
2911 if (mp->is_ipv6 == 0)
2912 dhcpv4_proxy_config_2 (mp);
2914 dhcpv6_proxy_config_2 (mp);
2917 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
2918 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
2920 unix_shared_memory_queue_t * q;
2921 vl_api_dhcp_compl_event_t * mp;
2923 q = vl_api_client_index_to_input_queue (client_index);
2927 mp = vl_msg_api_alloc (sizeof (*mp));
2928 mp->client_index = client_index;
2930 mp->is_ipv6 = is_ipv6;
2931 memcpy (&mp->hostname, hostname, vec_len(hostname));
2932 mp->hostname[vec_len(hostname) + 1] = '\n';
2933 memcpy (&mp->host_address[0], host_address, 16);
2934 memcpy (&mp->router_address[0], router_address, 16);
2935 memcpy (&mp->host_mac[0], host_mac, 6);
2937 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
2939 vl_msg_api_send_shmem (q, (u8 *)&mp);
2942 static void vl_api_dhcp_client_config_t_handler
2943 (vl_api_dhcp_client_config_t *mp)
2945 vlib_main_t *vm = vlib_get_main();
2946 vl_api_dhcp_client_config_reply_t * rmp;
2949 VALIDATE_SW_IF_INDEX(mp);
2951 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
2952 mp->hostname, mp->is_add, mp->client_index,
2953 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
2956 BAD_SW_IF_INDEX_LABEL;
2958 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
2962 vl_api_sw_interface_ip6nd_ra_config_t_handler
2963 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
2965 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
2967 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
2969 is_no = mp->is_no == 1;
2970 surpress = mp->surpress == 1;
2971 managed = mp->managed == 1;
2972 other = mp->other == 1;
2973 ll_option = mp->ll_option == 1;
2974 send_unicast = mp->send_unicast == 1;
2975 cease = mp->cease == 1;
2976 default_router = mp->default_router == 1;
2978 VALIDATE_SW_IF_INDEX(mp);
2980 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
2981 surpress, managed, other,
2982 ll_option, send_unicast, cease,
2983 default_router, ntohl (mp->lifetime),
2984 ntohl(mp->initial_count), ntohl(mp->initial_interval),
2985 ntohl(mp->max_interval), ntohl( mp->min_interval),
2988 BAD_SW_IF_INDEX_LABEL;
2990 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
2994 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
2995 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
2997 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
2999 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3001 VALIDATE_SW_IF_INDEX(mp);
3003 is_no = mp->is_no == 1;
3004 use_default = mp->use_default == 1;
3005 no_advertise = mp->no_advertise == 1;
3006 off_link = mp->off_link == 1;
3007 no_autoconfig = mp->no_autoconfig == 1;
3008 no_onlink = mp->no_onlink == 1;
3010 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3011 (ip6_address_t *)mp->address, mp->address_length,
3012 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3013 no_advertise, off_link, no_autoconfig, no_onlink,
3016 BAD_SW_IF_INDEX_LABEL;
3017 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3021 vl_api_sw_interface_ip6_enable_disable_t_handler
3022 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3024 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3025 vnet_main_t * vnm = vnet_get_main();
3027 clib_error_t * error;
3031 VALIDATE_SW_IF_INDEX(mp);
3033 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3034 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3037 clib_error_report(error);
3038 rv = VNET_API_ERROR_UNSPECIFIED;
3040 rv = vnm->api_errno;
3043 BAD_SW_IF_INDEX_LABEL;
3045 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3049 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3050 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3052 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3054 clib_error_t * error;
3055 vnet_main_t * vnm = vnet_get_main();
3059 VALIDATE_SW_IF_INDEX(mp);
3061 error = set_ip6_link_local_address(vm,
3062 ntohl(mp->sw_if_index),
3063 (ip6_address_t *)mp->address,
3064 mp->address_length);
3066 clib_error_report(error);
3067 rv = VNET_API_ERROR_UNSPECIFIED;
3069 rv = vnm->api_errno;
3072 BAD_SW_IF_INDEX_LABEL;
3074 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3077 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3079 vl_api_set_ip_flow_hash_reply_t *rmp;
3080 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3082 clib_warning ("unimplemented...");
3084 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3087 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3089 vl_api_set_ip_flow_hash_reply_t *rmp;
3092 u32 flow_hash_config = 0;
3094 table_id = ntohl(mp->vrf_id);
3096 #define _(a,b) if (mp->a) flow_hash_config |= b;
3097 foreach_flow_hash_bit;
3100 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3102 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3106 static void vl_api_set_ip_flow_hash_t_handler
3107 (vl_api_set_ip_flow_hash_t *mp)
3109 if (mp->is_ipv6 == 0)
3110 set_ip4_flow_hash (mp);
3112 set_ip6_flow_hash (mp);
3115 static void vl_api_sw_interface_set_unnumbered_t_handler
3116 (vl_api_sw_interface_set_unnumbered_t *mp)
3118 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3120 vnet_sw_interface_t * si;
3121 vnet_main_t *vnm = vnet_get_main();
3122 u32 sw_if_index, unnumbered_sw_if_index;
3124 sw_if_index = ntohl(mp->sw_if_index);
3125 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3128 * The API message field names are backwards from
3129 * the underlying data structure names.
3130 * It's not worth changing them now.
3132 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3133 unnumbered_sw_if_index)) {
3134 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3138 /* Only check the "use loop0" field when setting the binding */
3140 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3141 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3145 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3148 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3149 si->unnumbered_sw_if_index = sw_if_index;
3151 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3152 si->unnumbered_sw_if_index = (u32)~0;
3156 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3159 static void vl_api_create_loopback_t_handler
3160 (vl_api_create_loopback_t *mp)
3162 vl_api_create_loopback_reply_t * rmp;
3166 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3168 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3170 rmp->sw_if_index = ntohl (sw_if_index);
3174 static void vl_api_delete_loopback_t_handler
3175 (vl_api_delete_loopback_t *mp)
3177 vl_api_delete_loopback_reply_t * rmp;
3181 sw_if_index = ntohl (mp->sw_if_index);
3182 rv = vnet_delete_loopback_interface (sw_if_index);
3184 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3187 static void vl_api_control_ping_t_handler
3188 (vl_api_control_ping_t *mp)
3190 vl_api_control_ping_reply_t * rmp;
3193 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3195 rmp->vpe_pid = ntohl (getpid());
3199 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3201 u8 **shmem_vecp = (u8 **)arg;
3204 api_main_t * am = &api_main;
3207 shmem_vec = *shmem_vecp;
3209 offset = vec_len (shmem_vec);
3211 pthread_mutex_lock (&am->vlib_rp->mutex);
3212 oldheap = svm_push_data_heap (am->vlib_rp);
3214 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3216 memcpy (shmem_vec + offset, buffer, buffer_bytes);
3218 svm_pop_heap (oldheap);
3219 pthread_mutex_unlock (&am->vlib_rp->mutex);
3221 *shmem_vecp = shmem_vec;
3225 static void vl_api_cli_request_t_handler
3226 (vl_api_cli_request_t *mp)
3228 vl_api_cli_reply_t *rp;
3229 unix_shared_memory_queue_t *q;
3230 vlib_main_t * vm = vlib_get_main();
3231 api_main_t * am = &api_main;
3232 unformat_input_t input;
3236 q = vl_api_client_index_to_input_queue (mp->client_index);
3240 rp = vl_msg_api_alloc (sizeof (*rp));
3241 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3242 rp->context = mp->context;
3244 unformat_init_vector (&input, (u8 *)mp->cmd_in_shmem);
3246 vlib_cli_input (vm, &input, shmem_cli_output,
3249 pthread_mutex_lock (&am->vlib_rp->mutex);
3250 oldheap = svm_push_data_heap (am->vlib_rp);
3252 vec_add1(shmem_vec, 0);
3254 svm_pop_heap (oldheap);
3255 pthread_mutex_unlock (&am->vlib_rp->mutex);
3257 rp->reply_in_shmem = (uword)shmem_vec;
3259 vl_msg_api_send_shmem (q, (u8 *)&rp);
3262 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3265 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3266 vnet_main_t *vnm = vnet_get_main();
3267 clib_error_t * error;
3272 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3274 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3277 clib_error_report(error);
3278 rv = VNET_API_ERROR_UNSPECIFIED;
3280 rv = vnm->api_errno;
3283 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3286 static void vl_api_sr_tunnel_add_del_t_handler
3287 (vl_api_sr_tunnel_add_del_t *mp)
3290 clib_warning ("unimplemented");
3292 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3294 vl_api_sr_tunnel_add_del_reply_t * rmp;
3295 ip6_address_t * segments = 0, * seg;
3296 ip6_address_t * tags = 0, *tag;
3297 ip6_address_t * this_address;
3300 if (mp->n_segments == 0) {
3305 memset (a, 0, sizeof (*a));
3306 a->src_address = (ip6_address_t *)&mp->src_address;
3307 a->dst_address = (ip6_address_t *)&mp->dst_address;
3308 a->dst_mask_width = mp->dst_mask_width;
3309 a->flags_net_byte_order = mp->flags_net_byte_order;
3310 a->is_del = (mp->is_add == 0);
3311 a->rx_table_id = ntohl(mp->outer_vrf_id);
3312 a->tx_table_id = ntohl(mp->inner_vrf_id);
3314 /* Yank segments and tags out of the API message */
3315 this_address = (ip6_address_t *)mp->segs_and_tags;
3316 for (i = 0; i < mp->n_segments; i++) {
3317 vec_add2 (segments, seg, 1);
3318 memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3321 for (i = 0; i < mp->n_tags; i++) {
3322 vec_add2 (tags, tag, 1);
3323 memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3327 a->segments = segments;
3330 rv = ip6_sr_add_del_tunnel (a);
3334 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3338 #define foreach_classify_add_del_table_field \
3343 _(match_n_vectors) \
3344 _(next_table_index) \
3347 static void vl_api_classify_add_del_table_t_handler
3348 (vl_api_classify_add_del_table_t * mp)
3350 vl_api_classify_add_del_table_reply_t * rmp;
3351 vnet_classify_main_t * cm = &vnet_classify_main;
3352 vnet_classify_table_t * t;
3356 foreach_classify_add_del_table_field;
3359 #define _(a) a = ntohl(mp->a);
3360 foreach_classify_add_del_table_field;
3363 /* The underlying API fails silently, on purpose, so check here */
3364 if (mp->is_add == 0)
3365 if (pool_is_free_index (cm->tables, table_index)) {
3366 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3370 rv = vnet_classify_add_del_table
3371 (cm, mp->mask, nbuckets, memory_size,
3372 skip_n_vectors, match_n_vectors,
3373 next_table_index, miss_next_index,
3374 &table_index, mp->is_add);
3377 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3379 if (rv == 0 && mp->is_add) {
3380 t = pool_elt_at_index (cm->tables, table_index);
3381 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3382 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3383 rmp->new_table_index = ntohl(table_index);
3385 rmp->skip_n_vectors = ~0;
3386 rmp->match_n_vectors = ~0;
3387 rmp->new_table_index = ~0;
3392 static void vl_api_classify_add_del_session_t_handler
3393 (vl_api_classify_add_del_session_t * mp)
3395 vnet_classify_main_t * cm = &vnet_classify_main;
3396 vl_api_classify_add_del_session_reply_t * rmp;
3398 u32 table_index, hit_next_index, opaque_index;
3401 table_index = ntohl (mp->table_index);
3402 hit_next_index = ntohl (mp->hit_next_index);
3403 opaque_index = ntohl (mp->opaque_index);
3404 advance = ntohl (mp->advance);
3406 rv = vnet_classify_add_del_session
3407 (cm, table_index, mp->match, hit_next_index, opaque_index,
3408 advance, mp->is_add);
3410 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3413 static void vl_api_classify_set_interface_ip_table_t_handler
3414 (vl_api_classify_set_interface_ip_table_t * mp)
3416 vlib_main_t * vm = vlib_get_main();
3417 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3419 u32 table_index, sw_if_index;
3421 table_index = ntohl (mp->table_index);
3422 sw_if_index = ntohl (mp->sw_if_index);
3424 VALIDATE_SW_IF_INDEX(mp);
3427 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3429 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3431 BAD_SW_IF_INDEX_LABEL;
3433 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3436 static void vl_api_classify_set_interface_l2_tables_t_handler
3437 (vl_api_classify_set_interface_l2_tables_t * mp)
3439 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3441 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3444 ip4_table_index = ntohl(mp->ip4_table_index);
3445 ip6_table_index = ntohl(mp->ip6_table_index);
3446 other_table_index = ntohl(mp->other_table_index);
3447 sw_if_index = ntohl(mp->sw_if_index);
3449 VALIDATE_SW_IF_INDEX(mp);
3451 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3452 ip6_table_index, other_table_index);
3455 if (ip4_table_index != ~0 || ip6_table_index != ~0
3456 || other_table_index != ~0)
3461 vnet_l2_classify_enable_disable (sw_if_index, enable);
3464 BAD_SW_IF_INDEX_LABEL;
3466 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3470 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3473 vl_api_l2_fib_clear_table_reply_t * rmp;
3475 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3476 * that is not currently implemented. When that TODO is fixed
3477 * this call should be changed to pass 1 instead of 0.
3479 l2fib_clear_table (0);
3481 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3484 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3489 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3492 vl_api_l2_interface_efp_filter_reply_t * rmp;
3493 vnet_main_t *vnm = vnet_get_main();
3495 // enable/disable the feature
3496 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3497 rv = vnm->api_errno;
3499 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3503 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3506 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3507 vnet_main_t * vnm = vnet_get_main();
3508 vlib_main_t * vm = vlib_get_main();
3511 VALIDATE_SW_IF_INDEX(mp);
3513 vtr_op = ntohl(mp->vtr_op);
3515 /* The L2 code is unsuspicious */
3517 case L2_VTR_DISABLED:
3522 case L2_VTR_TRANSLATE_1_1:
3523 case L2_VTR_TRANSLATE_1_2:
3524 case L2_VTR_TRANSLATE_2_1:
3525 case L2_VTR_TRANSLATE_2_2:
3529 rv = VNET_API_ERROR_INVALID_VALUE;
3530 goto bad_sw_if_index;
3533 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3534 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3537 BAD_SW_IF_INDEX_LABEL;
3539 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3543 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3547 vl_api_create_vhost_user_if_reply_t * rmp;
3548 u32 sw_if_index = (u32)~0;
3550 vnet_main_t * vnm = vnet_get_main();
3551 vlib_main_t * vm = vlib_get_main();
3553 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3554 mp->is_server, &sw_if_index, (u64)~0,
3555 mp->renumber, ntohl(mp->custom_dev_instance),
3556 (mp->use_custom_mac)?mp->mac_address:NULL);
3558 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3560 rmp->sw_if_index = ntohl (sw_if_index);
3566 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3570 vl_api_modify_vhost_user_if_reply_t * rmp;
3571 u32 sw_if_index = ntohl(mp->sw_if_index);
3573 vnet_main_t * vnm = vnet_get_main();
3574 vlib_main_t * vm = vlib_get_main();
3576 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3577 mp->is_server, sw_if_index, (u64)~0,
3578 mp->renumber, ntohl(mp->custom_dev_instance));
3580 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3585 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3589 vpe_api_main_t * vam = &vpe_api_main;
3590 vl_api_delete_vhost_user_if_reply_t * rmp;
3591 u32 sw_if_index = ntohl(mp->sw_if_index);
3593 vnet_main_t * vnm = vnet_get_main();
3594 vlib_main_t * vm = vlib_get_main();
3596 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3598 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3600 unix_shared_memory_queue_t * q =
3601 vl_api_client_index_to_input_queue (mp->client_index);
3605 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3610 static void vl_api_sw_interface_vhost_user_details_t_handler (
3611 vl_api_sw_interface_vhost_user_details_t * mp)
3613 clib_warning ("BUG");
3617 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3618 unix_shared_memory_queue_t *q,
3619 vhost_user_intf_details_t * vui)
3621 vl_api_sw_interface_vhost_user_details_t * mp;
3623 mp = vl_msg_api_alloc (sizeof (*mp));
3624 memset (mp, 0, sizeof (*mp));
3625 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3626 mp->sw_if_index = ntohl(vui->sw_if_index);
3627 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3628 mp->features = clib_net_to_host_u64 (vui->features);
3629 mp->is_server = vui->is_server;
3630 mp->num_regions = ntohl(vui->num_regions);
3631 mp->sock_errno = ntohl(vui->sock_errno);
3633 strncpy ((char *) mp->sock_filename,
3634 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3635 strncpy ((char *) mp->interface_name,
3636 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3638 vl_msg_api_send_shmem (q, (u8 *)&mp);
3643 vl_api_sw_interface_vhost_user_dump_t_handler (
3644 vl_api_sw_interface_vhost_user_dump_t *mp)
3648 vpe_api_main_t * am = &vpe_api_main;
3649 vnet_main_t * vnm = vnet_get_main();
3650 vlib_main_t * vm = vlib_get_main();
3651 vhost_user_intf_details_t *ifaces = NULL;
3652 vhost_user_intf_details_t *vuid = NULL;
3653 unix_shared_memory_queue_t * q;
3655 q = vl_api_client_index_to_input_queue (mp->client_index);
3659 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3663 vec_foreach (vuid, ifaces) {
3664 send_sw_interface_vhost_user_details (am, q, vuid);
3670 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3671 unix_shared_memory_queue_t *q,
3675 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3676 u8 * if_name = NULL;
3677 vnet_sw_interface_t * si = NULL;
3679 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3681 if_name = format(if_name, "%U",
3682 format_vnet_sw_interface_name, lm->vnet_main, si);
3684 mp = vl_msg_api_alloc (sizeof (*mp));
3685 memset (mp, 0, sizeof (*mp));
3686 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3687 strncpy((char *)mp->interface_name,
3688 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3689 mp->sw_if_index = ntohl(si->sw_if_index);
3690 mp->local_session_id = s->local_session_id;
3691 mp->remote_session_id = s->remote_session_id;
3692 mp->local_cookie[0] = s->local_cookie[0];
3693 mp->local_cookie[1] = s->local_cookie[1];
3694 mp->remote_cookie = s->remote_cookie;
3695 memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3696 memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3697 mp->l2_sublayer_present = s->l2_sublayer_present;
3699 vl_msg_api_send_shmem (q, (u8 *)&mp);
3702 static void send_ip_address_details (vpe_api_main_t * am,
3703 unix_shared_memory_queue_t * q,
3708 vl_api_ip_address_details_t * mp;
3710 mp = vl_msg_api_alloc (sizeof (*mp));
3711 memset (mp, 0, sizeof (*mp));
3712 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3715 memcpy(&mp->ip, ip, sizeof(mp->ip));
3717 u32 * tp = (u32 *)mp->ip;
3718 *tp = ntohl(*(u32*)ip);
3720 mp->prefix_length = prefix_length;
3722 vl_msg_api_send_shmem (q, (u8 *)&mp);
3726 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3728 vpe_api_main_t * am = &vpe_api_main;
3729 unix_shared_memory_queue_t * q;
3732 ip6_main_t * im6 = &ip6_main;
3733 ip4_main_t * im4 = &ip4_main;
3734 ip_lookup_main_t * lm6 = &im6->lookup_main;
3735 ip_lookup_main_t * lm4 = &im4->lookup_main;
3736 ip_interface_address_t * ia = 0;
3737 u32 sw_if_index = ~0;
3739 sw_if_index = ntohl(mp->sw_if_index);
3741 q = vl_api_client_index_to_input_queue (mp->client_index);
3747 foreach_ip_interface_address (lm6, ia, sw_if_index,
3748 1 /* honor unnumbered */,
3750 r6 = ip_interface_address_get_address (lm6, ia);
3751 u16 prefix_length = ia->address_length;
3752 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1);
3755 foreach_ip_interface_address (lm4, ia, sw_if_index,
3756 1 /* honor unnumbered */,
3758 r4 = ip_interface_address_get_address (lm4, ia);
3759 u16 prefix_length = ia->address_length;
3760 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0);
3765 static void send_ip_details (vpe_api_main_t * am,
3766 unix_shared_memory_queue_t *q,
3769 vl_api_ip_details_t * mp;
3771 mp = vl_msg_api_alloc (sizeof (*mp));
3772 memset (mp, 0, sizeof (*mp));
3773 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3775 mp->sw_if_index = ntohl(sw_if_index);
3777 vl_msg_api_send_shmem (q, (u8 *)&mp);
3781 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3782 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3784 vpe_api_main_t * am = &vpe_api_main;
3785 l2t_main_t * lm = &l2t_main;
3786 unix_shared_memory_queue_t * q;
3787 l2t_session_t *session;
3789 q = vl_api_client_index_to_input_queue (mp->client_index);
3793 pool_foreach (session, lm->sessions,
3795 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm);
3800 static void send_sw_interface_tap_details (vpe_api_main_t * am,
3801 unix_shared_memory_queue_t *q,
3802 tapcli_interface_details_t *tap_if)
3804 vl_api_sw_interface_tap_details_t * mp;
3805 mp = vl_msg_api_alloc (sizeof (*mp));
3806 memset (mp, 0, sizeof (*mp));
3807 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
3808 mp->sw_if_index = ntohl(tap_if->sw_if_index);
3809 strncpy((char *)mp->dev_name,
3810 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
3812 vl_msg_api_send_shmem (q, (u8 *)&mp);
3816 vl_api_sw_interface_tap_dump_t_handler (
3817 vl_api_sw_interface_tap_dump_t *mp)
3820 vpe_api_main_t * am = &vpe_api_main;
3821 unix_shared_memory_queue_t * q;
3822 tapcli_interface_details_t *tapifs = NULL;
3823 tapcli_interface_details_t *tap_if = NULL;
3825 q = vl_api_client_index_to_input_queue (mp->client_index);
3829 rv = vnet_tap_dump_ifs(&tapifs);
3833 vec_foreach(tap_if, tapifs) {
3834 send_sw_interface_tap_details(am, q, tap_if);
3841 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
3843 vpe_api_main_t * am = &vpe_api_main;
3844 vnet_main_t * vnm = vnet_get_main();
3845 vlib_main_t * vm = vlib_get_main();
3846 vnet_interface_main_t * im = &vnm->interface_main;
3847 unix_shared_memory_queue_t * q;
3848 vnet_sw_interface_t * si, * sorted_sis;
3849 u32 sw_if_index = ~0;
3851 q = vl_api_client_index_to_input_queue (mp->client_index);
3856 /* Gather interfaces. */
3857 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
3858 _vec_len (sorted_sis) = 0;
3859 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
3861 vec_foreach (si, sorted_sis) {
3862 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
3863 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
3866 sw_if_index = si->sw_if_index;
3867 send_ip_details(am, q, sw_if_index);
3872 static void vl_api_l2_fib_table_entry_t_handler (
3873 vl_api_l2_fib_table_entry_t * mp)
3875 clib_warning ("BUG");
3878 static void send_l2fib_table_entry (vpe_api_main_t * am,
3879 unix_shared_memory_queue_t *q,
3880 l2fib_entry_key_t * l2fe_key,
3881 l2fib_entry_result_t * l2fe_res)
3883 vl_api_l2_fib_table_entry_t * mp;
3885 mp = vl_msg_api_alloc (sizeof (*mp));
3886 memset (mp, 0, sizeof (*mp));
3887 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
3889 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
3891 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
3892 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
3893 mp->static_mac = l2fe_res->fields.static_mac;
3894 mp->filter_mac = l2fe_res->fields.filter;
3895 mp->bvi_mac = l2fe_res->fields.bvi;
3897 vl_msg_api_send_shmem (q, (u8 *)&mp);
3901 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
3903 vpe_api_main_t * am = &vpe_api_main;
3904 bd_main_t * bdm = &bd_main;
3905 l2fib_entry_key_t *l2fe_key = NULL;
3906 l2fib_entry_result_t *l2fe_res = NULL;
3907 u32 ni, bd_id = ntohl (mp->bd_id);
3909 unix_shared_memory_queue_t * q;
3912 q = vl_api_client_index_to_input_queue (mp->client_index);
3916 /* see l2fib_table_dump: ~0 means "any" */
3920 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
3927 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
3929 vec_foreach_index (ni, l2fe_key) {
3930 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
3931 vec_elt_at_index(l2fe_res, ni));
3938 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
3940 vl_api_show_version_reply_t *rmp;
3942 char * vpe_api_get_build_directory(void);
3943 char * vpe_api_get_version(void);
3944 char * vpe_api_get_build_date(void);
3946 unix_shared_memory_queue_t * q =
3947 vl_api_client_index_to_input_queue (mp->client_index);
3952 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
3954 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
3955 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
3956 ARRAY_LEN(rmp->build_directory)-1);
3957 strncpy ((char *) rmp->version, vpe_api_get_version(),
3958 ARRAY_LEN(rmp->version)-1);
3959 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
3960 ARRAY_LEN(rmp->build_date)-1);
3964 static void vl_api_get_node_index_t_handler
3965 (vl_api_get_node_index_t * mp)
3967 vlib_main_t * vm = vlib_get_main();
3968 vl_api_get_node_index_reply_t * rmp;
3971 u32 node_index = ~0;
3973 n = vlib_get_node_by_name (vm, mp->node_name);
3976 rv = VNET_API_ERROR_NO_SUCH_NODE;
3978 node_index = n->index;
3980 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
3982 rmp->node_index = ntohl(node_index);
3986 static void vl_api_add_node_next_t_handler
3987 (vl_api_add_node_next_t * mp)
3989 vlib_main_t * vm = vlib_get_main();
3990 vl_api_add_node_next_reply_t * rmp;
3991 vlib_node_t * n, * next;
3993 u32 next_index = ~0;
3995 n = vlib_get_node_by_name (vm, mp->node_name);
3998 rv = VNET_API_ERROR_NO_SUCH_NODE;
4002 next = vlib_get_node_by_name (vm, mp->next_name);
4005 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4007 next_index = vlib_node_add_next (vm, n->index, next->index);
4010 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4012 rmp->next_index = ntohl(next_index);
4016 static void vl_api_l2tpv3_create_tunnel_t_handler
4017 (vl_api_l2tpv3_create_tunnel_t *mp)
4019 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4020 l2t_main_t *lm = &l2t_main;
4021 u32 sw_if_index = (u32)~0;
4024 if (mp->is_ipv6 != 1) {
4025 rv = VNET_API_ERROR_UNIMPLEMENTED;
4029 rv = create_l2tpv3_ipv6_tunnel (lm,
4030 (ip6_address_t *) mp->client_address,
4031 (ip6_address_t *) mp->our_address,
4032 ntohl(mp->local_session_id),
4033 ntohl(mp->remote_session_id),
4034 clib_net_to_host_u64(mp->local_cookie),
4035 clib_net_to_host_u64(mp->remote_cookie),
4036 mp->l2_sublayer_present,
4040 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4042 rmp->sw_if_index = ntohl (sw_if_index);
4046 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4047 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4049 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4050 l2t_main_t *lm = &l2t_main;
4053 VALIDATE_SW_IF_INDEX(mp);
4055 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4056 clib_net_to_host_u64(mp->new_local_cookie),
4057 clib_net_to_host_u64(mp->new_remote_cookie));
4059 BAD_SW_IF_INDEX_LABEL;
4061 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4064 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4065 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4068 vnet_main_t * vnm = vnet_get_main();
4069 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4071 VALIDATE_SW_IF_INDEX(mp);
4073 rv = l2tpv3_interface_enable_disable
4074 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4076 BAD_SW_IF_INDEX_LABEL;
4078 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4081 static void vl_api_l2tpv3_set_lookup_key_t_handler
4082 (vl_api_l2tpv3_set_lookup_key_t * mp)
4085 l2t_main_t *lm = &l2t_main;
4086 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4088 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4089 rv = VNET_API_ERROR_INVALID_VALUE;
4093 lm->lookup_type = mp->key;
4096 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4099 static void vl_api_vxlan_add_del_tunnel_t_handler
4100 (vl_api_vxlan_add_del_tunnel_t * mp)
4102 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4104 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4105 u32 encap_fib_index;
4107 ip4_main_t * im = &ip4_main;
4108 u32 sw_if_index = ~0;
4110 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4112 rv = VNET_API_ERROR_NO_SUCH_FIB;
4115 encap_fib_index = p[0];
4117 memset (a, 0, sizeof (*a));
4119 a->is_add = mp->is_add;
4121 /* ip addresses sent in network byte order */
4122 a->src.as_u32 = mp->src_address;
4123 a->dst.as_u32 = mp->dst_address;
4125 a->encap_fib_index = encap_fib_index;
4126 a->decap_next_index = ntohl(mp->decap_next_index);
4127 a->vni = ntohl(mp->vni);
4128 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4131 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4133 rmp->sw_if_index = ntohl (sw_if_index);
4137 static void send_vxlan_tunnel_details
4138 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q)
4140 vl_api_vxlan_tunnel_details_t * rmp;
4141 ip4_main_t * im = &ip4_main;
4143 rmp = vl_msg_api_alloc (sizeof (*rmp));
4144 memset (rmp, 0, sizeof (*rmp));
4145 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4146 rmp->src_address = t->src.data_u32;
4147 rmp->dst_address = t->dst.data_u32;
4148 rmp->encap_vrf_id = htonl(im->fibs[t->encap_fib_index].table_id);
4149 rmp->vni = htonl(t->vni);
4150 rmp->decap_next_index = htonl(t->decap_next_index);
4151 rmp->sw_if_index = htonl(t->sw_if_index);
4153 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4156 static void vl_api_vxlan_tunnel_dump_t_handler
4157 (vl_api_vxlan_tunnel_dump_t * mp)
4159 unix_shared_memory_queue_t * q;
4160 vxlan_main_t * vxm = &vxlan_main;
4164 q = vl_api_client_index_to_input_queue (mp->client_index);
4169 sw_if_index = ntohl(mp->sw_if_index);
4171 if (~0 == sw_if_index) {
4172 pool_foreach (t, vxm->tunnels,
4174 send_vxlan_tunnel_details(t, q);
4177 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4178 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4181 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4182 send_vxlan_tunnel_details(t, q);
4187 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4189 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4191 vl_api_l2_patch_add_del_reply_t * rmp;
4192 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4196 VALIDATE_RX_SW_IF_INDEX(mp);
4197 VALIDATE_TX_SW_IF_INDEX(mp);
4199 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4200 ntohl(mp->tx_sw_if_index),
4201 (int)(mp->is_add != 0));
4203 BAD_RX_SW_IF_INDEX_LABEL;
4204 BAD_TX_SW_IF_INDEX_LABEL;
4206 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4210 vl_api_nsh_gre_add_del_tunnel_t_handler
4211 (vl_api_nsh_gre_add_del_tunnel_t * mp)
4213 vl_api_nsh_gre_add_del_tunnel_reply_t * rmp;
4215 vnet_nsh_gre_add_del_tunnel_args_t _a, *a = &_a;
4216 u32 encap_fib_index, decap_fib_index;
4217 u32 decap_next_index;
4219 ip4_main_t * im = &ip4_main;
4221 u32 sw_if_index = ~0;
4224 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4226 rv = VNET_API_ERROR_NO_SUCH_FIB;
4229 encap_fib_index = p[0];
4231 decap_next_index = ntohl(mp->decap_next_index);
4233 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4234 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4235 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4237 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4240 decap_fib_index = p[0];
4242 decap_fib_index = ntohl(mp->decap_vrf_id);
4245 memset (a, 0, sizeof (*a));
4247 a->is_add = mp->is_add;
4248 /* ip addresses sent in network byte order */
4249 a->src.as_u32 = ntohl(mp->src);
4250 a->dst.as_u32 = ntohl(mp->dst);
4251 a->encap_fib_index = encap_fib_index;
4252 a->decap_fib_index = decap_fib_index;
4253 a->decap_next_index = decap_next_index;
4254 a->ver_o_c = mp->ver_o_c;
4255 a->length = mp->length;
4256 a->md_type = mp->md_type;
4257 a->next_protocol = mp->next_protocol;
4258 a->spi_si = ntohl(mp->spi_si);
4259 a->c1 = ntohl(mp->c1);
4260 a->c2 = ntohl(mp->c2);
4261 a->c3 = ntohl(mp->c3);
4262 a->c4 = ntohl(mp->c4);
4264 for (i = 0; i < mp->tlv_len_in_words; i++)
4265 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4269 rv = vnet_nsh_gre_add_del_tunnel (a, &sw_if_index);
4272 REPLY_MACRO2(VL_API_NSH_GRE_ADD_DEL_TUNNEL_REPLY,
4274 rmp->sw_if_index = ntohl (sw_if_index);
4279 vl_api_nsh_vxlan_gpe_add_del_tunnel_t_handler
4280 (vl_api_nsh_vxlan_gpe_add_del_tunnel_t * mp)
4282 vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4284 vnet_nsh_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4285 u32 encap_fib_index, decap_fib_index;
4286 u32 decap_next_index;
4288 ip4_main_t * im = &ip4_main;
4290 u32 sw_if_index = ~0;
4293 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4295 rv = VNET_API_ERROR_NO_SUCH_FIB;
4298 encap_fib_index = p[0];
4300 decap_next_index = ntohl(mp->decap_next_index);
4302 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4303 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4304 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4306 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4309 decap_fib_index = p[0];
4311 decap_fib_index = ntohl(mp->decap_vrf_id);
4314 memset (a, 0, sizeof (*a));
4316 a->is_add = mp->is_add;
4317 /* ip addresses sent in network byte order */
4318 a->src.as_u32 = ntohl(mp->src);
4319 a->dst.as_u32 = ntohl(mp->dst);
4320 a->encap_fib_index = encap_fib_index;
4321 a->decap_fib_index = decap_fib_index;
4322 a->decap_next_index = decap_next_index;
4323 a->vni = ntohl(mp->vni);
4324 a->ver_o_c = mp->ver_o_c;
4325 a->length = mp->length;
4326 a->md_type = mp->md_type;
4327 a->next_protocol = mp->next_protocol;
4328 a->spi_si = ntohl(mp->spi_si);
4329 a->c1 = ntohl(mp->c1);
4330 a->c2 = ntohl(mp->c2);
4331 a->c3 = ntohl(mp->c3);
4332 a->c4 = ntohl(mp->c4);
4334 for (i = 0; i < mp->tlv_len_in_words; i++)
4335 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4339 rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4342 REPLY_MACRO2(VL_API_NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4344 rmp->sw_if_index = ntohl (sw_if_index);
4349 vl_api_lisp_gpe_add_del_tunnel_t_handler
4350 (vl_api_lisp_gpe_add_del_tunnel_t * mp)
4352 vl_api_lisp_gpe_add_del_tunnel_reply_t * rmp;
4354 vnet_lisp_gpe_add_del_tunnel_args_t _a, *a = &_a;
4355 u32 encap_fib_index, decap_fib_index;
4356 u32 decap_next_index;
4358 ip4_main_t * im = &ip4_main;
4359 u32 sw_if_index = ~0;
4361 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4363 rv = VNET_API_ERROR_NO_SUCH_FIB;
4366 encap_fib_index = p[0];
4368 decap_next_index = ntohl(mp->decap_next_index);
4370 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4371 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4372 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4374 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4377 decap_fib_index = p[0];
4379 decap_fib_index = ntohl(mp->decap_vrf_id);
4382 memset (a, 0, sizeof (*a));
4384 a->is_add = mp->is_add;
4385 /* ip addresses sent in network byte order */
4386 a->src.as_u32 = mp->src;
4387 a->dst.as_u32 = mp->dst;
4388 a->encap_fib_index = encap_fib_index;
4389 a->decap_fib_index = decap_fib_index;
4390 a->decap_next_index = decap_next_index;
4391 a->flags = mp->flags;
4392 a->ver_res = mp->ver_res;
4394 a->next_protocol = mp->next_protocol;
4395 a->iid = clib_net_to_host_u32 (mp->iid);
4397 rv = vnet_lisp_gpe_add_del_tunnel (a, &sw_if_index);
4400 REPLY_MACRO2(VL_API_LISP_GPE_ADD_DEL_TUNNEL_REPLY,
4402 rmp->sw_if_index = ntohl (sw_if_index);
4407 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
4409 vl_api_interface_name_renumber_reply_t * rmp;
4412 VALIDATE_SW_IF_INDEX(mp);
4414 rv = vnet_interface_name_renumber
4415 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
4417 BAD_SW_IF_INDEX_LABEL;
4419 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
4422 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
4423 u32 sw_if_index, u32 address)
4425 vpe_api_main_t * am = &vpe_api_main;
4426 vlib_main_t * vm = am->vlib_main;
4427 vl_api_ip4_arp_event_t * event;
4428 static f64 arp_event_last_time;
4429 f64 now = vlib_time_now (vm);
4431 if (pool_is_free_index (am->arp_events, pool_index))
4434 event = pool_elt_at_index (am->arp_events, pool_index);
4435 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
4436 memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
4437 } else { /* same mac */
4438 if ((sw_if_index == event->sw_if_index) &&
4440 /* for BD case, also check IP address with 10 sec timeout */
4441 ((address == event->address) &&
4442 ((now - arp_event_last_time) < 10.0))))
4446 arp_event_last_time = now;
4447 event->sw_if_index = sw_if_index;
4448 if (address) event->address = address;
4452 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
4454 vpe_api_main_t * am = &vpe_api_main;
4456 if (pool_is_free_index (am->arp_events, pool_index))
4459 pool_put_index (am->arp_events, pool_index);
4464 vl_api_want_ip4_arp_events_t_handler
4465 (vl_api_want_ip4_arp_events_t * mp)
4467 vpe_api_main_t * am = &vpe_api_main;
4468 vnet_main_t * vnm = vnet_get_main();
4469 vl_api_want_ip4_arp_events_reply_t *rmp;
4470 vl_api_ip4_arp_event_t * event;
4473 if (mp->enable_disable) {
4474 pool_get (am->arp_events, event);
4475 memset (event, 0, sizeof (*event));
4477 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
4478 event->client_index = mp->client_index;
4479 event->context = mp->context;
4480 event->address = mp->address;
4481 event->pid = mp->pid;
4483 rv = vnet_add_del_ip4_arp_change_event
4484 (vnm, arp_change_data_callback,
4486 &mp->address /* addr, in net byte order */,
4487 vpe_resolver_process_node.index,
4488 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
4490 rv = vnet_add_del_ip4_arp_change_event
4491 (vnm, arp_change_delete_callback,
4493 &mp->address /* addr, in net byte order */,
4494 vpe_resolver_process_node.index,
4495 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
4497 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
4500 static void vl_api_input_acl_set_interface_t_handler
4501 (vl_api_input_acl_set_interface_t * mp)
4503 vlib_main_t *vm = vlib_get_main();
4504 vl_api_input_acl_set_interface_reply_t * rmp;
4506 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
4508 ip4_table_index = ntohl(mp->ip4_table_index);
4509 ip6_table_index = ntohl(mp->ip6_table_index);
4510 l2_table_index = ntohl(mp->l2_table_index);
4511 sw_if_index = ntohl(mp->sw_if_index);
4513 VALIDATE_SW_IF_INDEX(mp);
4515 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
4516 ip6_table_index, l2_table_index,
4519 BAD_SW_IF_INDEX_LABEL;
4521 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
4524 static void vl_api_ipsec_spd_add_del_t_handler
4525 (vl_api_ipsec_spd_add_del_t * mp)
4528 clib_warning ("unimplemented");
4531 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4532 vl_api_ipsec_spd_add_del_reply_t * rmp;
4536 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
4538 rv = VNET_API_ERROR_UNIMPLEMENTED;
4541 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
4545 static void vl_api_ipsec_interface_add_del_spd_t_handler
4546 (vl_api_ipsec_interface_add_del_spd_t * mp)
4548 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4549 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
4551 u32 sw_if_index __attribute__((unused));
4552 u32 spd_id __attribute__((unused));
4554 sw_if_index = ntohl(mp->sw_if_index);
4555 spd_id = ntohl(mp->spd_id);
4557 VALIDATE_SW_IF_INDEX(mp);
4560 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
4562 rv = VNET_API_ERROR_UNIMPLEMENTED;
4565 BAD_SW_IF_INDEX_LABEL;
4567 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
4570 static void vl_api_ipsec_spd_add_del_entry_t_handler
4571 (vl_api_ipsec_spd_add_del_entry_t * mp)
4573 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4574 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
4580 p.id = ntohl(mp->spd_id);
4581 p.priority = ntohl(mp->priority);
4582 p.is_outbound = mp->is_outbound;
4583 p.is_ipv6 = mp->is_ipv6;
4585 memcpy(&p.raddr.start, mp->remote_address_start, 16);
4586 memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
4587 memcpy(&p.laddr.start, mp->local_address_start, 16);
4588 memcpy(&p.laddr.stop, mp->local_address_stop, 16);
4590 p.protocol = mp->protocol;
4591 p.rport.start = ntohs(mp->remote_port_start);
4592 p.rport.stop = ntohs(mp->remote_port_stop);
4593 p.lport.start = ntohs(mp->local_port_start);
4594 p.lport.stop = ntohs(mp->local_port_stop);
4595 /* policy action resolve unsupported */
4596 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
4597 clib_warning("unsupported action: 'resolve'");
4598 rv = VNET_API_ERROR_UNIMPLEMENTED;
4601 p.policy = mp->policy;
4602 p.sa_id = ntohl(mp->sa_id);
4604 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4608 if (mp->is_ip_any) {
4610 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4613 rv = VNET_API_ERROR_UNIMPLEMENTED;
4618 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
4621 static void vl_api_ipsec_sad_add_del_entry_t_handler
4622 (vl_api_ipsec_sad_add_del_entry_t * mp)
4624 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4625 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
4630 sa.id = ntohl(mp->sad_id);
4631 sa.spi = ntohl(mp->spi);
4632 /* security protocol AH unsupported */
4633 if (mp->protocol == IPSEC_PROTOCOL_AH) {
4634 clib_warning("unsupported security protocol 'AH'");
4635 rv = VNET_API_ERROR_UNIMPLEMENTED;
4638 sa.protocol = mp->protocol;
4639 /* check for unsupported crypto-alg */
4640 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
4641 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
4642 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
4643 mp->crypto_algorithm);
4644 rv = VNET_API_ERROR_UNIMPLEMENTED;
4647 sa.crypto_alg = mp->crypto_algorithm;
4648 sa.crypto_key_len = mp->crypto_key_length;
4649 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
4650 /* check for unsupported integ-alg */
4651 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
4652 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
4653 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
4654 mp->integrity_algorithm);
4655 rv = VNET_API_ERROR_UNIMPLEMENTED;
4658 sa.integ_alg = mp->integrity_algorithm;
4659 sa.integ_key_len = mp->integrity_key_length;
4660 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
4661 sa.use_esn = mp->use_extended_sequence_number;
4662 sa.is_tunnel = mp->is_tunnel;
4663 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
4664 memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
4665 memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
4667 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
4669 rv = VNET_API_ERROR_UNIMPLEMENTED;
4674 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
4677 vl_api_map_add_domain_t_handler
4678 (vl_api_map_add_domain_t * mp)
4680 vl_api_map_add_domain_reply_t * rmp;
4683 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
4684 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
4685 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
4686 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
4687 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
4689 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
4691 rmp->index = ntohl(index);
4696 vl_api_map_del_domain_t_handler
4697 (vl_api_map_del_domain_t * mp)
4699 vl_api_map_del_domain_reply_t * rmp;
4702 rv = map_delete_domain(ntohl(mp->index));
4704 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
4708 vl_api_map_add_del_rule_t_handler
4709 (vl_api_map_add_del_rule_t * mp)
4711 vl_api_map_del_domain_reply_t * rmp;
4714 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
4716 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
4720 vl_api_map_domain_dump_t_handler
4721 (vl_api_map_domain_dump_t * mp)
4723 vl_api_map_domain_details_t * rmp;
4724 map_main_t *mm = &map_main;
4726 unix_shared_memory_queue_t * q;
4728 if (pool_elts (mm->domains) == 0)
4731 q = vl_api_client_index_to_input_queue (mp->client_index);
4736 pool_foreach(d, mm->domains, ({
4737 rmp = vl_msg_api_alloc (sizeof (*rmp));
4738 memset (rmp, 0, sizeof (*rmp));
4739 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
4740 rmp->domain_index = htonl(d - mm->domains);
4741 rmp->ea_bits_len = d->ea_bits_len;
4742 rmp->psid_offset = d->psid_offset;
4743 rmp->psid_length = d->psid_length;
4744 memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
4745 rmp->ip4_prefix_len = d->ip4_prefix_len;
4746 memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
4747 rmp->ip6_prefix_len = d->ip6_prefix_len;
4748 memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
4749 rmp->ip6_src_len = d->ip6_src_len;
4750 rmp->mtu = htons(d->mtu);
4751 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
4753 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4758 vl_api_map_rule_dump_t_handler
4759 (vl_api_map_rule_dump_t * mp)
4761 unix_shared_memory_queue_t * q;
4764 vl_api_map_rule_details_t * rmp;
4765 map_main_t *mm = &map_main;
4766 u32 domain_index = ntohl(mp->domain_index);
4769 if (pool_elts (mm->domains) == 0)
4772 d = pool_elt_at_index(mm->domains, domain_index);
4773 if (!d || !d->rules) {
4777 q = vl_api_client_index_to_input_queue (mp->client_index);
4782 for (i = 0; i < (0x1 << d->psid_length); i++) {
4784 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
4787 rmp = vl_msg_api_alloc(sizeof(*rmp));
4788 memset(rmp, 0, sizeof(*rmp));
4789 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
4790 rmp->psid = htons(i);
4791 memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
4792 vl_msg_api_send_shmem(q, (u8 *)&rmp);
4797 vl_api_map_summary_stats_t_handler (
4798 vl_api_map_summary_stats_t *mp)
4800 vl_api_map_summary_stats_reply_t *rmp;
4801 vlib_combined_counter_main_t *cm;
4804 u64 total_pkts[VLIB_N_RX_TX];
4805 u64 total_bytes[VLIB_N_RX_TX];
4806 map_main_t *mm = &map_main;
4807 unix_shared_memory_queue_t *q =
4808 vl_api_client_index_to_input_queue(mp->client_index);
4813 rmp = vl_msg_api_alloc (sizeof (*rmp));
4814 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
4815 rmp->context = mp->context;
4818 memset (total_pkts, 0, sizeof (total_pkts));
4819 memset (total_bytes, 0, sizeof (total_bytes));
4821 map_domain_counter_lock (mm);
4822 vec_foreach(cm, mm->domain_counters) {
4823 which = cm - mm->domain_counters;
4825 for (i = 0; i < vec_len(cm->maxi); i++) {
4826 vlib_get_combined_counter (cm, i, &v);
4827 total_pkts[which] += v.packets;
4828 total_bytes[which] += v.bytes;
4832 map_domain_counter_unlock (mm);
4834 /* Note: in HOST byte order! */
4835 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = total_pkts[MAP_DOMAIN_COUNTER_RX];
4836 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = total_bytes[MAP_DOMAIN_COUNTER_RX];
4837 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = total_pkts[MAP_DOMAIN_COUNTER_TX];
4838 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = total_bytes[MAP_DOMAIN_COUNTER_TX];
4839 rmp->total_bindings = pool_elts(mm->domains);
4840 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
4841 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK);
4842 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK);
4844 vl_msg_api_send_shmem(q, (u8 *)&rmp);
4847 static void vl_api_ipsec_sa_set_key_t_handler
4848 (vl_api_ipsec_sa_set_key_t * mp)
4850 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4851 vl_api_ipsec_sa_set_key_reply_t *rmp;
4855 sa.id = ntohl(mp->sa_id);
4856 sa.crypto_key_len = mp->crypto_key_length;
4857 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
4858 sa.integ_key_len = mp->integrity_key_length;
4859 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
4861 rv = ipsec_set_sa_key(vm, &sa);
4863 rv = VNET_API_ERROR_UNIMPLEMENTED;
4866 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
4869 static void vl_api_cop_interface_enable_disable_t_handler
4870 (vl_api_cop_interface_enable_disable_t * mp)
4872 vl_api_cop_interface_enable_disable_reply_t * rmp;
4874 u32 sw_if_index = ntohl(mp->sw_if_index);
4877 VALIDATE_SW_IF_INDEX(mp);
4879 enable_disable = (int) mp->enable_disable;
4881 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
4883 BAD_SW_IF_INDEX_LABEL;
4885 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
4888 static void vl_api_cop_whitelist_enable_disable_t_handler
4889 (vl_api_cop_whitelist_enable_disable_t * mp)
4891 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
4892 cop_whitelist_enable_disable_args_t _a, *a=&_a;
4893 u32 sw_if_index = ntohl(mp->sw_if_index);
4896 VALIDATE_SW_IF_INDEX(mp);
4898 a->sw_if_index = sw_if_index;
4901 a->default_cop = mp->default_cop;
4902 a->fib_id = ntohl(mp->fib_id);
4904 rv = cop_whitelist_enable_disable (a);
4906 BAD_SW_IF_INDEX_LABEL;
4908 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
4911 static void vl_api_get_node_graph_t_handler
4912 (vl_api_get_node_graph_t * mp)
4916 api_main_t * am = &api_main;
4917 vlib_main_t * vm = vlib_get_main();
4919 vl_api_get_node_graph_reply_t * rmp;
4921 pthread_mutex_lock (&am->vlib_rp->mutex);
4922 oldheap = svm_push_data_heap (am->vlib_rp);
4925 * Keep the number of memcpy ops to a minimum (e.g. 1).
4926 * The current size of the serialized vector is
4927 * slightly under 4K.
4929 vec_validate (vector, 4095);
4930 vec_reset_length (vector);
4932 vector = vlib_node_serialize (&vm->node_main, vector);
4934 svm_pop_heap (oldheap);
4935 pthread_mutex_unlock (&am->vlib_rp->mutex);
4937 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
4938 rmp->reply_in_shmem = (uword) vector);
4941 #define BOUNCE_HANDLER(nn) \
4942 static void vl_api_##nn##_t_handler ( \
4943 vl_api_##nn##_t *mp) \
4945 vpe_client_registration_t *reg; \
4946 vpe_api_main_t * vam = &vpe_api_main; \
4947 unix_shared_memory_queue_t * q; \
4949 /* One registration only... */ \
4950 pool_foreach(reg, vam->nn##_registrations, \
4952 q = vl_api_client_index_to_input_queue (reg->client_index); \
4955 * If the queue is stuffed, turf the msg and complain \
4956 * It's unlikely that the intended recipient is \
4957 * alive; avoid deadlock at all costs. \
4959 if (q->cursize == q->maxsize) { \
4960 clib_warning ("ERROR: receiver queue full, drop msg"); \
4961 vl_msg_api_free (mp); \
4964 vl_msg_api_send_shmem (q, (u8 *)&mp); \
4968 vl_msg_api_free (mp); \
4971 BOUNCE_HANDLER(to_netconf_server);
4972 BOUNCE_HANDLER(from_netconf_server);
4973 BOUNCE_HANDLER(to_netconf_client);
4974 BOUNCE_HANDLER(from_netconf_client);
4978 * Add vpe's API message handlers to the table.
4979 * vlib has alread mapped shared memory and
4980 * added the client registration handlers.
4981 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
4984 static clib_error_t *
4985 vpe_api_hookup (vlib_main_t *vm)
4987 api_main_t * am = &api_main;
4990 vl_msg_api_set_handlers(VL_API_##N, #n, \
4991 vl_api_##n##_t_handler, \
4993 vl_api_##n##_t_endian, \
4994 vl_api_##n##_t_print, \
4995 sizeof(vl_api_##n##_t), 1);
4996 foreach_vpe_api_msg;
5000 * Manually register the sr tunnel add del msg, so we trace
5001 * enough bytes to capture a typical segment list
5003 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
5004 "sr_tunnel_add_del",
5005 vl_api_sr_tunnel_add_del_t_handler,
5007 vl_api_sr_tunnel_add_del_t_endian,
5008 vl_api_sr_tunnel_add_del_t_print,
5011 am->message_bounce [VL_API_FROM_NETCONF_SERVER] = 1;
5012 am->message_bounce [VL_API_TO_NETCONF_SERVER] = 1;
5013 am->message_bounce [VL_API_FROM_NETCONF_CLIENT] = 1;
5014 am->message_bounce [VL_API_TO_NETCONF_CLIENT] = 1;
5017 * Trace space for 8 MPLS encap labels, classifier mask+match
5019 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
5020 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
5021 += 5 * sizeof (u32x4);
5022 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
5023 += 5 * sizeof (u32x4);
5024 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
5025 += 16 * sizeof (u32);
5028 * trace space for 4 nsh-gre variable TLV words
5030 am->api_trace_cfg [VL_API_NSH_GRE_ADD_DEL_TUNNEL].size
5031 += 4 * sizeof (u32);
5036 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
5038 static clib_error_t *
5039 vpe_api_init (vlib_main_t *vm)
5041 vpe_api_main_t *am = &vpe_api_main;
5044 am->vnet_main = vnet_get_main();
5045 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
5046 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5047 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5048 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5049 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5050 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
5053 vl_set_memory_region_name ("/vpe-api");
5054 vl_enable_disable_memory_api (vm, 1 /* enable it */);
5059 VLIB_INIT_FUNCTION(vpe_api_init);
5061 static clib_error_t *
5062 chroot_config (vlib_main_t * vm, unformat_input_t * input)
5066 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5068 if (unformat (input, "prefix %s", &chroot_path))
5070 vec_add1 (chroot_path, 0);
5071 vl_set_memory_root_path ((char *)chroot_path);
5074 return clib_error_return (0, "unknown input `%U'",
5075 format_unformat_error, input);
5079 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
5081 void * get_unformat_vnet_sw_interface (void)
5083 return (void *) &unformat_vnet_sw_interface;
5086 #undef vl_api_version
5087 #define vl_api_version(n,v) static u32 vpe_api_version = v;
5088 #include <api/vpe.api.h>
5089 #undef vl_api_version
5091 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
5093 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
5094 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
5095 clib_host_to_net_u32 (mp->api_versions[0]),
5102 static u8 * format_arp_event (u8 * s, va_list * args)
5104 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
5106 s = format (s, "pid %d: %U", event->pid,
5107 format_ip4_address, &event->address);
5111 static clib_error_t *
5112 show_ip4_arp_events_fn (vlib_main_t * vm,
5113 unformat_input_t * input,
5114 vlib_cli_command_t * cmd)
5116 vpe_api_main_t * am = &vpe_api_main;
5117 vl_api_ip4_arp_event_t * event;
5119 if (pool_elts (am->arp_events) == 0) {
5120 vlib_cli_output (vm, "No active arp event registrations");
5124 pool_foreach (event, am->arp_events,
5126 vlib_cli_output (vm, "%U", format_arp_event, event);
5132 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
5133 .path = "show arp event registrations",
5134 .function = show_ip4_arp_events_fn,
5135 .short_help = "Show arp event registrations",