DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH v2 1/2] net/cnxk: move socket from /tmp to runtime dir
Date: Thu, 23 Jul 2026 11:10:27 -0700	[thread overview]
Message-ID: <20260723181153.195915-2-stephen@networkplumber.org> (raw)
In-Reply-To: <20260723181153.195915-1-stephen@networkplumber.org>

The eswitch control message socket was created at a fixed path in
/tmp, which is world-writable and shared across DPDK instances.

Build the path under the EAL runtime directory (e.g. /run/dpdk/<prefix>)
instead, so it follows the configured prefix and is isolated per
instance.

Add cnxk_eswitch_ctrl_msg_sock_addr() to fill the sockaddr_un from the
runtime dir and use it on both the server (bind) and client (connect)
paths.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/cnxk/cnxk_eswitch.c | 29 +++++++++++++++++++++++++----
 drivers/net/cnxk/cnxk_eswitch.h |  3 ++-
 drivers/net/cnxk/cnxk_rep_msg.c | 26 ++++++++++++--------------
 3 files changed, 39 insertions(+), 19 deletions(-)

diff --git a/drivers/net/cnxk/cnxk_eswitch.c b/drivers/net/cnxk/cnxk_eswitch.c
index 7e717a2fbf..0a6482462c 100644
--- a/drivers/net/cnxk/cnxk_eswitch.c
+++ b/drivers/net/cnxk/cnxk_eswitch.c
@@ -9,6 +9,24 @@
 
 #define CNXK_NIX_DEF_SQ_COUNT 512
 
+/* Build the control message unix socket address under the EAL runtime
+ * directory (e.g. /run/dpdk/<prefix>) rather than a fixed path in /tmp.
+ */
+int
+cnxk_eswitch_ctrl_msg_sock_addr(struct sockaddr_un *un)
+{
+	int ret;
+
+	memset(un, 0, sizeof(*un));
+	un->sun_family = AF_UNIX;
+	ret = snprintf(un->sun_path, sizeof(un->sun_path), "%s/%s",
+		       rte_eal_get_runtime_dir(), CNXK_ESWITCH_CTRL_MSG_SOCK_NAME);
+	if (ret < 0 || (size_t)ret >= sizeof(un->sun_path))
+		return -ENAMETOOLONG;
+
+	return 0;
+}
+
 int
 cnxk_eswitch_representor_id(struct cnxk_eswitch_dev *eswitch_dev, uint16_t hw_func,
 			    uint16_t *rep_id)
@@ -122,14 +140,17 @@ cnxk_eswitch_dev_remove(struct rte_pci_device *pci_dev)
 					plt_err("Failed to open socket. err %d", -errno);
 					return -errno;
 				}
-				sun.sun_family = AF_UNIX;
+				rc = cnxk_eswitch_ctrl_msg_sock_addr(&sun);
+				if (rc) {
+					plt_err("Control message socket path too long");
+					close(sock_fd);
+					return rc;
+				}
 				sunlen = sizeof(struct sockaddr_un);
-				strncpy(sun.sun_path, CNXK_ESWITCH_CTRL_MSG_SOCK_PATH,
-					sizeof(sun.sun_path) - 1);
 
 				if (connect(sock_fd, (struct sockaddr *)&sun, sunlen) < 0) {
 					plt_err("Failed to connect socket: %s, err %d",
-						CNXK_ESWITCH_CTRL_MSG_SOCK_PATH, errno);
+						sun.sun_path, errno);
 					close(sock_fd);
 					return -errno;
 				}
diff --git a/drivers/net/cnxk/cnxk_eswitch.h b/drivers/net/cnxk/cnxk_eswitch.h
index 0275e760fb..b35a615edd 100644
--- a/drivers/net/cnxk/cnxk_eswitch.h
+++ b/drivers/net/cnxk/cnxk_eswitch.h
@@ -12,7 +12,7 @@
 
 #include "cn10k_tx.h"
 
-#define CNXK_ESWITCH_CTRL_MSG_SOCK_PATH "/tmp/cxk_rep_ctrl_msg_sock"
+#define CNXK_ESWITCH_CTRL_MSG_SOCK_NAME "cnxk_ctrl_msg_sock"
 #define CNXK_ESWITCH_VLAN_TPID		ROC_ESWITCH_VLAN_TPID
 #define CNXK_REP_ESWITCH_DEV_MZ		"cnxk_eswitch_dev"
 #define CNXK_ESWITCH_MAX_TXQ		256
@@ -179,6 +179,7 @@ cnxk_eswitch_pmd_priv(void)
 }
 
 /* HW Resources */
+int cnxk_eswitch_ctrl_msg_sock_addr(struct sockaddr_un *un);
 int cnxk_eswitch_nix_rsrc_start(struct cnxk_eswitch_dev *eswitch_dev);
 int cnxk_eswitch_representor_id(struct cnxk_eswitch_dev *eswitch_dev, uint16_t hw_func,
 				uint16_t *rep_id);
diff --git a/drivers/net/cnxk/cnxk_rep_msg.c b/drivers/net/cnxk/cnxk_rep_msg.c
index a222e2b5cd..9662213139 100644
--- a/drivers/net/cnxk/cnxk_rep_msg.c
+++ b/drivers/net/cnxk/cnxk_rep_msg.c
@@ -14,8 +14,11 @@
 static void
 close_socket(int fd)
 {
+	struct sockaddr_un un;
+
 	close(fd);
-	unlink(CNXK_ESWITCH_CTRL_MSG_SOCK_PATH);
+	if (cnxk_eswitch_ctrl_msg_sock_addr(&un) == 0)
+		unlink(un.sun_path);
 }
 
 static int
@@ -113,6 +116,7 @@ open_socket_ctrl_channel(void)
 {
 	struct sockaddr_un un;
 	int sock_fd;
+	int ret;
 
 	sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
 	if (sock_fd < 0) {
@@ -120,26 +124,20 @@ open_socket_ctrl_channel(void)
 		return -1;
 	}
 
-	/* Set unix socket path and bind */
-	memset(&un, 0, sizeof(un));
-	un.sun_family = AF_UNIX;
-
-	if (strlen(CNXK_ESWITCH_CTRL_MSG_SOCK_PATH) > sizeof(un.sun_path) - 1) {
-		plt_err("Server socket path too long: %s", CNXK_ESWITCH_CTRL_MSG_SOCK_PATH);
+	/* Set unix socket path under the runtime dir and bind */
+	ret = cnxk_eswitch_ctrl_msg_sock_addr(&un);
+	if (ret) {
+		plt_err("Server socket path too long");
 		close(sock_fd);
-		return -E2BIG;
+		return ret;
 	}
 
-	if (remove(CNXK_ESWITCH_CTRL_MSG_SOCK_PATH) == -1 && errno != ENOENT) {
-		plt_err("remove-%s", CNXK_ESWITCH_CTRL_MSG_SOCK_PATH);
+	if (remove(un.sun_path) == -1 && errno != ENOENT) {
+		plt_err("remove-%s", un.sun_path);
 		close(sock_fd);
 		return -errno;
 	}
 
-	memset(&un, 0, sizeof(struct sockaddr_un));
-	un.sun_family = AF_UNIX;
-	strncpy(un.sun_path, CNXK_ESWITCH_CTRL_MSG_SOCK_PATH, sizeof(un.sun_path) - 1);
-
 	if (bind(sock_fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
 		plt_err("Failed to bind %s: %s", un.sun_path, strerror(errno));
 		close(sock_fd);
-- 
2.53.0


  reply	other threads:[~2026-07-23 18:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-31 18:56 [RFC 0/4] move unix domain sockets from /tmp to /run/dpdk Stephen Hemminger
2025-12-31 18:56 ` [RFC 1/4] net/af_xdp: replace /tmp with /run/dpdk Stephen Hemminger
2025-12-31 18:56 ` [RFC 2/4] examples/vm_power_manager: " Stephen Hemminger
2025-12-31 18:56 ` [RFC 3/4] net/nfp: " Stephen Hemminger
2025-12-31 18:56 ` [RFC 4/4] net/cnxk: move socket from /tmp to /run/dpdk Stephen Hemminger
2026-07-23 18:10 ` [PATCH v2 0/2] drivers: remove use of /tmp Stephen Hemminger
2026-07-23 18:10   ` Stephen Hemminger [this message]
2026-07-23 18:10   ` [PATCH v2 2/2] net/nfp: move socket from /tmp to runtime dir Stephen Hemminger

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=20260723181153.195915-2-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    /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