Skip to contentSkip to conversation

act_nat: fix the wrong checksum when addr isn't in old_addr/mask

PATCH Superseded Changli Gao 1 participant 1 message May 29, 2010

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 act_nat: fix the wrong checksum when addr isn't in old_addr/mask

fix the wrong checksum when addr isn't in old_addr/mask

When addr isn't in old_addr/mask we don't do SNAT or DNAT, and we should not update the checksum too.

----

 net/sched/act_nat.c |   32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)
net/sched/act_nat.c +17 -15
index d885ba3..f9b12a9 100644
@@ -142,24 +142,25 @@ static int tcf_nat(struct sk_buff *skb, struct tc_action *a,
 	else
 		addr = iph->daddr;
 
-	if (!((old_addr ^ addr) & mask)) {
-		if (skb_cloned(skb) &&
-		    !skb_clone_writable(skb, sizeof(*iph)) &&
-		    pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
-			goto drop;
+	if ((old_addr ^ addr) & mask)
+		goto out;
 
-		new_addr &= mask;
-		new_addr |= addr & ~mask;
+	if (skb_cloned(skb) &&
+	    !skb_clone_writable(skb, sizeof(*iph)) &&
+	    pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
+		goto drop;
 
-		/* Rewrite IP header */
-		iph = ip_hdr(skb);
-		if (egress)
-			iph->saddr = new_addr;
-		else
-			iph->daddr = new_addr;
+	new_addr &= mask;
+	new_addr |= addr & ~mask;
 
-		csum_replace4(&iph->check, addr, new_addr);
-	}
+	/* Rewrite IP header */
+	iph = ip_hdr(skb);
+	if (egress)
+		iph->saddr = new_addr;
+	else
+		iph->daddr = new_addr;
+
+	csum_replace4(&iph->check, addr, new_addr);
 
 	ihl = iph->ihl * 4;
 
@@ -247,6 +248,7 @@ static int tcf_nat(struct sk_buff *skb, struct tc_action *a,
 		break;
 	}
 
+out:
 	return action;
 
 drop: