aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/ip/rd_cp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/ip/rd_cp.c')
-rw-r--r--src/vnet/ip/rd_cp.c427
1 files changed, 75 insertions, 352 deletions
diff --git a/src/vnet/ip/rd_cp.c b/src/vnet/ip/rd_cp.c
index 89a01e32643..d999ed46fad 100644
--- a/src/vnet/ip/rd_cp.c
+++ b/src/vnet/ip/rd_cp.c
@@ -2,6 +2,8 @@
#include <vlibmemory/api.h>
#include <vnet/vnet_msg_enum.h>
#include <vnet/ip/ip6.h>
+#include <vnet/ethernet/ethernet.h>
+#include <vnet/ip/ip6_neighbor.h>
#include <signal.h>
#include <math.h>
@@ -18,15 +20,6 @@
#define foreach_rd_cp_msg \
_(IP6_ND_ADDRESS_AUTOCONFIG, ip6_nd_address_autoconfig)
-#define foreach_client_rd_cp_msg \
-_(IP6_RA_EVENT, ip6_ra_event) \
-_(IP6ND_SEND_ROUTER_SOLICITATION_REPLY, ip6nd_send_router_solicitation_reply) \
-_(WANT_IP6_RA_EVENTS_REPLY, want_ip6_ra_events_reply) \
-_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, sw_interface_add_del_address_reply) \
-_(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
-_(SW_INTERFACE_GET_MAC_ADDRESS_REPLY, sw_interface_get_mac_address_reply) \
-_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, sw_interface_ip6_enable_disable_reply)
-
typedef struct
{
u32 sw_if_index;
@@ -61,16 +54,6 @@ typedef struct
u8 api_connected;
svm_queue_t *vl_input_queue;
u32 my_client_index;
- void (**msg_handlers) (void *);
- struct
- {
- u8 arrived;
- i32 retval;
- union
- {
- u8 mac_address[6];
- };
- } api_reply;
/* convenience */
vlib_main_t *vlib_main;
@@ -89,171 +72,19 @@ enum
#define vl_api_ip6_nd_address_autoconfig_t_print vl_noop_handler
static void
-msg_api_config (vl_msg_api_msg_config_t * c)
-{
- rd_cp_main_t *rm = &rd_cp_main;
-
- vec_validate (rm->msg_handlers, c->id);
-
- if (rm->msg_handlers[c->id] && rm->msg_handlers[c->id] != c->handler)
- clib_warning
- ("BUG: re-registering 'vl_api_%s_t_handler'."
- "Handler was %llx, replaced by %llx",
- c->name, rm->msg_handlers[c->id], c->handler);
-
- rm->msg_handlers[c->id] = c->handler;
-}
-
-static void
-set_handler (int id, char *name, void *handler)
-{
- vl_msg_api_msg_config_t cfg;
- vl_msg_api_msg_config_t *c = &cfg;
-
- memset (c, 0, sizeof (*c));
-
- c->id = id;
- c->name = name;
- c->handler = handler;
- c->replay = 1;
- c->message_bounce = 0;
- c->is_mp_safe = 0;
- msg_api_config (c);
-}
-
-static_always_inline void
-check_queue (void)
-{
- rd_cp_main_t *rm = &rd_cp_main;
- uword msgp;
-
- if (!rm->api_connected)
- return;
-
- if (svm_queue_sub2 (rm->vl_input_queue, (u8 *) & msgp))
- return;
-
- u16 id = ntohs (*((u16 *) msgp));
- u8 *(*handler) (void *);
-
- if (id < vec_len (rm->msg_handlers) && rm->msg_handlers[id])
- {
- handler = (void *) rm->msg_handlers[id];
- (*handler) ((void *) msgp);
- }
- else
- {
- if (id != VL_API_MEMCLNT_KEEPALIVE)
- clib_warning ("no handler for msg id %d", id);
- }
-}
-
-static_always_inline int
-wait_for_reply (void)
-{
- rd_cp_main_t *rm = &rd_cp_main;
- vlib_main_t *vm = rm->vlib_main;
- f64 timeout;
-
- timeout = vlib_time_now (vm) + 1.0;
- while (vlib_time_now (vm) < timeout)
- {
- check_queue ();
- if (rm->api_reply.arrived)
- break;
- vlib_process_suspend (vm, 1e-5);
- }
-
- if (!rm->api_reply.arrived)
- return 1;
-
- return rm->api_reply.retval;
-}
-
-static_always_inline void
-send_msg (void *msg)
-{
- rd_cp_main_t *rm = &rd_cp_main;
-
- vl_msg_api_send_shmem (rm->api_main->shmem_hdr->vl_input_queue,
- (u8 *) & msg);
-}
-
-static_always_inline int
-send_msg_and_wait_for_reply (void *msg)
-{
- rd_cp_main_t *rm = &rd_cp_main;
-
- rm->api_reply.arrived = 0;
- send_msg (msg);
- return wait_for_reply ();
-}
-
-static int
router_solicitation_start_stop (u32 sw_if_index, u8 start)
{
rd_cp_main_t *rm = &rd_cp_main;
- vl_api_ip6nd_send_router_solicitation_t *mp;
- int rv;
+ icmp6_send_router_solicitation_params_t params = { 0, };
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = htons (VL_API_IP6ND_SEND_ROUTER_SOLICITATION);
- mp->client_index = rm->my_client_index;
- mp->sw_if_index = htonl (sw_if_index);
if (start)
{
- mp->irt = htonl (1);
- mp->mrt = htonl (120);
+ params.irt = 1;
+ params.mrt = 120;
}
- else
- mp->stop = 1;
-
- rv = send_msg_and_wait_for_reply (mp);
-
- return rv;
-}
-
-static void
- vl_api_ip6nd_send_router_solicitation_reply_t_handler
- (vl_api_ip6nd_send_router_solicitation_reply_t * mp)
-{
- rd_cp_main_t *rm = &rd_cp_main;
-
- rm->api_reply.arrived = 1;
- rm->api_reply.retval = ntohl (mp->retval);
-}
-
-static int
-ip6_ra_events_enable_disable (int enable)
-{
- rd_cp_main_t *rm = &rd_cp_main;
- vl_api_want_ip6_ra_events_t *mp;
- int rv;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = htons (VL_API_WANT_IP6_RA_EVENTS);
- mp->client_index = rm->my_client_index;
- mp->enable_disable = enable;
- mp->pid = htonl (getpid ());
-
- rv = send_msg_and_wait_for_reply (mp);
-
- if (!rv)
- rm->events_on = enable;
-
- return rv;
-}
-
-static void
-vl_api_want_ip6_ra_events_reply_t_handler (vl_api_want_ip6_ra_events_reply_t *
- mp)
-{
- rd_cp_main_t *rm = &rd_cp_main;
- rm->api_reply.arrived = 1;
- rm->api_reply.retval = ntohl (mp->retval);
+ icmp6_send_router_solicitation (rm->vlib_main, sw_if_index, !start,
+ &params);
}
static void interrupt_process (void);
@@ -264,8 +95,7 @@ add_slaac_address (vlib_main_t * vm, u32 sw_if_index, u8 address_length,
{
rd_cp_main_t *rm = &rd_cp_main;
slaac_address_t *slaac_address;
- vl_api_sw_interface_add_del_address_t *mp;
- int rv;
+ clib_error_t *rv = 0;
pool_get (rm->slaac_address_pool, slaac_address);
@@ -274,30 +104,14 @@ add_slaac_address (vlib_main_t * vm, u32 sw_if_index, u8 address_length,
slaac_address->address = *address;
slaac_address->due_time = due_time;
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS);
- mp->client_index = rm->my_client_index;
- mp->is_add = 1;
- mp->is_ipv6 = 1;
- mp->sw_if_index = htonl (sw_if_index);
- mp->address_length = slaac_address->address_length;
- clib_memcpy (mp->address, slaac_address->address.as_u8, 16);
-
- rv = send_msg_and_wait_for_reply (mp);
+ rv =
+ ip6_add_del_interface_address (vm, sw_if_index, &slaac_address->address,
+ address_length, 0);
- return rv;
+ return rv != 0;
}
-static void
- vl_api_sw_interface_add_del_address_reply_t_handler
- (vl_api_sw_interface_add_del_address_reply_t * mp)
-{
- rd_cp_main_t *rm = &rd_cp_main;
-
- rm->api_reply.arrived = 1;
- rm->api_reply.retval = ntohl (mp->retval);
-}
+int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
static int
add_default_route (vlib_main_t * vm, u32 sw_if_index,
@@ -305,7 +119,7 @@ add_default_route (vlib_main_t * vm, u32 sw_if_index,
{
rd_cp_main_t *rm = &rd_cp_main;
default_route_t *default_route;
- vl_api_ip_add_del_route_t *mp;
+ vl_api_ip_add_del_route_t mp = { 0, };
int rv;
pool_get (rm->default_route_pool, default_route);
@@ -314,137 +128,81 @@ add_default_route (vlib_main_t * vm, u32 sw_if_index,
default_route->router_address = *next_hop_address;
default_route->due_time = due_time;
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = htons (VL_API_IP_ADD_DEL_ROUTE);
- mp->client_index = rm->my_client_index;
- mp->is_add = 1;
- mp->is_ipv6 = 1;
- mp->dst_address_length = 0;
- mp->next_hop_sw_if_index = htonl (default_route->sw_if_index);
- clib_memcpy (mp->next_hop_address, default_route->router_address.as_u8, 16);
+ mp.is_add = 1;
+ mp.is_ipv6 = 1;
+ mp.dst_address_length = 0;
+ mp.next_hop_sw_if_index = htonl (default_route->sw_if_index);
+ clib_memcpy (mp.next_hop_address, default_route->router_address.as_u8, 16);
- rv = send_msg_and_wait_for_reply (mp);
+ rv = ip6_add_del_route_t_handler (&mp);
return rv;
}
-static void
-vl_api_ip_add_del_route_reply_t_handler (vl_api_ip_add_del_route_reply_t * mp)
-{
- rd_cp_main_t *rm = &rd_cp_main;
-
- rm->api_reply.arrived = 1;
- rm->api_reply.retval = ntohl (mp->retval);
-}
-
static int
remove_slaac_address (vlib_main_t * vm, slaac_address_t * slaac_address)
{
- rd_cp_main_t *rm = &rd_cp_main;
- vl_api_sw_interface_add_del_address_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS);
- mp->client_index = rm->my_client_index;
- mp->is_add = 0;
- mp->is_ipv6 = 1;
- mp->sw_if_index = htonl (slaac_address->sw_if_index);
- mp->address_length = slaac_address->address_length;
- clib_memcpy (mp->address, slaac_address->address.as_u8, 16);
+ clib_error_t *rv = 0;
- send_msg_and_wait_for_reply (mp);
+ rv = ip6_add_del_interface_address (vm, slaac_address->sw_if_index,
+ &slaac_address->address,
+ slaac_address->address_length, 1);
- pool_put (rm->slaac_address_pool, slaac_address);
-
- return 0;
+ return rv != 0;
}
static int
remove_default_route (vlib_main_t * vm, default_route_t * default_route)
{
rd_cp_main_t *rm = &rd_cp_main;
- vl_api_ip_add_del_route_t *mp;
+ vl_api_ip_add_del_route_t mp = { 0, };
+ int rv;
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = htons (VL_API_IP_ADD_DEL_ROUTE);
- mp->client_index = rm->my_client_index;
- mp->is_add = 0;
- mp->is_ipv6 = 1;
- mp->dst_address_length = 0;
- mp->next_hop_sw_if_index = htonl (default_route->sw_if_index);
- clib_memcpy (mp->next_hop_address, default_route->router_address.as_u8, 16);
+ mp.is_add = 0;
+ mp.is_ipv6 = 1;
+ mp.dst_address_length = 0;
+ mp.next_hop_sw_if_index = htonl (default_route->sw_if_index);
+ clib_memcpy (mp.next_hop_address, default_route->router_address.as_u8, 16);
- send_msg_and_wait_for_reply (mp);
+ rv = ip6_add_del_route_t_handler (&mp);
- pool_put (rm->default_route_pool, default_route);
+ if (!rv)
+ pool_put (rm->default_route_pool, default_route);
- return 0;
+ return rv;
}
static u32
get_interface_mac_address (u32 sw_if_index, u8 mac[])
{
rd_cp_main_t *rm = &rd_cp_main;
- vl_api_sw_interface_get_mac_address_t *mp;
- int rv;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_GET_MAC_ADDRESS);
- mp->client_index = rm->my_client_index;
- mp->sw_if_index = htonl (sw_if_index);
-
- rv = send_msg_and_wait_for_reply (mp);
+ vnet_sw_interface_t *si;
+ ethernet_interface_t *eth_if = 0;
- if (!rv)
- clib_memcpy (mac, rm->api_reply.mac_address, 6);
-
- return rv;
-}
+ if (!vnet_sw_interface_is_api_valid (rm->vnet_main, sw_if_index))
+ {
+ clib_warning ("Invalid sw_if_index");
+ return 1;
+ }
-static void
- vl_api_sw_interface_get_mac_address_reply_t_handler
- (vl_api_sw_interface_get_mac_address_reply_t * mp)
-{
- rd_cp_main_t *rm = &rd_cp_main;
+ si = vnet_get_sup_sw_interface (rm->vnet_main, sw_if_index);
+ if (si->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
+ eth_if = ethernet_get_interface (&ethernet_main, si->hw_if_index);
- rm->api_reply.arrived = 1;
- rm->api_reply.retval = ntohl (mp->retval);
+ clib_memcpy (mac, eth_if->address, 6);
- if (rm->api_reply.retval == 0)
- clib_memcpy (rm->api_reply.mac_address, mp->mac_address, 6);
+ return 0;
}
static u32
ip6_enable (u32 sw_if_index)
{
rd_cp_main_t *rm = &rd_cp_main;
- vl_api_sw_interface_ip6_enable_disable_t *mp;
- int rv;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE);
- mp->client_index = rm->my_client_index;
- mp->sw_if_index = htonl (sw_if_index);
- mp->enable = 1;
+ clib_error_t *rv;
- rv = send_msg_and_wait_for_reply (mp);
+ rv = enable_ip6_interface (rm->vlib_main, sw_if_index);
- return rv;
-}
-
-static void
- vl_api_sw_interface_ip6_enable_disable_reply_t_handler
- (vl_api_sw_interface_ip6_enable_disable_reply_t * mp)
-{
- rd_cp_main_t *rm = &rd_cp_main;
-
- rm->api_reply.arrived = 1;
- rm->api_reply.retval = ntohl (mp->retval);
+ return rv != 0;
}
static u8
@@ -465,31 +223,35 @@ ip6_prefixes_equal (ip6_address_t * prefix1, ip6_address_t * prefix2, u8 len)
#define PREFIX_FLAG_A (1 << 6)
#define PREFIX_FLAG_L (1 << 7)
-static void
-vl_api_ip6_ra_event_t_handler (vl_api_ip6_ra_event_t * mp)
+static clib_error_t *
+ip6_ra_report_handler (void *data)
{
rd_cp_main_t *rm = &rd_cp_main;
vlib_main_t *vm = rm->vlib_main;
+ clib_error_t *error = 0;
+ ra_report_t *r = data;
interface_config_t *if_config;
default_route_t *default_route;
slaac_address_t *slaac_address;
u32 sw_if_index;
u16 router_lifetime_in_sec;
u32 n_prefixes;
- vl_api_ip6_ra_prefix_info_t *prefix;
+ ra_report_prefix_info_t *prefix;
u8 mac[6];
f64 current_time;
u32 i;
current_time = vlib_time_now (vm);
- sw_if_index = ntohl (mp->sw_if_index);
+ sw_if_index = r->sw_if_index;
+ if (sw_if_index >= vec_len (rm->config_by_sw_if_index))
+ return 0;
if_config = &rm->config_by_sw_if_index[sw_if_index];
if (if_config->install_default_routes)
{
- router_lifetime_in_sec = ntohs (mp->router_lifetime_in_sec);
+ router_lifetime_in_sec = r->router_lifetime_in_sec;
u8 route_already_present = 0;
/* *INDENT-OFF* */
pool_foreach (default_route, rm->default_route_pool,
@@ -497,7 +259,7 @@ vl_api_ip6_ra_event_t_handler (vl_api_ip6_ra_event_t * mp)
if (default_route->sw_if_index != sw_if_index)
;
else if (0 != memcmp (&default_route->router_address,
- mp->router_address, 16))
+ r->router_address, 16))
;
else
{
@@ -511,7 +273,7 @@ vl_api_ip6_ra_event_t_handler (vl_api_ip6_ra_event_t * mp)
if (!route_already_present)
{
if (router_lifetime_in_sec != 0)
- add_default_route (vm, sw_if_index, (void *) mp->router_address,
+ add_default_route (vm, sw_if_index, (void *) r->router_address,
current_time + router_lifetime_in_sec);
}
else
@@ -526,13 +288,13 @@ vl_api_ip6_ra_event_t_handler (vl_api_ip6_ra_event_t * mp)
if (get_interface_mac_address (sw_if_index, mac) != 0)
{
clib_warning ("Error getting MAC address");
- return;
+ return clib_error_return (0, "Error getting MAC address");
}
if (!if_config->enabled)
- return;
+ return 0;
- n_prefixes = ntohl (mp->n_prefixes);
+ n_prefixes = vec_len (r->prefixes);
for (i = 0; i < n_prefixes; i++)
{
ip6_address_t *dst_address;
@@ -541,19 +303,19 @@ vl_api_ip6_ra_event_t_handler (vl_api_ip6_ra_event_t * mp)
u32 preferred_time;
f64 due_time;
- prefix = &mp->prefixes[i];
+ prefix = &r->prefixes[i];
if (!(prefix->flags & PREFIX_FLAG_A))
continue;
- dst_address = (ip6_address_t *) prefix->dst_address;
+ dst_address = &prefix->dst_address;
prefix_length = prefix->dst_address_length;
if (ip6_address_is_link_local_unicast (dst_address))
continue;
- valid_time = ntohl (prefix->valid_time);
- preferred_time = ntohl (prefix->preferred_time);
+ valid_time = prefix->valid_time;
+ preferred_time = prefix->preferred_time;
if (preferred_time > valid_time)
continue;
@@ -612,35 +374,27 @@ vl_api_ip6_ra_event_t_handler (vl_api_ip6_ra_event_t * mp)
}
interrupt_process ();
+
+ return error;
}
+VNET_IP6_NEIGHBOR_RA_FUNCTION (ip6_ra_report_handler);
+
static uword
rd_cp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
{
- uword event_type;
uword *event_data = 0;
rd_cp_main_t *rm = &rd_cp_main;
slaac_address_t *slaac_address;
default_route_t *default_route;
f64 sleep_time = 1e9;
- const f64 micro_sleep_time = 1e-5;
- f64 start_time;
f64 current_time;
f64 due_time;
while (1)
{
- start_time = vlib_time_now (vm);
-
- while (1)
- {
- check_queue ();
- vlib_process_wait_for_event_or_clock (vm, micro_sleep_time);
- event_type = vlib_process_get_events (vm, &event_data);
- if (event_type != ~0
- || vlib_time_now (vm) > start_time + sleep_time)
- break;
- }
+ vlib_process_wait_for_event_or_clock (vm, sleep_time);
+ vlib_process_get_events (vm, &event_data);
vec_reset_length (event_data);
@@ -703,29 +457,6 @@ interrupt_process (void)
}
static int
-create_api_loopback (void)
-{
- rd_cp_main_t *rm = &rd_cp_main;
- api_main_t *am = &api_main;
- svm_region_t *svm;
-
- svm = am->vlib_rp;
-
- pthread_mutex_lock (&svm->mutex);
- rd_cp_main.vl_input_queue =
- svm_queue_init (1024, sizeof (uword), getpid (), 0);
- pthread_mutex_unlock (&svm->mutex);
-
- rd_cp_main.my_client_index =
- vl_api_memclnt_create_internal ("ndp_rd_client",
- rd_cp_main.vl_input_queue);
-
- rm->api_connected = 1;
-
- return 0;
-}
-
-static int
set_address_autoconfig (u32 sw_if_index, u8 enable, u8 install_default_routes)
{
rd_cp_main_t *rm = &rd_cp_main;
@@ -739,7 +470,6 @@ set_address_autoconfig (u32 sw_if_index, u8 enable, u8 install_default_routes)
if (!enable)
install_default_routes = 0;
- // TODO: makes direct interaction with data plane
if (!vnet_sw_interface_is_api_valid (vnm, sw_if_index))
{
clib_warning ("Invalid sw_if_index");
@@ -748,10 +478,8 @@ set_address_autoconfig (u32 sw_if_index, u8 enable, u8 install_default_routes)
if (!rm->enabled)
{
- create_api_loopback ();
/* process kickoff */
interrupt_process ();
- ip6_ra_events_enable_disable (1);
rm->enabled = 1;
}
@@ -905,11 +633,6 @@ rd_cp_init (vlib_main_t * vm)
foreach_rd_cp_msg;
#undef _
-#define _(N,n) \
- set_handler(VL_API_##N, #n, vl_api_##n##_t_handler);
- foreach_client_rd_cp_msg;
-#undef _
-
/*
* Set up the (msg_name, crc, message-id) table
*/