From mboxrd@z Thu Jan  1 00:00:00 1970
Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com
Authentication-Results: passt.top;
	dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bu6t5mDe;
	dkim-atps=neutral
Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124])
	by passt.top (Postfix) with ESMTP id 3B07C5A0262
	for <passt-dev@passt.top>; Tue, 24 Sep 2024 17:46:54 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
	s=mimecast20190719; t=1727192813;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=yZ/JiApAtiQfPgOj5tS4HoCwYeFWuGUJ0y+88aug7mw=;
	b=bu6t5mDe+WenjISQt77dJqolSF5XPP64C5Vysw3rCG6pIV0aomqpt2dLtSZgRJv7PskY7d
	VQBENe8QhsngVhPCcsJE4RZR17iVDGdGqAzecjqPxzc2AFW55vqTF8sgcqqgNt+zgeqpbI
	t9Q6N/R2viRx3A/K6s7afF6EPNiq8x4=
Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com
 (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by
 relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,
 cipher=TLS_AES_256_GCM_SHA384) id us-mta-111-zOKS1C9FNAals6y7TcEsAg-1; Tue,
 24 Sep 2024 11:46:51 -0400
X-MC-Unique: zOKS1C9FNAals6y7TcEsAg-1
Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.17])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7194C196C42B
	for <passt-dev@passt.top>; Tue, 24 Sep 2024 15:46:50 +0000 (UTC)
Received: from lenovo-t14s.redhat.com (unknown [10.39.192.244])
	by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7A7CC1956053;
	Tue, 24 Sep 2024 15:46:49 +0000 (UTC)
From: Laurent Vivier <lvivier@redhat.com>
To: passt-dev@passt.top
Subject: [PATCH 3/4] checksum: Add an offset argument in csum_iov()
Date: Tue, 24 Sep 2024 17:46:41 +0200
Message-ID: <20240924154642.182857-4-lvivier@redhat.com>
In-Reply-To: <20240924154642.182857-1-lvivier@redhat.com>
References: <20240924154642.182857-1-lvivier@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset="US-ASCII"; x-default=true
Message-ID-Hash: OJIV4ILFL62FHBRW4O2TJBPJJLQVVSFF
X-Message-ID-Hash: OJIV4ILFL62FHBRW4O2TJBPJJLQVVSFF
X-MailFrom: lvivier@redhat.com
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: Laurent Vivier <lvivier@redhat.com>
X-Mailman-Version: 3.3.8
Precedence: list
List-Id: Development discussion and patches for passt <passt-dev.passt.top>
Archived-At: <https://archives.passt.top/passt-dev/20240924154642.182857-4-lvivier@redhat.com/>
Archived-At: <https://passt.top/hyperkitty/list/passt-dev@passt.top/message/OJIV4ILFL62FHBRW4O2TJBPJJLQVVSFF/>
List-Archive: <https://archives.passt.top/passt-dev/>
List-Archive: <https://passt.top/hyperkitty/list/passt-dev@passt.top/>
List-Help: <mailto:passt-dev-request@passt.top?subject=help>
List-Owner: <mailto:passt-dev-owner@passt.top>
List-Post: <mailto:passt-dev@passt.top>
List-Subscribe: <mailto:passt-dev-join@passt.top>
List-Unsubscribe: <mailto:passt-dev-leave@passt.top>

The offset allows any headers are that are not part
of the data to checksum to be skipped.

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 checksum.c | 13 +++++++++++--
 checksum.h |  3 ++-
 2 files changed, 13 insertions(+), 3 deletions(-)

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"
 
 /* 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;
 
-	for (i = 0; i < n; i++)
+	i = iov_skip_bytes(iov, n, offset, &first);
+	init = csum_unfolded((char *)iov[i].iov_base + first,
+			     iov[i].iov_len, 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 */
-- 
2.46.0