From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=W7Nih3/Z; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 2E2095A0269 for ; Tue, 03 Mar 2026 20:11:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772565103; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=63OQJwK1YVDWQwzlGR3PRVVpD5Pgp4Bn6hUBw6sb2is=; b=W7Nih3/ZVKnCk7Y+U7BSz4uEmqCTwp9iY8ENVmRXMqif1FwSzmBjN+YSXVg/LSU1T0L2Bu bS3Sho/OulqFpkGLy9Z3l4yjOey3uym9QCtmp1F297S1F8vElk+dNRvbGrR7lD0JKFyLlw EsXZ12BgHUL6cDbvskApLiOXpwdbWA4= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-TWRVfzEYO-qkzsRpV7oJ4g-1; Tue, 03 Mar 2026 14:11:42 -0500 X-MC-Unique: TWRVfzEYO-qkzsRpV7oJ4g-1 X-Mimecast-MFC-AGG-ID: TWRVfzEYO-qkzsRpV7oJ4g_1772565101 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-439c4d71603so272069f8f.0 for ; Tue, 03 Mar 2026 11:11:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772565101; x=1773169901; h=date:content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=63OQJwK1YVDWQwzlGR3PRVVpD5Pgp4Bn6hUBw6sb2is=; b=BqpBoThXRwbiH/U9UDTxXFVJLpjl2ASGGfskWkT/AIG1fGZxi4s3885bfItI0jRJDX +HH3Xsyt7CJa00+M+vl3VSBSHbIAKILFSa73dkkfo41NixOVgCXY0aOjKXuz8VDT/686 +XEepD3WL0XyumJK/DWKnwOYI5E7gfGNU6gXYrOSWEclEU67XZCf9+RY+PFlPne49Zo0 oCqx9oviaawS1aG1g2joKuaLaZ3wx5tZutLaXI30R5DpY3FT533CNzUFekMcfY07bpKI EfAfPmIXOP/zVBdvkEXSjRxJNFDvCJObSG6jCZAk9ZvkFxHJIL/GpU2vxeBK6C5ORP17 NfPQ== X-Gm-Message-State: AOJu0YztYpbRRWQRnZkO5L9udaOtY1iYlZwOTCsuNKRHuE2TM28/BM+f fACvO6VbAPcjtdyS6iD2bi68KLgJNmo8ssFoRyqmugLuyo4kZDIPJCLbtrOakBwOjjWCAb4fOf6 S0oFt/EjEqjUmedq6jlkaI+Hr++ZRK0FKaFhQbGzWdub9N/t9dd1YC/fb3gkLlg== X-Gm-Gg: ATEYQzyWeB/pSGvseSMDlRt6qUGXXmm3MFeJdm9S+UInDTMCaCD/JnT7NR28pa/xSQ4 LyAkPMLgY97Z9nh46DmlcWu79A/yhaFCSCuDQiLN6t4moUTXXwMIfXIiihC0YfaPtxlFK8xQ95Q P75WTnOIZO7vc4gRquMq/0wiPWGiZxEsETbrQtRUC9tAM6tYifwk4RczuF8O6GZWLWwyBqRFy5O w/y4p2E+NWjF1rAA5PuIhMd+MYCBoNneqMsOqwtqLQURARKYFMj6QVQnfig/+PIbOF9M373ew8L 9I3CzJPCmUcyVjqkrKzF5Pdw5Mds3A/AwokI39Ek1qThh+Jo26yPWymy611dY4eLkvbPLON0NNw 3vB1CtoWj+gle/ZYf9T/rSCcY0HpwZOnDpZPAUXnY/Zxn8vMugw== X-Received: by 2002:a05:6000:250f:b0:436:1597:7c7c with SMTP id ffacd0b85a97d-439c10b9a27mr6623298f8f.13.1772565100871; Tue, 03 Mar 2026 11:11:40 -0800 (PST) X-Received: by 2002:a05:6000:250f:b0:436:1597:7c7c with SMTP id ffacd0b85a97d-439c10b9a27mr6623253f8f.13.1772565100353; Tue, 03 Mar 2026 11:11:40 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-439ae0e7abasm23208511f8f.23.2026.03.03.11.11.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2026 11:11:39 -0800 (PST) From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 2/3] fwd, pif: Replace with pif_sock_l4() with pif_listen() Message-ID: <20260303201138.293e2f83@elisabeth> In-Reply-To: <20260302043135.800803-3-david@gibson.dropbear.id.au> References: <20260302043135.800803-1-david@gibson.dropbear.id.au> <20260302043135.800803-3-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 Date: Tue, 03 Mar 2026 20:11:39 +0100 (CET) X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Uwug22qCbmpZGxvlxBRbUgZD7QTYZ6r6_HMA4bdU8p8_1772565101 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: LQQHY2QFV6KW4ES6COMVQBAUHL2RTXIK X-Message-ID-Hash: LQQHY2QFV6KW4ES6COMVQBAUHL2RTXIK X-MailFrom: sbrivio@redhat.com 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: On Mon, 2 Mar 2026 15:31:34 +1100 David Gibson wrote: > 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 advantage > of that to pass the necessary epoll information into pif_sock_l4() in a > more natural way, rather than as an opaque u32. > > 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(). > > Rename pif_sock_l4() to pif_listen() to reflect the new semantics. While > 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 only > 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. > > 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(-) > > 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) > > /** > - * 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) == sizeof(uint32_t)); Reported-by: Peter Foley > > enum fwd_ports_mode { > FWD_UNSET = 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 sockaddr_inany *sa, > } > } > > -/** pif_sock_l4() - Open a socket bound to an address on a specified interface > +/** 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 entered 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; > > ref.type = type; > - ref.data = data; > + ref.listen.port = port; > + ref.listen.pif = pif; > + ref.listen.rule = rule; > > ret = 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) > > 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); > > #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 port) > { > - union fwd_listen_ref ref = { > - .port = port, > - .pif = pif, > - .rule = rule, > - }; > int s; > > ASSERT(!c->no_tcp); > @@ -2722,8 +2717,7 @@ int tcp_listen(const struct ctx *c, uint8_t pif, unsigned rule, > return -EAFNOSUPPORT; > } > > - s = pif_sock_l4(c, EPOLL_TYPE_TCP_LISTEN, pif, addr, ifname, > - port, ref.u32); > + s = pif_listen(c, EPOLL_TYPE_TCP_LISTEN, pif, addr, ifname, port, rule); > > 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 port) > { > - union fwd_listen_ref ref = { > - .pif = pif, > - .port = port, > - .rule = rule, > - }; > int s; > > ASSERT(!c->no_udp); > @@ -1163,8 +1158,7 @@ int udp_listen(const struct ctx *c, uint8_t pif, unsigned rule, > return -EAFNOSUPPORT; > } > > - s = pif_sock_l4(c, EPOLL_TYPE_UDP_LISTEN, pif, > - addr, ifname, port, ref.u32); > + s = pif_listen(c, EPOLL_TYPE_UDP_LISTEN, pif, addr, ifname, port, rule); > > return s; > } -- Stefano