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=202608 header.b=gw94lMVS; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id B30E75A0269 for ; Fri, 07 Aug 2026 12:02:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202608; t=1786096958; bh=7aiSRt0Nu4s1fmToPe3tpUSzMwGFjdaUVNXiYU5wmUI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gw94lMVSAYR2y+Ozvw5fpeUaxNpWUMBjUUpNeIk8JBenbx9RyiJXxNHc0sBa1eegc eadRosrmwxu+vy5X56Tv5a/XCboVkltLAlbFAbcICqWSnM/ib4bHX/Gfzr7wSBZ5CU 5s3UEF4+UYxSNXz5Em2yuUvXaVZuyFON3ux4d3tJg7b5qV2e1yvCxX4mcS94dFlYGV gyBgWRdSpm2wkk/nNhej5fkJXxlAYDothW/rzClIsJgMHRqJAIg89ta9LuLqEkdlQG zZbuDLWR/7sO06oXcrDv0aT8mwBOoLCh2FM++cG1hZ2VnsO3nPpddL23EElGHsqbEX acbAFwJY49kpw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4hGfpQ6Rknz4wGH; Fri, 07 Aug 2026 20:02:38 +1000 (AEST) Date: Fri, 7 Aug 2026 15:56:12 +1000 From: David Gibson To: Ammar Yasser Subject: Re: [RFC v3 2/8] udp,tcp: Make protocol specific buffers public Message-ID: References: <20260802132155.870796-1-aerosound161@gmail.com> <20260802132155.870796-3-aerosound161@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="oKr3DBmib8pOv2TL" Content-Disposition: inline In-Reply-To: <20260802132155.870796-3-aerosound161@gmail.com> Message-ID-Hash: TL5HIL22KX62IIJBNF2VF4C3ZQKGSGOG X-Message-ID-Hash: TL5HIL22KX62IIJBNF2VF4C3ZQKGSGOG 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, eperezma@redhat.com 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: --oKr3DBmib8pOv2TL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Aug 02, 2026 at 01:21:49PM +0000, Ammar Yasser wrote: > Move the buffers used to split tcp and udp packets coming from the host > from being static definitions in tcp_buf.c and udp.c to structs exported > through extern on the their respective header files. >=20 > Also move the udp_meta_t definition to the public udp.h file instead of > it living in udp_internal.h This commit message needs more of a rationale as to why this is a desirable change. I presume it's because something later in the series needs to access these variables and types, but this commit message should summarise that for easier review. The content looks fine assuming the premise makes sense. > Signed-off-by: Ammar Yasser > --- > tcp_buf.c | 14 +++++--------- > tcp_buf.h | 16 +++++++++++++++- > udp.c | 40 ++++++++++++---------------------------- > udp.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ > udp_internal.h | 13 ------------- > 5 files changed, 81 insertions(+), 51 deletions(-) >=20 > diff --git a/tcp_buf.c b/tcp_buf.c > index 72c4541..4452337 100644 > --- a/tcp_buf.c > +++ b/tcp_buf.c > @@ -33,23 +33,19 @@ > #include "tcp_internal.h" > #include "tcp_buf.h" > =20 > -#define TCP_FRAMES_MEM 128 > -#define TCP_FRAMES \ > - (c->mode =3D=3D MODE_PASTA ? 1 : TCP_FRAMES_MEM) > - > /* Static buffers */ > =20 > /* Ethernet header for IPv4 and IPv6 frames */ > -static struct ethhdr tcp_eth_hdr[TCP_FRAMES_MEM]; > +struct ethhdr tcp_eth_hdr[TCP_FRAMES_MEM]; > =20 > -static struct tap_hdr tcp_payload_tap_hdr[TCP_FRAMES_MEM]; > +struct tap_hdr tcp_payload_tap_hdr[TCP_FRAMES_MEM]; > =20 > /* IP headers for IPv4 and IPv6 */ > -static struct iphdr tcp4_payload_ip[TCP_FRAMES_MEM]; > -static struct ipv6hdr tcp6_payload_ip[TCP_FRAMES_MEM]; > +struct iphdr tcp4_payload_ip[TCP_FRAMES_MEM]; > +struct ipv6hdr tcp6_payload_ip[TCP_FRAMES_MEM]; > =20 > /* TCP segments with payload for IPv4 and IPv6 frames */ > -static struct tcp_payload_t tcp_payload[TCP_FRAMES_MEM]; > +struct tcp_payload_t tcp_payload[TCP_FRAMES_MEM]; > =20 > static_assert(MSS4 <=3D sizeof(tcp_payload[0].data), "MSS4 is greater th= an 65516"); > static_assert(MSS6 <=3D sizeof(tcp_payload[0].data), "MSS6 is greater th= an 65516"); > diff --git a/tcp_buf.h b/tcp_buf.h > index 5d31cea..c749038 100644 > --- a/tcp_buf.h > +++ b/tcp_buf.h > @@ -6,11 +6,25 @@ > #ifndef TCP_BUF_H > #define TCP_BUF_H > =20 > -void tcp_sock_iov_init(const struct ctx *c); > +#include "tcp_conn.h" > +#include "tcp_internal.h" > + > +void tcp_sock_iov_init(); > void tcp_payload_flush(const struct ctx *c, const struct timespec *now); > int tcp_buf_data_from_sock(const struct ctx *c, struct tcp_tap_conn *con= n, > uint32_t already_sent, const struct timespec *now); > int tcp_buf_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, in= t flags, > const struct timespec *now); > =20 > +#define TCP_FRAMES_MEM 128 > +#define TCP_FRAMES \ > +(c->mode =3D=3D MODE_PASTA ? 1 : TCP_FRAMES_MEM) > + > +extern struct tap_hdr tcp_payload_tap_hdr[TCP_FRAMES_MEM]; > +extern struct ethhdr tcp_eth_hdr[TCP_FRAMES_MEM]; > +extern struct tcp_payload_t tcp_payload[TCP_FRAMES_MEM]; > + > +extern struct iphdr tcp4_payload_ip[TCP_FRAMES_MEM]; > +extern struct ipv6hdr tcp6_payload_ip[TCP_FRAMES_MEM]; > + > #endif /*TCP_BUF_H */ > diff --git a/udp.c b/udp.c > index 505e554..d05ee66 100644 > --- a/udp.c > +++ b/udp.c > @@ -119,7 +119,6 @@ > #include "udp_vu.h" > #include "epoll_ctl.h" > =20 > -#define UDP_MAX_FRAMES 32 /* max # of frames to receive at once */ > =20 > #define UDP_TIMEOUT "/proc/sys/net/netfilter/nf_conntrack_udp_timeout" > #define UDP_TIMEOUT_STREAM \ > @@ -134,30 +133,6 @@ > - sizeof(struct udphdr) \ > - sizeof(struct ipv6hdr)) > =20 > -/* Static buffers */ > - > -/* UDP header and data for inbound messages */ > -static struct udp_payload_t udp_payload[UDP_MAX_FRAMES]; > - > -/* Ethernet headers for IPv4 and IPv6 frames */ > -static struct ethhdr udp_eth_hdr[UDP_MAX_FRAMES]; > - > -/** > - * struct udp_meta_t - Pre-cooked headers for UDP packets > - * @ip6h: Pre-filled IPv6 header (except for payload_len and addresses) > - * @ip4h: Pre-filled IPv4 header (except for tot_len and saddr) > - * @taph: Tap backend specific header > - */ > -static struct udp_meta_t { > - struct ipv6hdr ip6h; > - struct iphdr ip4h; > - struct tap_hdr taph; > -} > -#ifdef __AVX2__ > -__attribute__ ((aligned(32))) > -#endif > -udp_meta[UDP_MAX_FRAMES]; > - > #define PKTINFO_SPACE \ > MAX(CMSG_SPACE(sizeof(struct in_pktinfo)), \ > CMSG_SPACE(sizeof(struct in6_pktinfo))) > @@ -186,9 +161,6 @@ enum udp_iov_idx { > UDP_NUM_IOVS, > }; > =20 > -/* IOVs and msghdr arrays for receiving datagrams from sockets */ > -static struct iovec udp_iov_recv [UDP_MAX_FRAMES]; > -static struct mmsghdr udp_mh_recv [UDP_MAX_FRAMES]; > =20 > /* IOVs and msghdr arrays for sending "spliced" datagrams to sockets */ > static union sockaddr_inany udp_splice_to; > @@ -199,6 +171,18 @@ static struct mmsghdr udp_mh_splice [UDP_MAX_FRAMES= ]; > /* IOVs for L2 frames */ > static struct iovec udp_l2_iov [UDP_MAX_FRAMES][UDP_NUM_IOVS]; > =20 > +struct udp_payload_t udp_payload[UDP_MAX_FRAMES]; > + > +/* Ethernet headers for IPv4 and IPv6 frames */ > +struct ethhdr udp_eth_hdr[UDP_MAX_FRAMES]; > + > +/* IOVs and msghdr arrays for receiving datagrams from sockets */ > +struct iovec udp_iov_recv [UDP_MAX_FRAMES]; > +struct mmsghdr udp_mh_recv [UDP_MAX_FRAMES]; > + > +/* Pre-cooked headers for UDP packets */ > +struct udp_meta_t udp_meta[UDP_MAX_FRAMES]; > + > /** > * udp_update_l2_buf() - Update L2 buffers with Ethernet and IPv4 addres= ses > * @eth_d: Ethernet destination address, NULL if unchanged > diff --git a/udp.h b/udp.h > index b50283e..b7a367c 100644 > --- a/udp.h > +++ b/udp.h > @@ -8,9 +8,58 @@ > =20 > #include > #include > +#include > =20 > +#include "tap_hdr.h" > #include "fwd.h" > =20 > +/** > + * struct udp_payload_t - UDP header and data for inbound messages > + * @uh: UDP header > + * @data: UDP data > + */ > +struct udp_payload_t { > + struct udphdr uh; > + char data[USHRT_MAX - sizeof(struct udphdr)]; > +#ifdef __AVX2__ > +} __attribute__ ((packed, aligned(32))); > +#else > +} __attribute__ ((packed, aligned(__alignof__(unsigned int)))); > +#endif > + > +#define UDP_MAX_FRAMES 32 /* max # of frames to receive at once */ > + > +/* UDP header and data for inbound messages */ > +extern struct udp_payload_t udp_payload[UDP_MAX_FRAMES]; > + > +/* Ethernet headers for IPv4 and IPv6 frames */ > +extern struct ethhdr udp_eth_hdr[UDP_MAX_FRAMES]; > + > +/* IOVs and msghdr arrays for receiving datagrams from sockets */ > +extern struct iovec udp_iov_recv [UDP_MAX_FRAMES]; > +extern struct mmsghdr udp_mh_recv [UDP_MAX_FRAMES]; > + > + > +/** > + * struct udp_meta_t - Pre-cooked headers for UDP packets > + * @ip6h: Pre-filled IPv6 header (except for payload_len and addresses) > + * @ip4h: Pre-filled IPv4 header (except for tot_len and saddr) > + * @taph: Tap backend specific header > + */ > +struct udp_meta_t { > + struct ipv6hdr ip6h; > + struct iphdr ip4h; > + struct tap_hdr taph; > +#ifdef __AVX2__ > +} __attribute__((aligned(32))); > +#else > +}; > +#endif > + > +/* Pre-cooked headers for UDP packets */ > +extern struct udp_meta_t udp_meta[UDP_MAX_FRAMES]; > + > + > void udp_listen_sock_handler(const struct ctx *c, union epoll_ref ref, > uint32_t events, const struct timespec *now); > void udp_sock_handler(const struct ctx *c, union epoll_ref ref, > diff --git a/udp_internal.h b/udp_internal.h > index 361cc74..6804843 100644 > --- a/udp_internal.h > +++ b/udp_internal.h > @@ -11,19 +11,6 @@ > =20 > #include "tap.h" /* needed by udp_meta_t */ > =20 > -/** > - * struct udp_payload_t - UDP header and data for inbound messages > - * @uh: UDP header > - * @data: UDP data > - */ > -struct udp_payload_t { > - struct udphdr uh; > - char data[USHRT_MAX - sizeof(struct udphdr)]; > -#ifdef __AVX2__ > -} __attribute__ ((packed, aligned(32))); > -#else > -} __attribute__ ((packed, aligned(__alignof__(unsigned int)))); > -#endif > =20 > size_t udp_update_hdr4(struct iphdr *ip4h, struct udphdr *uh, > struct iov_tail *payload, > --=20 > 2.34.1 >=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 --oKr3DBmib8pOv2TL Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmp1c20ACgkQzQJF27ox 2GcPOQ//bWLRDitVn0LnDId9XUP9Av286r0PUBbxb1nYr4eBg8jr/zkeIUKz1rFm kP9ZUKPL7H8/MEYTkSuMeprRe6PIpvXHXdOPTYIT8AVQZ941YXiUBdAjrM6MxoiZ C7Z4PLLw8CB3q2OJ2w2xV15aOm7u6sS9VgJM1MxofA7a+E92858VUB3V+p9bhoA0 7BuQugFiX+4gq/upqEYHCesdc6dM8NxcI0ZUFulPkhAGyyZxgTvfOEOy9wbxITtj l05dRg9Cf3S1k+YUodO+R25dXIlgUs2gjD/hCyQBymuZIdO3WG0+drQHuz48s4le ScGJTaXYvbQShUNlspPMpoc28EbvKO9du/l8S6ytsgYb70DHF9KWKpXbSFamXUKm mnMp64dgsf6FllSVeDxiNnucfoxh7I/tu259bI2rO4Dd2goqH3caSYO8y/8uxvMK Azo4Xg3RCR9gc9pApOr/B+P8V/PzcddYanmAcVapm20IeVuYWhsSvIuOLS+w4ozm n/Hnh0hQNPpTOA438nKC6Td0adDiluSs5NWsJ9fStItA4VLw1yxhDoeYDH7Semn4 1QLnpFIdhuRbOcQ1kHHaeNd7PqxbVQt1aiPMl4NPuFJQwHh8x0fZyzdd52k28oan BZzecHZijLZ5QVxKne+uPmN29w6Ui+UsvwvcEeGETViIR/nOS2E= =R7ZU -----END PGP SIGNATURE----- --oKr3DBmib8pOv2TL--