diff options
| author | David Gibson <david@gibson.dropbear.id.au> | 2026-01-13 14:06:14 +1100 |
|---|---|---|
| committer | Stefano Brivio <sbrivio@redhat.com> | 2026-01-14 01:07:51 +0100 |
| commit | a54274d28ba21e09909cc012315ffa078ef41fd8 (patch) | |
| tree | a753346f31237482e0a058279414e084ac326a3c | |
| parent | d5fd945ceb379b695b8d58aeab9363509fcf6587 (diff) | |
| download | passt-a54274d28ba21e09909cc012315ffa078ef41fd8.tar passt-a54274d28ba21e09909cc012315ffa078ef41fd8.tar.gz passt-a54274d28ba21e09909cc012315ffa078ef41fd8.tar.bz2 passt-a54274d28ba21e09909cc012315ffa078ef41fd8.tar.lz passt-a54274d28ba21e09909cc012315ffa078ef41fd8.tar.xz passt-a54274d28ba21e09909cc012315ffa078ef41fd8.tar.zst passt-a54274d28ba21e09909cc012315ffa078ef41fd8.zip | |
tcp, udp: Make {tcp,udp}_listen() return socket fds
{tcp,udp}_listen() currently return 0 on success, rather than the socket
fd they created. Historically, that was because these functions could
sometimes create multiple sockets. We've now refactored things to avoid
that, so it makes more sense for them to return the socket on success.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
| -rw-r--r-- | conf.c | 14 | ||||
| -rw-r--r-- | tcp.c | 7 | ||||
| -rw-r--r-- | udp.c | 4 |
3 files changed, 11 insertions, 14 deletions
@@ -149,7 +149,7 @@ static void conf_ports_range_except(const struct ctx *c, char optname, { bool bound_one = false; unsigned i; - int ret; + int fd; if (first == 0) { die("Can't forward port 0 for option '-%c %s'", @@ -185,23 +185,23 @@ static void conf_ports_range_except(const struct ctx *c, char optname, fwd->delta[i] = to - first; if (optname == 't') - ret = tcp_listen(c, PIF_HOST, addr, ifname, i); + fd = tcp_listen(c, PIF_HOST, addr, ifname, i); else if (optname == 'u') - ret = udp_listen(c, PIF_HOST, addr, ifname, i); + fd = udp_listen(c, PIF_HOST, addr, ifname, i); else /* No way to check in advance for -T and -U */ - ret = 0; + fd = 0; - if (ret == -ENFILE || ret == -EMFILE) { + if (fd == -ENFILE || fd == -EMFILE) { die("Can't open enough sockets for port specifier: %s", optarg); } - if (!ret) { + if (fd >= 0) { bound_one = true; } else if (!weak) { die("Failed to bind port %u (%s) for option '-%c %s'", - i, strerror_(-ret), optname, optarg); + i, strerror_(-fd), optname, optarg); } } @@ -2679,7 +2679,7 @@ void tcp_sock_handler(const struct ctx *c, union epoll_ref ref, * @ifname: Name of interface to bind to, NULL for any * @port: Port, host order * - * Return: 0 on success, negative error code on failure + * Return: socket fd on success, negative error code on failure */ int tcp_listen(const struct ctx *c, uint8_t pif, const union inany_addr *addr, const char *ifname, in_port_t port) @@ -2728,10 +2728,7 @@ int tcp_listen(const struct ctx *c, uint8_t pif, socks[port][V6] = s < 0 ? -1 : s; } - if (s < 0) - return s; - - return 0; + return s; } /** @@ -1136,7 +1136,7 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif, * @ifname: Name of interface to bind to, NULL if not configured * @port: Port, host order * - * Return: 0 on success, negative error code on failure + * Return: socket fd on success, negative error code on failure */ int udp_listen(const struct ctx *c, uint8_t pif, const union inany_addr *addr, const char *ifname, in_port_t port) @@ -1180,7 +1180,7 @@ int udp_listen(const struct ctx *c, uint8_t pif, if (!addr || !inany_v4(addr)) socks[V6][port] = s < 0 ? -1 : s; - return s < 0 ? s : 0; + return s; } /** |
