From: menglong8.dong@gmail.com
To: kuba@kernel.org
Cc: davem@davemloft.net, viro@zeniv.linux.org.uk, rdna@fb.com,
nicolas.dichtel@6wind.com, maheshb@google.com,
keescook@chromium.org, dong.menglong@zte.com.cn,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next] net: core: init every ctl_table in netns_core_table
Date: Sun, 17 Jan 2021 17:52:28 +0800 [thread overview]
Message-ID: <20210117095228.173512-1-dong.menglong@zte.com.cn> (raw)
From: Menglong Dong <dong.menglong@zte.com.cn>
For now, there is only one element in netns_core_table, and it is inited
directly in sysctl_core_net_init. To make it more flexible, we can init
every element at once, just like what ipv4_sysctl_init_net() did.
Signed-off-by: Menglong Dong <dong.menglong@zte.com.cn>
---
net/core/sysctl_net_core.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index d86d8d11cfe4..966d976dee84 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -606,15 +606,19 @@ static __net_init int sysctl_core_net_init(struct net *net)
tbl = netns_core_table;
if (!net_eq(net, &init_net)) {
+ int i;
+
tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
if (tbl == NULL)
goto err_dup;
- tbl[0].data = &net->core.sysctl_somaxconn;
+ /* Update the variables to point into the current struct net */
+ for (i = 0; i < ARRAY_SIZE(netns_core_table) - 1; i++) {
+ tbl[i].data += (void *)net - (void *)&init_net;
- /* Don't export any sysctls to unprivileged users */
- if (net->user_ns != &init_user_ns) {
- tbl[0].procname = NULL;
+ /* Don't export any sysctls to unprivileged users */
+ if (net->user_ns != &init_user_ns)
+ tbl[i].procname = NULL;
}
}
--
2.30.0
reply other threads:[~2021-01-17 9:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20210117095228.173512-1-dong.menglong@zte.com.cn \
--to=menglong8.dong@gmail.com \
--cc=davem@davemloft.net \
--cc=dong.menglong@zte.com.cn \
--cc=keescook@chromium.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maheshb@google.com \
--cc=netdev@vger.kernel.org \
--cc=nicolas.dichtel@6wind.com \
--cc=rdna@fb.com \
--cc=viro@zeniv.linux.org.uk \
/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).