Skip to contentSkip to conversation

BUG: src: Fix UDP checksum calculation

PATCH In review Duncan Roe 2 participants 3 messages Sep 27, 2019 – Oct 1, 2019 netfilter

lore
Share & tools
lore

Duncan Roe

author
#0 lore raw

PATCH 1/1 BUG: src: Fix UDP checksum calculation

The level 4 protocol is part of the UDP and TCP calculations. nfq_checksum_tcpudp_ipv4() was using IPPROTO_TCP in this calculation, which gave the wrong answer for UDP.

---
 src/extra/checksum.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/extra/checksum.c +1 -1
index f367f75..3ef288f 100644
@@ -46,7 +46,7 @@ uint16_t nfq_checksum_tcpudp_ipv4(struct iphdr *iph)
 	sum += (iph->saddr) & 0xFFFF;
 	sum += (iph->daddr >> 16) & 0xFFFF;
 	sum += (iph->daddr) & 0xFFFF;
-	sum += htons(IPPROTO_TCP);
+	sum += htons(iph->protocol);
 	sum += htons(len);
 
 	return nfq_checksum(sum, (uint16_t *)payload, len);
Signature · 1 line
2.14.5
#1 lore raw
Quoted 3 lines · Duncan Roe

The level 4 protocol is part of the UDP and TCP calculations. nfq_checksum_tcpudp_ipv4() was using IPPROTO_TCP in this calculation, which gave the wrong answer for UDP.

Thanks Duncan, I sent this patch to fix IPv6 too:

https://patchwork.ozlabs.org/patch/1169407/