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=nKVN0Gix; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id DD9E65A0624 for ; Mon, 12 Jan 2026 04:50:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1768189832; bh=3EpaeNKXxq1/ww+W70M9Az+wALmq5r5Ij8RRhaOGc0Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nKVN0GixjxsEFwO1NyVfOXSvLe4Lv2LRC2ITTd4lzZalRhjSlGvSVipE+R3Wp+ea6 2h8VroM40FLycFBU1a5wCD8A0NcMqAmj5FVy6D88t587bdEP5JuoeeRscaVzR10NnB JN176kLLXFSlZu52gab1eOZr7/vBUhZyb97opgCl3ElSvnDip8J7rrytjlh4qtNgtl +U3R5o5ZB+49VjUygNcnj3Yi+BCbR02Xgpqu/nBiTxqbefTsKSAvxfP/5T8jwFS3kc KYMv59JvxklSfKmxgdyQJxWkg5Sglv4K4BAc8uCQAnpYdKpGX2JpVqDxZ8QAZf9kiA MQ2wwSha13hGQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4dqJLc48LRz4wCY; Mon, 12 Jan 2026 14:50:32 +1100 (AEDT) Date: Mon, 12 Jan 2026 14:50:21 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 3/3] tcp, udp: Make {tcp,udp}_listen() return socket fds Message-ID: References: <20260105082850.1985300-1-david@gibson.dropbear.id.au> <20260105082850.1985300-4-david@gibson.dropbear.id.au> <20260111003339.5c2c979c@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="V68+TilIPnjJ+OUa" Content-Disposition: inline In-Reply-To: <20260111003339.5c2c979c@elisabeth> Message-ID-Hash: 6UED7BVRUVL4PLBHKAID6AJGRBFLTALS X-Message-ID-Hash: 6UED7BVRUVL4PLBHKAID6AJGRBFLTALS 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: passt-dev@passt.top 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: --V68+TilIPnjJ+OUa Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Jan 11, 2026 at 12:33:39AM +0100, Stefano Brivio wrote: > On Mon, 5 Jan 2026 19:28:50 +1100 > David Gibson wrote: >=20 > > {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. > >=20 > > Signed-off-by: David Gibson > > --- > > conf.c | 14 +++++++------- > > tcp.c | 7 ++----- > > udp.c | 4 ++-- > > 3 files changed, 11 insertions(+), 14 deletions(-) > >=20 > > 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 ct= x *c, char optname, > > { > > bool bound_one =3D false; > > unsigned i; > > - int ret; > > + int fd; > > =20 > > if (first =3D=3D 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] =3D to - first; > > =20 > > if (optname =3D=3D 't') > > - ret =3D tcp_listen(c, PIF_HOST, addr, ifname, i); > > + fd =3D tcp_listen(c, PIF_HOST, addr, ifname, i); > > else if (optname =3D=3D 'u') > > - ret =3D udp_listen(c, PIF_HOST, addr, ifname, i); > > + fd =3D udp_listen(c, PIF_HOST, addr, ifname, i); > > else > > /* No way to check in advance for -T and -U */ > > - ret =3D 0; > > + fd =3D 0; > > =20 > > - if (ret =3D=3D -ENFILE || ret =3D=3D -EMFILE) { > > + if (fd =3D=3D -ENFILE || fd =3D=3D -EMFILE) { > > die("Can't open enough sockets for port specifier: %s", > > optarg); > > } > > =20 > > - if (!ret) { > > + if (fd >=3D 0) { > > bound_one =3D 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); > > } > > } > > =20 > > 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 >=20 > Nit, here and on udp_listen(): "socket". See also 9e0423e13541 ("style: > Fix 'Return' comment style"). Oops, fixed. --=20 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 --V68+TilIPnjJ+OUa Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmlkb30ACgkQzQJF27ox 2GeAdg/+LAyoFtHXzrc8GNj6G9l5Ce/A3GTVWfjWSltsjNcm4OlSh8gs5Ja/aMXG E2x902Mq2srXlLyctIjQJ2uyzO4vhkrvb+kymxF6yxXSmJrkfRPuLhpWmb77AlGd MOcCFziOx41Zyg6pjBpFY30j48HrqYCtiHEgYoF1gEsJY+VvbeLYt2Vba0S2Olb4 ksg3LFzBolsTi3UNS3MUN3P5JkTxkxyT0reMZ2ljmwdsBknuJ689/ddwy782gLIE EX70DaAk4Xlzaegda7tfSl7uITXPHjKBjuITpPea4mw769avora4/6MX6SCKtRMH yQU3+jT0OTyX83DuN/FrVnUSDOyb8Nuwi5YGoSqNNfjYM6/ownx5ikfRXuU7oIo6 XGKXDyyw4TIkJKekqX2ep9Q20+Chw76+/cFTl5H/8p7l9fP+CCTJ2T+tpAEw6UJf b/x2+IfG7KsE9mJ3sW3t/nHgOFwH2PuFImiAHawX24LP2KyIipnZhkMmILMY7Pm3 1hJIpEm77uUbeznEsd1p3ntZdv4xM9aNpj6kbWR/G3H+SfpiqhCG8cWIQhbWVVQJ Yhvm7DNVtkWFg4Rg4uaebKeitNKjCcFJCfZhizxuerY1f9X7YuF1OZwtpJLikoNC xdQrsAoJuHC5wtEerbQnWVugCkpjXjmSrsNYdzWH9nedmksVYl0= =/vGm -----END PGP SIGNATURE----- --V68+TilIPnjJ+OUa--