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=dnvh6WY0; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id E976F5A004C for ; Mon, 30 Sep 2024 06:24:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202408; t=1727670274; bh=6UAqLvlBzkkNSvzZIPDervY1GGoeGYZqWEquEl1XVug=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dnvh6WY0EI7iIDE6Y2hZ+L0gNR7treOLSl7ljIexoQtWPp02oPsAcac+LyRNdf8u9 hyZPgCA3jrkZ0hZ/Nyn0lvX8iCHsOw29+fkm+oCAq38C8XPAcfSTAW/RkiCksazsPz sKN8lOfLAGI0al9dcCM5M1R3rlmLDc+gZBQCB7c60DrmX9RJ4/egOO/BNXmRr9s8/T shCirnj2/4UBbtlxo4TnCN+QFfJSr16e0sVodiDoGwaYJSqiGT65MUQhsQgpAU7HVp ANw6suWPdErYl0U0R8uAbmCdTBOv+Sx4F4ZnK8Q+t9W4Zn5iGMOgTXcwneQlzsyotu 8BPZBcwyuE7Kw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4XH7JL4sNdz4wc3; Mon, 30 Sep 2024 14:24:34 +1000 (AEST) Date: Mon, 30 Sep 2024 12:51:30 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v5 3/5] checksum: Add an offset argument in csum_iov() Message-ID: References: <20240927135349.675850-1-lvivier@redhat.com> <20240927135349.675850-4-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="OV6ZY5MMCv3S33C/" Content-Disposition: inline In-Reply-To: <20240927135349.675850-4-lvivier@redhat.com> Message-ID-Hash: LN67JIXKFYB3NIOSKVYEGYUP2V7HFPMQ X-Message-ID-Hash: LN67JIXKFYB3NIOSKVYEGYUP2V7HFPMQ 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: --OV6ZY5MMCv3S33C/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Sep 27, 2024 at 03:53:47PM +0200, Laurent Vivier wrote: > The offset allows any headers that are not part of the data > to checksum to be skipped. >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson > --- >=20 > Notes: > v5: > - correctly set the length for the partial csum_unfolded() > v3: > - reorder @offset and @init > v2: > - check iov_skip_bytes() return value >=20 > checksum.c | 16 ++++++++++++++-- > checksum.h | 3 ++- > 2 files changed, 16 insertions(+), 3 deletions(-) >=20 > diff --git a/checksum.c b/checksum.c > index 006614fcbb28..05d002ab0c25 100644 > --- a/checksum.c > +++ b/checksum.c > @@ -59,6 +59,7 @@ > #include "util.h" > #include "ip.h" > #include "checksum.h" > +#include "iov.h" > =20 > /* Checksums are optional for UDP over IPv4, so we usually just set > * them to 0. Change this to 1 to calculate real UDP over IPv4 > @@ -497,16 +498,27 @@ uint16_t csum(const void *buf, size_t len, uint32_t= init) > * > * @iov Pointer to the array of IO vectors > * @n Length of the array > + * @offset: Offset of the data to checksum within the full data length > * @init Initial 32-bit checksum, 0 for no pre-computed checksum > * > * Return: 16-bit folded, complemented checksum > */ > /* cppcheck-suppress unusedFunction */ > -uint16_t csum_iov(const struct iovec *iov, size_t n, uint32_t init) > +uint16_t csum_iov(const struct iovec *iov, size_t n, size_t offset, > + uint32_t init) > { > unsigned int i; > + size_t first; > =20 > - for (i =3D 0; i < n; i++) > + i =3D iov_skip_bytes(iov, n, offset, &first); > + if (i >=3D n) > + return (uint16_t)~csum_fold(init); > + > + init =3D csum_unfolded((char *)iov[i].iov_base + first, > + iov[i].iov_len - first, init); > + i++; > + > + for (; i < n; i++) > init =3D csum_unfolded(iov[i].iov_base, iov[i].iov_len, init); > =20 > return (uint16_t)~csum_fold(init); > diff --git a/checksum.h b/checksum.h > index c5964ac78921..49f7472dd1b6 100644 > --- a/checksum.h > +++ b/checksum.h > @@ -32,6 +32,7 @@ void csum_icmp6(struct icmp6hdr *icmp6hr, > const void *payload, size_t dlen); > uint32_t csum_unfolded(const void *buf, size_t len, uint32_t init); > uint16_t csum(const void *buf, size_t len, uint32_t init); > -uint16_t csum_iov(const struct iovec *iov, size_t n, uint32_t init); > +uint16_t csum_iov(const struct iovec *iov, size_t n, size_t offset, > + uint32_t init); > =20 > #endif /* CHECKSUM_H */ --=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 --OV6ZY5MMCv3S33C/ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmb6EhgACgkQzQJF27ox 2Gfblg//SUWgiVnHfz2+r3M1eRBSjY3/3S29dhZY0JeVpnbQw+ElbLshMokY3rdr J7VRr3fhLbuJw13VDGoWl7hwSXqN0/U7uYjpY17Z4jeiz04T4INdvuaiK8nrczSw 8QcEodTEZIyWPBVsJV5r5f0wAp6CgPPwNejd2wtgD1yUtRC5P5bIAD8OFhEBgkGC 4jwKMMH2Nf4NwjqMF2EzOBr4slx8b2tj6epUjTVlJ0lroOpClxHhql/HijI/tiPA Aw8FL53Gypt1NrDCCwAE07mNDTcUvtMmHH8+ykGXmwDd5zMgGu4OmWINWEehEUX7 tmUEdQCM2VG67y/ZW8oYjZ/EXLYCsYF8Qngke4qRUbTdfyLeo2QmCZYt8k6ejw2+ qODSJCQ3jTw3kX8OK5H9K6PoUZSSqVrm84r7t/BmNU/b6iIMI0CC7XJ0KR6wDZte rMAIUbOEimJ3Z357uv/oQz6ZhGSUSWEfoM3VtYz3uFzYX0amW209u1/ILs/z7qXE iUA/62T2IlZMDrUAOzF3NE9UyzB5a1b6aVZeHYIe3OMvZlzAwOznpTEtVoBSBVXe eATxYsE0GyEcU4f+qTSkHQdil66wdKmep9/qxWO/laA1UYBCkZ6jLc608Ee4YOqp r6ku+rrSnA/cUnLm9D+v4R2XDtuTOtYt14vF3hLxTYLdi/3/2GQ= =yYUH -----END PGP SIGNATURE----- --OV6ZY5MMCv3S33C/--