Patchwork nf_nat_snmp: fix checksum calculation (v3)

login
register
mail settings
Submitter Patrick McHardy
Date Sept. 20, 2010, 5:35 p.m.
Message ID <4C979B4C.4020605@trash.net>
Download mbox | patch
Permalink /patch/65229/
State Not Applicable
Delegated to: David Miller
Headers show

Comments

Patrick McHardy - Sept. 20, 2010, 5:35 p.m.
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 <wtweeker@163.com>
> 
> 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 <shemminger@vyatta.com>

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 <kaber@trash.net>
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 <wtweeker@163.com> and
    Stephen Hemminger <shemminger@vyatta.com>.
    
    https://bugzilla.kernel.org/show_bug.cgi?id=17622
    
    Signed-off-by: Patrick McHardy <kaber@trash.net>

Patch

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)));