public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 2/2] udp: Rename udp_sock_init() to udp_listen() with small cleanups
Date: Thu, 18 Dec 2025 17:22:42 +1100	[thread overview]
Message-ID: <20251218062242.728289-3-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20251218062242.728289-1-david@gibson.dropbear.id.au>

Despite the name, this functions is specifically for creating
"listening" sockets, not any others.  While we're there remove a redundant
check for (s > FD_REF_MAX).  pif_sock_l4() already checks for this (and
must, in order to properly populate the epoll reference).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 conf.c |  2 +-
 udp.c  | 32 ++++++++++++++------------------
 udp.h  |  6 +++---
 3 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/conf.c b/conf.c
index dada3b1f..84ae12b2 100644
--- a/conf.c
+++ b/conf.c
@@ -177,7 +177,7 @@ static void conf_ports_range_except(const struct ctx *c, char optname,
 		if (optname == 't')
 			ret = tcp_listen(c, PIF_HOST, addr, ifname, i);
 		else if (optname == 'u')
-			ret = udp_sock_init(c, PIF_HOST, addr, ifname, i);
+			ret = udp_listen(c, PIF_HOST, addr, ifname, i);
 		else
 			/* No way to check in advance for -T and -U */
 			ret = 0;
diff --git a/udp.c b/udp.c
index 08bec50a..eda55c39 100644
--- a/udp.c
+++ b/udp.c
@@ -1129,7 +1129,7 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif,
 }
 
 /**
- * udp_sock_init() - Initialise listening socket for a given port
+ * udp_listen() - Initialise listening socket for a given port
  * @c:		Execution context
  * @pif:	Interface to open the socket for (PIF_HOST or PIF_SPLICE)
  * @addr:	Pointer to address for binding, NULL if not configured
@@ -1138,9 +1138,8 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif,
  *
  * Return: 0 on success, negative error code on failure
  */
-int udp_sock_init(const struct ctx *c, uint8_t pif,
-		  const union inany_addr *addr, const char *ifname,
-		  in_port_t port)
+int udp_listen(const struct ctx *c, uint8_t pif,
+	       const union inany_addr *addr, const char *ifname, in_port_t port)
 {
 	union udp_listen_epoll_ref uref = {
 		.pif = pif,
@@ -1150,12 +1149,13 @@ int udp_sock_init(const struct ctx *c, uint8_t pif,
 	int s;
 
 	ASSERT(!c->no_udp);
-	ASSERT(pif_is_socket(pif));
 
-	if (pif == PIF_HOST)
+	if (pif == PIF_HOST) {
 		socks = udp_splice_init;
-	else
+	} else {
+		ASSERT(pif == PIF_SPLICE);
 		socks = udp_splice_ns;
+	}
 
 	if (!c->ifi4) {
 		if (!addr)
@@ -1176,10 +1176,6 @@ int udp_sock_init(const struct ctx *c, uint8_t pif,
 
 	s = pif_sock_l4(c, EPOLL_TYPE_UDP_LISTEN, pif,
 			addr, ifname, port, uref.u32);
-	if (s > FD_REF_MAX) {
-		close(s);
-		s = -EIO;
-	}
 
 	if (!addr || inany_v4(addr))
 		socks[V4][port] = s < 0 ? -1 : s;
@@ -1210,23 +1206,23 @@ static void udp_splice_iov_init(void)
 }
 
 /**
- * udp_ns_sock_init() - Init socket to listen for spliced outbound connections
+ * udp_ns_listen() - Init socket to listen for spliced outbound connections
  * @c:		Execution context
  * @port:	Port, host order
  */
-static void udp_ns_sock_init(const struct ctx *c, in_port_t port)
+static void udp_ns_listen(const struct ctx *c, in_port_t port)
 {
 	ASSERT(!c->no_udp);
 
 	if (!c->no_bindtodevice) {
-		udp_sock_init(c, PIF_SPLICE, NULL, "lo", port);
+		udp_listen(c, PIF_SPLICE, NULL, "lo", port);
 		return;
 	}
 
 	if (c->ifi4)
-		udp_sock_init(c, PIF_SPLICE, &inany_loopback4, NULL, port);
+		udp_listen(c, PIF_SPLICE, &inany_loopback4, NULL, port);
 	if (c->ifi6)
-		udp_sock_init(c, PIF_SPLICE, &inany_loopback6, NULL, port);
+		udp_listen(c, PIF_SPLICE, &inany_loopback6, NULL, port);
 }
 
 /**
@@ -1261,9 +1257,9 @@ static void udp_port_rebind(struct ctx *c, bool outbound)
 		if ((c->ifi4 && socks[V4][port] == -1) ||
 		    (c->ifi6 && socks[V6][port] == -1)) {
 			if (outbound)
-				udp_ns_sock_init(c, port);
+				udp_ns_listen(c, port);
 			else
-				udp_sock_init(c, PIF_HOST, NULL, NULL, port);
+				udp_listen(c, PIF_HOST, NULL, NULL, port);
 		}
 	}
 }
diff --git a/udp.h b/udp.h
index 03e8dc54..5407db3b 100644
--- a/udp.h
+++ b/udp.h
@@ -15,9 +15,9 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif,
 		    sa_family_t af, const void *saddr, const void *daddr,
 		    uint8_t ttl, const struct pool *p, int idx,
 		    const struct timespec *now);
-int udp_sock_init(const struct ctx *c, uint8_t pif,
-		  const union inany_addr *addr, const char *ifname,
-		  in_port_t port);
+int udp_listen(const struct ctx *c, uint8_t pif,
+	       const union inany_addr *addr, const char *ifname,
+	       in_port_t port);
 int udp_init(struct ctx *c);
 void udp_port_rebind_all(struct ctx *c);
 void udp_update_l2_buf(const unsigned char *eth_d);
-- 
2.52.0


      parent reply	other threads:[~2025-12-18  6:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-18  6:22 [PATCH 0/2] Cleanups to listening socket init functions David Gibson
2025-12-18  6:22 ` [PATCH 1/2] tcp: Combine tcp_sock_init_one() and tcp_sock_init() into tcp_listen() David Gibson
2025-12-18  6:22 ` David Gibson [this message]

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=20251218062242.728289-3-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

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 IMAP folder(s).