* [PATCH net-next] net: core: init every ctl_table in netns_core_table
@ 2021-01-17 9:52 menglong8.dong
0 siblings, 0 replies; only message in thread
From: menglong8.dong @ 2021-01-17 9:52 UTC (permalink / raw)
To: kuba
Cc: davem, viro, rdna, nicolas.dichtel, maheshb, keescook,
dong.menglong, netdev, linux-kernel
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-01-17 9:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-17 9:52 [PATCH net-next] net: core: init every ctl_table in netns_core_table menglong8.dong
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).