netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org
Subject: [PATCH net 4/6] netfilter: conntrack: adjust stop timestamp to real expiry value
Date: Fri, 23 Jul 2021 17:54:10 +0200	[thread overview]
Message-ID: <20210723155412.17916-5-pablo@netfilter.org> (raw)
In-Reply-To: <20210723155412.17916-1-pablo@netfilter.org>

From: Florian Westphal <fw@strlen.de>

In case the entry is evicted via garbage collection there is
delay between the timeout value and the eviction event.

This adjusts the stop value based on how much time has passed.

Fixes: b87a2f9199ea82 ("netfilter: conntrack: add gc worker to remove timed-out entries")
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_conntrack_core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 83c52df85870..5c03e5106751 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -670,8 +670,13 @@ bool nf_ct_delete(struct nf_conn *ct, u32 portid, int report)
 		return false;
 
 	tstamp = nf_conn_tstamp_find(ct);
-	if (tstamp && tstamp->stop == 0)
+	if (tstamp) {
+		s32 timeout = ct->timeout - nfct_time_stamp;
+
 		tstamp->stop = ktime_get_real_ns();
+		if (timeout < 0)
+			tstamp->stop -= jiffies_to_nsecs(-timeout);
+	}
 
 	if (nf_conntrack_event_report(IPCT_DESTROY, ct,
 				    portid, report) < 0) {
-- 
2.20.1


  parent reply	other threads:[~2021-07-23 15:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-23 15:54 [PATCH net 0/6] Netfilter fixes for net Pablo Neira Ayuso
2021-07-23 15:54 ` [PATCH net 1/6] netfilter: nf_tables: fix audit memory leak in nf_tables_commit Pablo Neira Ayuso
2021-07-23 16:50   ` patchwork-bot+netdevbpf
2021-07-23 15:54 ` [PATCH net 2/6] netfilter: flowtable: avoid possible false sharing Pablo Neira Ayuso
2021-07-23 15:54 ` [PATCH net 3/6] netfilter: nft_last: " Pablo Neira Ayuso
2021-07-23 15:54 ` Pablo Neira Ayuso [this message]
2021-07-23 15:54 ` [PATCH net 5/6] netfilter: nft_nat: allow to specify layer 4 protocol NAT only Pablo Neira Ayuso
2021-07-23 15:54 ` [PATCH net 6/6] netfilter: nfnl_hook: fix unused variable warning Pablo Neira Ayuso

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=20210723155412.17916-5-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@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;
as well as URLs for NNTP newsgroup(s).