netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lance Yang <lance.yang@linux.dev>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: fw@strlen.de, coreteam@netfilter.org, davem@davemloft.net,
	edumazet@google.com, horms@kernel.org, kadlec@netfilter.org,
	kuba@kernel.org, linux-kernel@vger.kernel.org,
	netfilter-devel@vger.kernel.org, pabeni@redhat.com,
	zi.li@linux.dev, Lance Yang <ioworker0@gmail.com>
Subject: Re: [PATCH v2 1/1] netfilter: load nf_log_syslog on enabling nf_conntrack_log_invalid
Date: Thu, 24 Jul 2025 20:48:45 +0800	[thread overview]
Message-ID: <ba6d5737-863b-4cf1-8b26-f74e494e9b19@linux.dev> (raw)
In-Reply-To: <aIIl9u1TY84Q9mnD@calendula>



On 2025/7/24 20:24, Pablo Neira Ayuso wrote:
> Hi,
> 
> On Mon, May 26, 2025 at 04:59:02PM +0800, Lance Yang wrote:
>> diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
>> index 2f666751c7e7..cdc27424f84a 100644
>> --- a/net/netfilter/nf_conntrack_standalone.c
>> +++ b/net/netfilter/nf_conntrack_standalone.c
>> @@ -14,6 +14,7 @@
>>   #include <linux/sysctl.h>
>>   #endif
>>   
>> +#include <net/netfilter/nf_log.h>
>>   #include <net/netfilter/nf_conntrack.h>
>>   #include <net/netfilter/nf_conntrack_core.h>
>>   #include <net/netfilter/nf_conntrack_l4proto.h>
>> @@ -543,6 +544,29 @@ nf_conntrack_hash_sysctl(const struct ctl_table *table, int write,
>>   	return ret;
>>   }
>>   
>> +static int
>> +nf_conntrack_log_invalid_sysctl(const struct ctl_table *table, int write,
>> +				void *buffer, size_t *lenp, loff_t *ppos)
>> +{
>> +	int ret, i;
>> +
>> +	ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
>> +	if (ret < 0 || !write)
>> +		return ret;
>> +
>> +	if (*(u8 *)table->data == 0)
>> +		return ret;
> 
> What is this table->data check for? I don't find any similar idiom
> like this in the existing proc_dou8vec_minmax() callers.

My intention was to avoid the unnecessary nf_log_is_registered()
calls when a user disables the feature by writing '0' to the sysctl.

But it's not a big deal. I will remove this check in v3 ;)

>> +
>> +	/* Load nf_log_syslog only if no logger is currently registered */
>> +	for (i = 0; i < NFPROTO_NUMPROTO; i++) {
>> +		if (nf_log_is_registered(i))
>> +			return ret;
>> +	}
>> +	request_module("%s", "nf_log_syslog");
>> +
>> +	return ret;
>> +}
>> +
>>   static struct ctl_table_header *nf_ct_netfilter_header;
>>   
>>   enum nf_ct_sysctl_index {
>> @@ -649,7 +673,7 @@ static struct ctl_table nf_ct_sysctl_table[] = {
>>   		.data		= &init_net.ct.sysctl_log_invalid,
>>   		.maxlen		= sizeof(u8),
>>   		.mode		= 0644,
>> -		.proc_handler	= proc_dou8vec_minmax,
>> +		.proc_handler	= nf_conntrack_log_invalid_sysctl,
>>   	},
>>   	[NF_SYSCTL_CT_EXPECT_MAX] = {
>>   		.procname	= "nf_conntrack_expect_max",
>> diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
>> index 6dd0de33eebd..c7dd5019a89d 100644
>> --- a/net/netfilter/nf_log.c
>> +++ b/net/netfilter/nf_log.c
>> @@ -125,6 +125,33 @@ void nf_log_unregister(struct nf_logger *logger)
>>   }
>>   EXPORT_SYMBOL(nf_log_unregister);
>>   
>> +/**
>> + * nf_log_is_registered - Check if any logger is registered for a given
>> + * protocol family.
>> + *
>> + * @pf: Protocol family
>> + *
>> + * Returns: true if at least one logger is active for @pf, false otherwise.
>> + */
>> +bool nf_log_is_registered(u_int8_t pf)
>> +{
>> +	int i;
>> +
>> +	/* Out of bounds. */
> 
> No need for this comment, please remove it.

OK, will remove it.

Thanks,
Lance

> 
>> +	if (pf >= NFPROTO_NUMPROTO) {
>> +		WARN_ON_ONCE(1);
>> +		return false;
>> +	}


      reply	other threads:[~2025-07-24 12:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-26  8:59 [PATCH v2 1/1] netfilter: load nf_log_syslog on enabling nf_conntrack_log_invalid Lance Yang
2025-05-28 11:05 ` Florian Westphal
2025-05-28 11:42   ` Lance Yang
2025-05-30  3:10     ` Lance Yang
2025-07-14 12:05   ` Lance Yang
2025-07-24 12:24 ` Pablo Neira Ayuso
2025-07-24 12:48   ` Lance Yang [this message]

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=ba6d5737-863b-4cf1-8b26-f74e494e9b19@linux.dev \
    --to=lance.yang@linux.dev \
    --cc=coreteam@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=horms@kernel.org \
    --cc=ioworker0@gmail.com \
    --cc=kadlec@netfilter.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    --cc=zi.li@linux.dev \
    /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).