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);
2378 strncpy ((char *) mp->interface_name,
2379 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2381 /* Send the L2 address for ethernet physical intfcs */
2382 if (swif->sup_sw_if_index == swif->sw_if_index
2383 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2384 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2385 ethernet_interface_t *ei;
2387 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2388 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2389 memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2390 mp->l2_address_length = ntohl(sizeof (ei->address));
2391 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2392 vnet_sub_interface_t *sub = &swif->sub;
2393 mp->sub_id = ntohl(sub->id);
2394 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2395 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2396 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2397 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2398 mp->sub_exact_match = sub->eth.flags.exact_match;
2399 mp->sub_default = sub->eth.flags.default_sub;
2400 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2401 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2403 /* vlan tag rewrite data */
2404 u32 vtr_op = L2_VTR_DISABLED;
2405 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2407 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2408 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2409 // error - default to disabled
2410 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2411 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2414 mp->vtr_op = ntohl(vtr_op);
2415 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2416 mp->vtr_tag1 = ntohl(vtr_tag1);
2417 mp->vtr_tag2 = ntohl(vtr_tag2);
2421 vl_msg_api_send_shmem (q, (u8 *)&mp);
2424 static void send_sw_interface_flags (vpe_api_main_t * am,
2425 unix_shared_memory_queue_t *q,
2426 vnet_sw_interface_t * swif)
2428 vl_api_sw_interface_set_flags_t *mp;
2429 vnet_main_t * vnm = am->vnet_main;
2431 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2433 mp = vl_msg_api_alloc (sizeof (*mp));
2434 memset (mp, 0, sizeof (*mp));
2435 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2436 mp->sw_if_index = ntohl(swif->sw_if_index);
2438 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2440 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2442 vl_msg_api_send_shmem (q, (u8 *)&mp);
2445 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2446 unix_shared_memory_queue_t *q,
2448 __attribute__((unused));
2450 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2451 unix_shared_memory_queue_t *q,
2454 vl_api_sw_interface_set_flags_t *mp;
2456 mp = vl_msg_api_alloc (sizeof (*mp));
2457 memset (mp, 0, sizeof (*mp));
2458 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2459 mp->sw_if_index = ntohl(sw_if_index);
2461 mp->admin_up_down = 0;
2462 mp->link_up_down = 0;
2464 vl_msg_api_send_shmem (q, (u8 *)&mp);
2467 static void vl_api_sw_interface_dump_t_handler (
2468 vl_api_sw_interface_dump_t *mp)
2470 vpe_api_main_t * am = &vpe_api_main;
2471 vnet_sw_interface_t * swif;
2472 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2473 u8 * filter_string = 0, * name_string = 0;
2474 unix_shared_memory_queue_t * q;
2475 char * strcasestr (char *, char *); /* lnx hdr file botch */
2477 q = vl_api_client_index_to_input_queue (mp->client_index);
2482 if (mp->name_filter_valid) {
2483 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2484 filter_string = format (0, "%s%c", mp->name_filter, 0);
2487 pool_foreach (swif, im->sw_interfaces,
2489 name_string = format (name_string, "%U%c",
2490 format_vnet_sw_interface_name,
2491 am->vnet_main, swif, 0);
2493 if (mp->name_filter_valid == 0 ||
2494 strcasestr((char *) name_string, (char *) filter_string)) {
2496 send_sw_interface_details (am, q, swif, name_string);
2497 send_sw_interface_flags (am, q, swif);
2499 _vec_len (name_string) = 0;
2502 vec_free (name_string);
2503 vec_free (filter_string);
2506 void send_oam_event (oam_target_t * t)
2508 vpe_api_main_t * vam = &vpe_api_main;
2509 unix_shared_memory_queue_t * q;
2510 vpe_client_registration_t *reg;
2511 vl_api_oam_event_t * mp;
2513 pool_foreach(reg, vam->oam_events_registrations,
2515 q = vl_api_client_index_to_input_queue (reg->client_index);
2517 mp = vl_msg_api_alloc (sizeof (*mp));
2518 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2519 memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2520 mp->state = t->state;
2521 vl_msg_api_send_shmem (q, (u8 *)&mp);
2527 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2529 vl_api_oam_add_del_reply_t * rmp;
2532 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2533 (ip4_address_t *)mp->dst_address,
2537 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2541 vl_api_vnet_get_summary_stats_t_handler (
2542 vl_api_vnet_get_summary_stats_t *mp)
2544 stats_main_t * sm = &stats_main;
2545 vnet_interface_main_t * im = sm->interface_main;
2546 vl_api_vnet_summary_stats_reply_t *rmp;
2547 vlib_combined_counter_main_t * cm;
2550 u64 total_pkts[VLIB_N_RX_TX];
2551 u64 total_bytes[VLIB_N_RX_TX];
2553 unix_shared_memory_queue_t * q =
2554 vl_api_client_index_to_input_queue (mp->client_index);
2559 rmp = vl_msg_api_alloc (sizeof (*rmp));
2560 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2561 rmp->context = mp->context;
2564 memset (total_pkts, 0, sizeof (total_pkts));
2565 memset (total_bytes, 0, sizeof (total_bytes));
2567 vnet_interface_counter_lock (im);
2569 vec_foreach (cm, im->combined_sw_if_counters) {
2570 which = cm - im->combined_sw_if_counters;
2572 for (i = 0; i < vec_len (cm->maxi); i++) {
2573 vlib_get_combined_counter (cm, i, &v);
2574 total_pkts[which] += v.packets;
2575 total_bytes[which] += v.bytes;
2578 vnet_interface_counter_unlock (im);
2580 /* Note: in HOST byte order! */
2581 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2582 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2583 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2584 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2585 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2587 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2590 typedef CLIB_PACKED (struct {
2591 ip4_address_t address;
2593 u32 address_length : 6;
2598 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2600 vnet_main_t * vnm = vnet_get_main();
2601 vnet_interface_main_t * im = &vnm->interface_main;
2602 ip4_main_t * im4 = &ip4_main;
2603 static ip4_route_t * routes;
2604 static u32 * sw_if_indices_to_shut;
2605 stats_main_t * sm = &stats_main;
2610 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2611 u32 target_fib_id = ntohl(mp->vrf_id);
2613 dslock (sm, 1 /* release hint */, 8 /* tag */);
2615 vec_foreach (fib, im4->fibs) {
2616 vnet_sw_interface_t * si;
2618 if (fib->table_id != target_fib_id)
2621 /* remove any mpls/gre tunnels in this fib */
2622 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2624 /* remove any mpls encap/decap labels */
2625 mpls_fib_reset_labels (fib->table_id);
2627 /* remove any proxy arps in this fib */
2628 vnet_proxy_arp_fib_reset (fib->table_id);
2630 /* Set the flow hash for this fib to the default */
2631 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2633 vec_reset_length (sw_if_indices_to_shut);
2635 /* Shut down interfaces in this FIB / clean out intfc routes */
2636 pool_foreach (si, im->sw_interfaces,
2638 u32 sw_if_index = si->sw_if_index;
2640 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2641 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2643 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2646 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2647 sw_if_index = sw_if_indices_to_shut[i];
2648 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2650 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2651 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2652 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2655 vec_reset_length (routes);
2657 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2658 uword * hash = fib->adj_index_by_dst_address[i];
2662 x.address_length = i;
2664 hash_foreach_pair (p, hash,
2666 x.address.data_u32 = p->key;
2667 vec_add1 (routes, x);
2671 vec_foreach (r, routes) {
2672 ip4_add_del_route_args_t a;
2674 memset (&a, 0, sizeof (a));
2675 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2676 a.table_index_or_table_id = fib - im4->fibs;
2677 a.dst_address = r->address;
2678 a.dst_address_length = r->address_length;
2681 ip4_add_del_route (im4, &a);
2682 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2683 IP4_ROUTE_FLAG_FIB_INDEX);
2687 } /* vec_foreach (fib) */
2694 ip6_address_t address;
2701 ip6_route_t ** routep;
2702 } add_routes_in_fib_arg_t;
2704 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2706 add_routes_in_fib_arg_t * ap = arg;
2708 if (kvp->key[2]>>32 == ap->fib_index)
2710 ip6_address_t *addr;
2712 addr = (ip6_address_t *) kvp;
2713 vec_add2 (*ap->routep, r, 1);
2714 r->address = addr[0];
2715 r->address_length = kvp->key[2] & 0xFF;
2716 r->index = kvp->value;
2720 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2722 vnet_main_t * vnm = vnet_get_main();
2723 vnet_interface_main_t * im = &vnm->interface_main;
2724 ip6_main_t * im6 = &ip6_main;
2725 stats_main_t * sm = &stats_main;
2726 static ip6_route_t * routes;
2727 static u32 * sw_if_indices_to_shut;
2732 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2733 u32 target_fib_id = ntohl(mp->vrf_id);
2734 add_routes_in_fib_arg_t _a, *a=&_a;
2735 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2737 dslock (sm, 1 /* release hint */, 9 /* tag */);
2739 vec_foreach (fib, im6->fibs) {
2740 vnet_sw_interface_t * si;
2742 if (fib->table_id != target_fib_id)
2745 vec_reset_length (sw_if_indices_to_shut);
2747 /* Shut down interfaces in this FIB / clean out intfc routes */
2748 pool_foreach (si, im->sw_interfaces,
2750 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2752 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2755 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2756 sw_if_index = sw_if_indices_to_shut[i];
2757 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2759 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2760 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2761 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2764 vec_reset_length (routes);
2766 a->fib_index = fib - im6->fibs;
2767 a->routep = &routes;
2769 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2771 vec_foreach (r, routes) {
2772 ip6_add_del_route_args_t a;
2774 memset (&a, 0, sizeof (a));
2775 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2776 a.table_index_or_table_id = fib - im6->fibs;
2777 a.dst_address = r->address;
2778 a.dst_address_length = r->address_length;
2781 ip6_add_del_route (im6, &a);
2782 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2783 IP6_ROUTE_FLAG_FIB_INDEX);
2786 /* Reinstall the neighbor / router discovery routes */
2787 vnet_ip6_fib_init (im6, fib - im6->fibs);
2789 } /* vec_foreach (fib) */
2795 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2798 vl_api_reset_fib_reply_t * rmp;
2801 rv = ip6_reset_fib_t_handler (mp);
2803 rv = ip4_reset_fib_t_handler (mp);
2805 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2810 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2812 vl_api_dhcp_proxy_config_reply_t * rmp;
2815 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2816 (ip4_address_t *)(&mp->dhcp_src_address),
2817 (u32) ntohl(mp->vrf_id),
2818 (int) mp->insert_circuit_id,
2819 (int) (mp->is_add == 0));
2821 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2826 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2828 vl_api_dhcp_proxy_config_reply_t * rmp;
2831 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2832 (ip6_address_t *)(&mp->dhcp_src_address),
2833 (u32) ntohl(mp->vrf_id),
2834 (int) mp->insert_circuit_id,
2835 (int) (mp->is_add == 0));
2837 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2841 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2843 vl_api_dhcp_proxy_config_reply_t * rmp;
2846 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2847 (ip4_address_t *)(&mp->dhcp_src_address),
2848 (u32) ntohl(mp->rx_vrf_id),
2849 (u32) ntohl(mp->server_vrf_id),
2850 (int) mp->insert_circuit_id,
2851 (int) (mp->is_add == 0));
2853 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2858 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2860 vl_api_dhcp_proxy_config_reply_t * rmp;
2864 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2865 (ip6_address_t *)(&mp->dhcp_src_address),
2866 (u32) ntohl(mp->rx_vrf_id),
2867 (u32) ntohl(mp->server_vrf_id),
2868 (int) mp->insert_circuit_id,
2869 (int) (mp->is_add == 0));
2871 rv = VNET_API_ERROR_UNIMPLEMENTED;
2874 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2879 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2881 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2884 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2887 (int)mp->is_add == 0);
2889 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2892 (int)mp->is_add == 0);
2894 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2898 static void vl_api_dhcp_proxy_config_t_handler
2899 (vl_api_dhcp_proxy_config_t *mp)
2901 if (mp->is_ipv6 == 0)
2902 dhcpv4_proxy_config (mp);
2904 dhcpv6_proxy_config (mp);
2907 static void vl_api_dhcp_proxy_config_2_t_handler
2908 (vl_api_dhcp_proxy_config_2_t *mp)
2910 if (mp->is_ipv6 == 0)
2911 dhcpv4_proxy_config_2 (mp);
2913 dhcpv6_proxy_config_2 (mp);
2916 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
2917 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
2919 unix_shared_memory_queue_t * q;
2920 vl_api_dhcp_compl_event_t * mp;
2922 q = vl_api_client_index_to_input_queue (client_index);
2926 mp = vl_msg_api_alloc (sizeof (*mp));
2927 mp->client_index = client_index;
2929 mp->is_ipv6 = is_ipv6;
2930 memcpy (&mp->hostname, hostname, vec_len(hostname));
2931 mp->hostname[vec_len(hostname) + 1] = '\n';
2932 memcpy (&mp->host_address[0], host_address, 16);
2933 memcpy (&mp->router_address[0], router_address, 16);
2934 memcpy (&mp->host_mac[0], host_mac, 6);
2936 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
2938 vl_msg_api_send_shmem (q, (u8 *)&mp);
2941 static void vl_api_dhcp_client_config_t_handler
2942 (vl_api_dhcp_client_config_t *mp)
2944 vlib_main_t *vm = vlib_get_main();
2945 vl_api_dhcp_client_config_reply_t * rmp;
2948 VALIDATE_SW_IF_INDEX(mp);
2950 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
2951 mp->hostname, mp->is_add, mp->client_index,
2952 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
2955 BAD_SW_IF_INDEX_LABEL;
2957 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
2961 vl_api_sw_interface_ip6nd_ra_config_t_handler
2962 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
2964 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
2966 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
2968 is_no = mp->is_no == 1;
2969 surpress = mp->surpress == 1;
2970 managed = mp->managed == 1;
2971 other = mp->other == 1;
2972 ll_option = mp->ll_option == 1;
2973 send_unicast = mp->send_unicast == 1;
2974 cease = mp->cease == 1;
2975 default_router = mp->default_router == 1;
2977 VALIDATE_SW_IF_INDEX(mp);
2979 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
2980 surpress, managed, other,
2981 ll_option, send_unicast, cease,
2982 default_router, ntohl (mp->lifetime),
2983 ntohl(mp->initial_count), ntohl(mp->initial_interval),
2984 ntohl(mp->max_interval), ntohl( mp->min_interval),
2987 BAD_SW_IF_INDEX_LABEL;
2989 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
2993 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
2994 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
2996 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
2998 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3000 VALIDATE_SW_IF_INDEX(mp);
3002 is_no = mp->is_no == 1;
3003 use_default = mp->use_default == 1;
3004 no_advertise = mp->no_advertise == 1;
3005 off_link = mp->off_link == 1;
3006 no_autoconfig = mp->no_autoconfig == 1;
3007 no_onlink = mp->no_onlink == 1;
3009 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3010 (ip6_address_t *)mp->address, mp->address_length,
3011 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3012 no_advertise, off_link, no_autoconfig, no_onlink,
3015 BAD_SW_IF_INDEX_LABEL;
3016 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3020 vl_api_sw_interface_ip6_enable_disable_t_handler
3021 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3023 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3024 vnet_main_t * vnm = vnet_get_main();
3026 clib_error_t * error;
3030 VALIDATE_SW_IF_INDEX(mp);
3032 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3033 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3036 clib_error_report(error);
3037 rv = VNET_API_ERROR_UNSPECIFIED;
3039 rv = vnm->api_errno;
3042 BAD_SW_IF_INDEX_LABEL;
3044 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3048 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3049 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3051 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3053 clib_error_t * error;
3054 vnet_main_t * vnm = vnet_get_main();
3058 VALIDATE_SW_IF_INDEX(mp);
3060 error = set_ip6_link_local_address(vm,
3061 ntohl(mp->sw_if_index),
3062 (ip6_address_t *)mp->address,
3063 mp->address_length);
3065 clib_error_report(error);
3066 rv = VNET_API_ERROR_UNSPECIFIED;
3068 rv = vnm->api_errno;
3071 BAD_SW_IF_INDEX_LABEL;
3073 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3076 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3078 vl_api_set_ip_flow_hash_reply_t *rmp;
3079 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3081 clib_warning ("unimplemented...");
3083 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3086 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3088 vl_api_set_ip_flow_hash_reply_t *rmp;
3091 u32 flow_hash_config = 0;
3093 table_id = ntohl(mp->vrf_id);
3095 #define _(a,b) if (mp->a) flow_hash_config |= b;
3096 foreach_flow_hash_bit;
3099 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3101 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3105 static void vl_api_set_ip_flow_hash_t_handler
3106 (vl_api_set_ip_flow_hash_t *mp)
3108 if (mp->is_ipv6 == 0)
3109 set_ip4_flow_hash (mp);
3111 set_ip6_flow_hash (mp);
3114 static void vl_api_sw_interface_set_unnumbered_t_handler
3115 (vl_api_sw_interface_set_unnumbered_t *mp)
3117 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3119 vnet_sw_interface_t * si;
3120 vnet_main_t *vnm = vnet_get_main();
3121 u32 sw_if_index, unnumbered_sw_if_index;
3123 sw_if_index = ntohl(mp->sw_if_index);
3124 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3127 * The API message field names are backwards from
3128 * the underlying data structure names.
3129 * It's not worth changing them now.
3131 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3132 unnumbered_sw_if_index)) {
3133 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3137 /* Only check the "use loop0" field when setting the binding */
3139 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3140 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3144 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3147 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3148 si->unnumbered_sw_if_index = sw_if_index;
3150 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3151 si->unnumbered_sw_if_index = (u32)~0;
3155 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3158 static void vl_api_create_loopback_t_handler
3159 (vl_api_create_loopback_t *mp)
3161 vl_api_create_loopback_reply_t * rmp;
3165 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3167 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3169 rmp->sw_if_index = ntohl (sw_if_index);
3173 static void vl_api_delete_loopback_t_handler
3174 (vl_api_delete_loopback_t *mp)
3176 vl_api_delete_loopback_reply_t * rmp;
3180 sw_if_index = ntohl (mp->sw_if_index);
3181 rv = vnet_delete_loopback_interface (sw_if_index);
3183 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3186 static void vl_api_control_ping_t_handler
3187 (vl_api_control_ping_t *mp)
3189 vl_api_control_ping_reply_t * rmp;
3192 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3194 rmp->vpe_pid = ntohl (getpid());
3198 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3200 u8 **shmem_vecp = (u8 **)arg;
3203 api_main_t * am = &api_main;
3206 shmem_vec = *shmem_vecp;
3208 offset = vec_len (shmem_vec);
3210 pthread_mutex_lock (&am->vlib_rp->mutex);
3211 oldheap = svm_push_data_heap (am->vlib_rp);
3213 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3215 memcpy (shmem_vec + offset, buffer, buffer_bytes);
3217 svm_pop_heap (oldheap);
3218 pthread_mutex_unlock (&am->vlib_rp->mutex);
3220 *shmem_vecp = shmem_vec;
3224 static void vl_api_cli_request_t_handler
3225 (vl_api_cli_request_t *mp)
3227 vl_api_cli_reply_t *rp;
3228 unix_shared_memory_queue_t *q;
3229 vlib_main_t * vm = vlib_get_main();
3230 api_main_t * am = &api_main;
3231 unformat_input_t input;
3235 q = vl_api_client_index_to_input_queue (mp->client_index);
3239 rp = vl_msg_api_alloc (sizeof (*rp));
3240 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3241 rp->context = mp->context;
3243 unformat_init_vector (&input, (u8 *)mp->cmd_in_shmem);
3245 vlib_cli_input (vm, &input, shmem_cli_output,
3248 pthread_mutex_lock (&am->vlib_rp->mutex);
3249 oldheap = svm_push_data_heap (am->vlib_rp);
3251 vec_add1(shmem_vec, 0);
3253 svm_pop_heap (oldheap);
3254 pthread_mutex_unlock (&am->vlib_rp->mutex);
3256 rp->reply_in_shmem = (uword)shmem_vec;
3258 vl_msg_api_send_shmem (q, (u8 *)&rp);
3261 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3264 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3265 vnet_main_t *vnm = vnet_get_main();
3266 clib_error_t * error;
3271 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3273 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3276 clib_error_report(error);
3277 rv = VNET_API_ERROR_UNSPECIFIED;
3279 rv = vnm->api_errno;
3282 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3285 static void vl_api_sr_tunnel_add_del_t_handler
3286 (vl_api_sr_tunnel_add_del_t *mp)
3289 clib_warning ("unimplemented");
3291 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3293 vl_api_sr_tunnel_add_del_reply_t * rmp;
3294 ip6_address_t * segments = 0, * seg;
3295 ip6_address_t * tags = 0, *tag;
3296 ip6_address_t * this_address;
3299 if (mp->n_segments == 0) {
3304 memset (a, 0, sizeof (*a));
3305 a->src_address = (ip6_address_t *)&mp->src_address;
3306 a->dst_address = (ip6_address_t *)&mp->dst_address;
3307 a->dst_mask_width = mp->dst_mask_width;
3308 a->flags_net_byte_order = mp->flags_net_byte_order;
3309 a->is_del = (mp->is_add == 0);
3310 a->rx_table_id = ntohl(mp->outer_vrf_id);
3311 a->tx_table_id = ntohl(mp->inner_vrf_id);
3313 /* Yank segments and tags out of the API message */
3314 this_address = (ip6_address_t *)mp->segs_and_tags;
3315 for (i = 0; i < mp->n_segments; i++) {
3316 vec_add2 (segments, seg, 1);
3317 memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3320 for (i = 0; i < mp->n_tags; i++) {
3321 vec_add2 (tags, tag, 1);
3322 memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3326 a->segments = segments;
3329 rv = ip6_sr_add_del_tunnel (a);
3333 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3337 #define foreach_classify_add_del_table_field \
3342 _(match_n_vectors) \
3343 _(next_table_index) \
3346 static void vl_api_classify_add_del_table_t_handler
3347 (vl_api_classify_add_del_table_t * mp)
3349 vl_api_classify_add_del_table_reply_t * rmp;
3350 vnet_classify_main_t * cm = &vnet_classify_main;
3351 vnet_classify_table_t * t;
3355 foreach_classify_add_del_table_field;
3358 #define _(a) a = ntohl(mp->a);
3359 foreach_classify_add_del_table_field;
3362 /* The underlying API fails silently, on purpose, so check here */
3363 if (mp->is_add == 0)
3364 if (pool_is_free_index (cm->tables, table_index)) {
3365 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3369 rv = vnet_classify_add_del_table
3370 (cm, mp->mask, nbuckets, memory_size,
3371 skip_n_vectors, match_n_vectors,
3372 next_table_index, miss_next_index,
3373 &table_index, mp->is_add);
3376 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3378 if (rv == 0 && mp->is_add) {
3379 t = pool_elt_at_index (cm->tables, table_index);
3380 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3381 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3382 rmp->new_table_index = ntohl(table_index);
3384 rmp->skip_n_vectors = ~0;
3385 rmp->match_n_vectors = ~0;
3386 rmp->new_table_index = ~0;
3391 static void vl_api_classify_add_del_session_t_handler
3392 (vl_api_classify_add_del_session_t * mp)
3394 vnet_classify_main_t * cm = &vnet_classify_main;
3395 vl_api_classify_add_del_session_reply_t * rmp;
3397 u32 table_index, hit_next_index, opaque_index;
3400 table_index = ntohl (mp->table_index);
3401 hit_next_index = ntohl (mp->hit_next_index);
3402 opaque_index = ntohl (mp->opaque_index);
3403 advance = ntohl (mp->advance);
3405 rv = vnet_classify_add_del_session
3406 (cm, table_index, mp->match, hit_next_index, opaque_index,
3407 advance, mp->is_add);
3409 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3412 static void vl_api_classify_set_interface_ip_table_t_handler
3413 (vl_api_classify_set_interface_ip_table_t * mp)
3415 vlib_main_t * vm = vlib_get_main();
3416 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3418 u32 table_index, sw_if_index;
3420 table_index = ntohl (mp->table_index);
3421 sw_if_index = ntohl (mp->sw_if_index);
3423 VALIDATE_SW_IF_INDEX(mp);
3426 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3428 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3430 BAD_SW_IF_INDEX_LABEL;
3432 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3435 static void vl_api_classify_set_interface_l2_tables_t_handler
3436 (vl_api_classify_set_interface_l2_tables_t * mp)
3438 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3440 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3443 ip4_table_index = ntohl(mp->ip4_table_index);
3444 ip6_table_index = ntohl(mp->ip6_table_index);
3445 other_table_index = ntohl(mp->other_table_index);
3446 sw_if_index = ntohl(mp->sw_if_index);
3448 VALIDATE_SW_IF_INDEX(mp);
3450 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3451 ip6_table_index, other_table_index);
3454 if (ip4_table_index != ~0 || ip6_table_index != ~0
3455 || other_table_index != ~0)
3460 vnet_l2_classify_enable_disable (sw_if_index, enable);
3463 BAD_SW_IF_INDEX_LABEL;
3465 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3469 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3472 vl_api_l2_fib_clear_table_reply_t * rmp;
3474 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3475 * that is not currently implemented. When that TODO is fixed
3476 * this call should be changed to pass 1 instead of 0.
3478 l2fib_clear_table (0);
3480 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3483 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3488 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3491 vl_api_l2_interface_efp_filter_reply_t * rmp;
3492 vnet_main_t *vnm = vnet_get_main();
3494 // enable/disable the feature
3495 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3496 rv = vnm->api_errno;
3498 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3502 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3505 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3506 vnet_main_t * vnm = vnet_get_main();
3507 vlib_main_t * vm = vlib_get_main();
3510 VALIDATE_SW_IF_INDEX(mp);
3512 vtr_op = ntohl(mp->vtr_op);
3514 /* The L2 code is unsuspicious */
3516 case L2_VTR_DISABLED:
3521 case L2_VTR_TRANSLATE_1_1:
3522 case L2_VTR_TRANSLATE_1_2:
3523 case L2_VTR_TRANSLATE_2_1:
3524 case L2_VTR_TRANSLATE_2_2:
3528 rv = VNET_API_ERROR_INVALID_VALUE;
3529 goto bad_sw_if_index;
3532 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3533 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3536 BAD_SW_IF_INDEX_LABEL;
3538 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3542 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3546 vl_api_create_vhost_user_if_reply_t * rmp;
3547 u32 sw_if_index = (u32)~0;
3549 vnet_main_t * vnm = vnet_get_main();
3550 vlib_main_t * vm = vlib_get_main();
3552 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3553 mp->is_server, &sw_if_index, (u64)~0,
3554 mp->renumber, ntohl(mp->custom_dev_instance),
3555 (mp->use_custom_mac)?mp->mac_address:NULL);
3557 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3559 rmp->sw_if_index = ntohl (sw_if_index);
3565 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3569 vl_api_modify_vhost_user_if_reply_t * rmp;
3570 u32 sw_if_index = ntohl(mp->sw_if_index);
3572 vnet_main_t * vnm = vnet_get_main();
3573 vlib_main_t * vm = vlib_get_main();
3575 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3576 mp->is_server, sw_if_index, (u64)~0,
3577 mp->renumber, ntohl(mp->custom_dev_instance));
3579 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3584 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3588 vpe_api_main_t * vam = &vpe_api_main;
3589 vl_api_delete_vhost_user_if_reply_t * rmp;
3590 u32 sw_if_index = ntohl(mp->sw_if_index);
3592 vnet_main_t * vnm = vnet_get_main();
3593 vlib_main_t * vm = vlib_get_main();
3595 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3597 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3599 unix_shared_memory_queue_t * q =
3600 vl_api_client_index_to_input_queue (mp->client_index);
3604 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3609 static void vl_api_sw_interface_vhost_user_details_t_handler (
3610 vl_api_sw_interface_vhost_user_details_t * mp)
3612 clib_warning ("BUG");
3616 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3617 unix_shared_memory_queue_t *q,
3618 vhost_user_intf_details_t * vui)
3620 vl_api_sw_interface_vhost_user_details_t * mp;
3622 mp = vl_msg_api_alloc (sizeof (*mp));
3623 memset (mp, 0, sizeof (*mp));
3624 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3625 mp->sw_if_index = ntohl(vui->sw_if_index);
3626 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3627 mp->features = clib_net_to_host_u64 (vui->features);
3628 mp->is_server = vui->is_server;
3629 mp->num_regions = ntohl(vui->num_regions);
3630 mp->sock_errno = ntohl(vui->sock_errno);
3632 strncpy ((char *) mp->sock_filename,
3633 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3634 strncpy ((char *) mp->interface_name,
3635 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3637 vl_msg_api_send_shmem (q, (u8 *)&mp);
3642 vl_api_sw_interface_vhost_user_dump_t_handler (
3643 vl_api_sw_interface_vhost_user_dump_t *mp)
3647 vpe_api_main_t * am = &vpe_api_main;
3648 vnet_main_t * vnm = vnet_get_main();
3649 vlib_main_t * vm = vlib_get_main();
3650 vhost_user_intf_details_t *ifaces = NULL;
3651 vhost_user_intf_details_t *vuid = NULL;
3652 unix_shared_memory_queue_t * q;
3654 q = vl_api_client_index_to_input_queue (mp->client_index);
3658 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3662 vec_foreach (vuid, ifaces) {
3663 send_sw_interface_vhost_user_details (am, q, vuid);
3669 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3670 unix_shared_memory_queue_t *q,
3674 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3675 u8 * if_name = NULL;
3676 vnet_sw_interface_t * si = NULL;
3678 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3680 if_name = format(if_name, "%U",
3681 format_vnet_sw_interface_name, lm->vnet_main, si);
3683 mp = vl_msg_api_alloc (sizeof (*mp));
3684 memset (mp, 0, sizeof (*mp));
3685 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3686 strncpy((char *)mp->interface_name,
3687 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3688 mp->sw_if_index = ntohl(si->sw_if_index);
3689 mp->local_session_id = s->local_session_id;
3690 mp->remote_session_id = s->remote_session_id;
3691 mp->local_cookie[0] = s->local_cookie[0];
3692 mp->local_cookie[1] = s->local_cookie[1];
3693 mp->remote_cookie = s->remote_cookie;
3694 memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3695 memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3696 mp->l2_sublayer_present = s->l2_sublayer_present;
3698 vl_msg_api_send_shmem (q, (u8 *)&mp);
3701 static void send_ip_address_details (vpe_api_main_t * am,
3702 unix_shared_memory_queue_t * q,
3707 vl_api_ip_address_details_t * mp;
3709 mp = vl_msg_api_alloc (sizeof (*mp));
3710 memset (mp, 0, sizeof (*mp));
3711 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3714 memcpy(&mp->ip, ip, sizeof(mp->ip));
3716 u32 * tp = (u32 *)mp->ip;
3717 *tp = ntohl(*(u32*)ip);
3719 mp->prefix_length = prefix_length;
3721 vl_msg_api_send_shmem (q, (u8 *)&mp);
3725 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3727 vpe_api_main_t * am = &vpe_api_main;
3728 unix_shared_memory_queue_t * q;
3731 ip6_main_t * im6 = &ip6_main;
3732 ip4_main_t * im4 = &ip4_main;
3733 ip_lookup_main_t * lm6 = &im6->lookup_main;
3734 ip_lookup_main_t * lm4 = &im4->lookup_main;
3735 ip_interface_address_t * ia = 0;
3736 u32 sw_if_index = ~0;
3738 sw_if_index = ntohl(mp->sw_if_index);
3740 q = vl_api_client_index_to_input_queue (mp->client_index);
3746 foreach_ip_interface_address (lm6, ia, sw_if_index,
3747 1 /* honor unnumbered */,
3749 r6 = ip_interface_address_get_address (lm6, ia);
3750 u16 prefix_length = ia->address_length;
3751 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1);
3754 foreach_ip_interface_address (lm4, ia, sw_if_index,
3755 1 /* honor unnumbered */,
3757 r4 = ip_interface_address_get_address (lm4, ia);
3758 u16 prefix_length = ia->address_length;
3759 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0);
3764 static void send_ip_details (vpe_api_main_t * am,
3765 unix_shared_memory_queue_t *q,
3768 vl_api_ip_details_t * mp;
3770 mp = vl_msg_api_alloc (sizeof (*mp));
3771 memset (mp, 0, sizeof (*mp));
3772 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3774 mp->sw_if_index = ntohl(sw_if_index);
3776 vl_msg_api_send_shmem (q, (u8 *)&mp);
3780 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3781 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3783 vpe_api_main_t * am = &vpe_api_main;
3784 l2t_main_t * lm = &l2t_main;
3785 unix_shared_memory_queue_t * q;
3786 l2t_session_t *session;
3788 q = vl_api_client_index_to_input_queue (mp->client_index);
3792 pool_foreach (session, lm->sessions,
3794 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm);
3799 static void send_sw_interface_tap_details (vpe_api_main_t * am,
3800 unix_shared_memory_queue_t *q,
3801 tapcli_interface_details_t *tap_if)
3803 vl_api_sw_interface_tap_details_t * mp;
3804 mp = vl_msg_api_alloc (sizeof (*mp));
3805 memset (mp, 0, sizeof (*mp));
3806 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
3807 mp->sw_if_index = ntohl(tap_if->sw_if_index);
3808 strncpy((char *)mp->dev_name,
3809 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
3811 vl_msg_api_send_shmem (q, (u8 *)&mp);
3815 vl_api_sw_interface_tap_dump_t_handler (
3816 vl_api_sw_interface_tap_dump_t *mp)
3819 vpe_api_main_t * am = &vpe_api_main;
3820 unix_shared_memory_queue_t * q;
3821 tapcli_interface_details_t *tapifs = NULL;
3822 tapcli_interface_details_t *tap_if = NULL;
3824 q = vl_api_client_index_to_input_queue (mp->client_index);
3828 rv = vnet_tap_dump_ifs(&tapifs);
3832 vec_foreach(tap_if, tapifs) {
3833 send_sw_interface_tap_details(am, q, tap_if);
3840 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
3842 vpe_api_main_t * am = &vpe_api_main;
3843 vnet_main_t * vnm = vnet_get_main();
3844 vlib_main_t * vm = vlib_get_main();
3845 vnet_interface_main_t * im = &vnm->interface_main;
3846 unix_shared_memory_queue_t * q;
3847 vnet_sw_interface_t * si, * sorted_sis;
3848 u32 sw_if_index = ~0;
3850 q = vl_api_client_index_to_input_queue (mp->client_index);
3855 /* Gather interfaces. */
3856 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
3857 _vec_len (sorted_sis) = 0;
3858 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
3860 vec_foreach (si, sorted_sis) {
3861 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
3862 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
3865 sw_if_index = si->sw_if_index;
3866 send_ip_details(am, q, sw_if_index);
3871 static void vl_api_l2_fib_table_entry_t_handler (
3872 vl_api_l2_fib_table_entry_t * mp)
3874 clib_warning ("BUG");
3877 static void send_l2fib_table_entry (vpe_api_main_t * am,
3878 unix_shared_memory_queue_t *q,
3879 l2fib_entry_key_t * l2fe_key,
3880 l2fib_entry_result_t * l2fe_res)
3882 vl_api_l2_fib_table_entry_t * mp;
3884 mp = vl_msg_api_alloc (sizeof (*mp));
3885 memset (mp, 0, sizeof (*mp));
3886 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
3888 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
3890 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
3891 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
3892 mp->static_mac = l2fe_res->fields.static_mac;
3893 mp->filter_mac = l2fe_res->fields.filter;
3894 mp->bvi_mac = l2fe_res->fields.bvi;
3896 vl_msg_api_send_shmem (q, (u8 *)&mp);
3900 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
3902 vpe_api_main_t * am = &vpe_api_main;
3903 bd_main_t * bdm = &bd_main;
3904 l2fib_entry_key_t *l2fe_key = NULL;
3905 l2fib_entry_result_t *l2fe_res = NULL;
3906 u32 ni, bd_id = ntohl (mp->bd_id);
3908 unix_shared_memory_queue_t * q;
3911 q = vl_api_client_index_to_input_queue (mp->client_index);
3915 /* see l2fib_table_dump: ~0 means "any" */
3919 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
3926 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
3928 vec_foreach_index (ni, l2fe_key) {
3929 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
3930 vec_elt_at_index(l2fe_res, ni));
3937 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
3939 vl_api_show_version_reply_t *rmp;
3941 char * vpe_api_get_build_directory(void);
3942 char * vpe_api_get_version(void);
3943 char * vpe_api_get_build_date(void);
3945 unix_shared_memory_queue_t * q =
3946 vl_api_client_index_to_input_queue (mp->client_index);
3951 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
3953 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
3954 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
3955 ARRAY_LEN(rmp->build_directory)-1);
3956 strncpy ((char *) rmp->version, vpe_api_get_version(),
3957 ARRAY_LEN(rmp->version)-1);
3958 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
3959 ARRAY_LEN(rmp->build_date)-1);
3963 static void vl_api_get_node_index_t_handler
3964 (vl_api_get_node_index_t * mp)
3966 vlib_main_t * vm = vlib_get_main();
3967 vl_api_get_node_index_reply_t * rmp;
3970 u32 node_index = ~0;
3972 n = vlib_get_node_by_name (vm, mp->node_name);
3975 rv = VNET_API_ERROR_NO_SUCH_NODE;
3977 node_index = n->index;
3979 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
3981 rmp->node_index = ntohl(node_index);
3985 static void vl_api_add_node_next_t_handler
3986 (vl_api_add_node_next_t * mp)
3988 vlib_main_t * vm = vlib_get_main();
3989 vl_api_add_node_next_reply_t * rmp;
3990 vlib_node_t * n, * next;
3992 u32 next_index = ~0;
3994 n = vlib_get_node_by_name (vm, mp->node_name);
3997 rv = VNET_API_ERROR_NO_SUCH_NODE;
4001 next = vlib_get_node_by_name (vm, mp->next_name);
4004 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4006 next_index = vlib_node_add_next (vm, n->index, next->index);
4009 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4011 rmp->next_index = ntohl(next_index);
4015 static void vl_api_l2tpv3_create_tunnel_t_handler
4016 (vl_api_l2tpv3_create_tunnel_t *mp)
4018 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4019 l2t_main_t *lm = &l2t_main;
4020 u32 sw_if_index = (u32)~0;
4023 if (mp->is_ipv6 != 1) {
4024 rv = VNET_API_ERROR_UNIMPLEMENTED;
4028 rv = create_l2tpv3_ipv6_tunnel (lm,
4029 (ip6_address_t *) mp->client_address,
4030 (ip6_address_t *) mp->our_address,
4031 ntohl(mp->local_session_id),
4032 ntohl(mp->remote_session_id),
4033 clib_net_to_host_u64(mp->local_cookie),
4034 clib_net_to_host_u64(mp->remote_cookie),
4035 mp->l2_sublayer_present,
4039 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4041 rmp->sw_if_index = ntohl (sw_if_index);
4045 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4046 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4048 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4049 l2t_main_t *lm = &l2t_main;
4052 VALIDATE_SW_IF_INDEX(mp);
4054 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4055 clib_net_to_host_u64(mp->new_local_cookie),
4056 clib_net_to_host_u64(mp->new_remote_cookie));
4058 BAD_SW_IF_INDEX_LABEL;
4060 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4063 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4064 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4067 vnet_main_t * vnm = vnet_get_main();
4068 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4070 VALIDATE_SW_IF_INDEX(mp);
4072 rv = l2tpv3_interface_enable_disable
4073 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4075 BAD_SW_IF_INDEX_LABEL;
4077 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4080 static void vl_api_l2tpv3_set_lookup_key_t_handler
4081 (vl_api_l2tpv3_set_lookup_key_t * mp)
4084 l2t_main_t *lm = &l2t_main;
4085 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4087 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4088 rv = VNET_API_ERROR_INVALID_VALUE;
4092 lm->lookup_type = mp->key;
4095 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4098 static void vl_api_vxlan_add_del_tunnel_t_handler
4099 (vl_api_vxlan_add_del_tunnel_t * mp)
4101 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4103 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4104 u32 encap_fib_index;
4106 ip4_main_t * im = &ip4_main;
4107 u32 sw_if_index = ~0;
4109 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4111 rv = VNET_API_ERROR_NO_SUCH_FIB;
4114 encap_fib_index = p[0];
4116 memset (a, 0, sizeof (*a));
4118 a->is_add = mp->is_add;
4120 /* ip addresses sent in network byte order */
4121 a->src.as_u32 = mp->src_address;
4122 a->dst.as_u32 = mp->dst_address;
4124 a->encap_fib_index = encap_fib_index;
4125 a->decap_next_index = ntohl(mp->decap_next_index);
4126 a->vni = ntohl(mp->vni);
4127 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4130 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4132 rmp->sw_if_index = ntohl (sw_if_index);
4136 static void send_vxlan_tunnel_details
4137 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q)
4139 vl_api_vxlan_tunnel_details_t * rmp;
4140 ip4_main_t * im = &ip4_main;
4142 rmp = vl_msg_api_alloc (sizeof (*rmp));
4143 memset (rmp, 0, sizeof (*rmp));
4144 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4145 rmp->src_address = t->src.data_u32;
4146 rmp->dst_address = t->dst.data_u32;
4147 rmp->encap_vrf_id = htonl(im->fibs[t->encap_fib_index].table_id);
4148 rmp->vni = htonl(t->vni);
4149 rmp->decap_next_index = htonl(t->decap_next_index);
4150 rmp->sw_if_index = htonl(t->sw_if_index);
4152 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4155 static void vl_api_vxlan_tunnel_dump_t_handler
4156 (vl_api_vxlan_tunnel_dump_t * mp)
4158 unix_shared_memory_queue_t * q;
4159 vxlan_main_t * vxm = &vxlan_main;
4163 q = vl_api_client_index_to_input_queue (mp->client_index);
4168 sw_if_index = ntohl(mp->sw_if_index);
4170 if (~0 == sw_if_index) {
4171 pool_foreach (t, vxm->tunnels,
4173 send_vxlan_tunnel_details(t, q);
4176 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4177 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4180 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4181 send_vxlan_tunnel_details(t, q);
4186 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4188 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4190 vl_api_l2_patch_add_del_reply_t * rmp;
4191 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4195 VALIDATE_RX_SW_IF_INDEX(mp);
4196 VALIDATE_TX_SW_IF_INDEX(mp);
4198 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4199 ntohl(mp->tx_sw_if_index),
4200 (int)(mp->is_add != 0));
4202 BAD_RX_SW_IF_INDEX_LABEL;
4203 BAD_TX_SW_IF_INDEX_LABEL;
4205 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4209 vl_api_nsh_gre_add_del_tunnel_t_handler
4210 (vl_api_nsh_gre_add_del_tunnel_t * mp)
4212 vl_api_nsh_gre_add_del_tunnel_reply_t * rmp;
4214 vnet_nsh_gre_add_del_tunnel_args_t _a, *a = &_a;
4215 u32 encap_fib_index, decap_fib_index;
4216 u32 decap_next_index;
4218 ip4_main_t * im = &ip4_main;
4220 u32 sw_if_index = ~0;
4223 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4225 rv = VNET_API_ERROR_NO_SUCH_FIB;
4228 encap_fib_index = p[0];
4230 decap_next_index = ntohl(mp->decap_next_index);
4232 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4233 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4234 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4236 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4239 decap_fib_index = p[0];
4241 decap_fib_index = ntohl(mp->decap_vrf_id);
4244 memset (a, 0, sizeof (*a));
4246 a->is_add = mp->is_add;
4247 /* ip addresses sent in network byte order */
4248 a->src.as_u32 = ntohl(mp->src);
4249 a->dst.as_u32 = ntohl(mp->dst);
4250 a->encap_fib_index = encap_fib_index;
4251 a->decap_fib_index = decap_fib_index;
4252 a->decap_next_index = decap_next_index;
4253 a->ver_o_c = mp->ver_o_c;
4254 a->length = mp->length;
4255 a->md_type = mp->md_type;
4256 a->next_protocol = mp->next_protocol;
4257 a->spi_si = ntohl(mp->spi_si);
4258 a->c1 = ntohl(mp->c1);
4259 a->c2 = ntohl(mp->c2);
4260 a->c3 = ntohl(mp->c3);
4261 a->c4 = ntohl(mp->c4);
4263 for (i = 0; i < mp->tlv_len_in_words; i++)
4264 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4268 rv = vnet_nsh_gre_add_del_tunnel (a, &sw_if_index);
4271 REPLY_MACRO2(VL_API_NSH_GRE_ADD_DEL_TUNNEL_REPLY,
4273 rmp->sw_if_index = ntohl (sw_if_index);
4278 vl_api_nsh_vxlan_gpe_add_del_tunnel_t_handler
4279 (vl_api_nsh_vxlan_gpe_add_del_tunnel_t * mp)
4281 vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4283 vnet_nsh_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4284 u32 encap_fib_index, decap_fib_index;
4285 u32 decap_next_index;
4287 ip4_main_t * im = &ip4_main;
4289 u32 sw_if_index = ~0;
4292 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4294 rv = VNET_API_ERROR_NO_SUCH_FIB;
4297 encap_fib_index = p[0];
4299 decap_next_index = ntohl(mp->decap_next_index);
4301 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4302 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4303 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4305 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4308 decap_fib_index = p[0];
4310 decap_fib_index = ntohl(mp->decap_vrf_id);
4313 memset (a, 0, sizeof (*a));
4315 a->is_add = mp->is_add;
4316 /* ip addresses sent in network byte order */
4317 a->src.as_u32 = ntohl(mp->src);
4318 a->dst.as_u32 = ntohl(mp->dst);
4319 a->encap_fib_index = encap_fib_index;
4320 a->decap_fib_index = decap_fib_index;
4321 a->decap_next_index = decap_next_index;
4322 a->vni = ntohl(mp->vni);
4323 a->ver_o_c = mp->ver_o_c;
4324 a->length = mp->length;
4325 a->md_type = mp->md_type;
4326 a->next_protocol = mp->next_protocol;
4327 a->spi_si = ntohl(mp->spi_si);
4328 a->c1 = ntohl(mp->c1);
4329 a->c2 = ntohl(mp->c2);
4330 a->c3 = ntohl(mp->c3);
4331 a->c4 = ntohl(mp->c4);
4333 for (i = 0; i < mp->tlv_len_in_words; i++)
4334 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4338 rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4341 REPLY_MACRO2(VL_API_NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4343 rmp->sw_if_index = ntohl (sw_if_index);
4348 vl_api_lisp_gpe_add_del_tunnel_t_handler
4349 (vl_api_lisp_gpe_add_del_tunnel_t * mp)
4351 vl_api_lisp_gpe_add_del_tunnel_reply_t * rmp;
4353 vnet_lisp_gpe_add_del_tunnel_args_t _a, *a = &_a;
4354 u32 encap_fib_index, decap_fib_index;
4355 u32 decap_next_index;
4357 ip4_main_t * im = &ip4_main;
4358 u32 sw_if_index = ~0;
4360 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4362 rv = VNET_API_ERROR_NO_SUCH_FIB;
4365 encap_fib_index = p[0];
4367 decap_next_index = ntohl(mp->decap_next_index);
4369 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4370 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4371 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4373 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4376 decap_fib_index = p[0];
4378 decap_fib_index = ntohl(mp->decap_vrf_id);
4381 memset (a, 0, sizeof (*a));
4383 a->is_add = mp->is_add;
4384 /* ip addresses sent in network byte order */
4385 a->src.as_u32 = mp->src;
4386 a->dst.as_u32 = mp->dst;
4387 a->encap_fib_index = encap_fib_index;
4388 a->decap_fib_index = decap_fib_index;
4389 a->decap_next_index = decap_next_index;
4390 a->flags = mp->flags;
4391 a->ver_res = mp->ver_res;
4393 a->next_protocol = mp->next_protocol;
4394 a->iid = clib_net_to_host_u32 (mp->iid);
4396 rv = vnet_lisp_gpe_add_del_tunnel (a, &sw_if_index);
4399 REPLY_MACRO2(VL_API_LISP_GPE_ADD_DEL_TUNNEL_REPLY,
4401 rmp->sw_if_index = ntohl (sw_if_index);
4406 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
4408 vl_api_interface_name_renumber_reply_t * rmp;
4411 VALIDATE_SW_IF_INDEX(mp);
4413 rv = vnet_interface_name_renumber
4414 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
4416 BAD_SW_IF_INDEX_LABEL;
4418 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
4421 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
4422 u32 sw_if_index, u32 address)
4424 vpe_api_main_t * am = &vpe_api_main;
4425 vlib_main_t * vm = am->vlib_main;
4426 vl_api_ip4_arp_event_t * event;
4427 static f64 arp_event_last_time;
4428 f64 now = vlib_time_now (vm);
4430 if (pool_is_free_index (am->arp_events, pool_index))
4433 event = pool_elt_at_index (am->arp_events, pool_index);
4434 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
4435 memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
4436 } else { /* same mac */
4437 if ((sw_if_index == event->sw_if_index) &&
4439 /* for BD case, also check IP address with 10 sec timeout */
4440 ((address == event->address) &&
4441 ((now - arp_event_last_time) < 10.0))))
4445 arp_event_last_time = now;
4446 event->sw_if_index = sw_if_index;
4447 if (address) event->address = address;
4451 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
4453 vpe_api_main_t * am = &vpe_api_main;
4455 if (pool_is_free_index (am->arp_events, pool_index))
4458 pool_put_index (am->arp_events, pool_index);
4463 vl_api_want_ip4_arp_events_t_handler
4464 (vl_api_want_ip4_arp_events_t * mp)
4466 vpe_api_main_t * am = &vpe_api_main;
4467 vnet_main_t * vnm = vnet_get_main();
4468 vl_api_want_ip4_arp_events_reply_t *rmp;
4469 vl_api_ip4_arp_event_t * event;
4472 if (mp->enable_disable) {
4473 pool_get (am->arp_events, event);
4474 memset (event, 0, sizeof (*event));
4476 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
4477 event->client_index = mp->client_index;
4478 event->context = mp->context;
4479 event->address = mp->address;
4480 event->pid = mp->pid;
4482 rv = vnet_add_del_ip4_arp_change_event
4483 (vnm, arp_change_data_callback,
4485 &mp->address /* addr, in net byte order */,
4486 vpe_resolver_process_node.index,
4487 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
4489 rv = vnet_add_del_ip4_arp_change_event
4490 (vnm, arp_change_delete_callback,
4492 &mp->address /* addr, in net byte order */,
4493 vpe_resolver_process_node.index,
4494 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
4496 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
4499 static void vl_api_input_acl_set_interface_t_handler
4500 (vl_api_input_acl_set_interface_t * mp)
4502 vlib_main_t *vm = vlib_get_main();
4503 vl_api_input_acl_set_interface_reply_t * rmp;
4505 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
4507 ip4_table_index = ntohl(mp->ip4_table_index);
4508 ip6_table_index = ntohl(mp->ip6_table_index);
4509 l2_table_index = ntohl(mp->l2_table_index);
4510 sw_if_index = ntohl(mp->sw_if_index);
4512 VALIDATE_SW_IF_INDEX(mp);
4514 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
4515 ip6_table_index, l2_table_index,
4518 BAD_SW_IF_INDEX_LABEL;
4520 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
4523 static void vl_api_ipsec_spd_add_del_t_handler
4524 (vl_api_ipsec_spd_add_del_t * mp)
4527 clib_warning ("unimplemented");
4530 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4531 vl_api_ipsec_spd_add_del_reply_t * rmp;
4535 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
4537 rv = VNET_API_ERROR_UNIMPLEMENTED;
4540 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
4544 static void vl_api_ipsec_interface_add_del_spd_t_handler
4545 (vl_api_ipsec_interface_add_del_spd_t * mp)
4547 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4548 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
4550 u32 sw_if_index __attribute__((unused));
4551 u32 spd_id __attribute__((unused));
4553 sw_if_index = ntohl(mp->sw_if_index);
4554 spd_id = ntohl(mp->spd_id);
4556 VALIDATE_SW_IF_INDEX(mp);
4559 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
4561 rv = VNET_API_ERROR_UNIMPLEMENTED;
4564 BAD_SW_IF_INDEX_LABEL;
4566 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
4569 static void vl_api_ipsec_spd_add_del_entry_t_handler
4570 (vl_api_ipsec_spd_add_del_entry_t * mp)
4572 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4573 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
4579 p.id = ntohl(mp->spd_id);
4580 p.priority = ntohl(mp->priority);
4581 p.is_outbound = mp->is_outbound;
4582 p.is_ipv6 = mp->is_ipv6;
4584 memcpy(&p.raddr.start, mp->remote_address_start, 16);
4585 memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
4586 memcpy(&p.laddr.start, mp->local_address_start, 16);
4587 memcpy(&p.laddr.stop, mp->local_address_stop, 16);
4589 p.protocol = mp->protocol;
4590 p.rport.start = ntohs(mp->remote_port_start);
4591 p.rport.stop = ntohs(mp->remote_port_stop);
4592 p.lport.start = ntohs(mp->local_port_start);
4593 p.lport.stop = ntohs(mp->local_port_stop);
4594 /* policy action resolve unsupported */
4595 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
4596 clib_warning("unsupported action: 'resolve'");
4597 rv = VNET_API_ERROR_UNIMPLEMENTED;
4600 p.policy = mp->policy;
4601 p.sa_id = ntohl(mp->sa_id);
4603 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4607 if (mp->is_ip_any) {
4609 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4612 rv = VNET_API_ERROR_UNIMPLEMENTED;
4617 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
4620 static void vl_api_ipsec_sad_add_del_entry_t_handler
4621 (vl_api_ipsec_sad_add_del_entry_t * mp)
4623 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4624 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
4629 sa.id = ntohl(mp->sad_id);
4630 sa.spi = ntohl(mp->spi);
4631 /* security protocol AH unsupported */
4632 if (mp->protocol == IPSEC_PROTOCOL_AH) {
4633 clib_warning("unsupported security protocol 'AH'");
4634 rv = VNET_API_ERROR_UNIMPLEMENTED;
4637 sa.protocol = mp->protocol;
4638 /* check for unsupported crypto-alg */
4639 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
4640 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
4641 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
4642 mp->crypto_algorithm);
4643 rv = VNET_API_ERROR_UNIMPLEMENTED;
4646 sa.crypto_alg = mp->crypto_algorithm;
4647 sa.crypto_key_len = mp->crypto_key_length;
4648 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
4649 /* check for unsupported integ-alg */
4650 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
4651 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
4652 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
4653 mp->integrity_algorithm);
4654 rv = VNET_API_ERROR_UNIMPLEMENTED;
4657 sa.integ_alg = mp->integrity_algorithm;
4658 sa.integ_key_len = mp->integrity_key_length;
4659 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
4660 sa.use_esn = mp->use_extended_sequence_number;
4661 sa.is_tunnel = mp->is_tunnel;
4662 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
4663 memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
4664 memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
4666 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
4668 rv = VNET_API_ERROR_UNIMPLEMENTED;
4673 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
4676 vl_api_map_add_domain_t_handler
4677 (vl_api_map_add_domain_t * mp)
4679 vl_api_map_add_domain_reply_t * rmp;
4682 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
4683 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
4684 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
4685 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
4686 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
4688 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
4690 rmp->index = ntohl(index);
4695 vl_api_map_del_domain_t_handler
4696 (vl_api_map_del_domain_t * mp)
4698 vl_api_map_del_domain_reply_t * rmp;
4701 rv = map_delete_domain(ntohl(mp->index));
4703 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
4707 vl_api_map_add_del_rule_t_handler
4708 (vl_api_map_add_del_rule_t * mp)
4710 vl_api_map_del_domain_reply_t * rmp;
4713 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
4715 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
4719 vl_api_map_domain_dump_t_handler
4720 (vl_api_map_domain_dump_t * mp)
4722 vl_api_map_domain_details_t * rmp;
4723 map_main_t *mm = &map_main;
4725 unix_shared_memory_queue_t * q;
4727 if (pool_elts (mm->domains) == 0)
4730 q = vl_api_client_index_to_input_queue (mp->client_index);
4735 pool_foreach(d, mm->domains, ({
4736 rmp = vl_msg_api_alloc (sizeof (*rmp));
4737 memset (rmp, 0, sizeof (*rmp));
4738 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
4739 rmp->domain_index = htonl(d - mm->domains);
4740 rmp->ea_bits_len = d->ea_bits_len;
4741 rmp->psid_offset = d->psid_offset;
4742 rmp->psid_length = d->psid_length;
4743 memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
4744 rmp->ip4_prefix_len = d->ip4_prefix_len;
4745 memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
4746 rmp->ip6_prefix_len = d->ip6_prefix_len;
4747 memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
4748 rmp->ip6_src_len = d->ip6_src_len;
4749 rmp->mtu = htons(d->mtu);
4750 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
4752 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4757 vl_api_map_rule_dump_t_handler
4758 (vl_api_map_rule_dump_t * mp)
4760 unix_shared_memory_queue_t * q;
4763 vl_api_map_rule_details_t * rmp;
4764 map_main_t *mm = &map_main;
4765 u32 domain_index = ntohl(mp->domain_index);
4768 if (pool_elts (mm->domains) == 0)
4771 d = pool_elt_at_index(mm->domains, domain_index);
4772 if (!d || !d->rules) {
4776 q = vl_api_client_index_to_input_queue (mp->client_index);
4781 for (i = 0; i < (0x1 << d->psid_length); i++) {
4783 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
4786 rmp = vl_msg_api_alloc(sizeof(*rmp));
4787 memset(rmp, 0, sizeof(*rmp));
4788 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
4789 rmp->psid = htons(i);
4790 memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
4791 vl_msg_api_send_shmem(q, (u8 *)&rmp);
4796 vl_api_map_summary_stats_t_handler (
4797 vl_api_map_summary_stats_t *mp)
4799 vl_api_map_summary_stats_reply_t *rmp;
4800 vlib_combined_counter_main_t *cm;
4803 u64 total_pkts[VLIB_N_RX_TX];
4804 u64 total_bytes[VLIB_N_RX_TX];
4805 map_main_t *mm = &map_main;
4806 unix_shared_memory_queue_t *q =
4807 vl_api_client_index_to_input_queue(mp->client_index);
4812 rmp = vl_msg_api_alloc (sizeof (*rmp));
4813 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
4814 rmp->context = mp->context;
4817 memset (total_pkts, 0, sizeof (total_pkts));
4818 memset (total_bytes, 0, sizeof (total_bytes));
4820 map_domain_counter_lock (mm);
4821 vec_foreach(cm, mm->domain_counters) {
4822 which = cm - mm->domain_counters;
4824 for (i = 0; i < vec_len(cm->maxi); i++) {
4825 vlib_get_combined_counter (cm, i, &v);
4826 total_pkts[which] += v.packets;
4827 total_bytes[which] += v.bytes;
4831 map_domain_counter_unlock (mm);
4833 /* Note: in HOST byte order! */
4834 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = total_pkts[MAP_DOMAIN_COUNTER_RX];
4835 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = total_bytes[MAP_DOMAIN_COUNTER_RX];
4836 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = total_pkts[MAP_DOMAIN_COUNTER_TX];
4837 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = total_bytes[MAP_DOMAIN_COUNTER_TX];
4838 rmp->total_bindings = pool_elts(mm->domains);
4839 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
4840 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK);
4841 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK);
4843 vl_msg_api_send_shmem(q, (u8 *)&rmp);
4846 static void vl_api_ipsec_sa_set_key_t_handler
4847 (vl_api_ipsec_sa_set_key_t * mp)
4849 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4850 vl_api_ipsec_sa_set_key_reply_t *rmp;
4854 sa.id = ntohl(mp->sa_id);
4855 sa.crypto_key_len = mp->crypto_key_length;
4856 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
4857 sa.integ_key_len = mp->integrity_key_length;
4858 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
4860 rv = ipsec_set_sa_key(vm, &sa);
4862 rv = VNET_API_ERROR_UNIMPLEMENTED;
4865 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
4868 static void vl_api_cop_interface_enable_disable_t_handler
4869 (vl_api_cop_interface_enable_disable_t * mp)
4871 vl_api_cop_interface_enable_disable_reply_t * rmp;
4873 u32 sw_if_index = ntohl(mp->sw_if_index);
4876 VALIDATE_SW_IF_INDEX(mp);
4878 enable_disable = (int) mp->enable_disable;
4880 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
4882 BAD_SW_IF_INDEX_LABEL;
4884 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
4887 static void vl_api_cop_whitelist_enable_disable_t_handler
4888 (vl_api_cop_whitelist_enable_disable_t * mp)
4890 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
4891 cop_whitelist_enable_disable_args_t _a, *a=&_a;
4892 u32 sw_if_index = ntohl(mp->sw_if_index);
4895 VALIDATE_SW_IF_INDEX(mp);
4897 a->sw_if_index = sw_if_index;
4900 a->default_cop = mp->default_cop;
4901 a->fib_id = ntohl(mp->fib_id);
4903 rv = cop_whitelist_enable_disable (a);
4905 BAD_SW_IF_INDEX_LABEL;
4907 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
4910 static void vl_api_get_node_graph_t_handler
4911 (vl_api_get_node_graph_t * mp)
4915 api_main_t * am = &api_main;
4916 vlib_main_t * vm = vlib_get_main();
4918 vl_api_get_node_graph_reply_t * rmp;
4920 pthread_mutex_lock (&am->vlib_rp->mutex);
4921 oldheap = svm_push_data_heap (am->vlib_rp);
4924 * Keep the number of memcpy ops to a minimum (e.g. 1).
4925 * The current size of the serialized vector is
4926 * slightly under 4K.
4928 vec_validate (vector, 4095);
4929 vec_reset_length (vector);
4931 vector = vlib_node_serialize (&vm->node_main, vector);
4933 svm_pop_heap (oldheap);
4934 pthread_mutex_unlock (&am->vlib_rp->mutex);
4936 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
4937 rmp->reply_in_shmem = (uword) vector);
4940 #define BOUNCE_HANDLER(nn) \
4941 static void vl_api_##nn##_t_handler ( \
4942 vl_api_##nn##_t *mp) \
4944 vpe_client_registration_t *reg; \
4945 vpe_api_main_t * vam = &vpe_api_main; \
4946 unix_shared_memory_queue_t * q; \
4948 /* One registration only... */ \
4949 pool_foreach(reg, vam->nn##_registrations, \
4951 q = vl_api_client_index_to_input_queue (reg->client_index); \
4954 * If the queue is stuffed, turf the msg and complain \
4955 * It's unlikely that the intended recipient is \
4956 * alive; avoid deadlock at all costs. \
4958 if (q->cursize == q->maxsize) { \
4959 clib_warning ("ERROR: receiver queue full, drop msg"); \
4960 vl_msg_api_free (mp); \
4963 vl_msg_api_send_shmem (q, (u8 *)&mp); \
4967 vl_msg_api_free (mp); \
4970 BOUNCE_HANDLER(to_netconf_server);
4971 BOUNCE_HANDLER(from_netconf_server);
4972 BOUNCE_HANDLER(to_netconf_client);
4973 BOUNCE_HANDLER(from_netconf_client);
4977 * Add vpe's API message handlers to the table.
4978 * vlib has alread mapped shared memory and
4979 * added the client registration handlers.
4980 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
4983 static clib_error_t *
4984 vpe_api_hookup (vlib_main_t *vm)
4986 api_main_t * am = &api_main;
4989 vl_msg_api_set_handlers(VL_API_##N, #n, \
4990 vl_api_##n##_t_handler, \
4992 vl_api_##n##_t_endian, \
4993 vl_api_##n##_t_print, \
4994 sizeof(vl_api_##n##_t), 1);
4995 foreach_vpe_api_msg;
4999 * Manually register the sr tunnel add del msg, so we trace
5000 * enough bytes to capture a typical segment list
5002 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
5003 "sr_tunnel_add_del",
5004 vl_api_sr_tunnel_add_del_t_handler,
5006 vl_api_sr_tunnel_add_del_t_endian,
5007 vl_api_sr_tunnel_add_del_t_print,
5010 am->message_bounce [VL_API_FROM_NETCONF_SERVER] = 1;
5011 am->message_bounce [VL_API_TO_NETCONF_SERVER] = 1;
5012 am->message_bounce [VL_API_FROM_NETCONF_CLIENT] = 1;
5013 am->message_bounce [VL_API_TO_NETCONF_CLIENT] = 1;
5016 * Trace space for 8 MPLS encap labels, classifier mask+match
5018 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
5019 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
5020 += 5 * sizeof (u32x4);
5021 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
5022 += 5 * sizeof (u32x4);
5023 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
5024 += 16 * sizeof (u32);
5027 * trace space for 4 nsh-gre variable TLV words
5029 am->api_trace_cfg [VL_API_NSH_GRE_ADD_DEL_TUNNEL].size
5030 += 4 * sizeof (u32);
5035 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
5037 static clib_error_t *
5038 vpe_api_init (vlib_main_t *vm)
5040 vpe_api_main_t *am = &vpe_api_main;
5043 am->vnet_main = vnet_get_main();
5044 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
5045 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5046 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5047 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5048 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5049 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
5052 vl_set_memory_region_name ("/vpe-api");
5053 vl_enable_disable_memory_api (vm, 1 /* enable it */);
5058 VLIB_INIT_FUNCTION(vpe_api_init);
5060 static clib_error_t *
5061 chroot_config (vlib_main_t * vm, unformat_input_t * input)
5065 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5067 if (unformat (input, "prefix %s", &chroot_path))
5069 vec_add1 (chroot_path, 0);
5070 vl_set_memory_root_path ((char *)chroot_path);
5073 return clib_error_return (0, "unknown input `%U'",
5074 format_unformat_error, input);
5078 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
5080 void * get_unformat_vnet_sw_interface (void)
5082 return (void *) &unformat_vnet_sw_interface;
5085 #undef vl_api_version
5086 #define vl_api_version(n,v) static u32 vpe_api_version = v;
5087 #include <api/vpe.api.h>
5088 #undef vl_api_version
5090 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
5092 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
5093 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
5094 clib_host_to_net_u32 (mp->api_versions[0]),
5101 static u8 * format_arp_event (u8 * s, va_list * args)
5103 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
5105 s = format (s, "pid %d: %U", event->pid,
5106 format_ip4_address, &event->address);
5110 static clib_error_t *
5111 show_ip4_arp_events_fn (vlib_main_t * vm,
5112 unformat_input_t * input,
5113 vlib_cli_command_t * cmd)
5115 vpe_api_main_t * am = &vpe_api_main;
5116 vl_api_ip4_arp_event_t * event;
5118 if (pool_elts (am->arp_events) == 0) {
5119 vlib_cli_output (vm, "No active arp event registrations");
5123 pool_foreach (event, am->arp_events,
5125 vlib_cli_output (vm, "%U", format_arp_event, event);
5131 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
5132 .path = "show arp event registrations",
5133 .function = show_ip4_arp_events_fn,
5134 .short_help = "Show arp event registrations",