From 9e22c53aa92552bd5c015c2597512056f8def4d8 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Wed, 1 May 2024 16:53:48 +1000 Subject: checksum: Make csum_ip4_header() take a host endian length csum_ip4_header() takes the packet length as a network endian value. In general it's very error-prone to pass non-native-endian values as a raw integer. It's particularly bad here because this differs from other checksum functions (e.g. proto_ipv4_header_psum()) which take host native lengths. It turns out all the callers have easy access to the native endian value, so switch it to use host order like everything else. Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tcp.c') diff --git a/tcp.c b/tcp.c index 24f99cd..3ba3aa4 100644 --- a/tcp.c +++ b/tcp.c @@ -1359,7 +1359,7 @@ static size_t tcp_fill_headers4(const struct ctx *c, iph->daddr = c->ip4.addr_seen.s_addr; iph->check = check ? *check : - csum_ip4_header(iph->tot_len, IPPROTO_TCP, + csum_ip4_header(ip_len, IPPROTO_TCP, *a4, c->ip4.addr_seen); tcp_fill_header(th, conn, seq); -- cgit v1.2.3