Skip to contentSkip to conversation

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

PATCH In review David Carlier 2 participants 3 messages Apr 4

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

PATCH v2 1/2 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

PATCH v2 2/2 selftests: net: add act_nat ICMP inner checksum test

Verify that act_nat correctly updates the inner IP header checksum when rewriting addresses inside ICMP error payloads.

The test sets up two namespaces with act_nat on a veth pair, triggers an ICMP destination unreachable, and validates the inner IP header checksum in the received ICMP error.

---
 tools/testing/selftests/net/Makefile          |   1 +
 .../selftests/net/act_nat_icmp_csum.sh        |  72 +++++++++
 .../selftests/net/act_nat_icmp_csum_verify.py | 144 ++++++++++++++++++
 3 files changed, 217 insertions(+)
 create mode 100755 tools/testing/selftests/net/act_nat_icmp_csum.sh
 create mode 100755 tools/testing/selftests/net/act_nat_icmp_csum_verify.py
tools/testing/selftests/net/Makefile +1 -0
index 6bced3ed798b..1683db55e36f 100644
@@ -7,6 +7,7 @@ CFLAGS += -I../../../../usr/include/ $(KHDR_INCLUDES)
 CFLAGS += -I../
 
 TEST_PROGS := \
+	act_nat_icmp_csum.sh \
 	altnames.sh \
 	amt.sh \
 	arp_ndisc_evict_nocarrier.sh \
tools/testing/selftests/net/act_nat_icmp_csum.sh new file +72 -0

72 lines not on this page · raw message

tools/testing/selftests/net/act_nat_icmp_csum_verify.py new file +144 -0

144 lines not on this page · raw message

Signature · 1 line
2.53.0
maintainer
#2 lore raw

Re: [PATCH v2 2/2] selftests: net: add act_nat ICMP inner checksum test

Quoted 10 lines · On Sat, 4 Apr 2026 13:03:10 +0100 David Carlier wrote:

Verify that act_nat correctly updates the inner IP header checksum when rewriting addresses inside ICMP error payloads.

The test sets up two namespaces with act_nat on a veth pair, triggers an ICMP destination unreachable, and validates the inner IP header checksum in the received ICMP error.

---
 tools/testing/selftests/net/Makefile          |   1 +

you need to add the CONFIG* dependencies to the relevant config file.