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=CJZ6nJ0j; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id B48A45A004C for ; Fri, 27 Sep 2024 15:54:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727445239; 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=Bi6ZXxj3Uv0e/ZgsC4vuDvRww6HVPB/b423uLecsyWw=; b=CJZ6nJ0jPa6ertOthgGliflsMTSuzTpbOShrC4RJL0zOWBHFtnjQfZAl4GSpBOrgdkyN5t i/Yc9UkwCS0vKHFC1v6ONWnPP4lUKcB41JOddjtFeTtKk7ZfqYr//DrOWmNdyYUu+tGwYD VHUKSNJqE93PY9yvSSLdB5tlzTAZDCg= Received: from mx-prod-mc-02.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-304-oOtGctjmMDOkuccnxU4YRA-1; Fri, 27 Sep 2024 09:53:58 -0400 X-MC-Unique: oOtGctjmMDOkuccnxU4YRA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.12]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B0E3618950F3 for ; Fri, 27 Sep 2024 13:53:57 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.39.192.222]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A9A5F19541A7; Fri, 27 Sep 2024 13:53:56 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v5 3/5] checksum: Add an offset argument in csum_iov() Date: Fri, 27 Sep 2024 15:53:47 +0200 Message-ID: <20240927135349.675850-4-lvivier@redhat.com> In-Reply-To: <20240927135349.675850-1-lvivier@redhat.com> References: <20240927135349.675850-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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: X6VNSKSZA7WJ7XGWRWKBVMKTM37OPW7T X-Message-ID-Hash: X6VNSKSZA7WJ7XGWRWKBVMKTM37OPW7T 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 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: The offset allows any headers that are not part of the data to checksum to be skipped. Signed-off-by: Laurent Vivier --- 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 */ -- 2.46.0