Skip to contentSkip to conversation

net/sched: act_nat: fix inner IP header checksum in ICMP error packets

PATCH Superseded David Carlier 2 participants 3 messages Apr 3

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/sched: act_nat: fix inner IP header checksum in ICMP error packets

Update the inner IP header checksum when rewriting addresses inside ICMP error payloads, matching netfilter's nf_nat_ipv4_manip_pkt() behavior.

Fixes b4219952356b ("[PKT_SCHED]: Add stateless NAT")
---
 net/sched/act_nat.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/sched/act_nat.c +3 -1
index abb332dee836..cd1d299da57c 100644
@@ -242,7 +242,9 @@ TC_INDIRECT_SCOPE int tcf_nat_act(struct sk_buff *skb,
 		new_addr &= mask;
 		new_addr |= addr & ~mask;
 
-		/* XXX Fix up the inner checksums. */
+		/* Update inner IP header checksum after address rewrite */
+		csum_replace4(&iph->check, addr, new_addr);
+
 		if (egress)
 			iph->daddr = new_addr;
 		else
Signature · 1 line
2.53.0
#1 lore raw
Quoted 17 lines · David Carlier

Update the inner IP header checksum when rewriting addresses inside ICMP error payloads, matching netfilter's nf_nat_ipv4_manip_pkt() behavior.

Fixes b4219952356b ("[PKT_SCHED]: Add stateless NAT")
---
 net/sched/act_nat.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/sched/act_nat.c +0 -0
index abb332dee836..cd1d299da57c 100644

net/sched/act_nat.c TC_INDIRECT_SCOPE int tcf_nat_act(struct sk_buff *skb, · line 247

Quoted 7 lines
net/sched/act_nat.c +3 -1
@@ -242,7 +242,9 @@ TC_INDIRECT_SCOPE int tcf_nat_act(struct sk_buff *skb,
                new_addr &= mask;
                new_addr |= addr & ~mask;
 
-               /* XXX Fix up the inner checksums. */
+               /* Update inner IP header checksum after address rewrite */
+               csum_replace4(&iph->check, addr, new_addr);
+

~20 years old code, are we sure this fix is needed? How was this patch was tested?

A selftest would be great.

#2 lore raw

Hi eric,

Quoted 30 lines · Eric Dumazet
Quoted 17 lines · David Carlier

Update the inner IP header checksum when rewriting addresses inside ICMP error payloads, matching netfilter's nf_nat_ipv4_manip_pkt() behavior.

Fixes b4219952356b ("[PKT_SCHED]: Add stateless NAT")
---
 net/sched/act_nat.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/sched/act_nat.c +0 -0
index abb332dee836..cd1d299da57c 100644

net/sched/act_nat.c TC_INDIRECT_SCOPE int tcf_nat_act(struct sk_buff *skb, · line 247

Quoted 7 lines
net/sched/act_nat.c +3 -1
@@ -242,7 +242,9 @@ TC_INDIRECT_SCOPE int tcf_nat_act(struct sk_buff *skb,
                new_addr &= mask;
                new_addr |= addr & ~mask;
 
-               /* XXX Fix up the inner checksums. */
+               /* Update inner IP header checksum after address rewrite */
+               csum_replace4(&iph->check, addr, new_addr);
+

~20 years old code, are we sure this fix is needed? How was this patch was tested?

Quoted 1 line

A selftest would be great.

Ok sounds fair