Subject: Re: [PATCH] nf_nat_snmp: fix checksum calculation (v3)

From: Patrick McHardy <[email-masked]>
Date: Mon, 20 Sep 2010 19:35:08 +0200

On 20.09.2010 18:44, Stephen Hemminger wrote:
> Revised version of the original patch in the bug
>   https://bugzilla.kernel.org/show_bug.cgi?id=17622
> from clark wang <[email-masked]>
> 
> I took the opportunity to do some cleanup here.
>  * reorder the assignment to make the byte order clear
>  * get rid of unnecessary ref/deref and just pass the bytes
>  * use sizeof() instead of hard coding size
> 
> Signed-off-by: Stephen Hemminger <[email-masked]>

Thanks Stephen, but this patch didn't compile:

net/ipv4/netfilter/nf_nat_snmp_basic.c: In function 'fast_csum':
net/ipv4/netfilter/nf_nat_snmp_basic.c:893: error: 's' undeclared (first
use in this function)
net/ipv4/netfilter/nf_nat_snmp_basic.c:893: error: (Each undeclared
identifier is reported only once
net/ipv4/netfilter/nf_nat_snmp_basic.c:893: error: for each function it
appears in.)
net/ipv4/netfilter/nf_nat_snmp_basic.c:890: warning: unused variable 'diff'

Since I prefer to keep this fix to the minimal size at this point,
I've committed this patch based on Clark's and your patches:

commit 8d70d82cdcc6da0a77440c6d860957a1f50b8089
Author: Patrick McHardy <[email-masked]>
Date:   Mon Sep 20 19:29:40 2010 +0200

    netfilter: nf_nat_snmp: fix checksum calculation (v4)
    
    Fix checksum calculation in nf_nat_snmp_basic.
    
    Based on patches by Clark Wang <[email-masked]> and
    Stephen Hemminger <[email-masked]>.
    
    https://bugzilla.kernel.org/show_bug.cgi?id=17622
    
    Signed-off-by: Patrick McHardy <[email-masked]>

diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
index 1679e2c..ee5f419 100644
--- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
+++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
@@ -893,13 +893,15 @@ static void fast_csum(__sum16 *csum,
 	unsigned char s[4];
 
 	if (offset & 1) {
-		s[0] = s[2] = 0;
+		s[0] = ~0;
 		s[1] = ~*optr;
+		s[2] = 0;
 		s[3] = *nptr;
 	} else {
-		s[1] = s[3] = 0;
 		s[0] = ~*optr;
+		s[1] = ~0;
 		s[2] = *nptr;
+		s[3] = 0;
 	}
 
 	*csum = csum_fold(csum_partial(s, 4, ~csum_unfold(*csum)));