Vhost-User: Fix bind sockaddr length
[vpp.git] / vnet / vnet / devices / dpdk / vhost_user.c
index 2e7ecb1..0df9f0b 100644 (file)
@@ -39,6 +39,8 @@
 #define DBG_SOCK(args...)
 #endif
 
+#if DPDK_VHOST_USER
+
 static const char *vhost_message_str[] __attribute__((unused)) = {
     [VHOST_USER_NONE] = "VHOST_USER_NONE",
     [VHOST_USER_GET_FEATURES] = "VHOST_USER_GET_FEATURES",
@@ -909,6 +911,8 @@ dpdk_vhost_user_if_disconnect(dpdk_device_t * xd)
     dpdk_vu_intf_t *vui = xd->vu_intf;
     vnet_main_t * vnm = vnet_get_main();
     dpdk_main_t * dm = &dpdk_main;
+    struct vhost_virtqueue *vq;
+    int q;
 
     xd->admin_up = 0;
     vnet_hw_interface_set_flags (vnm, xd->vlib_hw_if_index,  0);
@@ -924,6 +928,20 @@ dpdk_vhost_user_if_disconnect(dpdk_device_t * xd)
     vui->unix_fd = -1;
     vui->is_up = 0;
 
+    for (q = 0; q < vui->num_vrings; q++) {
+        vq = xd->vu_vhost_dev.virtqueue[q];
+        vui->vrings[q].enabled = 0; /* Reset local copy */
+        vui->vrings[q].callfd = -1; /* Reset FD */
+        vq->enabled = 0;
+#if RTE_VERSION >= RTE_VERSION_NUM(16, 4, 0, 0)
+        vq->log_guest_addr = 0;
+#endif
+        vq->desc = NULL;
+        vq->used = NULL;
+        vq->avail = NULL;
+    }
+    xd->vu_is_running = 0;
+
     dpdk_unmap_all_mem_regions(xd);
     DBG_SOCK("interface ifindex %d disconnected", xd->vlib_sw_if_index);
 }
@@ -1335,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);
@@ -1351,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;
   }
@@ -1901,3 +1917,4 @@ VLIB_CLI_COMMAND (show_vhost_user_command, static) = {
     .short_help = "show vhost-user interface",
     .function = show_dpdk_vhost_user_command_fn,
 };
+#endif