From: David Gibson <david@gibson.dropbear.id.au>
To: Laurent Vivier <lvivier@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH v5 3/5] checksum: Add an offset argument in csum_iov()
Date: Mon, 30 Sep 2024 12:51:30 +1000 [thread overview]
Message-ID: <ZvoSMjj4ro81H-MS@zatzit.fritz.box> (raw)
In-Reply-To: <20240927135349.675850-4-lvivier@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2781 bytes --]
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.
>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>
> Notes:
> v5:
> - correctly set the length for the partial csum_unfolded()
> v3:
> - reorder @offset and @init
> v2:
> - check iov_skip_bytes() return value
>
> checksum.c | 16 ++++++++++++++--
> checksum.h | 3 ++-
> 2 files changed, 16 insertions(+), 3 deletions(-)
>
> 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"
>
> /* 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;
>
> - for (i = 0; i < n; i++)
> + i = iov_skip_bytes(iov, n, offset, &first);
> + if (i >= n)
> + return (uint16_t)~csum_fold(init);
> +
> + init = csum_unfolded((char *)iov[i].iov_base + first,
> + iov[i].iov_len - first, init);
> + i++;
> +
> + for (; i < n; i++)
> init = csum_unfolded(iov[i].iov_base, iov[i].iov_len, init);
>
> 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);
>
> #endif /* CHECKSUM_H */
--
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2024-09-30 4:24 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-27 13:53 [PATCH v5 0/5] tcp: use csum_iov() in tcp_update_check_tcp[4|6]() Laurent Vivier
2024-09-27 13:53 ` [PATCH v5 1/5] tcp: Use tcp_payload_t rather than tcphdr Laurent Vivier
2024-09-27 13:53 ` [PATCH v5 2/5] pcap: Add an offset argument in pcap_iov() Laurent Vivier
2024-09-27 13:53 ` [PATCH v5 3/5] checksum: Add an offset argument in csum_iov() Laurent Vivier
2024-09-30 2:51 ` David Gibson [this message]
2024-09-27 13:53 ` [PATCH v5 4/5] tcp: Update TCP checksum using an iovec array Laurent Vivier
2024-09-30 2:56 ` David Gibson
2024-10-01 7:29 ` Stefano Brivio
2024-10-01 18:22 ` Stefano Brivio
2024-10-02 7:39 ` Laurent Vivier
2024-10-02 9:00 ` Stefano Brivio
2024-10-03 12:58 ` Laurent Vivier
2024-09-27 13:53 ` [PATCH v5 5/5] udp: Update UDP " Laurent Vivier
2024-09-30 2:58 ` David Gibson
2024-10-02 14:32 ` [PATCH v5 0/5] tcp: use csum_iov() in tcp_update_check_tcp[4|6]() Stefano Brivio
2024-10-02 14:46 ` Stefano Brivio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZvoSMjj4ro81H-MS@zatzit.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=lvivier@redhat.com \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).