Skip to contentSkip to conversation

netfilter: fix UDP incremental checksumming

PATCH Applied Harald Welte 2 participants 2 messages Oct 2, 2003 – Oct 3, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: fix UDP incremental checksumming

Hi Davem!

Please apply the following patchto your 2.6 tree and push it to Marcelo. Thanks.

Author: Patrick McHardy <[email protected]>

Fix UDP checksum in ip_nat_mangle_udp_packet, remove skb->csum hacks

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.1354 -> 1.1355
# net/ipv4/netfilter/ip_nat_helper.c 1.17 -> 1.18
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/09/27 [email protected] 1.1355
# [NETFILTER]: Fix UDP checksum in ip_nat_mangle_udp_packet, remove skb->csum hacks # --------------------------------------------
#

net/ipv4/netfilter/ip_nat_helper.c +13 -16
diff -Nru a/net/ipv4/netfilter/ip_nat_helper.c b/net/ipv4/netfilter/ip_nat_helper.c
@@ -122,7 +122,6 @@
 	/* fix IP hdr checksum information */
 	skb->nh.iph->tot_len = htons(skb->len);
 	ip_send_check(skb->nh.iph);
-	skb->csum = csum_partial(data, skb->len - dataoff, 0);
 }
 
 /* Unusual, but possible case. */
@@ -167,6 +166,7 @@
 {
 	struct iphdr *iph;
 	struct tcphdr *tcph;
+	int datalen;
 
 	if (!skb_ip_make_writable(pskb, (*pskb)->len))
 		return 0;
@@ -184,11 +184,11 @@
 	mangle_contents(*pskb, iph->ihl*4 + tcph->doff*4,
 			match_offset, match_len, rep_buffer, rep_len);
 
+	datalen = (*pskb)->len - iph->ihl*4;
 	tcph->check = 0;
-	tcph->check = tcp_v4_check(tcph, (*pskb)->len - iph->ihl*4,
-				   iph->saddr, iph->daddr,
-				   csum_partial((char *)tcph, tcph->doff*4,
-						(*pskb)->csum));
+	tcph->check = tcp_v4_check(tcph, datalen, iph->saddr, iph->daddr,
+				   csum_partial((char *)tcph, datalen, 0));
+
 	adjust_tcp_sequence(ntohl(tcph->seq),
 			    (int)rep_len - (int)match_len,
 			    ct, ctinfo);
@@ -216,7 +216,6 @@
 {
 	struct iphdr *iph;
 	struct udphdr *udph;
-	int need_csum = ((*pskb)->csum != 0);
 
 	if (!skb_ip_make_writable(pskb, (*pskb)->len))
 		return 0;
@@ -235,17 +234,15 @@
 	udph->len = htons((*pskb)->len - iph->ihl*4);
 
 	/* fix udp checksum if udp checksum was previously calculated */
-	if (need_csum) {
+	if (udph->check) {
+		int datalen = (*pskb)->len - iph->ihl * 4;
 		udph->check = 0;
-		udph->check
-			= csum_tcpudp_magic(iph->saddr, iph->daddr,
-					    (*pskb)->len - iph->ihl*4,
-					    IPPROTO_UDP,
-					    csum_partial((char *)udph,
-							 sizeof(struct udphdr),
-							 (*pskb)->csum));
-	} else
-		(*pskb)->csum = 0;
+		udph->check = csum_tcpudp_magic(iph->saddr, iph->daddr,
+		                                datalen, IPPROTO_UDP,
+		                                csum_partial((char *)udph,
+		                                             datalen, 0));
+	}
+
 	return 1;
 }
 
#1 lore raw
Quoted 1 line · On Thu, 2 Oct 2003 16:24:02 +0200 Harald Welte <[email protected]> wrote:

Please apply the following patchto your 2.6 tree and push it to Marcelo.

Applied, but I don't think Marcelo will be able to do much with any 2.6.x tree I push him :)