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=202408 header.b=kUAue6qP; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id ECC8E5A0262 for ; Tue, 17 Sep 2024 03:24:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202408; t=1726536241; bh=rC/YOfvmipgQoWfpsU+q9YjrRJqMICyTkK4SQ7IlKdk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kUAue6qPtKWsXlsZYMeXTrTwgHLY0k/uoQNhMbCYkqkCObRjQLkRD1t0Tt4gx6QpI rO+s7CCbIWoP1x9JHdvFf+buSa3iUhzXEiFl4Tv9el/9FlX2QWL4m596zUfFH9vgqI Uo1H3ZppvxWTg2LcplzWruX+fZ572Y1e6OMg9KUeQh2OSholbstBz3Or4/OPDamEKF M9C96PVPhqLqTtvF6MWuBH8RN/wGkTNMCPxzasmUjAxoIazg6pV/1B/z38UlM6sc1E 5CqSat6OD0c7n1iCSlzID5uSY14f787BwsdKjgW3TEgVnt5pHlh9/spSauSX25/5fN WeMzUfh2IcOKQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4X73w10l9jz4xZl; Tue, 17 Sep 2024 11:24:01 +1000 (AEST) Date: Tue, 17 Sep 2024 11:23:00 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH 1/2] udp: Allow checksum to be disabled Message-ID: References: <20240916121601.3655517-1-lvivier@redhat.com> <20240916121601.3655517-2-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="UHMuBsBrqaOTm6op" Content-Disposition: inline In-Reply-To: <20240916121601.3655517-2-lvivier@redhat.com> Message-ID-Hash: BROCVRFT7GF6BISF67MXSJZFQK6GMN5Z X-Message-ID-Hash: BROCVRFT7GF6BISF67MXSJZFQK6GMN5Z 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: --UHMuBsBrqaOTm6op Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Sep 16, 2024 at 02:16:00PM +0200, Laurent Vivier wrote: > We can need not to set the UDP checksum. Add a parameter to > udp_update_hdr4() and udp_update_hdr6() to disable it. >=20 > Signed-off-by: Laurent Vivier > --- > udp.c | 41 +++++++++++++++++++++++++++++++---------- > 1 file changed, 31 insertions(+), 10 deletions(-) >=20 > diff --git a/udp.c b/udp.c > index 2ba00c9c20a8..64a0d9f9dba2 100644 > --- a/udp.c > +++ b/udp.c > @@ -298,11 +298,13 @@ static void udp_splice_send(const struct ctx *c, si= ze_t start, size_t n, > * @bp: Pointer to udp_payload_t to update > * @toside: Flowside for destination side > * @dlen: Length of UDP payload > + * @no_udp_csum: Do not set UPD checksum s/UPD/UDP/g :) Otherwise LGTM. > * > * 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) > + 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); > @@ -319,7 +321,10 @@ static size_t udp_update_hdr4(struct iphdr *ip4h, st= ruct udp_payload_t *bp, > bp->uh.source =3D htons(toside->oport); > bp->uh.dest =3D htons(toside->eport); > bp->uh.len =3D htons(l4len); > - csum_udp4(&bp->uh, *src, *dst, bp->data, dlen); > + if (no_udp_csum) > + bp->uh.check =3D 0; > + else > + csum_udp4(&bp->uh, *src, *dst, bp->data, dlen); > =20 > return l4len; > } > @@ -330,11 +335,13 @@ static size_t udp_update_hdr4(struct iphdr *ip4h, s= truct udp_payload_t *bp, > * @bp: Pointer to udp_payload_t to update > * @toside: Flowside for destination side > * @dlen: Length of UDP payload > + * @no_udp_csum: Do not set UPD checksum > * > * 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) > + const struct flowside *toside, size_t dlen, > + bool no_udp_csum) > { > uint16_t l4len =3D dlen + sizeof(bp->uh); > =20 > @@ -348,7 +355,16 @@ static size_t udp_update_hdr6(struct ipv6hdr *ip6h, = struct udp_payload_t *bp, > bp->uh.source =3D htons(toside->oport); > bp->uh.dest =3D htons(toside->eport); > bp->uh.len =3D ip6h->payload_len; > - csum_udp6(&bp->uh, &toside->oaddr.a6, &toside->eaddr.a6, bp->data, dlen= ); > + if (no_udp_csum) { > + /* O is an invalid checksum for UDP IPv6 and dropped by > + * the kernel stack, even if the checksum is disabled by virtio > + * flags. We need to put any non-zero value here. > + */ > + bp->uh.check =3D 0xffff; > + } else { > + csum_udp6(&bp->uh, &toside->oaddr.a6, &toside->eaddr.a6, > + bp->data, dlen); > + } > =20 > return l4len; > } > @@ -358,9 +374,11 @@ static size_t udp_update_hdr6(struct ipv6hdr *ip6h, = struct udp_payload_t *bp, > * @mmh: Receiving mmsghdr array > * @idx: Index of the datagram to prepare > * @toside: Flowside for destination side > + * @no_udp_csum: Do not set UPD checksum > */ > -static void udp_tap_prepare(const struct mmsghdr *mmh, unsigned idx, > - const struct flowside *toside) > +static void udp_tap_prepare(const struct mmsghdr *mmh, > + unsigned idx, const struct flowside *toside, > + bool no_udp_csum) > { > struct iovec (*tap_iov)[UDP_NUM_IOVS] =3D &udp_l2_iov[idx]; > struct udp_payload_t *bp =3D &udp_payload[idx]; > @@ -368,13 +386,15 @@ static void udp_tap_prepare(const struct mmsghdr *m= mh, unsigned idx, > size_t l4len; > =20 > if (!inany_v4(&toside->eaddr) || !inany_v4(&toside->oaddr)) { > - l4len =3D udp_update_hdr6(&bm->ip6h, bp, toside, mmh[idx].msg_len); > + l4len =3D udp_update_hdr6(&bm->ip6h, bp, toside, > + mmh[idx].msg_len, no_udp_csum); > tap_hdr_update(&bm->taph, l4len + sizeof(bm->ip6h) + > sizeof(udp6_eth_hdr)); > (*tap_iov)[UDP_IOV_ETH] =3D IOV_OF_LVALUE(udp6_eth_hdr); > (*tap_iov)[UDP_IOV_IP] =3D IOV_OF_LVALUE(bm->ip6h); > } else { > - l4len =3D udp_update_hdr4(&bm->ip4h, bp, toside, mmh[idx].msg_len); > + l4len =3D udp_update_hdr4(&bm->ip4h, bp, toside, > + mmh[idx].msg_len, no_udp_csum); > tap_hdr_update(&bm->taph, l4len + sizeof(bm->ip4h) + > sizeof(udp4_eth_hdr)); > (*tap_iov)[UDP_IOV_ETH] =3D IOV_OF_LVALUE(udp4_eth_hdr); > @@ -565,7 +585,8 @@ void udp_listen_sock_handler(const struct ctx *c, uni= on epoll_ref ref, > udp_splice_prepare(udp_mh_recv, i); > } else if (batchpif =3D=3D PIF_TAP) { > udp_tap_prepare(udp_mh_recv, i, > - flowside_at_sidx(batchsidx)); > + flowside_at_sidx(batchsidx), > + false); > } > =20 > if (++i >=3D n) > @@ -636,7 +657,7 @@ void udp_reply_sock_handler(const struct ctx *c, unio= n epoll_ref ref, > if (pif_is_socket(topif)) > udp_splice_prepare(udp_mh_recv, i); > else if (topif =3D=3D PIF_TAP) > - udp_tap_prepare(udp_mh_recv, i, toside); > + udp_tap_prepare(udp_mh_recv, i, toside, false); > /* Restore sockaddr length clobbered by recvmsg() */ > udp_mh_recv[i].msg_hdr.msg_namelen =3D sizeof(udp_meta[i].s_in); > } --=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 --UHMuBsBrqaOTm6op Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmbo2fMACgkQzQJF27ox 2GcjkQ//UCiIzBDqqIGBKAGmahfZwdmDS1cbFBPqvILd8o5S1+o+ilD4aMJgyXyH xYiaF0giowRJR9SLtJpjZrAe3B5WBj1L/gd8dnfNo3SYuzIoprjM0u1aaqujipxf qG9W8dzWFUtFK8BfERRDbu/flY8Kh8vHcPGIv/oy8ESnLBdyg2mGYBDvRL7LnA4t 58/MSBQx7Oz4/so7axI5r0BD0ISCw1Ed5zlg/BlQ7BPBVj9ZTUF7RsG3MBO2uywf yhtCEdc3W/GG3vO7AuWCzCBBdL3nkpZmH59SqHbusQru2yRsaYdq7yUhSf9gDdeQ ys6NX/Xp6Y0U/VxLtE0xwLWRJJKXtdIS5z7x7ZNRVP8UbX9wZ1PSGhXrAsN7CbeB e4il3UjzO6RXmyZNuoW2LWdXlXauQq2pZ8BqvFUDQQWlrOkgguiGTeCFYeiY7dGA +df049tFLPqdwSogwsdahwUekhwIeijTRwp+i74++/pxb3DaZQsk05fb/Rxl5yiZ M2wAcrLEhd7uRQiQxr4UUsbvgH4tmUOag6Y7gR7VWs7rB8Sij3so1lngIfqb7ggU WAnAkPKZAdRTUYENqjU3EkjnFe1XcsMx+tro/aYtgpYWjjN3apPnWayyO+n7S2BH wAylZ2xC3FnMaCCeXNYa+dIXH/N1qLURRBVqHRHZzz5kZefV7HU= =ZQjd -----END PGP SIGNATURE----- --UHMuBsBrqaOTm6op--