git: 0ef3c9162330 - stable/14 - tests: fix checksum computation

Michael Tuexen <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a744603.3c8a5.6d95edc1__2319.14606863342$1786005012$gmane$org@gitrepo.freebsd.org>
The branch stable/14 has been updated by tuexen:

URL: https://cgit.FreeBSD.org/src/commit/?id=0ef3c91623307f04102e45bcff932388bb0f4ed1

commit 0ef3c91623307f04102e45bcff932388bb0f4ed1
Author:     Michael Tuexen <[email protected]>
AuthorDate: 2026-07-01 16:07:04 +0000
Commit:     Michael Tuexen <[email protected]>
CommitDate: 2026-08-06 05:52:32 +0000

    tests: fix checksum computation
    
    This fixes an endianness bug in sys/netinet/ip_reass_test.
    Just use the code from RFC 1071.
    
    Reported by:            glebius
    Reviewed by:            glebius, Timo Völker
    Sponsored by:           Netflix, Inc.
    Differential Revision:  https://reviews.freebsd.org/D57988
    
    (cherry picked from commit fbc039e512c3bb1635ad20cc8f70ad608ea818b7)
---
 tests/sys/netinet/ip_reass_test.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/tests/sys/netinet/ip_reass_test.c b/tests/sys/netinet/ip_reass_test.c
index f649dd9ad4db..dd18b56f069f 100644
--- a/tests/sys/netinet/ip_reass_test.c
+++ b/tests/sys/netinet/ip_reass_test.c
@@ -56,20 +56,28 @@ struct lopacket {
 	char		payload[];
 };
 
-static void
-update_cksum(struct ip *ip)
+static uint16_t
+in_cksum(void *data, size_t len)
 {
+	uint16_t *cksump;
 	size_t i;
 	uint32_t cksum;
-	uint16_t *cksump;
 
+	ATF_REQUIRE(len % 2 == 0);
+	cksump = (uint16_t *)data;
+	cksum = 0;
+	for (i = 0; i < len / sizeof(uint16_t); i++)
+		cksum += *cksump++;
+	while ((cksum >> 16) != 0)
+		cksum = (cksum & 0xffff) + (cksum >> 16);
+	return ((uint16_t)~cksum);
+}
+
+static void
+update_cksum(struct ip *ip)
+{
 	ip->ip_sum = 0;
-	cksump = (uint16_t *)ip;
-	for (cksum = 0, i = 0; i < sizeof(*ip) / sizeof(*cksump); cksump++, i++)
-		cksum += ntohs(*cksump);
-	cksum = (cksum >> 16) + (cksum & 0xffff);
-	cksum = ~(cksum + (cksum >> 16));
-	ip->ip_sum = htons((uint16_t)cksum);
+	ip->ip_sum = in_cksum(ip, sizeof(struct ip));
 }
 
 static struct lopacket *
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.