Skip to contentSkip to conversation

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

PATCH In review Changli Gao 4 participants 7 messages May 30, 2010 – Jun 2, 2010

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

PATCH v2 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

For TCP and UDP packets, when addr isn't in old_addr/mask we don't do SNAT or DNAT, and we should not update layer 4 checksum.

----

 net/sched/act_nat.c |    4 ++++
 1 file changed, 4 insertions(+)
net/sched/act_nat.c +4 -0
index d885ba3..5709494 100644
@@ -159,6 +159,9 @@ static int tcf_nat(struct sk_buff *skb, struct tc_action *a,
 			iph->daddr = new_addr;
 
 		csum_replace4(&iph->check, addr, new_addr);
+	} else if ((iph->frag_off & htons(IP_OFFSET)) ||
+		   iph->protocol != IPPROTO_ICMP) {
+		goto out;
 	}
 
 	ihl = iph->ihl * 4;
@@ -247,6 +250,7 @@ static int tcf_nat(struct sk_buff *skb, struct tc_action *a,
 		break;
 	}
 
+out:
 	return action;
 
 drop:
#1 lore raw

Copying Herbert, taking linux-kernel off...

Quoted 31 lines · Changli Gao

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

For TCP and UDP packets, when addr isn't in old_addr/mask we don't do SNAT or DNAT, and we should not update layer 4 checksum.

----

 net/sched/act_nat.c |    4 ++++
 1 file changed, 4 insertions(+)
net/sched/act_nat.c +4 -0
index d885ba3..5709494 100644
@@ -159,6 +159,9 @@ static int tcf_nat(struct sk_buff *skb, struct tc_action *a,
 			iph->daddr = new_addr;
 
 		csum_replace4(&iph->check, addr, new_addr);
+	} else if ((iph->frag_off & htons(IP_OFFSET)) ||
+		   iph->protocol != IPPROTO_ICMP) {
+		goto out;
 	}
 
 	ihl = iph->ihl * 4;
@@ -247,6 +250,7 @@ static int tcf_nat(struct sk_buff *skb, struct tc_action *a,
 		break;
 	}
 
+out:
 	return action;
 
 drop:
#2 lore raw
Quoted 2 lines · jamal

Copying Herbert, taking linux-kernel off...

Thanks Jamal.

Quoted 17 lines · Changli Gao
Quoted 16 lines

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

For TCP and UDP packets, when addr isn't in old_addr/mask we don't do SNAT or DNAT, and we should not update layer 4 checksum.

----

 net/sched/act_nat.c |    4 ++++
 1 file changed, 4 insertions(+)
net/sched/act_nat.c +0 -0
index d885ba3..5709494 100644
@@ -159,6 +159,9 @@ static int tcf_nat(struct sk_buff *skb, struct tc_action *a,
 			iph->daddr = new_addr;
 
Quoted 5 lines

net/sched/act_nat.c static int tcf_nat(struct sk_buff *skb, struct tc_action *a, · line 165

Quoted 5 lines
net/sched/act_nat.c +3 -0
 		csum_replace4(&iph->check, addr, new_addr);
+	} else if ((iph->frag_off & htons(IP_OFFSET)) ||
+		   iph->protocol != IPPROTO_ICMP) {
+		goto out;
 	}

Yes the patch is correct.

However, the fact that you need this patch means that your act_nat setup isn't perfect. Ideally all the unNATed packets should be filtered out before you hit act_nat.

Thanks,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#3 lore raw
Quoted 31 lines · Herbert Xu
Quoted 2 lines · jamal

Copying Herbert, taking linux-kernel off...

Thanks Jamal.

Quoted 17 lines · Changli Gao
Quoted 16 lines

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

For TCP and UDP packets, when addr isn't in old_addr/mask we don't do SNAT or DNAT, and we should not update layer 4 checksum.

----
 net/sched/act_nat.c |    4 ++++

 1 file changed, 4 insertions(+)
net/sched/act_nat.c +0 -0
index d885ba3..5709494 100644
@@ -159,6 +159,9 @@ static int tcf_nat(struct sk_buff *skb, struct tc_action *a,
                     iph->daddr = new_addr;
 
Quoted 5 lines

net/sched/act_nat.c static int tcf_nat(struct sk_buff *skb, struct tc_action *a, · line 165

Quoted 5 lines
net/sched/act_nat.c +3 -0
             csum_replace4(&iph->check, addr, new_addr);
+   } else if ((iph->frag_off & htons(IP_OFFSET)) ||
+              iph->protocol != IPPROTO_ICMP) {
+           goto out;
     }

Yes the patch is correct.

Quoted 3 lines

However, the fact that you need this patch means that your act_nat setup isn't perfect.  Ideally all the unNATed packets should be filtered out before you hit act_nat.

Thinking about this topologic:

client -> DNAT -> router -> server.

DNAT is used to map a public IP to server's private IP. If a DEST_UNREACH ICMP packet is sent out by router, in order to handle this ICMP packet correctly, I have to pass it to act_nat.c. How can I filter out the other packets? By inspecting the inner IP destination address of this ICMP packet? Maybe I can use u32 with complicate parameters.

Signature · 2 lines
Regards,
Changli Gao([email protected])
#4 lore raw
Quoted 10 lines · Changli Gao
Quoted 6 lines · Herbert Xu

Yes the patch is correct.

However, the fact that you need this patch means that your act_nat setup isn't perfect.  Ideally all the unNATed packets should be filtered out before you hit act_nat.

Thinking about this topologic:

Quoted 9 lines

client -> DNAT -> router -> server.

DNAT is used to map a public IP to server's private IP. If a DEST_UNREACH ICMP packet is sent out by router, in order to handle this ICMP packet correctly, I have to pass it to act_nat.c. How can I filter out the other packets? By inspecting the inner IP destination address of this ICMP packet? Maybe I can use u32 with complicate parameters.

Oh, I can pass all the ICMP packets, and the packets to the public IP and the packets from the private IP.

Signature · 2 lines
Regards,
Changli Gao([email protected])
#5 lore raw
In reply to Changli Gao
Quoted 11 lines · Changli Gao

Thinking about this topologic:

client -> DNAT -> router -> server.

DNAT is used to map a public IP to server's private IP. If a DEST_UNREACH ICMP packet is sent out by router, in order to handle this ICMP packet correctly, I have to pass it to act_nat.c. How can I filter out the other packets? By inspecting the inner IP destination address of this ICMP packet? Maybe I can use u32 with complicate parameters.

You should filter out all the non-ICMP packets, just like you do here.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer
#6 lore raw
In reply to Herbert Xu

From: Herbert Xu <[email protected]>
Date: Sun, 30 May 2010 22:58:11 +1000

Quoted 5 lines

Yes the patch is correct.

However, the fact that you need this patch means that your act_nat setup isn't perfect. Ideally all the unNATed packets should be filtered out before you hit act_nat.

Regardless of whether said configuration is optimal, we should handle this case correctly.

So I have applied this patch.