From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 6A90B5A0268 for ; Wed, 14 Dec 2022 02:47:36 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4NWyst35cHz4xYV; Wed, 14 Dec 2022 12:47:30 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1670982450; bh=2PhEdlvvGHp+EbiUhCLgH6G24MxGl9xL8ypTUn8C9R4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KAeKkKWdqjjrOVzVrjg7/BI8WKwfqaMb7gCgeB0TBafmbRl4X43oZXy6jISItKDxe ZoKqTctP6W4UTuyRcOV9Jdi2zPZfaWYATOtQnv02b2mFHN3OrpUT+hooPJyYgMYpnv FsjIxZA5ib6sokQL0uysY0DIzxJ2nhSFHZHcicOg= Date: Wed, 14 Dec 2022 12:19:14 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 6/8] udp: Unify udp_sock_handler_splice() with udp_sock_handler() Message-ID: References: <20221205081425.2614425-1-david@gibson.dropbear.id.au> <20221205081425.2614425-7-david@gibson.dropbear.id.au> <20221213234858.474602c1@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="rujO36dVU09W/LYw" Content-Disposition: inline In-Reply-To: <20221213234858.474602c1@elisabeth> Message-ID-Hash: 3ZM5ZWNIEYCVAW6DWAN5NRMWSCLTQUNQ X-Message-ID-Hash: 3ZM5ZWNIEYCVAW6DWAN5NRMWSCLTQUNQ 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.3 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: --rujO36dVU09W/LYw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Dec 13, 2022 at 11:48:58PM +0100, Stefano Brivio wrote: > On Mon, 5 Dec 2022 19:14:23 +1100 > David Gibson wrote: >=20 > > These two functions now have a very similar structure, and their first > > part (calling recvmmsg()) is functionally identical. So, merge the two > > functions into one. > >=20 > > Signed-off-by: David Gibson > > --- > > udp.c | 86 +++++++++++++++++++---------------------------------------- > > 1 file changed, 28 insertions(+), 58 deletions(-) > >=20 > > diff --git a/udp.c b/udp.c > > index 7c601cc..6ccfe8c 100644 > > --- a/udp.c > > +++ b/udp.c > > @@ -590,52 +590,6 @@ static void udp_splice_sendfrom(const struct ctx *= c, unsigned start, unsigned n, > > sendmmsg(s, mmh_send + start, n, MSG_NOSIGNAL); > > } > > =20 > > -/** > > - * udp_sock_handler_splice() - Handler for socket mapped to "spliced" = connection > > - * @c: Execution context > > - * @ref: epoll reference > > - * @events: epoll events bitmap > > - * @now: Current timestamp > > - */ > > -static void udp_sock_handler_splice(const struct ctx *c, union epoll_r= ef ref, > > - uint32_t events, const struct timespec *now) > > -{ > > - in_port_t dst =3D ref.r.p.udp.udp.port; > > - int v6 =3D ref.r.p.udp.udp.v6, n, i, m; > > - struct mmsghdr *mmh_recv; > > - > > - if (!(events & EPOLLIN)) > > - return; > > - > > - if (v6) > > - mmh_recv =3D udp6_l2_mh_sock; > > - else > > - mmh_recv =3D udp4_l2_mh_sock; > > - > > - n =3D recvmmsg(ref.r.s, mmh_recv, UDP_MAX_FRAMES, 0, NULL); > > - > > - if (n <=3D 0) > > - return; > > - > > - if (v6) > > - udp_localname6.sin6_port =3D htons(dst); > > - else > > - udp_localname4.sin_port =3D htons(dst); > > - > > - for (i =3D 0; i < n; i +=3D m) { > > - in_port_t src =3D sa_port(v6, mmh_recv[i].msg_hdr.msg_name); > > - > > - for (m =3D 1; i + m < n; m++) { > > - void *mname =3D mmh_recv[i + m].msg_hdr.msg_name; > > - if (sa_port(v6, mname) !=3D src) > > - break; > > - } > > - > > - udp_splice_sendfrom(c, i, m, src, dst, v6, ref.r.p.udp.udp.ns, > > - ref.r.p.udp.udp.orig, now); > > - } > > -} > > - > > /** > > * udp_update_hdr4() - Update headers for one IPv4 datagram > > * @c: Execution context > > @@ -945,27 +899,43 @@ void udp_sock_handler(const struct ctx *c, union = epoll_ref ref, uint32_t events, > > { > > in_port_t dstport =3D ref.r.p.udp.udp.port; > > bool v6 =3D ref.r.p.udp.udp.v6; > > - struct mmsghdr *sock_mmh; > > + struct mmsghdr *mmh_recv; > > + unsigned int i, m; > > ssize_t n; > > =20 > > - if (events =3D=3D EPOLLERR) > > + if (!(events & EPOLLIN)) >=20 > Pre-existing, unrelated issue, but this reminds me: we don't handle > socket errors here, and while udp_timer_one() will drop any sockets we > created, eventually, it would probably be better to act right away. Ok... I'm not sure what, if anything, you would like me to do about it, however. > Not that I have in mind a valid example of an error on UDP sockets, > except perhaps if the interface goes down (but we'll handle that > separately). --=20 David Gibson | 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 --rujO36dVU09W/LYw Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoULxWu4/Ws0dB+XtgypY4gEwYSIFAmOZJIsACgkQgypY4gEw YSJSjRAAwJaRRtNmxxr4u7xitD4CyP5JHnzmPV7yCFqz4XA/ZoDoVnPeStWoabbB 1SMZSY/VO8tyROdn7+u+/I6WHDTsywTMr/tJ3H0S/rASc0AUCL4O/N+tx3aNQksG wth+ATlA7ZlfJJ/FAASg9IV1PNR9xt/Ji9cZmyE8JMSXTYzkKOslicto/0hqQl3d 5CufpiQNSlw1Drv3N7z+YEzjAPv3yARRct9tfzWN7Lo9yz6E1UeNRTt5sKFfyHv1 uRSh/RRFJx7WbhZLkfYNgtVkQJRa0t4kx0FZRFEkHKpaxs+fD8ehatDxz+LqZeFm n1qO+qyZXopohiuoDw19rTHC050bn5AvIH/gjri3uXyFpWOxdbQAO+tdKYbRGi0v aM5GwhUMfHjYsQNJvmL/U9Nx7AzpKar9oFpdfUzyWwhFeNrDyeXlfy1nHVlUtAHx jrI9JPCg7N8/1Z/Haj4s6sIpcBTBM9KZ7SWTyqo5cwHNvMRwQe21dd9TaQmJsMrD tPMpigjWS/oYdAt335tpfcX7G7kJN41+PNPi6CYQwsYScQc4QYBNnBQGZBdH+dMz aLuaJjlbo0w/tz0uXx7MvRnW07a+HtJt8AHTsr7xe2NsIJi+MFJTKEUaLF97SEM+ B/BqE8ze+aiat0CR5m4vLTJYgKjj3TL6Ol0/5cCN8hUKoOFoXBk= =A4KD -----END PGP SIGNATURE----- --rujO36dVU09W/LYw--