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=202410 header.b=gMcpGk7y; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 996865A0262 for ; Mon, 14 Oct 2024 07:03:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202410; t=1728882164; bh=7DXrNARMHt1pow5q/e/FgZEVR6EdxJyxHXQtDZFAdYM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gMcpGk7yEY7ktzkLLxfY5voN13jrRqre9DxHuxqdpPqJ4lvvFVjuMKtYgAolSF7WI RhpBvmOy7+XqwjURFLKGcddvIiNH1x9Ex7ImmGfCMmxEOqYS6YnjKVONptHDTXnmBB th6Pq4lSvoWrGEDLYabnaPfdWKa8Qd74FpDwSHS35TIYwdM3+G4z2zSnIS95yJUWOe tMvEmchZKO9IEabAX+UBTF6pTIXhJLODxRw4KJPDBBwM1pGF5jKA7wYDi/URhw3Ap5 r/6XZciDCPu/HDwYw7j2db6fO0SiF+EXOwe1PYZ2jYyw0XhqMYpnaPSuFCq/8W9tgU cMl5ZJtkR4fMg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4XRlTw2fgJz4x9D; Mon, 14 Oct 2024 16:02:44 +1100 (AEDT) Date: Mon, 14 Oct 2024 15:29:07 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v8 4/8] udp: Prepare udp.c to be shared with vhost-user Message-ID: References: <20241010122903.1188992-1-lvivier@redhat.com> <20241010122903.1188992-5-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="jgevnAu91xhSyzKo" Content-Disposition: inline In-Reply-To: <20241010122903.1188992-5-lvivier@redhat.com> Message-ID-Hash: EHC7NIS73EH4FDTCCQ4WZ3NI5O5MPL4N X-Message-ID-Hash: EHC7NIS73EH4FDTCCQ4WZ3NI5O5MPL4N 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: --jgevnAu91xhSyzKo Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Oct 10, 2024 at 02:28:58PM +0200, Laurent Vivier wrote: > Export udp_payload_t, udp_update_hdr4(), udp_update_hdr6() and > udp_sock_errs(). >=20 > Rename udp_listen_sock_handler() to udp_buf_listen_sock_handler() and > udp_reply_sock_handler to udp_buf_reply_sock_handler(). >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson > --- > udp.c | 74 ++++++++++++++++++++++++++++++-------------------- > udp_internal.h | 34 +++++++++++++++++++++++ > 2 files changed, 79 insertions(+), 29 deletions(-) > create mode 100644 udp_internal.h >=20 > diff --git a/udp.c b/udp.c > index 100610f2472e..8fc5d8099310 100644 > --- a/udp.c > +++ b/udp.c > @@ -109,8 +109,7 @@ > #include "pcap.h" > #include "log.h" > #include "flow_table.h" > - > -#define UDP_MAX_FRAMES 32 /* max # of frames to receive at once */ > +#include "udp_internal.h" > =20 > /* "Spliced" sockets indexed by bound port (host order) */ > static int udp_splice_ns [IP_VERSIONS][NUM_PORTS]; > @@ -118,20 +117,8 @@ static int udp_splice_init[IP_VERSIONS][NUM_PORTS]; > =20 > /* Static buffers */ > =20 > -/** > - * struct udp_payload_t - UDP header and data for inbound messages > - * @uh: UDP header > - * @data: UDP data > - */ > -static 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 > -udp_payload[UDP_MAX_FRAMES]; > +/* UDP header and data for inbound messages */ > +static struct udp_payload_t udp_payload[UDP_MAX_FRAMES]; > =20 > /* Ethernet header for IPv4 frames */ > static struct ethhdr udp4_eth_hdr; > @@ -302,9 +289,9 @@ static void udp_splice_send(const struct ctx *c, size= _t start, size_t n, > * > * Return: size of IPv4 payload (UDP header + data) > */ > -static size_t udp_update_hdr4(struct iphdr *ip4h, struct udp_payload_t *= bp, > - const struct flowside *toside, size_t dlen, > - bool no_udp_csum) > +size_t udp_update_hdr4(struct iphdr *ip4h, struct udp_payload_t *bp, > + const struct flowside *toside, size_t dlen, > + bool no_udp_csum) > { > const struct in_addr *src =3D inany_v4(&toside->oaddr); > const struct in_addr *dst =3D inany_v4(&toside->eaddr); > @@ -345,9 +332,9 @@ static size_t udp_update_hdr4(struct iphdr *ip4h, str= uct udp_payload_t *bp, > * > * Return: size of IPv6 payload (UDP header + data) > */ > -static size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct udp_payload_t= *bp, > - const struct flowside *toside, size_t dlen, > - bool no_udp_csum) > +size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct udp_payload_t *bp, > + const struct flowside *toside, size_t dlen, > + bool no_udp_csum) > { > uint16_t l4len =3D dlen + sizeof(bp->uh); > =20 > @@ -477,7 +464,7 @@ static int udp_sock_recverr(int s) > * > * Return: Number of errors handled, or < 0 if we have an unrecoverable = error > */ > -static int udp_sock_errs(const struct ctx *c, int s, uint32_t events) > +int udp_sock_errs(const struct ctx *c, int s, uint32_t events) > { > unsigned n_err =3D 0; > socklen_t errlen; > @@ -554,7 +541,7 @@ static int udp_sock_recv(const struct ctx *c, int s, = uint32_t events, > } > =20 > /** > - * udp_listen_sock_handler() - Handle new data from socket > + * udp_buf_listen_sock_handler() - Handle new data from socket > * @c: Execution context > * @ref: epoll reference > * @events: epoll events bitmap > @@ -562,8 +549,9 @@ static int udp_sock_recv(const struct ctx *c, int s, = uint32_t events, > * > * #syscalls recvmmsg > */ > -void udp_listen_sock_handler(const struct ctx *c, union epoll_ref ref, > - uint32_t events, const struct timespec *now) > +static void udp_buf_listen_sock_handler(const struct ctx *c, > + union epoll_ref ref, uint32_t events, > + const struct timespec *now) > { > const socklen_t sasize =3D sizeof(udp_meta[0].s_in); > int n, i; > @@ -630,7 +618,21 @@ void udp_listen_sock_handler(const struct ctx *c, un= ion epoll_ref ref, > } > =20 > /** > - * udp_reply_sock_handler() - Handle new data from flow specific socket > + * udp_listen_sock_handler() - Handle new data from socket > + * @c: Execution context > + * @ref: epoll reference > + * @events: epoll events bitmap > + * @now: Current timestamp > + */ > +void udp_listen_sock_handler(const struct ctx *c, > + union epoll_ref ref, uint32_t events, > + const struct timespec *now) > +{ > + udp_buf_listen_sock_handler(c, ref, events, now); > +} > + > +/** > + * udp_buf_reply_sock_handler() - Handle new data from flow specific soc= ket > * @c: Execution context > * @ref: epoll reference > * @events: epoll events bitmap > @@ -638,8 +640,9 @@ void udp_listen_sock_handler(const struct ctx *c, uni= on epoll_ref ref, > * > * #syscalls recvmmsg > */ > -void udp_reply_sock_handler(const struct ctx *c, union epoll_ref ref, > - uint32_t events, const struct timespec *now) > +static void udp_buf_reply_sock_handler(const struct ctx *c, union epoll_= ref ref, > + uint32_t events, > + const struct timespec *now) > { > flow_sidx_t tosidx =3D flow_sidx_opposite(ref.flowside); > const struct flowside *toside =3D flowside_at_sidx(tosidx); > @@ -684,6 +687,19 @@ void udp_reply_sock_handler(const struct ctx *c, uni= on epoll_ref ref, > } > } > =20 > +/** > + * udp_reply_sock_handler() - Handle new data from flow specific socket > + * @c: Execution context > + * @ref: epoll reference > + * @events: epoll events bitmap > + * @now: Current timestamp > + */ > +void udp_reply_sock_handler(const struct ctx *c, union epoll_ref ref, > + uint32_t events, const struct timespec *now) > +{ > + udp_buf_reply_sock_handler(c, ref, events, now); > +} > + > /** > * udp_tap_handler() - Handle packets from tap > * @c: Execution context > diff --git a/udp_internal.h b/udp_internal.h > new file mode 100644 > index 000000000000..cc80e3055423 > --- /dev/null > +++ b/udp_internal.h > @@ -0,0 +1,34 @@ > +/* SPDX-License-Identifier: GPL-2.0-or-later > + * Copyright (c) 2021 Red Hat GmbH > + * Author: Stefano Brivio > + */ > + > +#ifndef UDP_INTERNAL_H > +#define UDP_INTERNAL_H > + > +#include "tap.h" /* needed by udp_meta_t */ > + > +#define UDP_MAX_FRAMES 32 /* max # of frames to receive at once */ > + > +/** > + * 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 > + > +size_t udp_update_hdr4(struct iphdr *ip4h, struct udp_payload_t *bp, > + const struct flowside *toside, size_t dlen, > + bool no_udp_csum); > +size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct udp_payload_t *bp, > + const struct flowside *toside, size_t dlen, > + bool no_udp_csum); > +int udp_sock_errs(const struct ctx *c, int s, uint32_t events); > +#endif /* UDP_INTERNAL_H */ --=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 --jgevnAu91xhSyzKo Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmcMnhIACgkQzQJF27ox 2Gf61BAAoVHO++jnp1vp6BIlwfGvUhDaiwN57e1nM6iEAiEkFRH/MmrQQjyux1Al /9+24XoeJCqhcjPd1r+/r2pbIrRa/M43xfSWQwbOfU+/sCv12p00Ke/CQFqpLFyK VXZMNM5F304X+n5QGpxItaa7cGmxZrbvZPiOBeCGE9v34a1oFForvtdb63eRwO8v HNnAlN5Mx/6Zp+L1p8GtFTc0Og6e8birT0Fa70l/PRh9P+MtplD/fr2XxTq6p2mP qIgo1PFVT48IJLxHLwmGQ6i+NWt5Vh/H/LkpIm2GLfyCe7NFriHKFvjJIm7omXQn y1OZATG+V3Z2Sj1MwAoQN7GvaNeMjqDGjo3+cxIO69dup6fzi6MxrC/zThg2OWck nStE9it2XQ4uqNBWFmRJRr1TpGek008QkX8YrXgM1iI+6K9bCLlBnMHsqkfwwD9+ P/zlbvN3XyLlbH0hwSytTtWaPiwmPqi+jWV03SJMgjqx4Ehy+Lx460uTRaG7Dvxy TisdQ64Lvx2u9j/007NUH4KqXZ1uyeRqaGaVxlFbKvkmO7eqbGt1/r7mw5lVTkJP ClFWATt1e/dfUfSv246aNwib0HxbKXQTFBTwc9YpFaEqcvXyi4CRXVSrBIrB1y5A P0rqAT9THN5bykhIs73oPMl1QEK+51ZLwZf3/LmrqmDGXYdFcQI= =vbra -----END PGP SIGNATURE----- --jgevnAu91xhSyzKo--