aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Pfister <ppfister@cisco.com>2016-07-25 14:32:02 +0100
committerChris Luke <chris_luke@comcast.com>2016-07-27 13:37:03 +0000
commit5afccb2578d767e3a2be4316211ff38006c336a6 (patch)
treede829bfef7b73f75f4ac717c7b5d1152fcb9091a
parenta8691754d2f7cdd960c3d8dc5fbff6367e9c36b8 (diff)
Vhost-User: Fix bind sockaddr length
The sockaddr length argument provided to bind was wrong. This patch also adds an error message in the CLI when the vhost-user add function fails. Change-Id: Ib4466accffe49c8c3f4951ebf3a83a24529f6a5b Signed-off-by: Pierre Pfister <ppfister@cisco.com>
-rw-r--r--vnet/vnet/devices/dpdk/vhost_user.c8
-rw-r--r--vnet/vnet/devices/virtio/vhost-user.c16
2 files changed, 12 insertions, 12 deletions
diff --git a/vnet/vnet/devices/dpdk/vhost_user.c b/vnet/vnet/devices/dpdk/vhost_user.c
index 212313a7069..0df9f0bd1a1 100644
--- a/vnet/vnet/devices/dpdk/vhost_user.c
+++ b/vnet/vnet/devices/dpdk/vhost_user.c
@@ -1353,8 +1353,8 @@ static clib_error_t * dpdk_vhost_user_socksvr_accept_ready (unix_file_t * uf)
// init server socket on specified sock_filename
static int dpdk_vhost_user_init_server_sock(const char * sock_filename, int *sockfd)
{
- int rv = 0, len;
- struct sockaddr_un un;
+ int rv = 0;
+ struct sockaddr_un un = {};
int fd;
/* create listening socket */
fd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -1369,9 +1369,7 @@ static int dpdk_vhost_user_init_server_sock(const char * sock_filename, int *soc
/* remove if exists */
unlink( (char *) sock_filename);
- len = strlen((char *) un.sun_path) + strlen((char *) sock_filename);
-
- if (bind(fd, (struct sockaddr *) &un, len) == -1) {
+ if (bind(fd, (struct sockaddr *) &un, sizeof(un)) == -1) {
rv = VNET_API_ERROR_SYSCALL_ERROR_2;
goto error;
}
diff --git a/vnet/vnet/devices/virtio/vhost-user.c b/vnet/vnet/devices/virtio/vhost-user.c
index afb2e0091cf..7dc7d0ebadf 100644
--- a/vnet/vnet/devices/virtio/vhost-user.c
+++ b/vnet/vnet/devices/virtio/vhost-user.c
@@ -1487,8 +1487,8 @@ int vhost_user_delete_if(vnet_main_t * vnm, vlib_main_t * vm,
// init server socket on specified sock_filename
static int vhost_user_init_server_sock(const char * sock_filename, int *sockfd)
{
- int rv = 0, len;
- struct sockaddr_un un;
+ int rv = 0;
+ struct sockaddr_un un = {};
int fd;
/* create listening socket */
fd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -1503,9 +1503,7 @@ static int vhost_user_init_server_sock(const char * sock_filename, int *sockfd)
/* remove if exists */
unlink( (char *) sock_filename);
- len = strlen((char *) un.sun_path) + strlen((char *) sock_filename);
-
- if (bind(fd, (struct sockaddr *) &un, len) == -1) {
+ if (bind(fd, (struct sockaddr *) &un, sizeof(un)) == -1) {
rv = VNET_API_ERROR_SYSCALL_ERROR_2;
goto error;
}
@@ -1778,9 +1776,13 @@ vhost_user_connect_command_fn (vlib_main_t * vm,
vnet_main_t *vnm = vnet_get_main();
- vhost_user_create_if(vnm, vm, (char *)sock_filename,
+ int rv;
+ if ((rv = vhost_user_create_if(vnm, vm, (char *)sock_filename,
is_server, &sw_if_index, feature_mask,
- renumber, custom_dev_instance, hw);
+ renumber, custom_dev_instance, hw))) {
+ vec_free(sock_filename);
+ return clib_error_return (0, "vhost_user_create_if returned %d", rv);
+ }
vec_free(sock_filename);
vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);