aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2025-12-18 17:22:42 +1100
committerStefano Brivio <sbrivio@redhat.com>2025-12-23 15:25:11 +0100
commit6292845bfed92c618480d58dae5cf9d045918191 (patch)
tree2fd628cace7c0f8412ce1fa532afe3667f844469
parent0f4ba615f59379edff5057c30b31328d60d71d08 (diff)
downloadpasst-6292845bfed92c618480d58dae5cf9d045918191.tar
passt-6292845bfed92c618480d58dae5cf9d045918191.tar.gz
passt-6292845bfed92c618480d58dae5cf9d045918191.tar.bz2
passt-6292845bfed92c618480d58dae5cf9d045918191.tar.lz
passt-6292845bfed92c618480d58dae5cf9d045918191.tar.xz
passt-6292845bfed92c618480d58dae5cf9d045918191.tar.zst
passt-6292845bfed92c618480d58dae5cf9d045918191.zip
udp: Rename udp_sock_init() to udp_listen() with small cleanups
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> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--conf.c2
-rw-r--r--udp.c32
-rw-r--r--udp.h6
3 files changed, 18 insertions, 22 deletions
diff --git a/conf.c b/conf.c
index dada3b1..84ae12b 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 08bec50..eda55c3 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 03e8dc5..5407db3 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);