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=slCfp/n/; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id EBA735A0262 for ; Wed, 25 Sep 2024 03:13:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202408; t=1727226789; bh=38tePVKlVC7mpDwxoMdeLfgcpM5lI2G4RFG3wiwA9Zk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=slCfp/n/mDhuygraSX11si4bzPVZcfa8vVnEbbR8G0QSC8RJuoCWeITOSb8OGfcoS rERE3DRLt9HwB0pgGVEguwFbApWWP1p4l0oqfQAZtv8eIfgZW8t03zIqBGgr1COTSK QYXPw95FxEokjMLY9GZhNBNjZhVEo54EKf/wuOX1DkNjYNxjvQ5nRzCbmRLIdbL0KT 6jQZ6PDVsvKjoRKy26bRXtgJF6QoC7lSs50ub7MLu79hhtAKmfbDxe9dcimTuaZDSk 2K59pGObIFdbSWmR9oFrqekfAN06ZRPlHvtBWqtzOMtHW16+34g0oU4PNKDAgKrqWM lz10BznuvRLZg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4XCzHn3QWPz4xPR; Wed, 25 Sep 2024 11:13:09 +1000 (AEST) Date: Wed, 25 Sep 2024 10:51:22 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH 3/4] checksum: Add an offset argument in csum_iov() Message-ID: References: <20240924154642.182857-1-lvivier@redhat.com> <20240924154642.182857-4-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="TkdFGvtp/c6Ten2A" Content-Disposition: inline In-Reply-To: <20240924154642.182857-4-lvivier@redhat.com> Message-ID-Hash: R37B74BQ4HWLKM4X3LIZJZSLZEBVKG5K X-Message-ID-Hash: R37B74BQ4HWLKM4X3LIZJZSLZEBVKG5K 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: --TkdFGvtp/c6Ten2A Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Sep 24, 2024 at 05:46:41PM +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 > --- > checksum.c | 13 +++++++++++-- > checksum.h | 3 ++- > 2 files changed, 13 insertions(+), 3 deletions(-) >=20 > diff --git a/checksum.c b/checksum.c > index 006614fcbb28..f80db4d309a2 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,23 @@ 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); Just to be safe, you should probably check for i >=3D n here: if offset is larger than the total length of the vector enough, iov_skip_bytes() will return that. > + 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 --TkdFGvtp/c6Ten2A Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmbzXoYACgkQzQJF27ox 2Gf1fhAAlW2nV15V/sqwviu52ZM4oEfaH+dD6F6By/D7ov84+vvtjwJ+ZdFUvLhS CjSk3unoUw77DUxnWAA2PiUM2lyw8MjiIdIB17Xf6MLmqP++eFqPGNouRj6d37g5 K7G0N4pf1ldN8NKPG0CCuuxp17QHHIzVB1w5ygIFb+qUB8KTQYGrL2seceZ5CLlj z9GqnQDfPRPrRNxeTNNyPYO3+l9oWCV4mFw5rEaCUeK7HkvMZWQb15akRU+8g/gB +eaCdnP+6Mx/Udp1CMuB6ev/M8g4TW9s2eC7J9HNWf1fc7VXRVHt+X5320yq7ieH AnxzYiYjCBCNh2y7ThVFxaHNLTae6Ag0kzu92rw6EWWb2j/6oEgYyjnO86iakHMt ywCb7XHGAzq7jo46R0z/PioFxBJq8CAslvujY38pZvJzN1jF0uDdGPO20Epya9N+ VZiOAmF6qX8PZsHwClmCtT317UKE+XFi8ymXI/Y1ENmFg0O2iVjkyci21P+XZNLh sB0fkz2RJWgR/JHvCq9JGI2vqr3p5vXWGRTZdmuP4kobfz79a3PrX5eQVgKDt3aY EDGcVfexdvDEJUWV37yEPdGpjmS9P2upXIv8zwKMka3pYRhdN+1Vs9x1kihsWXjM 41H+639sfdSiA1InADRVoJ/ruRVQeRqRzlf1fXP+P+Vwe0B9xPo= =pW3y -----END PGP SIGNATURE----- --TkdFGvtp/c6Ten2A--