From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8F8BCA0C47; Mon, 26 Jul 2021 13:37:14 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0FADE40F35; Mon, 26 Jul 2021 13:37:14 +0200 (CEST) Received: from aer-iport-4.cisco.com (aer-iport-4.cisco.com [173.38.203.54]) by mails.dpdk.org (Postfix) with ESMTP id 82B3F40040 for ; Fri, 23 Jul 2021 11:20:33 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.84,263,1620691200"; d="scan'208";a="38069707" Received: from aer-iport-nat.cisco.com (HELO aer-core-3.cisco.com) ([173.38.203.22]) by aer-iport-4.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 23 Jul 2021 09:20:33 +0000 Received: from NSKRZYPC-M-K2WD.cisco.com (dhcp-10-61-106-108.cisco.com [10.61.106.108]) (authenticated bits=0) by aer-core-3.cisco.com (8.15.2/8.15.2) with ESMTPSA id 16N9KOXW031338 (version=TLSv1.2 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 23 Jul 2021 09:20:32 GMT From: Nathan Skrzypczak To: dev@dpdk.org Cc: andrew.rybchenko@oktetlabs.ru, Jakub Grajciar Date: Fri, 23 Jul 2021 11:18:57 +0200 Message-Id: <20210723091857.9760-2-nathan.skrzypczak@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617162233.54296-1-nathan.skrzypczak@gmail.com> References: <20210617162233.54296-1-nathan.skrzypczak@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Authenticated-User: nskrzypc X-Outbound-SMTP-Client: 10.61.106.108, dhcp-10-61-106-108.cisco.com X-Outbound-Node: aer-core-3.cisco.com X-Mailman-Approved-At: Mon, 26 Jul 2021 13:37:13 +0200 Subject: [dpdk-dev] [PATCH v2] net/memif: fix abstract socket addr_len X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This fixes using abstract sockets with memifs. we were not passing the exact addr_len, which requires zeroing the remaining sun_path and doesn't appear well in other utilities (e.g. lsof -U) Signed-off-by: Nathan Skrzypczak --- drivers/net/memif/memif_socket.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/net/memif/memif_socket.c b/drivers/net/memif/memif_socket.c index 5b373738e6..f58ff4c0cb 100644 --- a/drivers/net/memif/memif_socket.c +++ b/drivers/net/memif/memif_socket.c @@ -866,6 +866,7 @@ memif_socket_create(char *key, uint8_t listener, bool is_abstract) { struct memif_socket *sock; struct sockaddr_un un = { 0 }; + uint32_t sunlen; int sockfd; int ret; int on = 1; @@ -890,7 +891,11 @@ memif_socket_create(char *key, uint8_t listener, bool is_abstract) /* abstract address */ un.sun_path[0] = '\0'; strlcpy(un.sun_path + 1, sock->filename, MEMIF_SOCKET_UN_SIZE - 1); + sunlen = RTE_MIN(1 + strlen(sock->filename), + MEMIF_SOCKET_UN_SIZE) + + sizeof(un) - sizeof(un.sun_path); } else { + sunlen = sizeof(un); strlcpy(un.sun_path, sock->filename, MEMIF_SOCKET_UN_SIZE); } @@ -899,7 +904,7 @@ memif_socket_create(char *key, uint8_t listener, bool is_abstract) if (ret < 0) goto error; - ret = bind(sockfd, (struct sockaddr *)&un, sizeof(un)); + ret = bind(sockfd, (struct sockaddr *)&un, sunlen); if (ret < 0) goto error; @@ -1061,6 +1066,7 @@ memif_connect_client(struct rte_eth_dev *dev) { int sockfd; int ret; + uint32_t sunlen; struct sockaddr_un sun = { 0 }; struct pmd_internals *pmd = dev->data->dev_private; @@ -1075,16 +1081,19 @@ memif_connect_client(struct rte_eth_dev *dev) } sun.sun_family = AF_UNIX; + sunlen = sizeof(struct sockaddr_un); if (pmd->flags & ETH_MEMIF_FLAG_SOCKET_ABSTRACT) { /* abstract address */ sun.sun_path[0] = '\0'; strlcpy(sun.sun_path + 1, pmd->socket_filename, MEMIF_SOCKET_UN_SIZE - 1); + sunlen = RTE_MIN(strlen(pmd->socket_filename) + 1, + MEMIF_SOCKET_UN_SIZE) + + sizeof(sun) - sizeof(sun.sun_path); } else { strlcpy(sun.sun_path, pmd->socket_filename, MEMIF_SOCKET_UN_SIZE); } - ret = connect(sockfd, (struct sockaddr *)&sun, - sizeof(struct sockaddr_un)); + ret = connect(sockfd, (struct sockaddr *)&sun, sunlen); if (ret < 0) { MIF_LOG(ERR, "Failed to connect socket: %s.", pmd->socket_filename); goto error; -- 2.30.2