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=Sz0D/U2a; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 52E345A0262 for ; Mon, 30 Sep 2024 06:24:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202408; t=1727670274; bh=MX6d8Mqn50fZVDJRfgnYcgT4acuyQOTK2aJRvHfRwUs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Sz0D/U2ainVBCMlaevtPx61seYZ5Ro8NkldpWHsmCGeCsKMEwcA+c85GMlnBTsZye EjTap0Y079OK5a9P6l0y4MwO9ayek8hRBqFmtf6wSXq3PDX7xq0nTyargM9iil6Goi FoGAyZb36ebqxHCL0tedj1AXI55H2xzpw3UHwpX5bOir44fxTYFa6rJh+ZJwm4UloI VtCg9GtO16TN0wJSQNI4y24xkAdd6DQJguxNm4fkQ1ekaQaofg67soRPvV1345PRZg lgQnXMJ0bf4bOPaNY0+CNp6HgyABStwctXp2V6LvU8BSDPmZ+VyAbhttwKB8Erc4Ve nb4SRGkDaBE5A== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4XH7JL51lkz4wcj; Mon, 30 Sep 2024 14:24:34 +1000 (AEST) Date: Mon, 30 Sep 2024 12:58:46 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v5 5/5] udp: Update UDP checksum using an iovec array Message-ID: References: <20240927135349.675850-1-lvivier@redhat.com> <20240927135349.675850-6-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="1Swoy5N4zDPb9FUA" Content-Disposition: inline In-Reply-To: <20240927135349.675850-6-lvivier@redhat.com> Message-ID-Hash: KMWEU6FUXX2OX7CD7AEIDV6M6EKTYY3Y X-Message-ID-Hash: KMWEU6FUXX2OX7CD7AEIDV6M6EKTYY3Y 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: --1Swoy5N4zDPb9FUA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Sep 27, 2024 at 03:53:49PM +0200, Laurent Vivier wrote: > As for tcp_update_check_tcp4()/tcp_update_check_tcp6(), > change csum_udp4() and csum_udp6() to use an iovec array. >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson > --- > checksum.c | 29 ++++++++++++++++++----------- > checksum.h | 4 ++-- > tap.c | 14 +++++++++++--- > tap.h | 2 +- > udp.c | 17 +++++++++++++---- > 5 files changed, 45 insertions(+), 21 deletions(-) >=20 > diff --git a/checksum.c b/checksum.c > index cf850196cca0..c673993d6f9c 100644 > --- a/checksum.c > +++ b/checksum.c > @@ -166,22 +166,24 @@ uint32_t proto_ipv4_header_psum(uint16_t l4len, uin= t8_t protocol, > * @udp4hr: UDP header, initialised apart from checksum > * @saddr: IPv4 source address > * @daddr: IPv4 destination address > - * @payload: UDP packet payload > - * @dlen: Length of @payload (not including UDP header) > + * @iov: Pointer to the array of IO vectors > + * @iov_cnt: Length of the array > + * @offset: UDP payload offset in the iovec array > */ > void csum_udp4(struct udphdr *udp4hr, > struct in_addr saddr, struct in_addr daddr, > - const void *payload, size_t dlen) > + const struct iovec *iov, int iov_cnt, size_t offset) > { > /* UDP checksums are optional, so don't bother */ > udp4hr->check =3D 0; > =20 > if (UDP4_REAL_CHECKSUMS) { > - uint16_t l4len =3D dlen + sizeof(struct udphdr); > + uint16_t l4len =3D iov_size(iov, iov_cnt) - offset + > + sizeof(struct udphdr); > uint32_t psum =3D proto_ipv4_header_psum(l4len, IPPROTO_UDP, > saddr, daddr); > psum =3D csum_unfolded(udp4hr, sizeof(struct udphdr), psum); > - udp4hr->check =3D csum(payload, dlen, psum); > + udp4hr->check =3D csum_iov(iov, iov_cnt, offset, psum); > } > } > =20 > @@ -227,19 +229,24 @@ uint32_t proto_ipv6_header_psum(uint16_t payload_le= n, uint8_t protocol, > /** > * csum_udp6() - Calculate and set checksum for a UDP over IPv6 packet > * @udp6hr: UDP header, initialised apart from checksum > - * @payload: UDP packet payload > - * @dlen: Length of @payload (not including UDP header) > + * @saddr: Source address > + * @daddr: Destination address > + * @iov: Pointer to the array of IO vectors > + * @iov_cnt: Length of the array > + * @offset: UDP payload offset in the iovec array > */ > void csum_udp6(struct udphdr *udp6hr, > const struct in6_addr *saddr, const struct in6_addr *daddr, > - const void *payload, size_t dlen) > + const struct iovec *iov, int iov_cnt, size_t offset) > { > - uint32_t psum =3D proto_ipv6_header_psum(dlen + sizeof(struct udphdr), > - IPPROTO_UDP, saddr, daddr); > + uint16_t l4len =3D iov_size(iov, iov_cnt) - offset + > + sizeof(struct udphdr); > + uint32_t psum =3D proto_ipv6_header_psum(l4len, IPPROTO_UDP, > + saddr, daddr); > udp6hr->check =3D 0; > =20 > psum =3D csum_unfolded(udp6hr, sizeof(struct udphdr), psum); > - udp6hr->check =3D csum(payload, dlen, psum); > + udp6hr->check =3D csum_iov(iov, iov_cnt, offset, psum); > } > =20 > /** > diff --git a/checksum.h b/checksum.h > index 49f7472dd1b6..31ba322fa98c 100644 > --- a/checksum.h > +++ b/checksum.h > @@ -19,14 +19,14 @@ uint32_t proto_ipv4_header_psum(uint16_t l4len, uint8= _t protocol, > struct in_addr saddr, struct in_addr daddr); > void csum_udp4(struct udphdr *udp4hr, > struct in_addr saddr, struct in_addr daddr, > - const void *payload, size_t dlen); > + const struct iovec *iov, int iov_cnt, size_t offset); > void csum_icmp4(struct icmphdr *icmp4hr, const void *payload, size_t dle= n); > uint32_t proto_ipv6_header_psum(uint16_t payload_len, uint8_t protocol, > const struct in6_addr *saddr, > const struct in6_addr *daddr); > void csum_udp6(struct udphdr *udp6hr, > const struct in6_addr *saddr, const struct in6_addr *daddr, > - const void *payload, size_t dlen); > + const struct iovec *iov, int iov_cnt, size_t offset); > void csum_icmp6(struct icmp6hdr *icmp6hr, > const struct in6_addr *saddr, const struct in6_addr *daddr, > const void *payload, size_t dlen); > diff --git a/tap.c b/tap.c > index 41af6a6d0c85..c53a39b79e62 100644 > --- a/tap.c > +++ b/tap.c > @@ -172,11 +172,15 @@ void tap_udp4_send(const struct ctx *c, struct in_a= ddr src, in_port_t sport, > struct iphdr *ip4h =3D tap_push_l2h(c, buf, ETH_P_IP); > struct udphdr *uh =3D tap_push_ip4h(ip4h, src, dst, l4len, IPPROTO_UDP); > char *data =3D (char *)(uh + 1); > + const struct iovec iov =3D { > + .iov_base =3D (void *)in, > + .iov_len =3D dlen > + }; > =20 > uh->source =3D htons(sport); > uh->dest =3D htons(dport); > uh->len =3D htons(l4len); > - csum_udp4(uh, src, dst, in, dlen); > + csum_udp4(uh, src, dst, &iov, 1, 0); > memcpy(data, in, dlen); > =20 > tap_send_single(c, buf, dlen + (data - buf)); > @@ -247,7 +251,7 @@ static void *tap_push_ip6h(struct ipv6hdr *ip6h, > void tap_udp6_send(const struct ctx *c, > const struct in6_addr *src, in_port_t sport, > const struct in6_addr *dst, in_port_t dport, > - uint32_t flow, const void *in, size_t dlen) > + uint32_t flow, void *in, size_t dlen) > { > size_t l4len =3D dlen + sizeof(struct udphdr); > char buf[USHRT_MAX]; > @@ -255,11 +259,15 @@ void tap_udp6_send(const struct ctx *c, > struct udphdr *uh =3D tap_push_ip6h(ip6h, src, dst, > l4len, IPPROTO_UDP, flow); > char *data =3D (char *)(uh + 1); > + const struct iovec iov =3D { > + .iov_base =3D in, > + .iov_len =3D dlen > + }; > =20 > uh->source =3D htons(sport); > uh->dest =3D htons(dport); > uh->len =3D htons(l4len); > - csum_udp6(uh, src, dst, in, dlen); > + csum_udp6(uh, src, dst, &iov, 1, 0); > memcpy(data, in, dlen); > =20 > tap_send_single(c, buf, dlen + (data - buf)); > diff --git a/tap.h b/tap.h > index ec9e2acec460..85f1e8473711 100644 > --- a/tap.h > +++ b/tap.h > @@ -53,7 +53,7 @@ const struct in6_addr *tap_ip6_daddr(const struct ctx *= c, > void tap_udp6_send(const struct ctx *c, > const struct in6_addr *src, in_port_t sport, > const struct in6_addr *dst, in_port_t dport, > - uint32_t flow, const void *in, size_t dlen); > + uint32_t flow, void *in, size_t dlen); > void tap_icmp6_send(const struct ctx *c, > const struct in6_addr *src, const struct in6_addr *dst, > const void *in, size_t l4len); > diff --git a/udp.c b/udp.c > index 7b2831386db8..ac34279db253 100644 > --- a/udp.c > +++ b/udp.c > @@ -321,10 +321,15 @@ static size_t udp_update_hdr4(struct iphdr *ip4h, s= truct udp_payload_t *bp, > bp->uh.source =3D htons(toside->oport); > bp->uh.dest =3D htons(toside->eport); > bp->uh.len =3D htons(l4len); > - if (no_udp_csum) > + if (no_udp_csum) { > bp->uh.check =3D 0; > - else > - csum_udp4(&bp->uh, *src, *dst, bp->data, dlen); > + } else { > + const struct iovec iov =3D { > + .iov_base =3D bp->data, > + .iov_len =3D dlen > + }; > + csum_udp4(&bp->uh, *src, *dst, &iov, 1, 0); > + } > =20 > return l4len; > } > @@ -363,8 +368,12 @@ static size_t udp_update_hdr6(struct ipv6hdr *ip6h, = struct udp_payload_t *bp, > */ > bp->uh.check =3D 0xffff; > } else { > + const struct iovec iov =3D { > + .iov_base =3D bp->data, > + .iov_len =3D dlen > + }; > csum_udp6(&bp->uh, &toside->oaddr.a6, &toside->eaddr.a6, > - bp->data, dlen); > + &iov, 1, 0); > } > =20 > return l4len; --=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 --1Swoy5N4zDPb9FUA Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmb6E+UACgkQzQJF27ox 2GfTLhAAhurqFJ3aKoZrOCuMocOlUDlzurNbqj4fzvZXoGhWn8mD/+PCU1psxsuo s68yg/DHn6uxCtHJ0tr04ULBhd606q3PI0DYL7nXNH71w4Ukk5Ekp1gfpg8qaIGY 3srogGJHA06nDAIaH/NkzTOt3Xbst+yRCUq6dVdzDd1XcwHyRKh2GYkWdboheMVt AftMU1hDTjZqOn2uGjkZRTnL5l35f0LAdrSnhERjKAEY3SnGGIaag9foBhUTV/3X 5CKiSn+P4lyWDr6Jl5J/DuWBD1Vj5FgKvU6NKrTrMNvG31BF4+V4WoM4R3Jg3CPB JVaElbqygw0r7dDFY2qW/+l955B2Cczh+utJadD/TsTkuf+lxGxJRN3eaM+kh8JH fX1qdiakAB/kaFg3JsgGmjvfcqWRGHliRDgTKI7RBWURSqHAPzY9A5zAHjEDlFsL 45NIp2MqxZM+CPkTxRCW1nR9qRp4fIIENjrxRJ1T9tlkGWnt53V5G3B8CjCMg3eV 2HwCI2lfk4Lkh/ZZHgOPry+v+2jgeg1dn7BZpSD/1Vhvk4+lrJ7WvJ/y72/vzJyo glBQcMIzyTNl7KykSfbrp2e/p5KnhA0PvnhEQcUcrVZWZgeKmkQZwMFjTYPTsdfS p6YeEWotswNq0Z4LksBQPUo+luDHrkhCsbcHTFEOSQmWCyq45k4= =iVpU -----END PGP SIGNATURE----- --1Swoy5N4zDPb9FUA--