From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 3/3] tcp, udp: Make {tcp,udp}_listen() return socket fds
Date: Mon, 12 Jan 2026 14:50:21 +1100 [thread overview]
Message-ID: <aWRvfQAUrwu1ULBI@zatzit> (raw)
In-Reply-To: <20260111003339.5c2c979c@elisabeth>
[-- Attachment #1: Type: text/plain, Size: 2852 bytes --]
On Sun, Jan 11, 2026 at 12:33:39AM +0100, Stefano Brivio wrote:
> On Mon, 5 Jan 2026 19:28:50 +1100
> David Gibson <david@gibson.dropbear.id.au> wrote:
>
> > {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>
> > ---
> > conf.c | 14 +++++++-------
> > tcp.c | 7 ++-----
> > udp.c | 4 ++--
> > 3 files changed, 11 insertions(+), 14 deletions(-)
> >
> > diff --git a/conf.c b/conf.c
> > index cc3c20a9..5db49653 100644
> > --- a/conf.c
> > +++ b/conf.c
> > @@ -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);
> > }
> > }
> >
> > diff --git a/tcp.c b/tcp.c
> > index 67007c05..80b47f3c 100644
> > --- a/tcp.c
> > +++ b/tcp.c
> > @@ -2680,7 +2680,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
>
> Nit, here and on udp_listen(): "socket". See also 9e0423e13541 ("style:
> Fix 'Return' comment style").
Oops, fixed.
--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2026-01-12 3:50 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-05 8:28 [PATCH 0/3] Allow listen functions to return fds David Gibson
2026-01-05 8:28 ` [PATCH 1/3] conf: Introduce --no-bindtodevice option for testing David Gibson
2026-01-10 23:33 ` Stefano Brivio
2026-01-12 3:42 ` David Gibson
2026-01-13 0:12 ` Stefano Brivio
2026-01-13 3:00 ` David Gibson
2026-01-13 22:13 ` Stefano Brivio
2026-01-05 8:28 ` [PATCH 2/3] tcp, udp, conf: Don't silently ignore listens on unsupported IP versions David Gibson
2026-01-10 23:33 ` Stefano Brivio
2026-01-12 3:48 ` David Gibson
2026-01-13 0:12 ` Stefano Brivio
2026-01-13 3:05 ` David Gibson
2026-01-05 8:28 ` [PATCH 3/3] tcp, udp: Make {tcp,udp}_listen() return socket fds David Gibson
2026-01-10 23:33 ` Stefano Brivio
2026-01-12 3:50 ` 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=aWRvfQAUrwu1ULBI@zatzit \
--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).