aboutgitcodebugslistschat
path: root/checksum.c
diff options
context:
space:
mode:
authorLaurent Vivier <lvivier@redhat.com>2024-10-03 16:51:06 +0200
committerStefano Brivio <sbrivio@redhat.com>2024-10-04 14:51:08 +0200
commite6548c643796f036de83163e395f0efd56da4790 (patch)
tree373cacbab76e3027c785815dba789652d8f11157 /checksum.c
parentfd8334b25dfa0cf4a93bb7fad6728f3bd0e31c6d (diff)
downloadpasst-e6548c643796f036de83163e395f0efd56da4790.tar
passt-e6548c643796f036de83163e395f0efd56da4790.tar.gz
passt-e6548c643796f036de83163e395f0efd56da4790.tar.bz2
passt-e6548c643796f036de83163e395f0efd56da4790.tar.lz
passt-e6548c643796f036de83163e395f0efd56da4790.tar.xz
passt-e6548c643796f036de83163e395f0efd56da4790.tar.zst
passt-e6548c643796f036de83163e395f0efd56da4790.zip
checksum: Add an offset argument in csum_iov()
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> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'checksum.c')
-rw-r--r--checksum.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/checksum.c b/checksum.c
index 006614f..05d002a 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);