aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authorJuraj Sloboda <jsloboda@cisco.com>2018-05-03 10:03:50 +0200
committerOle Trøan <otroan@employees.org>2018-05-14 10:20:24 +0000
commit5257452d38a3441b5cc22c010c3c586523919433 (patch)
treebed9790d8d7f20f73f9b38a68873e079e5525194 /src/vnet
parent17e5cfbe8d9b1f47b18eb1a43976fe322e3987a2 (diff)
Rework CP and DP communication in IPv6 RD (VPP-1256)
Replace binary API communication between CP and DP with direct communication using function calls and callbacks. Change-Id: Ib54f09062217c028e5ee0e96ae2449cf7e9224e3 Signed-off-by: Juraj Sloboda <jsloboda@cisco.com>
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/ip/ip6_neighbor.c24
-rw-r--r--src/vnet/ip/ip6_neighbor.h60
-rw-r--r--src/vnet/ip/ip_api.c11
-rw-r--r--src/vnet/ip/rd_cp.c427
4 files changed, 163 insertions, 359 deletions
diff --git a/src/vnet/ip/ip6_neighbor.c b/src/vnet/ip/ip6_neighbor.c
index 6b63e6fbbf6..5e98475f94d 100644
--- a/src/vnet/ip/ip6_neighbor.c
+++ b/src/vnet/ip/ip6_neighbor.c
@@ -230,6 +230,7 @@ typedef union
} ip6_icmp_neighbor_discovery_event_data_t;
static ip6_neighbor_main_t ip6_neighbor_main;
+ip6_neighbor_public_main_t ip6_neighbor_public_main;
static ip6_address_t ip6a_zero; /* ip6 address 0 */
static void wc_nd_signal_report (wc_nd_report_t * r);
@@ -1417,6 +1418,23 @@ ip6_neighbor_syslog (vlib_main_t * vm, int priority, char *fmt, ...)
return;
}
+clib_error_t *
+call_ip6_neighbor_callbacks (void *data,
+ _vnet_ip6_neighbor_function_list_elt_t * elt)
+{
+ clib_error_t *error = 0;
+
+ while (elt)
+ {
+ error = elt->fp (data);
+ if (error)
+ return error;
+ elt = elt->next_ip6_neighbor_function;
+ }
+
+ return error;
+}
+
/* ipv6 neighbor discovery - router advertisements */
typedef enum
{
@@ -2434,9 +2452,9 @@ icmp6_send_router_solicitation (vlib_main_t * vm, u32 sw_if_index, u8 stop,
rai = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
ra = pool_elt_at_index (nm->if_radv_pool, rai);
- if (stop)
- stop_sending_rs (vm, ra);
- else
+ stop_sending_rs (vm, ra);
+
+ if (!stop)
{
ra->keep_sending_rs = 1;
ra->params = *params;
diff --git a/src/vnet/ip/ip6_neighbor.h b/src/vnet/ip/ip6_neighbor.h
index 753de56072e..27d8cb27eae 100644
--- a/src/vnet/ip/ip6_neighbor.h
+++ b/src/vnet/ip/ip6_neighbor.h
@@ -138,6 +138,66 @@ typedef struct
void ra_set_publisher_node (uword node_index, uword event_type);
+typedef struct _vnet_ip6_neighbor_function_list_elt
+{
+ struct _vnet_ip6_neighbor_function_list_elt *next_ip6_neighbor_function;
+ clib_error_t *(*fp) (void *data);
+} _vnet_ip6_neighbor_function_list_elt_t;
+
+typedef struct
+{
+ _vnet_ip6_neighbor_function_list_elt_t *ra_report_functions;
+} ip6_neighbor_public_main_t;
+
+extern ip6_neighbor_public_main_t ip6_neighbor_public_main;
+
+#define _VNET_IP6_NEIGHBOR_FUNCTION_DECL(f,tag) \
+ \
+static void __vnet_ip6_neighbor_function_init_##tag##_##f (void) \
+ __attribute__((__constructor__)) ; \
+ \
+static void __vnet_ip6_neighbor_function_init_##tag##_##f (void) \
+{ \
+ ip6_neighbor_public_main_t * nm = &ip6_neighbor_public_main; \
+ static _vnet_ip6_neighbor_function_list_elt_t init_function; \
+ init_function.next_ip6_neighbor_function = nm->tag##_functions; \
+ nm->tag##_functions = &init_function; \
+ init_function.fp = (void *) &f; \
+} \
+ \
+static void __vnet_ip6_neighbor_function_deinit_##tag##_##f (void) \
+ __attribute__((__destructor__)) ; \
+ \
+static void __vnet_ip6_neighbor_function_deinit_##tag##_##f (void) \
+{ \
+ ip6_neighbor_public_main_t * nm = &ip6_neighbor_public_main; \
+ _vnet_ip6_neighbor_function_list_elt_t *next; \
+ if (nm->tag##_functions->fp == (void *) &f) \
+ { \
+ nm->tag##_functions = \
+ nm->tag##_functions->next_ip6_neighbor_function; \
+ return; \
+ } \
+ next = nm->tag##_functions; \
+ while (next->next_ip6_neighbor_function) \
+ { \
+ if (next->next_ip6_neighbor_function->fp == (void *) &f) \
+ { \
+ next->next_ip6_neighbor_function = \
+ next->next_ip6_neighbor_function->next_ip6_neighbor_function; \
+ return; \
+ } \
+ next = next->next_ip6_neighbor_function; \
+ } \
+}
+
+#define VNET_IP6_NEIGHBOR_RA_FUNCTION(f) \
+ _VNET_IP6_NEIGHBOR_FUNCTION_DECL(f,ra_report)
+
+clib_error_t *call_ip6_neighbor_callbacks (void *data,
+ _vnet_ip6_neighbor_function_list_elt_t
+ * elt);
+
#endif /* included_ip6_neighbor_h */
/*
diff --git a/src/vnet/ip/ip_api.c b/src/vnet/ip/ip_api.c
index 3711c40343b..ea71375f99d 100644
--- a/src/vnet/ip/ip_api.c
+++ b/src/vnet/ip/ip_api.c
@@ -1049,7 +1049,7 @@ ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
label_stack));
}
-static int
+int
ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
{
fib_mpls_label_t *label_stack = NULL;
@@ -2325,6 +2325,10 @@ wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
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,
@@ -2614,8 +2618,6 @@ vl_api_want_ip6_ra_events_t_handler (vl_api_want_ip6_ra_events_t * mp)
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);
- if (pool_elts (am->ip6_ra_events_registrations) == 0)
- ra_set_publisher_node (~0, REPORT_MAX);
goto reply;
}
}
@@ -2630,7 +2632,6 @@ vl_api_want_ip6_ra_events_t_handler (vl_api_want_ip6_ra_events_t * mp)
rp->client_pid = ntohl (mp->pid);
hash_set (am->ip6_ra_events_registration_hash, rp->client_index,
rp - am->ip6_ra_events_registrations);
- ra_set_publisher_node (wc_arp_process_node.index, RA_REPORT);
reply:
REPLY_MACRO (VL_API_WANT_IP6_RA_EVENTS_REPLY);
@@ -3014,6 +3015,8 @@ ip_api_hookup (vlib_main_t * vm)
*/
setup_message_id_table (am);
+ ra_set_publisher_node (wc_arp_process_node.index, RA_REPORT);
+
return 0;
}
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
*/