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=202602 header.b=XoewnyP2; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 09A295A0262 for ; Tue, 03 Mar 2026 23:55:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1772578524; bh=E1GKGTxB3CvdTxLiyP/6QKPRm6AdnfOwYg31N7vGiJ4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XoewnyP2lutmfL6SsS7fgbQzLSKR1Xi4vcMU+NEJPfJw+DTkesfUVxlNpA09f/xdh OPU3+CIZcxygBjTeE5a6361bEu5Nx5dsnvGJ2ncXPJF3+OB0aP/PRLuPf1QV84bKii khwOHkUiLrC4kf9yOdfbCphMpN7C6Y/JNRIAzxjRh3RRuSwmhFbM2p6JzEwnAW1cEn FPyheuQuu3mK/t6Y56hMs0YQu8fPXJHp3Rv//uiwaNSeTjqlmNbM3+Q+QT6EdqNGS7 7dvtbjpOBove9K+Aq2JQeo9VWZfjFGIgsLNbVtf2NYRxsqTWAg5iOLe0qH6393YnQS jHySCzhd2VKnw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fQWNX6gzTz4wCk; Wed, 04 Mar 2026 09:55:24 +1100 (AEDT) Date: Wed, 4 Mar 2026 09:55:21 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 2/3] fwd, pif: Replace with pif_sock_l4() with pif_listen() Message-ID: References: <20260302043135.800803-1-david@gibson.dropbear.id.au> <20260302043135.800803-3-david@gibson.dropbear.id.au> <20260303201138.293e2f83@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="5t0FjjqrQWIeZDCq" Content-Disposition: inline In-Reply-To: <20260303201138.293e2f83@elisabeth> Message-ID-Hash: QXGKX6EBLDHYRZCZGQ7NODVJEPJ5XXAT X-Message-ID-Hash: QXGKX6EBLDHYRZCZGQ7NODVJEPJ5XXAT 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, Peter Foley 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: --5t0FjjqrQWIeZDCq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Mar 03, 2026 at 08:11:39PM +0100, Stefano Brivio wrote: > On Mon, 2 Mar 2026 15:31:34 +1100 > David Gibson wrote: >=20 > > It turns out all users of pif_sock_l4() use it for "listening" sockets, > > which now all have a common epoll reference format. We can take advant= age > > of that to pass the necessary epoll information into pif_sock_l4() in a > > more natural way, rather than as an opaque u32. > >=20 > > That in turn allows union fwd_listen_ref can become a struct, since the > > union only exist to allow the meaningful fields to be coerced into a u32 > > for pif_sock_l4(). > >=20 > > Rename pif_sock_l4() to pif_listen() to reflect the new semantics. Whi= le > > we're there, remove the static_assert() on the fwd_listen_ref's size. = We > > do still need it to fit into 32 bits, but that constraint is imposed on= ly > > by the fact that it needs to fit into the whole, epoll_ref structure, > > which we already check with a static_assert() in epoll_ctl.h. > >=20 > > Signed-off-by: David Gibson > > --- > > epoll_ctl.h | 2 +- > > fwd.h | 14 +++++--------- > > pif.c | 14 ++++++++------ > > pif.h | 6 +++--- > > tcp.c | 8 +------- > > udp.c | 8 +------- > > 6 files changed, 19 insertions(+), 33 deletions(-) > >=20 > > diff --git a/epoll_ctl.h b/epoll_ctl.h > > index 2c103cde..879763cb 100644 > > --- a/epoll_ctl.h > > +++ b/epoll_ctl.h > > @@ -35,7 +35,7 @@ union epoll_ref { > > union { > > uint32_t flow; > > flow_sidx_t flowside; > > - union fwd_listen_ref listen; > > + struct fwd_listen_ref listen; > > uint32_t data; > > int nsdir_fd; > > int queue; > > diff --git a/fwd.h b/fwd.h > > index 16070111..b0e2373d 100644 > > --- a/fwd.h > > +++ b/fwd.h > > @@ -49,20 +49,16 @@ struct fwd_rule { > > #define FWD_NO_HINT (-1) > > =20 > > /** > > - * union fwd_listen_ref - information about a single listening socket > > + * struct fwd_listen_ref - information about a single listening socket > > * @port: Bound port number of the socket > > * @pif: pif in which the socket is listening > > * @rule: Index of forwarding rule > > */ > > -union fwd_listen_ref { > > - struct { > > - in_port_t port; > > - uint8_t pif; > > - unsigned rule :FWD_RULE_BITS; > > - }; > > - uint32_t u32; > > +struct fwd_listen_ref { > > + in_port_t port; > > + uint8_t pif; > > + unsigned rule :FWD_RULE_BITS; > > }; > > -static_assert(sizeof(union fwd_listen_ref) =3D=3D sizeof(uint32_t)); >=20 > Reported-by: Peter Foley Good point. Can you add this on merge? >=20 > > =20 > > enum fwd_ports_mode { > > FWD_UNSET =3D 0, > > diff --git a/pif.c b/pif.c > > index 6ae970a0..82a3b5e4 100644 > > --- a/pif.c > > +++ b/pif.c > > @@ -62,23 +62,23 @@ void pif_sockaddr(const struct ctx *c, union sockad= dr_inany *sa, > > } > > } > > =20 > > -/** pif_sock_l4() - Open a socket bound to an address on a specified i= nterface > > +/** pif_listen() - Open a listening socket on a specified pif > > * @c: Execution context > > * @type: Socket epoll type > > * @pif: Interface for this socket > > * @addr: Address to bind to, or NULL for dual-stack any > > * @ifname: Interface for binding, NULL for any > > * @port: Port number to bind to (host byte order) > > - * @data: epoll reference portion for protocol handlers > > + * @rule: Forwarding rule index this socket belongs to > > * > > * NOTE: For namespace pifs, this must be called having already entere= d the > > * relevant namespace. > > * > > * Return: newly created socket, negative error code on failure > > */ > > -int pif_sock_l4(const struct ctx *c, enum epoll_type type, uint8_t pif, > > - const union inany_addr *addr, const char *ifname, > > - in_port_t port, uint32_t data) > > +int pif_listen(const struct ctx *c, enum epoll_type type, uint8_t pif, > > + const union inany_addr *addr, const char *ifname, > > + in_port_t port, unsigned rule) > > { > > union epoll_ref ref; > > int ret; > > @@ -98,7 +98,9 @@ int pif_sock_l4(const struct ctx *c, enum epoll_type = type, uint8_t pif, > > return ref.fd; > > =20 > > ref.type =3D type; > > - ref.data =3D data; > > + ref.listen.port =3D port; > > + ref.listen.pif =3D pif; > > + ref.listen.rule =3D rule; > > =20 > > ret =3D epoll_add(c->epollfd, EPOLLIN, ref); > > if (ret < 0) { > > diff --git a/pif.h b/pif.h > > index 0f7f6672..0eb3626a 100644 > > --- a/pif.h > > +++ b/pif.h > > @@ -59,8 +59,8 @@ static inline bool pif_is_socket(uint8_t pif) > > =20 > > void pif_sockaddr(const struct ctx *c, union sockaddr_inany *sa, > > uint8_t pif, const union inany_addr *addr, in_port_t port); > > -int pif_sock_l4(const struct ctx *c, enum epoll_type type, uint8_t pif, > > - const union inany_addr *addr, const char *ifname, > > - in_port_t port, uint32_t data); > > +int pif_listen(const struct ctx *c, enum epoll_type type, uint8_t pif, > > + const union inany_addr *addr, const char *ifname, > > + in_port_t port, unsigned rule); > > =20 > > #endif /* PIF_H */ > > diff --git a/tcp.c b/tcp.c > > index 16470703..a0d7cd86 100644 > > --- a/tcp.c > > +++ b/tcp.c > > @@ -2698,11 +2698,6 @@ void tcp_sock_handler(const struct ctx *c, union= epoll_ref ref, > > int tcp_listen(const struct ctx *c, uint8_t pif, unsigned rule, > > const union inany_addr *addr, const char *ifname, in_port_t po= rt) > > { > > - union fwd_listen_ref ref =3D { > > - .port =3D port, > > - .pif =3D pif, > > - .rule =3D rule, > > - }; > > int s; > > =20 > > ASSERT(!c->no_tcp); > > @@ -2722,8 +2717,7 @@ int tcp_listen(const struct ctx *c, uint8_t pif, = unsigned rule, > > return -EAFNOSUPPORT; > > } > > =20 > > - s =3D pif_sock_l4(c, EPOLL_TYPE_TCP_LISTEN, pif, addr, ifname, > > - port, ref.u32); > > + s =3D pif_listen(c, EPOLL_TYPE_TCP_LISTEN, pif, addr, ifname, port, r= ule); > > =20 > > return s; > > } > > diff --git a/udp.c b/udp.c > > index 19adda06..464aa093 100644 > > --- a/udp.c > > +++ b/udp.c > > @@ -1139,11 +1139,6 @@ int udp_tap_handler(const struct ctx *c, uint8_t= pif, > > int udp_listen(const struct ctx *c, uint8_t pif, unsigned rule, > > const union inany_addr *addr, const char *ifname, in_port_t po= rt) > > { > > - union fwd_listen_ref ref =3D { > > - .pif =3D pif, > > - .port =3D port, > > - .rule =3D rule, > > - }; > > int s; > > =20 > > ASSERT(!c->no_udp); > > @@ -1163,8 +1158,7 @@ int udp_listen(const struct ctx *c, uint8_t pif, = unsigned rule, > > return -EAFNOSUPPORT; > > } > > =20 > > - s =3D pif_sock_l4(c, EPOLL_TYPE_UDP_LISTEN, pif, > > - addr, ifname, port, ref.u32); > > + s =3D pif_listen(c, EPOLL_TYPE_UDP_LISTEN, pif, addr, ifname, port, r= ule); > > =20 > > return s; > > } >=20 > --=20 > Stefano >=20 --=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 --5t0FjjqrQWIeZDCq Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmmnZtgACgkQzQJF27ox 2GcP1Q/9GIXZvNGskGP67Yl9bjZg3MTfOvjI/nLYm5aWXOUwDg8K8c8rWeiLZDQx 5gOB2rj5kgG5IwI4XifBx5gLIPh4rPVa8hs+v1+K90lP/C2eGYXhVdXOjysE5T61 mQ0kKSIu/H+rNwxI/sOB3VRfxkQS+fRmPtbhvf6PLbzpFbfHP+GS+cYlj3uFHrop /1w6BcZ+iLe/60D7xKLK6eX1uBjKMdowFx6wFzDatYwZw4EfOZiNdybR6H9mLYRt pekweaAYri3To3nxTvYR/Ym1V2WJTo79BIvMHhT+Ls8IYWMuM0N0YXjcVq0DhR2G efLVEZMagQZ75IlHNEVZslgkizv0VHdFhH7g0N4rGACQwU1ZtAv2U6L+k/B7LLbv ekga6iKbJUJ317OGd8zRR4SkN8tURgVZnDYpIFWYsvmga07PMPLM3uCDB2UmaD9x 7pOCUs/TNwjQbvFE2gogKwOcCuJy0XaCYBS6w0L+u7cTtWmHs4KnZj1yKAWSRjVo hbyu4KLNokYlQM0VU6KUhtJ8uvygZJra/Cbg1M9Tu+REPEAtfuLktta9R8fHK5tj o0GjGmY10mqnybWTN1YhadG7B/DKT9z5a5jxlEoEn6ufWo4q2oyJzJA91YqPsREz 40ZwBwomg/bUhJbKL0EjI/53Fn7fWMKUKtyG8RdE/OwCPlQ1m9s= =8DrE -----END PGP SIGNATURE----- --5t0FjjqrQWIeZDCq--