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=XrHT0hVV; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id D9F205A0262 for ; Thu, 26 Sep 2024 05:42:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202408; t=1727322125; bh=AO8ogkRLREXeDgTFss8Ti5+6XwjuyxwH8C9XHtBy99E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XrHT0hVVKehKOTm6zoc6iNNEbK7pfWmPA6re0hwx0PrejY+OUDSMFYKbgaWyNJjUv SDMBrTZFm1pTQ8bOKZYJCktv10BV5isU3j1lpeS7uZxUlVwHwXuAEJeJjI6Z0bwz7A OpXVyjvWdLi4c6Ck7/zWHOx1qE6x7UvDevbU07gk4Nff4S52nzbDf9iz/qd9I/hQza O2ZeAb205ABzVUxZr17SfDYxux9cz82v74WRFNVamZs8N2Pn/knPR8u3P59dDuBVzx 69qPJ4OyM25SXa62WtGO2iYYgyrPGZL9/EeZqb/69Ro2svF/Bbr8JkWT+gO1sGjkrG bkzn5DMNmuyHw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4XDfY907KDz4xQg; Thu, 26 Sep 2024 13:42:05 +1000 (AEST) Date: Thu, 26 Sep 2024 11:31:50 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v2 3/4] checksum: Add an offset argument in csum_iov() Message-ID: References: <20240925081125.205974-1-lvivier@redhat.com> <20240925081125.205974-4-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="dEMNpR3NN04750jx" Content-Disposition: inline In-Reply-To: <20240925081125.205974-4-lvivier@redhat.com> Message-ID-Hash: SBW2DEGVLDHIMDL57Y7QAY7MICMAM45D X-Message-ID-Hash: SBW2DEGVLDHIMDL57Y7QAY7MICMAM45D 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: --dEMNpR3NN04750jx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Sep 25, 2024 at 10:11:24AM +0200, Laurent Vivier wrote: > The offset allows any headers are that are not part > of the data to checksum to be skipped. >=20 > Signed-off-by: Laurent Vivier LGTM, with the exception of the nits that Stefano already noted. > --- >=20 > Notes: > 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..68ffaddb5bb0 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 > @@ -498,15 +499,26 @@ 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 > * @init Initial 32-bit checksum, 0 for no pre-computed checksum > + * @offset: Offset of the data to checksum within the full data length > * > * 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, 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 --dEMNpR3NN04750jx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmb0uWAACgkQzQJF27ox 2GfThg//V35EIt3p3bR9aJB5qDzVXA35GMcYjrZivQp9+vikWX1JBRD3Hize0zbU j0CrZ6dpRQWSoOnWHiPGBV0Wr5qgruwn3mQtvqvOHeklVDCO7VEozl49JRL2T7pN C/ZV8w2nVt8oh3kzVGS17qatkYLVuQRjJ9kw87QKLCfD/cXMlHE8M0CCnDUE5TYi zgkc/dSbuwn7A8OB2/qPD7158jl/apCGwqRbzv00djSY1fUjGeW9Vu4PCzYHdy/m oyVYtlKKIJVGp8YJyr+LZ6PK0rcx6XM5/98nztTIDCi43ipAe6Zv5b8oZqgOJ6oJ yewCmHsmYD/btHd9hy+V2UqLnK0ctM6SC2HPdGzM6Oj0iOtfGlzzWIW2Q0l+LwLG ST0FY1ttAa1LP7DbzmACzRD6juEpmHs82YLl3gWAFQwre8bJ9t8w4Pw8ytaH8vIC IAjyob6sAZQ53ri6FhUWz4ksz8w5ttamW1mjPckQVYJJdwgyBnuQ600TnCkqehFo +GmqBMobDZSR8AxO7x3NttYf+2e69EbalRS9kUtGaOXdOBgplQf9FpUZqu2jsoId ixyMfVtod8E4SJw8RYTaxnYs2ERNkT4OLwwv83pNP1Ga7oSrRnPWVD6WHxD7xTgV GXMXKSXSNrYohLTwrUsk93Y7MNM7bj6K7YL7nkEiKTX1Nk/gc6o= =rKgY -----END PGP SIGNATURE----- --dEMNpR3NN04750jx--