DPDK patches and discussions
 help / color / mirror / Atom feed
From: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
To: dev@dpdk.org
Cc: jgrajcia@cisco.com
Subject: [dpdk-dev] [PATCH] net/memif: fix abstract socket addr_len
Date: Thu, 17 Jun 2021 18:22:33 +0200	[thread overview]
Message-ID: <20210617162233.54296-1-nathan.skrzypczak@gmail.com> (raw)

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 <nathan.skrzypczak@gmail.com>
---
 drivers/net/memif/memif_socket.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/net/memif/memif_socket.c b/drivers/net/memif/memif_socket.c
index 5b373738e6..7498a2f58d 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,10 @@ 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 = 1 + strlen(sock->filename) +
+				 sizeof(un.sun_family);
 		} else {
+			sunlen = sizeof(un);
 			strlcpy(un.sun_path, sock->filename, MEMIF_SOCKET_UN_SIZE);
 		}
 
@@ -899,7 +903,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 +1065,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 +1080,18 @@ 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 = strlen(pmd->socket_filename) + 1 +
+			 sizeof(sun.sun_family);
 	} 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


             reply	other threads:[~2021-06-18  8:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-17 16:22 Nathan Skrzypczak [this message]
2021-07-01 15:01 ` Andrew Rybchenko
2021-07-23  9:18 ` [dpdk-dev] [PATCH v2] " Nathan Skrzypczak
2021-07-28 11:10   ` Jakub Grajciar -X (jgrajcia - PANTHEON TECH SRO at Cisco)
2021-07-30 11:24     ` Thomas Monjalon
2021-07-30 12:53       ` Nathan Skrzypczak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210617162233.54296-1-nathan.skrzypczak@gmail.com \
    --to=nathan.skrzypczak@gmail.com \
    --cc=dev@dpdk.org \
    --cc=jgrajcia@cisco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).