All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: Fernando Fernandez Mancera <fmancera@suse.de>
Cc: netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
	pablo@netfilter.org, phil@nwl.cc, aconole@redhat.com,
	echaudro@redhat.com, i.maximets@ovn.org
Subject: Re: [PATCH 2/4 nf-next v2] netfilter: nf_conncount: only track connection if it is not confirmed
Date: Mon, 10 Nov 2025 21:44:19 +0100	[thread overview]
Message-ID: <aRJOo4bN1DEhYvE7@strlen.de> (raw)
In-Reply-To: <20251110154249.3586-3-fmancera@suse.de>

Fernando Fernandez Mancera <fmancera@suse.de> wrote:
> diff --git a/net/netfilter/xt_connlimit.c b/net/netfilter/xt_connlimit.c
> index 0189f8b6b0bd..8c21890e4536 100644
> --- a/net/netfilter/xt_connlimit.c
> +++ b/net/netfilter/xt_connlimit.c
> @@ -29,24 +29,16 @@
>  static bool
>  connlimit_mt(const struct sk_buff *skb, struct xt_action_param *par)
>  {
> -	struct net *net = xt_net(par);
>  	const struct xt_connlimit_info *info = par->matchinfo;
> -	struct nf_conntrack_tuple tuple;
> -	const struct nf_conntrack_tuple *tuple_ptr = &tuple;
> -	const struct nf_conntrack_zone *zone = &nf_ct_zone_dflt;
> -	enum ip_conntrack_info ctinfo;
> -	const struct nf_conn *ct;
> +	struct net *net = xt_net(par);
>  	unsigned int connections;
> +	bool refcounted = false;
> +	struct nf_conn *ct;
>  	u32 key[5];
>  
> -	ct = nf_ct_get(skb, &ctinfo);
> -	if (ct != NULL) {
> -		tuple_ptr = &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple;
> -		zone = nf_ct_zone(ct);
> -	} else if (!nf_ct_get_tuplepr(skb, skb_network_offset(skb),
> -				      xt_family(par), net, &tuple)) {
> +	ct = nf_ct_get_or_find(net, skb, xt_family(par), &refcounted);
> +	if (!ct)
>  		goto hotdrop;
> -	}

This can't work this way for -t raw use case, which we need
to preserve.

Anyone who uses -t raw ... -m connlimit ...

will now have their packets dropped, so no connection
can make forward progress (not even when using iptables --syn).

We need to get rid of the
        if ((u32)jiffies == list->last_gc)
                goto add_new_node;

check in nf_conncount_add(), or, (to not add perf regress for ovs ...)
apply it when a (confirmed) conntrack entry is present.

Given that limitation, I don't think this nf_ct_get_or_find() helper
makes any sense, since you still need to pass the tupleptr down
to count_tree().

I think passing in the sk_buff is better, so all of this
conntrack/tuple/zone etc. stuff is hidden away in nf_conncount.c.

I think you could start by *adding*

unsigned int nf_conncount_count_skb(struct net *net,
				    const struct sk_buff *skb,
				    struct nf_conncount_data *data,
				    const u32 *key);

As frontend function for nf_conncount_count().
This new function could (re)use some of the code you made
for nf_ct_get_or_find(), the zone usage there looks correct
to me.

Then, in patch 2, convert -m connlimit.
You could send that as an initial patch set already.

Then, in patch 3 (or later followup patch set), convert remaining user
(ovs) and hide old api.

Then, in patch 4, start pushing down the sk_buff more in nf_conncount.c
until its available for nf_conncount_add().

Then, add nf_conncount_add_skb and repeat this process.

Does that make sense?

  reply	other threads:[~2025-11-10 20:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-10 15:42 [PATCH 0/4 nf-next v2] netfilter: rework conncount API to receive ct directly Fernando Fernandez Mancera
2025-11-10 15:42 ` [PATCH 1/4 nf-next v2] netfilter: conntrack: add nf_ct_get_or_find() helper Fernando Fernandez Mancera
2025-11-10 15:42 ` [PATCH 2/4 nf-next v2] netfilter: nf_conncount: only track connection if it is not confirmed Fernando Fernandez Mancera
2025-11-10 20:44   ` Florian Westphal [this message]
2025-11-10 21:40     ` Fernando Fernandez Mancera
2025-11-10 15:42 ` [PATCH 3/4 nf-next v2] netfilter: nf_conncount: make nf_conncount_gc_list() to disable BH Fernando Fernandez Mancera
2025-11-10 15:42 ` [PATCH 4/4 nf-next v2] netfilter: nft_connlimit: update connection list if add was skipped Fernando Fernandez Mancera

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=aRJOo4bN1DEhYvE7@strlen.de \
    --to=fw@strlen.de \
    --cc=aconole@redhat.com \
    --cc=coreteam@netfilter.org \
    --cc=echaudro@redhat.com \
    --cc=fmancera@suse.de \
    --cc=i.maximets@ovn.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=phil@nwl.cc \
    /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 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.