Netdev List
 help / color / mirror / Atom feed
From: "Baek Kyu, Kim" <pocj8ur4in@gmail.com>
To: Steffen Klassert <steffen.klassert@secunet.com>
Cc: "Baek Kyu, Kim" <pocj8ur4in@gmail.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Eyal Birger <eyal.birger@gmail.com>,
	netdev@vger.kernel.org
Subject: [PATCH net] xfrm: reschedule NAT keepalive work for new states
Date: Tue, 10 Nov 2026 23:43:21 +0900	[thread overview]
Message-ID: <20261110144321.94096-1-pocj8ur4in@gmail.com> (raw)

The per-net NAT keepalive work can already be pending for a state with a
long interval when a new state with a shorter interval is added.
schedule_delayed_work(..., 0) does not move the pending deadline, so the
new state's keepalive waits for the older state's deadline.

Use mod_delayed_work() for a newly added state to run the worker
immediately and recalculate the next deadline. Keep the existing
schedule_delayed_work() behavior when a state is deleted. States without
a keepalive interval still return early.

Fixes: f531d13bdfe3 ("xfrm: support sending NAT keepalives in ESP in UDP states")
Signed-off-by: Baek Kyu, Kim <pocj8ur4in@gmail.com>
---
An arm64 QEMU/KVM test of the immediate-reschedule change showed that a
new 2-second SA sent a keepalive immediately while the original kernel
sent none for five seconds. With a virtual NAT gateway, the original
mapping expired and a 9-second inbound UDP packet was lost; the changed
kernel retained the mapping and received it. A boot test of the final
patch confirmed an immediate keepalive for the new SA and no immediate
workqueue event or later keepalive for the deleted SA. An arm64 W=1
object build passed. No physical NAT device or ESP payload was tested.

 net/xfrm/xfrm_nat_keepalive.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/xfrm/xfrm_nat_keepalive.c b/net/xfrm/xfrm_nat_keepalive.c
index 8ed30e6c263b66..6814f9063969ef 100644
--- a/net/xfrm/xfrm_nat_keepalive.c
+++ b/net/xfrm/xfrm_nat_keepalive.c
@@ -288,7 +288,10 @@ void xfrm_nat_keepalive_state_updated(struct xfrm_state *x)
 		return;
 
 	net = xs_net(x);
-	schedule_delayed_work(&net->xfrm.nat_keepalive_work, 0);
+	if (x->km.state == XFRM_STATE_DEAD)
+		schedule_delayed_work(&net->xfrm.nat_keepalive_work, 0);
+	else
+		mod_delayed_work(system_wq, &net->xfrm.nat_keepalive_work, 0);
 }
 
 int __net_init xfrm_nat_keepalive_net_init(struct net *net)

             reply	other threads:[~2026-11-10 14:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 14:43 Baek Kyu, Kim [this message]
2026-11-10 14:46 ` [PATCH net] xfrm: reschedule NAT keepalive work for new states netdev-bot+sinfo
2026-11-10 14:53   ` Baek Kyu, Kim

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=20261110144321.94096-1-pocj8ur4in@gmail.com \
    --to=pocj8ur4in@gmail.com \
    --cc=eyal.birger@gmail.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=netdev@vger.kernel.org \
    --cc=steffen.klassert@secunet.com \
    /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