aboutsummaryrefslogtreecommitdiffstats
path: root/netlink
diff options
context:
space:
mode:
authorPierre Pfister <ppfister@cisco.com>2016-05-19 14:49:30 +0100
committerPierre Pfister <ppfister@cisco.com>2016-05-19 14:49:30 +0100
commit9f07da4aea0683dec4fdcd270c80e68b4acd057a (patch)
treeebb5cfc4f496db01467b7a827371db01db6f6d87 /netlink
parent83ddb4c4bf72b8317d8eda81dbfe3604c62b7f16 (diff)
[Netlink] Bugfix - Use indexes rather than pointers
Change-Id: I76d3400b4d62e871def81420203407761c8d5c7f Signed-off-by: Pierre Pfister <ppfister@cisco.com>
Diffstat (limited to 'netlink')
-rw-r--r--netlink/librtnl/netns.c6
-rw-r--r--netlink/librtnl/rtnl.c17
2 files changed, 12 insertions, 11 deletions
diff --git a/netlink/librtnl/netns.c b/netlink/librtnl/netns.c
index 0101392..6af2645 100644
--- a/netlink/librtnl/netns.c
+++ b/netlink/librtnl/netns.c
@@ -581,7 +581,7 @@ static void
ns_recv_error(rtnl_error_t err, uword o)
{
//An error was received. Reset everything.
- netns_p *ns = (netns_p *)o;
+ netns_p *ns = &netns_main.netnss[o];
u32 *indexes = 0;
u32 *i = 0;
@@ -604,7 +604,7 @@ ns_recv_error(rtnl_error_t err, uword o)
static void
ns_recv_rtnl(struct nlmsghdr *hdr, uword o)
{
- netns_p *ns = (netns_p *)o;
+ netns_p *ns = &netns_main.netnss[o];
switch (hdr->nlmsg_type) {
case RTM_NEWROUTE:
case RTM_DELROUTE:
@@ -657,7 +657,7 @@ netns_get(char *name)
rtnl_stream_t s = {
.recv_message = ns_recv_rtnl,
.error = ns_recv_error,
- .opaque = (uword)ns,
+ .opaque = (uword)(ns - nm->netnss),
};
strcpy(s.name, name);
diff --git a/netlink/librtnl/rtnl.c b/netlink/librtnl/rtnl.c
index a0726c9..c0b2327 100644
--- a/netlink/librtnl/rtnl.c
+++ b/netlink/librtnl/rtnl.c
@@ -101,9 +101,10 @@ rtnl_cancel_timeout(rtnl_ns_t *ns)
static clib_error_t *rtnl_read_cb(struct unix_file * f)
{
+ rtnl_main_t *rm = &rtnl_main;
vlib_main_t *vm = vlib_get_main();
- rtnl_ns_t *ns = (rtnl_ns_t *) f->private_data;
- vlib_process_signal_event_pointer(vm, rtnl_process_node.index, RTNL_E_READ, ns);
+ rtnl_ns_t *ns = &rm->streams[f->private_data];
+ vlib_process_signal_event(vm, rtnl_process_node.index, RTNL_E_READ, (uword)(ns - rm->streams));
return 0;
}
@@ -222,6 +223,7 @@ static void *rtnl_thread_fn(void *p)
static int rtnl_socket_open(rtnl_ns_t *ns)
{
+ rtnl_main_t *rm = &rtnl_main;
pthread_t thread;
void *thread_ret;
if(pthread_create(&thread, NULL, rtnl_thread_fn, ns)) {
@@ -257,7 +259,7 @@ static int rtnl_socket_open(rtnl_ns_t *ns)
unix_file_t template = {0};
template.read_function = rtnl_read_cb;
template.file_descriptor = ns->rtnl_socket;
- template.private_data = (uword) ns;
+ template.private_data = (uword) (ns - rm->streams);
ns->unix_index = unix_file_add (&unix_main, &template);
return 0;
}
@@ -442,7 +444,7 @@ rtnl_process_read(rtnl_ns_t *ns)
while(1) {
if((len = recv(ns->rtnl_socket, buff, RTNL_BUFFSIZ, MSG_DONTWAIT)) < 0) {
if(errno != EAGAIN) {
- clib_warning("rtnetlink recv error: %s", strerror(errno));
+ clib_warning("rtnetlink recv error (%d) [%s]: %s", ns->rtnl_socket, ns->stream.name, strerror(errno));
return -1;
}
return 0;
@@ -506,7 +508,7 @@ rtnl_process (vlib_main_t * vm,
rtnl_ns_t *ns;
uword *d;
vec_foreach(d, event_data) {
- ns = (rtnl_ns_t *)d[0];
+ ns = &rm->streams[d[0]];
switch (event_type)
{
case RTNL_E_CLOSE:
@@ -558,7 +560,7 @@ rtnl_stream_open(rtnl_stream_t *template)
ns->state = RTNL_S_INIT;
ns->ns_fd = fd;
ns->stream = *template;
- vlib_process_signal_event_pointer(vm, rtnl_process_node.index, RTNL_E_OPEN, ns);
+ vlib_process_signal_event(vm, rtnl_process_node.index, RTNL_E_OPEN, (uword)(ns - rm->streams));
return ns - rm->streams;
}
@@ -568,8 +570,7 @@ rtnl_stream_close(u32 stream_index)
vlib_main_t *vm = vlib_get_main();
rtnl_main_t *rm = &rtnl_main;
ASSERT(!pool_is_free_index(rm->streams, stream_index));
- rtnl_ns_t *ns = pool_elt_at_index(rm->streams, stream_index);
- vlib_process_signal_event_pointer(vm, rtnl_process_node.index, RTNL_E_CLOSE, ns);
+ vlib_process_signal_event(vm, rtnl_process_node.index, RTNL_E_CLOSE, stream_index);
}
clib_error_t *