From: Alexey Gladkov <legion@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>,
"Eric W . Biederman" <ebiederm@xmission.com>,
Kees Cook <kees@kernel.org>,
Joel Granados <joel.granados@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>, linux-fsdevel@vger.kernel.org
Subject: [RFC PATCH v1 25/30] sysctl: bridge: use sysctl_field for br_netfilter sysctls
Date: Wed, 26 Aug 2026 21:42:29 +0200 [thread overview]
Message-ID: <79750a1c9bc5b1bcdd86925800d4e668fde43112.1787771905.git.legion@kernel.org> (raw)
In-Reply-To: <cover.1787771905.git.legion@kernel.org>
br_netfilter clones its sysctl table for each non-init network namespace
so the registration path can patch in namespace-local data pointers. The
copied table then has to be kept alive until namespace teardown only so
it can be freed after unregistering the sysctls.
Use sysctl_field to derive the br_netfilter per-net data from the
registration context instead. This keeps the sysctl descriptors static
and const, and removes the per-net table copy and unregister-time free.
Signed-off-by: Alexey Gladkov <legion@kernel.org>
---
net/bridge/br_netfilter_hooks.c | 99 ++++++++++++---------------------
1 file changed, 37 insertions(+), 62 deletions(-)
diff --git a/net/bridge/br_netfilter_hooks.c b/net/bridge/br_netfilter_hooks.c
index 0a394e5f4391..18eccde39885 100644
--- a/net/bridge/br_netfilter_hooks.c
+++ b/net/bridge/br_netfilter_hooks.c
@@ -1181,43 +1181,37 @@ int brnf_sysctl_call_tables(const struct ctl_table *ctl, int write,
return ret;
}
-static struct ctl_table brnf_table[] = {
- {
- .procname = "bridge-nf-call-arptables",
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = brnf_sysctl_call_tables,
- },
- {
- .procname = "bridge-nf-call-iptables",
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = brnf_sysctl_call_tables,
- },
- {
- .procname = "bridge-nf-call-ip6tables",
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = brnf_sysctl_call_tables,
- },
- {
- .procname = "bridge-nf-filter-vlan-tagged",
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = brnf_sysctl_call_tables,
- },
- {
- .procname = "bridge-nf-filter-pppoe-tagged",
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = brnf_sysctl_call_tables,
- },
- {
- .procname = "bridge-nf-pass-vlan-input-dev",
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = brnf_sysctl_call_tables,
- },
+#define BRNF_DATA(field) \
+static void *brnf_ ## field ## _data(const struct sysctl_context *ctx) \
+{ \
+ struct brnf_net *brnet = net_generic(ctx->ns.net_ns, brnf_net_id); \
+ \
+ return &brnet->field; \
+}
+
+BRNF_DATA(call_arptables)
+BRNF_DATA(call_iptables)
+BRNF_DATA(call_ip6tables)
+BRNF_DATA(filter_vlan_tagged)
+BRNF_DATA(filter_pppoe_tagged)
+BRNF_DATA(pass_vlan_indev)
+#undef BRNF_DATA
+
+static const struct sysctl_field brnf_table[] = {
+ SYSCTL_FIELD_CUSTOM("bridge-nf-call-arptables", 0644, sizeof(int),
+ brnf_call_arptables_data, brnf_sysctl_call_tables),
+ SYSCTL_FIELD_CUSTOM("bridge-nf-call-iptables", 0644, sizeof(int),
+ brnf_call_iptables_data, brnf_sysctl_call_tables),
+ SYSCTL_FIELD_CUSTOM("bridge-nf-call-ip6tables", 0644, sizeof(int),
+ brnf_call_ip6tables_data, brnf_sysctl_call_tables),
+ SYSCTL_FIELD_CUSTOM("bridge-nf-filter-vlan-tagged", 0644, sizeof(int),
+ brnf_filter_vlan_tagged_data,
+ brnf_sysctl_call_tables),
+ SYSCTL_FIELD_CUSTOM("bridge-nf-filter-pppoe-tagged", 0644, sizeof(int),
+ brnf_filter_pppoe_tagged_data,
+ brnf_sysctl_call_tables),
+ SYSCTL_FIELD_CUSTOM("bridge-nf-pass-vlan-input-dev", 0644, sizeof(int),
+ brnf_pass_vlan_indev_data, brnf_sysctl_call_tables),
};
static inline void br_netfilter_sysctl_default(struct brnf_net *brnf)
@@ -1232,33 +1226,18 @@ static inline void br_netfilter_sysctl_default(struct brnf_net *brnf)
static int br_netfilter_sysctl_init_net(struct net *net)
{
- struct ctl_table *table = brnf_table;
+ struct sysctl_context ctx = {
+ .ns.net_ns = net,
+ };
struct brnf_net *brnet;
- if (!net_eq(net, &init_net)) {
- table = kmemdup(table, sizeof(brnf_table), GFP_KERNEL);
- if (!table)
- return -ENOMEM;
- }
-
brnet = net_generic(net, brnf_net_id);
- table[0].data = &brnet->call_arptables;
- table[1].data = &brnet->call_iptables;
- table[2].data = &brnet->call_ip6tables;
- table[3].data = &brnet->filter_vlan_tagged;
- table[4].data = &brnet->filter_pppoe_tagged;
- table[5].data = &brnet->pass_vlan_indev;
-
br_netfilter_sysctl_default(brnet);
- brnet->ctl_hdr = register_net_sysctl_sz(net, "net/bridge", table,
- ARRAY_SIZE(brnf_table));
- if (!brnet->ctl_hdr) {
- if (!net_eq(net, &init_net))
- kfree(table);
-
+ brnet->ctl_hdr = register_sysctl_fields(&net->sysctls, "net/bridge",
+ brnf_table, &ctx);
+ if (!brnet->ctl_hdr)
return -ENOMEM;
- }
return 0;
}
@@ -1266,11 +1245,7 @@ static int br_netfilter_sysctl_init_net(struct net *net)
static void br_netfilter_sysctl_exit_net(struct net *net,
struct brnf_net *brnet)
{
- const struct ctl_table *table = brnet->ctl_hdr->ctl_table_arg;
-
unregister_net_sysctl_table(brnet->ctl_hdr);
- if (!net_eq(net, &init_net))
- kfree(table);
}
static int __net_init brnf_init_net(struct net *net)
--
2.55.0
next prev parent reply other threads:[~2026-08-26 19:44 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1787771905.git.legion@kernel.org>
2026-08-26 19:42 ` [RFC PATCH v1 01/30] proc: sysctl: address table entries by index Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 02/30] sysctl: add unsigned int limit constants Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 03/30] sysctl: add typed field descriptors Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 04/30] sysctl: use sysctl_field in ucounts Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 05/30] sysctl: ipc: use sysctl_field in mq_sysctl Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 06/30] sysctl: ipc: use sysctl_field in ipc_sysctl Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 07/30] sysctl: use sysctl_field in pid sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 08/30] sysctl: net: use sysctl_field in unix sysctl Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 09/30] sysctl: net: use sysctl_field in xfrm sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 10/30] sysctl: net: use sysctl_field for simple IPv4 per-net sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 11/30] sysctl: net: use sysctl_field in IPv4 sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 12/30] sysctl: net: use sysctl_field in IPv6 xfrm sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 13/30] sysctl: net: use sysctl_field in IPv6 fragment sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 14/30] sysctl: net: use sysctl_field in 6lowpan " Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 15/30] sysctl: net: use sysctl_field in vsock sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 16/30] sysctl: net: use sysctl_field in MPTCP sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 17/30] sysctl: net: use sysctl_field in SCTP sysctls Alexey Gladkov
2026-08-26 20:29 ` Linus Torvalds
2026-08-29 16:14 ` Alexey Gladkov
2026-08-29 16:14 ` [RFC PATCH 1/4] sysctl: add typed field descriptors Alexey Gladkov
2026-08-29 16:14 ` [RFC PATCH 2/4] sysctl: ipc: use typed fields for IPC namespace sysctls Alexey Gladkov
2026-08-29 16:14 ` [RFC PATCH 3/4] sctp: use typed fields for per-net sysctls Alexey Gladkov
2026-08-29 16:14 ` [RFC PATCH 4/4] mpls: use typed fields for per-device sysctls Alexey Gladkov
2026-08-30 15:38 ` [RFC PATCH v1 17/30] sysctl: net: use sysctl_field in SCTP sysctls Linus Torvalds
2026-09-16 12:26 ` Joel Granados
2026-09-17 13:41 ` Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 18/30] sysctl: net: use sysctl_field in core IPv6 sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 19/30] sysctl: net: use sysctl_field in net core per-net sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 20/30] sysctl: net: use sysctl_field in SMC sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 21/30] sysctl: net: use sysctl_field in VRF sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 22/30] sysctl: net: use sysctl_field in RDS sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 23/30] sysctl: netfilter: use sysctl_field for per-net sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 24/30] sysctl: ipvs: " Alexey Gladkov
2026-08-26 19:42 ` Alexey Gladkov [this message]
2026-08-26 19:42 ` [RFC PATCH v1 26/30] sysctl: net: use sysctl_field for MPLS sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 27/30] sysctl: net: use sysctl_field in IPv4 devconf sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 28/30] sysctl: net: use sysctl_field in IPv6 " Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 29/30] sysctl: net: use sysctl_field in neighbour sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 30/30] sysctl: parport: use sysctl_field for dynamic sysctls Alexey Gladkov
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=79750a1c9bc5b1bcdd86925800d4e668fde43112.1787771905.git.legion@kernel.org \
--to=legion@kernel.org \
--cc=ebiederm@xmission.com \
--cc=joel.granados@kernel.org \
--cc=kees@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.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
all inboxes | Powered by JetHome®