All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nf-next] netfilter: nf_conncount: fix tracking of connections from localhost
@ 2026-01-18 11:13 Fernando Fernandez Mancera
  2026-01-18 12:22 ` Florian Westphal
  0 siblings, 1 reply; 7+ messages in thread
From: Fernando Fernandez Mancera @ 2026-01-18 11:13 UTC (permalink / raw)
  To: netfilter-devel
  Cc: coreteam, pablo, fw, phil, Fernando Fernandez Mancera,
	Michal Slabihoudek

Since commit be102eb6a0e7 ("netfilter: nf_conncount: rework API to use
sk_buff directly"), we skip the adding and trigger a GC when the ct is
confirmed. For connections originated from local to local it doesn't
work because the connection is confirmed from a early stage, therefore
tracking is always skipped.

In order to fix this, we check whether IPS_SEEN_REPLY_BIT is set to
understand if it is really confirmed. If it isn't then we fallback on a
GC plus track operation skipping the optimization. This fallback is
necessary to avoid duplicated tracking of a packet train e.g 10 UDP
datagrams sent on a burst when initiating the connection.

Tested with xt_connlimit/nft_connlimit and OVS limit and with a HTTP
server and iperf3 on UDP mode.

Fixes: be102eb6a0e7 ("netfilter: nf_conncount: rework API to use sk_buff directly")
Reported-by: Michal Slabihoudek <michal.slabihoudek@gooddata.com>
Closes: https://lore.kernel.org/netfilter/6989BD9F-8C24-4397-9AD7-4613B28BF0DB@gooddata.com/
Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
---
Note: rebased in top of nf-next/testing tree
 net/netfilter/nf_conncount.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/net/netfilter/nf_conncount.c b/net/netfilter/nf_conncount.c
index 288936f5c1bf..5588cd0fcd9a 100644
--- a/net/netfilter/nf_conncount.c
+++ b/net/netfilter/nf_conncount.c
@@ -179,14 +179,25 @@ static int __nf_conncount_add(struct net *net,
 		return -ENOENT;
 
 	if (ct && nf_ct_is_confirmed(ct)) {
-		err = -EEXIST;
-		goto out_put;
+		/* connections from localhost are confirmed almost instantly,
+		 * check if there has been a reply
+		 */
+		if (test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) {
+			err = -EEXIST;
+			goto out_put;
+		}
+
+		/* this is likely a local connection, skip optimization to avoid
+		 * adding duplicates from a 'packet train'
+		 */
+		goto check_connections;
 	}
 
 	if ((u32)jiffies == list->last_gc &&
 	    (list->count - list->last_gc_count) < CONNCOUNT_GC_MAX_COLLECT)
 		goto add_new_node;
 
+check_connections:
 	/* check the saved connections */
 	list_for_each_entry_safe(conn, conn_n, &list->head, node) {
 		if (collect > CONNCOUNT_GC_MAX_COLLECT)
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-01-19 16:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-18 11:13 [PATCH nf-next] netfilter: nf_conncount: fix tracking of connections from localhost Fernando Fernandez Mancera
2026-01-18 12:22 ` Florian Westphal
2026-01-18 15:50   ` Fernando Fernandez Mancera
2026-01-18 16:03     ` Florian Westphal
2026-01-18 16:34       ` Fernando Fernandez Mancera
2026-01-19  0:21         ` Florian Westphal
2026-01-19 16:37           ` Fernando Fernandez Mancera

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.