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 14C245A005E for ; Wed, 14 Dec 2022 02:47:34 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4NWyst3PsXz4xvT; 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=BuLPQrloyRIqsWJaDA22lwigyd5W8TUYtS/o0GhCgPs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Zvubu4Viovy/xCM81RIfzRRfltaqUO3akFYCUsjRLatLsGr+5OmNhMX1lUfMTnXEc 2F8iX+dlWmM2nCd3rf0lbjjfW5jkDI2fjmIcQQvxvmG9DcmvIhN/P6wOvLIPLvGEf+ Db61FxvaPvkMQ0DF4V+R+zWncfxpwP5TNC8oFISQ= Date: Wed, 14 Dec 2022 12:47:25 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 7/8] udp: Decide whether to "splice" per datagram rather than per socket Message-ID: References: <20221205081425.2614425-1-david@gibson.dropbear.id.au> <20221205081425.2614425-8-david@gibson.dropbear.id.au> <20221213234918.0b51893d@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="WoKMCzVYBe5BBlc2" Content-Disposition: inline In-Reply-To: <20221213234918.0b51893d@elisabeth> Message-ID-Hash: GIROT7FTV65JHSCI7VYP4EYT645OIBTN X-Message-ID-Hash: GIROT7FTV65JHSCI7VYP4EYT645OIBTN 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: --WoKMCzVYBe5BBlc2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Dec 13, 2022 at 11:49:18PM +0100, Stefano Brivio wrote: > On Mon, 5 Dec 2022 19:14:24 +1100 > David Gibson wrote: >=20 > > Currently we have special sockets for receiving datagrams from locahost > > which can use the optimized "splice" path rather than going across the = tap > > interface. > >=20 > > We want to loosen this so that sockets can receive sockets that will be > > forwarded by both the spliced and non-spliced paths. To do this, we al= ter > > the meaning of the @splice bit in the reference to mean that packets > > receieved on this socket *can* be spliced, not that they *will* be spli= ced. > > They'll only actually be spliced if they come from 127.0.0.1 or ::1. > >=20 > > We can't (for now) remove the splice bit entirely, unlike with TCP. Our > > gateway mapping means that if the ns initiates communication to the gw > > address, we'll translate that to target 127.0.0.1 on the host side. Re= ply > > packets will therefore have source address 127.0.0.1 when received on t= he > > host, but these need to go via the tap path where that will be translat= ed > > back to the gateway address. We need the @splice bit to distinguish th= at > > case from packets going from localhost to a port mapped explicitly with > > -u which should be spliced. > >=20 > > Signed-off-by: David Gibson > > --- > > udp.c | 54 +++++++++++++++++++++++++++++++++++------------------- > > udp.h | 2 +- > > 2 files changed, 36 insertions(+), 20 deletions(-) > >=20 > > diff --git a/udp.c b/udp.c > > index 6ccfe8c..011a157 100644 > > --- a/udp.c > > +++ b/udp.c > > @@ -513,16 +513,27 @@ static int udp_splice_new_ns(void *arg) > > } > > =20 > > /** > > - * sa_port() - Determine port from a sockaddr_in or sockaddr_in6 > > + * udp_mmh_splice_port() - Is source address of message suitable for s= plicing? > > * @v6: Is @sa a sockaddr_in6 (otherwise sockaddr_in)? > > - * @sa: Pointer to either sockaddr_in or sockaddr_in6 > > + * @mmh: mmsghdr of incoming message > > + * > > + * Return: if @sa refers to localhost (127.0.0.1 or ::1) the port from > > + * @sa, otherwise 0. > > + * > > + * NOTE: this relies on the fact that it's not valid to use UDP port 0 >=20 > The port is reserved by IANA indeed, but... it can actually be used. On > Linux, you can bind() it and you can connect() to it. As far as I can > tell from the new version of udp_sock_handler() we would actually > misdirect packets in that case. Hm, ok. Given the IANA reservation, I think it would be acceptable to simply drop such packets - but if we were to make that choice we should do so explicitly, rather than misdirecting them. > How bad would it be to use an int here? Pretty straightforward. Just means we have to use the somewhat abtruse "if (port <=3D USHRT_MAX)" or "if (port >=3D 0)" or something instead of just "if (port)". Should I go ahead and make that change? > By the way, I think the comment should also mention that the port is > returned in host order. Ok, easily done. Generally I try to keep the endianness associated with the type, rather than attempting to document it for each variable (or even worse, each point in time for each variable). --=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 --WoKMCzVYBe5BBlc2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoULxWu4/Ws0dB+XtgypY4gEwYSIFAmOZKyYACgkQgypY4gEw YSKs+Q/9HsdLdpmCaI0HEmVbcV09HUGyTv4swqPBVzsVeQWoEWP9O+8e59DdhWxT DKxjLCaw3NdBrmS3SmFFpz3tj4veJxopg0QsqgAME6u2gzZivz9/QHoUdDFkVach q2x4vYbMzQTw6XYjWxBtfqwkqd1DJQlnyh/xHlSGNmds28L0vIbq/0CqefpdlYoo 6yW0Hce8i5co5eQu3MIV1kKmngWovq00bkcMTDlVcR/eOViXDDR7MLTwZbnlNQ3u 89h8WL+1My5qEg6k9Ofa/nVlWwk/hNRrhmItcmVOYBYNT577MeFpWE7ouYhdqmEm t4I29+vf84V5BAkth3sSKfkHaY3Y4p3Fkw6dh61RRsa4UA88A1YtQpu+5MLqFjGF 5mz7uSKvQaObtm/GF9epWHhnKQvyime6+3U8x/zQx0J2Ww47vh87rh0OoQ6mc1AK PUSqzzyCvWeOGyxV39ol2NXjOB/JGa1s7weMrrxnFrWuoPzUtQ8CBPzr7fcgDcvG kWJe6jCDHmdKyO6cuNmFBKAl0D87iN6rnC6hzTnqPGY42GZu9pFlB42MtybN5Nni VIAS8LOeZYH0Sjurv4aQMxyqPI6zxpc/NLr6j1VyGcjoysT6bk2okiGAnzjMwjZ0 fqQ6W39XMfC1AQHY8VvQRd4+aSyj40dFnig3vuRo2BruTIoVUDQ= =m6Zj -----END PGP SIGNATURE----- --WoKMCzVYBe5BBlc2--