From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202512 header.b=ZYMFYAK/; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 1A87F5A065D for ; Thu, 18 Dec 2025 07:24:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1766039045; bh=BNjKUTNN5oMxIwLsC6ZxEMafImVXacxC1pNgrDU9Uhk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZYMFYAK/47fVYE3U+BpywPm72UmT4hybwDF/A7JDkXrU8xX1BrAXQ6G6RvgI20Hgl OMT45tCUd9tPqoeRZr+1hzsTN/NnaLqj7epWw6vIgiilkGB/rWbO5pwhuaktp8QmPM oYRtOJFZ/xhA6/ImLM2UFRp7X0UKtsj/WgOL5ARbIyDnwm1mRNXowOPe57tWu9bgAk hkQj2VXBuMZt4kyKA8T4DyVFbcH75cpnfKawjOM5v3BFYEVbaEqcG81PwuMQ+ggxuz I1LhPOq6NALCh+eNaC8RFX8uHxbvpKaB7qXauVgwqusMaCiJGTspVeCMJP1GL+Z/Dp vS0+O2h74+2qg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4dX0xK2rkMz4wGr; Thu, 18 Dec 2025 17:24:05 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 2/2] udp: Rename udp_sock_init() to udp_listen() with small cleanups Date: Thu, 18 Dec 2025 17:22:42 +1100 Message-ID: <20251218062242.728289-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251218062242.728289-1-david@gibson.dropbear.id.au> References: <20251218062242.728289-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: NVLTWH7YIQJXHI5VEL7B36XYU6VOJZHE X-Message-ID-Hash: NVLTWH7YIQJXHI5VEL7B36XYU6VOJZHE X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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