From: lvjunyu <lvjunyu@cmss.chinamobile.com>
To: pablo@netfilter.org
Cc: fw@strlen.de, phil@nwl.cc, netfilter-devel@vger.kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, lvjunyu <lvjunyu@cmss.chinamobile.com>
Subject: [PATCH] netfilter: nf_nat: Fix stale outer UDP checksum on VXLAN encapsulated packets
Date: Sun, 20 Sep 2026 15:45:43 +0800 [thread overview]
Message-ID: <20260920074543.525572-1-lvjunyu@cmss.chinamobile.com> (raw)
When MASQUERADE --random-fully rewrites the outer UDP source port of a
VXLAN-encapsulated packet whose inner header has CHECKSUM_PARTIAL, the
outer UDP checksum is not updated. inet_proto_csum_replace2() is a
no-op for CHECKSUM_PARTIAL skb's, so the stale checksum causes remote
VTEP to drop the first packet (UdpInCsumErrors) until a ~1s SYN
retransmission.
Add an explicit csum_replace2() call to update the outer UDP checksum
when the skb is encapsulated, has CHECKSUM_PARTIAL, and is not GSO
(hardware offload handles the non-encapsulated case).
Test results (10 connections, single netns vxlan + veth environment):
Before fix: ~1080ms avg first-connection latency, 10 SYN retransmits,
UdpInCsumErrors incremented per connection
After fix: ~29ms avg first-connection latency, 0 SYN retransmits,
UdpInCsumErrors unchanged
Fixes: faec18dbb0405 ("netfilter: nat: remove l4proto->manip_pkt")
Cc: stable@vger.kernel.org
Signed-off-by: lvjunyu <lvjunyu@cmss.chinamobile.com>
---
net/netfilter/nf_nat_proto.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/net/netfilter/nf_nat_proto.c b/net/netfilter/nf_nat_proto.c
index 64b9bac228e..35cc6e10b5b 100644
--- a/net/netfilter/nf_nat_proto.c
+++ b/net/netfilter/nf_nat_proto.c
@@ -57,6 +57,20 @@ __udp_manip_pkt(struct sk_buff *skb,
nf_csum_update(skb, iphdroff, &hdr->check, tuple, maniptype);
inet_proto_csum_replace2(&hdr->check, skb, *portptr, newport,
false);
+ /* For CHECKSUM_PARTIAL encapsulated non-GSO packets,
+ * inet_proto_csum_replace2() above is a no-op because the
+ * port field is data, not pseudo-header. The outer uh->check
+ * was computed by udp_set_csum() with a temporary sport, and
+ * the subsequent NAT sport rewrite leaves it stale. On devices
+ * without hw_enc_features, the software fallback
+ * skb_checksum_help() honors csum_start which points at the
+ * inner transport header and only recomputes the inner
+ * checksum. The stale outer checksum goes out and the
+ * receiver drops the packet with UdpInCsumErrors.
+ */
+ if (skb->ip_summed == CHECKSUM_PARTIAL &&
+ skb->encapsulation && !skb_is_gso(skb))
+ csum_replace2(&hdr->check, *portptr, newport);
if (!hdr->check)
hdr->check = CSUM_MANGLED_0;
}
--
2.43.0
next reply other threads:[~2026-09-20 7:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-20 7:45 lvjunyu [this message]
2026-09-21 7:49 ` [PATCH] netfilter: nf_nat: Fix stale outer UDP checksum on VXLAN encapsulated packets netdev-bot+sashiko
2026-09-21 13:01 ` lvjunyu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260920074543.525572-1-lvjunyu@cmss.chinamobile.com \
--to=lvjunyu@cmss.chinamobile.com \
--cc=fw@strlen.de \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=phil@nwl.cc \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox