Skip to content

Commit 8eaf71f

Browse files
q2vendavem330
authored andcommitted
net: Initialise net.core sysctl defaults in preinit_net().
Commit 7c3f187 ("net: move somaxconn init from sysctl code") introduced net_defaults_ops to make sure that net.core sysctl knobs are always initialised even if CONFIG_SYSCTL is disabled. Such operations better fit preinit_net() added for a similar purpose by commit 6e77a5a ("net: initialize net->notrefcnt_tracker earlier"). Let's initialise the sysctl defaults in preinit_net(). Signed-off-by: Kuniyuki Iwashima <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 05be801 commit 8eaf71f

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

net/core/net_namespace.c

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,16 @@ struct net *get_net_ns_by_id(const struct net *net, int id)
309309
}
310310
EXPORT_SYMBOL_GPL(get_net_ns_by_id);
311311

312+
static __net_init void preinit_net_sysctl(struct net *net)
313+
{
314+
net->core.sysctl_somaxconn = SOMAXCONN;
315+
/* Limits per socket sk_omem_alloc usage.
316+
* TCP zerocopy regular usage needs 128 KB.
317+
*/
318+
net->core.sysctl_optmem_max = 128 * 1024;
319+
net->core.sysctl_txrehash = SOCK_TXREHASH_ENABLED;
320+
}
321+
312322
/* init code that must occur even if setup_net() is not called. */
313323
static __net_init void preinit_net(struct net *net, struct user_namespace *user_ns)
314324
{
@@ -324,6 +334,7 @@ static __net_init void preinit_net(struct net *net, struct user_namespace *user_
324334
idr_init(&net->netns_ids);
325335
spin_lock_init(&net->nsid_lock);
326336
mutex_init(&net->ipv4.ra_mutex);
337+
preinit_net_sysctl(net);
327338
}
328339

329340
/*
@@ -384,32 +395,6 @@ static __net_init int setup_net(struct net *net)
384395
goto out;
385396
}
386397

387-
static int __net_init net_defaults_init_net(struct net *net)
388-
{
389-
net->core.sysctl_somaxconn = SOMAXCONN;
390-
/* Limits per socket sk_omem_alloc usage.
391-
* TCP zerocopy regular usage needs 128 KB.
392-
*/
393-
net->core.sysctl_optmem_max = 128 * 1024;
394-
net->core.sysctl_txrehash = SOCK_TXREHASH_ENABLED;
395-
396-
return 0;
397-
}
398-
399-
static struct pernet_operations net_defaults_ops = {
400-
.init = net_defaults_init_net,
401-
};
402-
403-
static __init int net_defaults_init(void)
404-
{
405-
if (register_pernet_subsys(&net_defaults_ops))
406-
panic("Cannot initialize net default settings");
407-
408-
return 0;
409-
}
410-
411-
core_initcall(net_defaults_init);
412-
413398
#ifdef CONFIG_NET_NS
414399
static struct ucounts *inc_net_namespaces(struct user_namespace *ns)
415400
{

0 commit comments

Comments
 (0)