aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/memif
diff options
context:
space:
mode:
authorMilan Lenco <milan.lenco@pantheon.tech>2017-03-31 15:32:09 +0200
committerMilan Lenco <milan.lenco@pantheon.tech>2017-04-03 10:25:38 +0200
commitde9a7eacd5c86cc791fe72a6184c2a05fe7d3fda (patch)
treebfb03ae34ecba693954f4d05cdd7abd86f7292c4 /src/plugins/memif
parentf6fc6b674ddff19cbcbeb32433157d1ea0fe8acd (diff)
Fix memif coverity issues
Change-Id: I1cd649e1d4582792f75d0db60a9524471fc76a9f Signed-off-by: Milan Lenco <milan.lenco@pantheon.tech>
Diffstat (limited to 'src/plugins/memif')
-rw-r--r--src/plugins/memif/device.c14
-rw-r--r--src/plugins/memif/memif.c26
-rw-r--r--src/plugins/memif/memif.h1
3 files changed, 32 insertions, 9 deletions
diff --git a/src/plugins/memif/device.c b/src/plugins/memif/device.c
index 446537a3792..899c78dc38f 100644
--- a/src/plugins/memif/device.c
+++ b/src/plugins/memif/device.c
@@ -272,9 +272,11 @@ static clib_error_t *
memif_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
{
memif_main_t *apm = &memif_main;
- memif_msg_t msg;
+ vlib_main_t *vm = vlib_get_main ();
+ memif_msg_t msg = { 0 };
vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
memif_if_t *mif = pool_elt_at_index (apm->interfaces, hw->dev_instance);
+ static clib_error_t *error = 0;
if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
mif->flags |= MEMIF_IF_FLAG_ADMIN_UP;
@@ -286,11 +288,17 @@ memif_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
{
msg.version = MEMIF_VERSION;
msg.type = MEMIF_MSG_TYPE_DISCONNECT;
- send (mif->connection.fd, &msg, sizeof (msg), 0);
+ if (send (mif->connection.fd, &msg, sizeof (msg), 0) < 0)
+ {
+ clib_unix_warning ("Failed to send disconnect request");
+ error = clib_error_return_unix (0, "send fd %d",
+ mif->connection.fd);
+ memif_disconnect (vm, mif);
+ }
}
}
- return 0;
+ return error;
}
static clib_error_t *
diff --git a/src/plugins/memif/memif.c b/src/plugins/memif/memif.c
index 7ba67c5b898..3ea95f3bb6e 100644
--- a/src/plugins/memif/memif.c
+++ b/src/plugins/memif/memif.c
@@ -85,7 +85,7 @@ memif_connect (vlib_main_t * vm, memif_if_t * mif)
VNET_HW_INTERFACE_FLAG_LINK_UP);
}
-static void
+void
memif_disconnect (vlib_main_t * vm, memif_if_t * mif)
{
vnet_main_t *vnm = vnet_get_main ();
@@ -248,7 +248,12 @@ response:
resp.version = MEMIF_VERSION;
resp.type = MEMIF_MSG_TYPE_CONNECT_RESP;
resp.retval = retval;
- send (fd, &resp, sizeof (resp), 0);
+ if (send (fd, &resp, sizeof (resp), 0) < 0)
+ {
+ DEBUG_UNIX_LOG ("Failed to send connection response");
+ error = clib_error_return_unix (0, "send fd %d", fd);
+ memif_disconnect (vm, mif);
+ }
return error;
}
@@ -511,7 +516,8 @@ memif_connect_master (vlib_main_t * vm, memif_if_t * mif)
{
u16 slot = i * (1 << mif->log2_ring_size) + j;
ring->desc[j].region = 0;
- ring->desc[j].offset = buffer_offset + (slot * mif->buffer_size);
+ ring->desc[j].offset =
+ buffer_offset + (u32) (slot * mif->buffer_size);
ring->desc[j].buffer_length = mif->buffer_size;
}
}
@@ -524,7 +530,8 @@ memif_connect_master (vlib_main_t * vm, memif_if_t * mif)
u16 slot =
(i + mif->num_s2m_rings) * (1 << mif->log2_ring_size) + j;
ring->desc[j].region = 0;
- ring->desc[j].offset = buffer_offset + (slot * mif->buffer_size);
+ ring->desc[j].offset =
+ buffer_offset + (u32) (slot * mif->buffer_size);
ring->desc[j].buffer_length = mif->buffer_size;
}
}
@@ -595,6 +602,11 @@ memif_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
f64 start_time, last_run_duration = 0, now;
sockfd = socket (AF_UNIX, SOCK_STREAM, 0);
+ if (sockfd < 0)
+ {
+ DEBUG_UNIX_LOG ("socket AF_UNIX");
+ return 0;
+ }
sun.sun_family = AF_UNIX;
template.read_function = memif_conn_fd_read_ready;
@@ -734,26 +746,28 @@ int
memif_worker_thread_enable ()
{
/* if worker threads are enabled, switch to polling mode */
+ /* *INDENT-OFF* */
foreach_vlib_main ((
{
vlib_node_set_state (this_vlib_main,
memif_input_node.index,
VLIB_NODE_STATE_POLLING);
}));
-
+ /* *INDENT-ON* */
return 0;
}
int
memif_worker_thread_disable ()
{
+ /* *INDENT-OFF* */
foreach_vlib_main ((
{
vlib_node_set_state (this_vlib_main,
memif_input_node.index,
VLIB_NODE_STATE_INTERRUPT);
}));
-
+ /* *INDENT-ON* */
return 0;
}
diff --git a/src/plugins/memif/memif.h b/src/plugins/memif/memif.h
index a7a88e07b0e..6154829764f 100644
--- a/src/plugins/memif/memif.h
+++ b/src/plugins/memif/memif.h
@@ -194,6 +194,7 @@ typedef struct
int memif_create_if (vlib_main_t * vm, memif_create_if_args_t * args);
int memif_delete_if (vlib_main_t * vm, u64 key);
+void memif_disconnect (vlib_main_t * vm, memif_if_t * mif);
clib_error_t *memif_plugin_api_hookup (vlib_main_t * vm);
#ifndef __NR_memfd_create