-static uword
-wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
-{
- /* These cross the longjmp boundry (vlib_process_wait_for_event)
- * and need to be volatile - to prevent them from being optimized into
- * a register - which could change during suspension */
-
- volatile wc_arp_report_t arp_prev = { 0 };
- volatile wc_nd_report_t nd_prev = { 0 };
- volatile f64 last_arp = vlib_time_now (vm);
- volatile f64 last_nd = vlib_time_now (vm);
-
- while (1)
- {
- vlib_process_wait_for_event (vm);
- uword event_type = WC_ARP_REPORT;
- void *event_data = vlib_process_get_event_data (vm, &event_type);
-
- f64 now = vlib_time_now (vm);
- int i;
- if (event_type == WC_ARP_REPORT)
- {
- wc_arp_report_t *arp_events = event_data;
- for (i = 0; i < vec_len (arp_events); i++)
- {
- /* discard dup event */
- if (arp_prev.ip4 == arp_events[i].ip4 &&
- eth_mac_equal ((u8 *) arp_prev.mac, arp_events[i].mac) &&
- arp_prev.sw_if_index == arp_events[i].sw_if_index &&
- (now - last_arp) < 10.0)
- {
- continue;
- }
- arp_prev = arp_events[i];
- last_arp = now;
- vpe_client_registration_t *reg;
- /* *INDENT-OFF* */
- pool_foreach(reg, vpe_api_main.wc_ip4_arp_events_registrations,
- ({
- vl_api_registration_t *vl_reg;
- vl_reg = vl_api_client_index_to_registration (reg->client_index);
- ASSERT (vl_reg != NULL);
- if (reg && vl_api_can_send_msg (vl_reg))
- {
- vl_api_ip4_arp_event_t * event = vl_msg_api_alloc (sizeof *event);
- clib_memset (event, 0, sizeof *event);
- event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT);
- event->client_index = reg->client_index;
- event->pid = reg->client_pid;
- event->mac_ip = 1;
- event->address = arp_events[i].ip4;
- event->sw_if_index = htonl(arp_events[i].sw_if_index);
- memcpy(event->new_mac, arp_events[i].mac, sizeof event->new_mac);
- vl_api_send_msg (vl_reg, (u8 *) event);
- }
- }));
- /* *INDENT-ON* */
- }
- }
- else if (event_type == WC_ND_REPORT)
- {
- wc_nd_report_t *nd_events = event_data;
- for (i = 0; i < vec_len (nd_events); i++)
- {
- /* discard dup event */
- if (ip6_address_is_equal
- ((ip6_address_t *) & nd_prev.ip6, &nd_events[i].ip6)
- && eth_mac_equal ((u8 *) nd_prev.mac, nd_events[i].mac)
- && nd_prev.sw_if_index == nd_events[i].sw_if_index
- && (now - last_nd) < 10.0)
- {
- continue;
- }
- nd_prev = nd_events[i];
- last_nd = now;
- vpe_client_registration_t *reg;
- /* *INDENT-OFF* */
- pool_foreach(reg, vpe_api_main.wc_ip6_nd_events_registrations,
- ({
- vl_api_registration_t *vl_reg;
- vl_reg = vl_api_client_index_to_registration (reg->client_index);
- if (vl_reg && vl_api_can_send_msg (vl_reg))
- {
- vl_api_ip6_nd_event_t * event = vl_msg_api_alloc (sizeof *event);
- clib_memset (event, 0, sizeof *event);
- event->_vl_msg_id = htons (VL_API_IP6_ND_EVENT);
- event->client_index = reg->client_index;
- event->pid = reg->client_pid;
- event->mac_ip = 1;
- memcpy(event->address, nd_events[i].ip6.as_u8, sizeof event->address);
- event->sw_if_index = htonl(nd_events[i].sw_if_index);
- memcpy(event->new_mac, nd_events[i].mac, sizeof event->new_mac);
- vl_api_send_msg (vl_reg, (u8 *) event);
- }
- }));
- /* *INDENT-ON* */
- }
- }
- else if (event_type == RA_REPORT)
- {
- ra_report_t *ra_events = event_data;
- for (i = 0; i < vec_len (ra_events); i++)
- {
- ip6_neighbor_public_main_t *npm = &ip6_neighbor_public_main;
- call_ip6_neighbor_callbacks (&ra_events[i],
- npm->ra_report_functions);
-
- vpe_client_registration_t *reg;
- /* *INDENT-OFF* */
- pool_foreach(reg, vpe_api_main.ip6_ra_events_registrations,
- ({
- vl_api_registration_t *vl_reg;
- vl_reg =
- vl_api_client_index_to_registration (reg->client_index);
- if (vl_reg && vl_api_can_send_msg (vl_reg))
- {
- u32 event_size =
- sizeof (vl_api_ip6_ra_event_t) +
- vec_len (ra_events[i].prefixes) *
- sizeof (vl_api_ip6_ra_prefix_info_t);
- vl_api_ip6_ra_event_t *event =
- vl_msg_api_alloc (event_size);
- clib_memset (event, 0, event_size);
- event->_vl_msg_id = htons (VL_API_IP6_RA_EVENT);
- event->client_index = reg->client_index;
- event->pid = reg->client_pid;
-
- event->sw_if_index = clib_host_to_net_u32 (ra_events[i].sw_if_index);
-
- memcpy (event->router_address, ra_events[i].router_address, 16);
-
- event->current_hop_limit = ra_events[i].current_hop_limit;
- event->flags = ra_events[i].flags;
- event->router_lifetime_in_sec =
- clib_host_to_net_u16 (ra_events
- [i].router_lifetime_in_sec);
- event->neighbor_reachable_time_in_msec =
- clib_host_to_net_u32 (ra_events
- [i].neighbor_reachable_time_in_msec);
- event->time_in_msec_between_retransmitted_neighbor_solicitations
- =
- clib_host_to_net_u32 (ra_events
- [i].time_in_msec_between_retransmitted_neighbor_solicitations);
-
- event->n_prefixes =
- clib_host_to_net_u32 (vec_len (ra_events[i].prefixes));
- vl_api_ip6_ra_prefix_info_t *prefix =
- (typeof (prefix)) event->prefixes;
- u32 j;
- for (j = 0; j < vec_len (ra_events[i].prefixes); j++)
- {
- ra_report_prefix_info_t *info =
- &ra_events[i].prefixes[j];
- memcpy (prefix->dst_address, info->dst_address.as_u8,
- 16);
- prefix->dst_address_length = info->dst_address_length;
- prefix->flags = info->flags;
- prefix->valid_time =
- clib_host_to_net_u32 (info->valid_time);
- prefix->preferred_time =
- clib_host_to_net_u32 (info->preferred_time);
- prefix++;
- }
-
- vl_api_send_msg (vl_reg, (u8 *) event);
- }
- }));
- /* *INDENT-ON* */
- vec_free (ra_events[i].prefixes);
- }
- }
- vlib_process_put_event_data (vm, event_data);
- }
-
- return 0;
-}
-
-/* *INDENT-OFF* */
-VLIB_REGISTER_NODE (wc_arp_process_node,static) = {
- .function = wc_arp_process,
- .type = VLIB_NODE_TYPE_PROCESS,
- .name = "wildcard-ip4-arp-publisher-process",
-};
-/* *INDENT-ON* */
-
-static int
-arp_change_data_callback (u32 pool_index, u8 * new_mac,
- u32 sw_if_index, u32 address)
-{
- vpe_api_main_t *am = &vpe_api_main;
- vl_api_ip4_arp_event_t *event;
-
- if (pool_is_free_index (am->arp_events, pool_index))
- return 1;
-
- event = pool_elt_at_index (am->arp_events, pool_index);
- if (eth_mac_equal (event->new_mac, new_mac) &&
- sw_if_index == ntohl (event->sw_if_index))
- {
- return 1;
- }
-
- clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
- event->sw_if_index = htonl (sw_if_index);
- return 0;
-}
-
-static void
-vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
-{
- vpe_api_main_t *am = &vpe_api_main;
- vnet_main_t *vnm = vnet_get_main ();
- vl_api_want_ip4_arp_events_reply_t *rmp;
- int rv = 0;
-
- if (mp->address == 0)
- {
- uword *p =
- hash_get (am->wc_ip4_arp_events_registration_hash, mp->client_index);
- vpe_client_registration_t *rp;
- if (p)
- {
- if (mp->enable_disable)
- {
- clib_warning ("pid %d: already enabled...", mp->pid);
- rv = VNET_API_ERROR_INVALID_REGISTRATION;
- goto reply;
- }
- else
- {
- rp =
- pool_elt_at_index (am->wc_ip4_arp_events_registrations, p[0]);
- pool_put (am->wc_ip4_arp_events_registrations, rp);
- hash_unset (am->wc_ip4_arp_events_registration_hash,
- mp->client_index);
- if (pool_elts (am->wc_ip4_arp_events_registrations) == 0)
- wc_arp_set_publisher_node (~0, REPORT_MAX);
- goto reply;
- }
- }
- if (mp->enable_disable == 0)
- {
- clib_warning ("pid %d: already disabled...", mp->pid);
- rv = VNET_API_ERROR_INVALID_REGISTRATION;
- goto reply;
- }
- pool_get (am->wc_ip4_arp_events_registrations, rp);
- rp->client_index = mp->client_index;
- rp->client_pid = mp->pid;
- hash_set (am->wc_ip4_arp_events_registration_hash, rp->client_index,
- rp - am->wc_ip4_arp_events_registrations);
- wc_arp_set_publisher_node (wc_arp_process_node.index, WC_ARP_REPORT);
- goto reply;
- }
-
- if (mp->enable_disable)
- {
- vl_api_ip4_arp_event_t *event;
- pool_get (am->arp_events, event);
- rv = vnet_add_del_ip4_arp_change_event
- (vnm, arp_change_data_callback,
- mp->pid, &mp->address /* addr, in net byte order */ ,
- ip_resolver_process_node.index,
- IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
-
- if (rv)
- {
- pool_put (am->arp_events, event);
- goto reply;
- }
- clib_memset (event, 0, sizeof (*event));
-
- /* Python API expects events to have no context */
- event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT);
- event->client_index = mp->client_index;
- event->address = mp->address;
- event->pid = mp->pid;
- if (mp->address == 0)
- event->mac_ip = 1;
- }
- else
- {
- rv = vnet_add_del_ip4_arp_change_event
- (vnm, arp_change_delete_callback,
- mp->pid, &mp->address /* addr, in net byte order */ ,
- ip_resolver_process_node.index,
- IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
- }
-reply:
- REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
-}
-
-static clib_error_t *
-want_ip4_arp_events_reaper (u32 client_index)
-{
- vpe_client_registration_t *rp;
- vl_api_ip4_arp_event_t *event;
- u32 *to_delete, *event_id;
- vpe_api_main_t *am;
- vnet_main_t *vnm;
- uword *p;
-
- am = &vpe_api_main;
- vnm = vnet_get_main ();
- to_delete = NULL;
-
- /* clear out all of its pending resolutions */
- /* *INDENT-OFF* */
- pool_foreach(event, am->arp_events,
- ({
- if (event->client_index == client_index)
- {
- vec_add1(to_delete, event - am->arp_events);
- }
- }));
- /* *INDENT-ON* */
-
- vec_foreach (event_id, to_delete)
- {
- event = pool_elt_at_index (am->arp_events, *event_id);
- vnet_add_del_ip4_arp_change_event
- (vnm, arp_change_delete_callback,
- event->pid, &event->address,
- ip_resolver_process_node.index, IP4_ARP_EVENT,
- ~0 /* pool index, notused */ , 0 /* is_add */ );
- }
- vec_free (to_delete);
-
- /* remove from the registration hash */
- p = hash_get (am->wc_ip4_arp_events_registration_hash, client_index);
-
- if (p)
- {
- rp = pool_elt_at_index (am->wc_ip4_arp_events_registrations, p[0]);
- pool_put (am->wc_ip4_arp_events_registrations, rp);
- hash_unset (am->wc_ip4_arp_events_registration_hash, client_index);
- if (pool_elts (am->wc_ip4_arp_events_registrations) == 0)
- wc_arp_set_publisher_node (~0, REPORT_MAX);
- }
- return (NULL);
-}
-
-VL_MSG_API_REAPER_FUNCTION (want_ip4_arp_events_reaper);
-
-static void
-vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
-{
- vpe_api_main_t *am = &vpe_api_main;
- vnet_main_t *vnm = vnet_get_main ();
- vl_api_want_ip6_nd_events_reply_t *rmp;
- int rv = 0;
-
- if (ip6_address_is_zero ((ip6_address_t *) mp->address))
- {
- uword *p =
- hash_get (am->wc_ip6_nd_events_registration_hash, mp->client_index);
- vpe_client_registration_t *rp;
- if (p)
- {
- if (mp->enable_disable)
- {
- clib_warning ("pid %d: already enabled...", mp->pid);
- rv = VNET_API_ERROR_INVALID_REGISTRATION;
- goto reply;
- }
- else
- {
- rp =
- pool_elt_at_index (am->wc_ip6_nd_events_registrations, p[0]);
- pool_put (am->wc_ip6_nd_events_registrations, rp);
- hash_unset (am->wc_ip6_nd_events_registration_hash,
- mp->client_index);
- if (pool_elts (am->wc_ip6_nd_events_registrations) == 0)
- wc_nd_set_publisher_node (~0, REPORT_MAX);
- goto reply;
- }
- }
- if (mp->enable_disable == 0)
- {
- clib_warning ("pid %d: already disabled...", mp->pid);
- rv = VNET_API_ERROR_INVALID_REGISTRATION;
- goto reply;
- }
- pool_get (am->wc_ip6_nd_events_registrations, rp);
- rp->client_index = mp->client_index;
- rp->client_pid = mp->pid;
- hash_set (am->wc_ip6_nd_events_registration_hash, rp->client_index,
- rp - am->wc_ip6_nd_events_registrations);
- wc_nd_set_publisher_node (wc_arp_process_node.index, WC_ND_REPORT);
- goto reply;
- }
-
- if (mp->enable_disable)
- {
- vl_api_ip6_nd_event_t *event;
- pool_get (am->nd_events, event);
-
- rv = vnet_add_del_ip6_nd_change_event
- (vnm, nd_change_data_callback,
- mp->pid, mp->address /* addr, in net byte order */ ,
- ip_resolver_process_node.index,
- IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
-
- if (rv)
- {
- pool_put (am->nd_events, event);
- goto reply;
- }
- clib_memset (event, 0, sizeof (*event));
-
- event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
- event->client_index = mp->client_index;
- clib_memcpy (event->address, mp->address, sizeof event->address);
- event->pid = mp->pid;
- }
- else
- {
- rv = vnet_add_del_ip6_nd_change_event
- (vnm, nd_change_delete_callback,
- mp->pid, mp->address /* addr, in net byte order */ ,
- ip_resolver_process_node.index,
- IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
- }
-reply:
- REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
-}
-
-static clib_error_t *
-want_ip6_nd_events_reaper (u32 client_index)
-{
-
- vpe_client_registration_t *rp;
- vl_api_ip6_nd_event_t *event;
- u32 *to_delete, *event_id;
- vpe_api_main_t *am;
- vnet_main_t *vnm;
- uword *p;
-
- am = &vpe_api_main;
- vnm = vnet_get_main ();
- to_delete = NULL;
-
- /* clear out all of its pending resolutions */
- /* *INDENT-OFF* */
- pool_foreach(event, am->nd_events,
- ({
- if (event->client_index == client_index)
- {
- vec_add1(to_delete, event - am->nd_events);
- }
- }));
- /* *INDENT-ON* */
-
- vec_foreach (event_id, to_delete)
- {
- event = pool_elt_at_index (am->nd_events, *event_id);
- vnet_add_del_ip6_nd_change_event
- (vnm, nd_change_delete_callback,
- event->pid, &event->address,
- ip_resolver_process_node.index, IP6_ND_EVENT,
- ~0 /* pool index, notused */ , 0 /* is_add */ );
- }
- vec_free (to_delete);
-
- /* remove from the registration hash */
- p = hash_get (am->wc_ip6_nd_events_registration_hash, client_index);
-
- if (p)
- {
- rp = pool_elt_at_index (am->wc_ip6_nd_events_registrations, p[0]);
- pool_put (am->wc_ip6_nd_events_registrations, rp);
- hash_unset (am->wc_ip6_nd_events_registration_hash, client_index);
- if (pool_elts (am->wc_ip6_nd_events_registrations) == 0)
- wc_nd_set_publisher_node (~0, REPORT_MAX);
- }
- return (NULL);
-}
-
-VL_MSG_API_REAPER_FUNCTION (want_ip6_nd_events_reaper);
-
-static void
-vl_api_want_ip6_ra_events_t_handler (vl_api_want_ip6_ra_events_t * mp)
-{
- vpe_api_main_t *am = &vpe_api_main;
- vl_api_want_ip6_ra_events_reply_t *rmp;
- int rv = 0;
-
- uword *p = hash_get (am->ip6_ra_events_registration_hash, mp->client_index);
- vpe_client_registration_t *rp;
- if (p)
- {
- if (mp->enable_disable)
- {
- clib_warning ("pid %d: already enabled...", ntohl (mp->pid));
- rv = VNET_API_ERROR_INVALID_REGISTRATION;
- goto reply;
- }
- else
- {
- rp = pool_elt_at_index (am->ip6_ra_events_registrations, p[0]);
- pool_put (am->ip6_ra_events_registrations, rp);
- hash_unset (am->ip6_ra_events_registration_hash, mp->client_index);
- goto reply;
- }
- }
- if (mp->enable_disable == 0)
- {
- clib_warning ("pid %d: already disabled...", ntohl (mp->pid));
- rv = VNET_API_ERROR_INVALID_REGISTRATION;
- goto reply;
- }
- pool_get (am->ip6_ra_events_registrations, rp);
- rp->client_index = mp->client_index;
- rp->client_pid = ntohl (mp->pid);
- hash_set (am->ip6_ra_events_registration_hash, rp->client_index,
- rp - am->ip6_ra_events_registrations);
-
-reply:
- REPLY_MACRO (VL_API_WANT_IP6_RA_EVENTS_REPLY);
-}
-
-static clib_error_t *
-want_ip6_ra_events_reaper (u32 client_index)
-{
- vpe_api_main_t *am = &vpe_api_main;
- vpe_client_registration_t *rp;
- uword *p;
-
- p = hash_get (am->ip6_ra_events_registration_hash, client_index);
-
- if (p)
- {
- rp = pool_elt_at_index (am->ip6_ra_events_registrations, p[0]);
- pool_put (am->ip6_ra_events_registrations, rp);
- hash_unset (am->ip6_ra_events_registration_hash, client_index);
- }
- return (NULL);
-}
-
-VL_MSG_API_REAPER_FUNCTION (want_ip6_ra_events_reaper);
-
-static void
-vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
-{
- vl_api_proxy_arp_add_del_reply_t *rmp;
- u32 fib_index;
- int rv;
- ip4_main_t *im = &ip4_main;
- uword *p;
-
- stats_dslock_with_hint (1 /* release hint */ , 6 /* tag */ );
-
- p = hash_get (im->fib_index_by_table_id, ntohl (mp->proxy.vrf_id));
-
- if (!p)
- {
- rv = VNET_API_ERROR_NO_SUCH_FIB;
- goto out;
- }
-
- fib_index = p[0];
-
- rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->proxy.low_address,
- (ip4_address_t *) mp->proxy.hi_address,
- fib_index, mp->is_add == 0);
-
-out:
- stats_dsunlock ();
- REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
-}
-
-typedef struct proxy_arp_walk_ctx_t_
-{
- vl_api_registration_t *reg;
- u32 context;
-} proxy_arp_walk_ctx_t;
-
-static walk_rc_t
-send_proxy_arp_details (const ip4_address_t * lo_addr,
- const ip4_address_t * hi_addr,
- u32 fib_index, void *data)
-{
- vl_api_proxy_arp_details_t *mp;
- proxy_arp_walk_ctx_t *ctx;
-
- ctx = data;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_PROXY_ARP_DETAILS);
- mp->context = ctx->context;
- mp->proxy.vrf_id = htonl (fib_index);
- clib_memcpy (mp->proxy.low_address, lo_addr,
- sizeof (mp->proxy.low_address));
- clib_memcpy (mp->proxy.hi_address, hi_addr, sizeof (mp->proxy.hi_address));