From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 322785A0050 for ; Fri, 14 Jun 2024 03:10:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1718327396; bh=1mW4Z+3eF9uikOtckLyp+dtc4QHQia9AgSaSuQfIDsc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=j+/ymNvN8YExfVoCOmGIJfGuUe3Z/+aONkT4EBX+ZNLjWOhXKnQXhy76P3wFGk4oN 9SuTN48eR9rDoFutl84ZIfh974F6fkgfUfI4zJ/x3maO+K58f8aNrGCSvd+ORwicFo mV/RIE69+3btgaMseX03W/ccxcs9RPYLTlU/AuDUfq6nWnNj0hx3dm+JPZ/wlg3UDI 1T4y/ASuNfyXhUGilXzUMG4S+Ck7pPYVVd6AVNUVSgQf2p/q5/xWA4+1Z0s02su3H2 NXKDTW8jEPLOr9iOulPvEh0wfRqEYtUkStTceQSTtoMSlAjro9vNl26gtsUjMx3SEU dbsNgsiI9mtDg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4W0h5c6rHHz4wc4; Fri, 14 Jun 2024 11:09:56 +1000 (AEST) Date: Fri, 14 Jun 2024 10:50:38 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 2/4] udp: Fold checking of splice flag into udp_mmh_splice_port() Message-ID: References: <20240605013903.3694452-1-david@gibson.dropbear.id.au> <20240605013903.3694452-3-david@gibson.dropbear.id.au> <20240613170654.4a2b9731@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="4g0mkOvJbe4gCIgm" Content-Disposition: inline In-Reply-To: <20240613170654.4a2b9731@elisabeth> Message-ID-Hash: X46V4FNTJBZEF3THDMVVJ6YOBO73MXEV X-Message-ID-Hash: X46V4FNTJBZEF3THDMVVJ6YOBO73MXEV 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: --4g0mkOvJbe4gCIgm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jun 13, 2024 at 05:06:54PM +0200, Stefano Brivio wrote: > On Wed, 5 Jun 2024 11:39:01 +1000 > David Gibson wrote: >=20 > > udp_mmh_splice_port() is used to determine if a UDP datagram can be > > "spliced" (forwarded via a socket instead of tap). We only invoke it if > > the origin socket has the 'splice' flag set. > >=20 > > Fold the checking of the flag into the helper itself, which makes the > > caller simpler. It does mean we have a loop looking for a batch of > > spliceable or non-spliceable packets even in the case where the flag is > > clear. This shouldn't be that expensive though, since each call to > > udp_mmh_splice_port() will return without accessing memory in that case. > > In any case we're going to need a similar loop in more cases with upcom= ing > > flow table work. > >=20 > > Signed-off-by: David Gibson > > --- > > udp.c | 31 ++++++++++++++++--------------- > > 1 file changed, 16 insertions(+), 15 deletions(-) > >=20 > > diff --git a/udp.c b/udp.c > > index 3abafc99..7487d2b2 100644 > > --- a/udp.c > > +++ b/udp.c > > @@ -467,21 +467,25 @@ static int udp_splice_new_ns(void *arg) > > =20 > > /** > > * udp_mmh_splice_port() - Is source address of message suitable for s= plicing? > > - * @v6: Is @sa a sockaddr_in6 (otherwise sockaddr_in)? > > + * @uref: UDP epoll reference for incoming message's origin socket > > * @mmh: mmsghdr of incoming message > > * > > - * Return: if @sa refers to localhost (127.0.0.1 or ::1) the port from > > - * @sa in host order, otherwise -1. > > + * Return: if source address of message in @mmh refers to localhost (1= 27.0.0.1 >=20 > Pre-existing, and I guess this might change again with the complete > flow table implementation, so it probably doesn't make sense to fix > this now: it's 127.0.0.0/8, not necessarily 127.0.0.1. Right. In fact this function will go away entirely with the flow table. > As to whether we actually need to preserve a source address that's not > 127.0.0.1, but in 127.0.0.0/8, as we "splice", I'm not quite sure. I > think we could bind() the socket in the target namespace, but I haven't > tried, and I don't know if it makes sense at all (I can't think of any > use case). So, how to handle 127.0.0.0/8 is something I'm actively thinking about. It should be much easier to tweak this with the flow table in place. > > + * or ::1) its source port (host order), otherwise -1. > > */ > > -static int udp_mmh_splice_port(bool v6, const struct mmsghdr *mmh) > > +static int udp_mmh_splice_port(union udp_epoll_ref uref, > > + const struct mmsghdr *mmh) > > { > > const struct sockaddr_in6 *sa6 =3D mmh->msg_hdr.msg_name; > > const struct sockaddr_in *sa4 =3D mmh->msg_hdr.msg_name; > > =20 > > - if (v6 && IN6_IS_ADDR_LOOPBACK(&sa6->sin6_addr)) > > + if (!uref.splice) > > + return -1; > > + > > + if (uref.v6 && IN6_IS_ADDR_LOOPBACK(&sa6->sin6_addr)) > > return ntohs(sa6->sin6_port); > > =20 > > - if (!v6 && IN4_IS_ADDR_LOOPBACK(&sa4->sin_addr)) > > + if (!uref.v6 && IN4_IS_ADDR_LOOPBACK(&sa4->sin_addr)) > > return ntohs(sa4->sin_port); > > =20 > > return -1; > > @@ -768,18 +772,15 @@ void udp_sock_handler(const struct ctx *c, union = epoll_ref ref, uint32_t events, >=20 > (now renamed to udp_buf_sock_handler() if you're wondering) >=20 > > =20 > > for (i =3D 0; i < n; i +=3D m) { > > int splicefrom =3D -1; > > - m =3D n; > > =20 > > - if (ref.udp.splice) { > > - splicefrom =3D udp_mmh_splice_port(v6, mmh_recv + i); > > + splicefrom =3D udp_mmh_splice_port(ref.udp, mmh_recv + i); > > =20 > > - for (m =3D 1; i + m < n; m++) { > > - int p; > > + for (m =3D 1; i + m < n; m++) { > > + int p; > > =20 > > - p =3D udp_mmh_splice_port(v6, mmh_recv + i + m); > > - if (p !=3D splicefrom) > > - break; > > - } > > + p =3D udp_mmh_splice_port(ref.udp, mmh_recv + i + m); > > + if (p !=3D splicefrom) > > + break; > > } > > =20 > > if (splicefrom >=3D 0) >=20 --=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 --4g0mkOvJbe4gCIgm Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmZrk90ACgkQzQJF27ox 2GcpdA//VLtUDimASfBfHtT6HPMH/2aejb+yW0877M/3hJpZyW8Aibg7RhORDbaK Hts7YCny1wSECrsz3V8ZR+EWQRMJpgrWap/Alb79GoKYAhyPKsgCrSEj13n3hPOY qMsmBN0QsqrkKFPwI6rOhHT3xFrwb3RA9DtbyTOXFiiZm9hKAS5CyKywSS1SA5Lg shQBUc6n7cV61TjjoYz2lp1DPJYsUl24GLomhnf+5RWRoYGKAP1useipfAUnXRUt 3FXu5YQjfEPvI2KL4j9XjgJsVAehmJznPhoDv7wE0704JoxksJry35khn2nHuE9q 0RY9rjNh/c1FE/T/5XrAEHYqtWeQj+T5ABqChzpn0mriysyshsLMqKCDmAujC2t0 3e+bYBcRVcourmkNZ8yGoYakD372Oh3unzDGCtjCddxBgRHOCPxDx8UCkiXYmvCZ hybxofxmgUd1XyRWaKXZ/kfwIyToBGh4lpPxuOw28XcFr/ue+2xlaoMruPzH77fq MpMUFPQW3NQTWmBPVX717O9/NdlmHh8a/u9QL/pSSNEMte/h2RDyH/Zoon2LCUhN LDsyr9jI3zyKVMuAVX7NyCud40tzsDjXOjT4LX2EqHn7hpY4Zz7O/Ngf/JrYcvaG NKGeIWbY5J7IW+f4bRZxplru10Z3SWdZOVN001yayTr309RdnQI= =MrQK -----END PGP SIGNATURE----- --4g0mkOvJbe4gCIgm--