Skip to content

Commit

Permalink
net: Move all of the network sysctls without a namespace into init_net.
Browse files Browse the repository at this point in the history
This makes it clearer which sysctls are relative to your current network
namespace.

This makes it a little less error prone by not exposing sysctls for the
initial network namespace in other namespaces.

This is the same way we handle all of our other network interfaces to
userspace and I can't honestly remember why we didn't do this for
sysctls right from the start.

Signed-off-by: Eric W. Biederman <[email protected]>
Acked-by: Pavel Emelyanov <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
ebiederm authored and davem330 committed Apr 21, 2012
1 parent 4344475 commit 5dd3df1
Show file tree
Hide file tree
Showing 31 changed files with 60 additions and 58 deletions.
4 changes: 2 additions & 2 deletions drivers/infiniband/core/ucma.c
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ static int __init ucma_init(void)
goto err1;
}

ucma_ctl_table_hdr = register_sysctl_paths(ucma_ctl_path, ucma_ctl_table);
ucma_ctl_table_hdr = register_net_sysctl_table(&init_net, ucma_ctl_path, ucma_ctl_table);
if (!ucma_ctl_table_hdr) {
printk(KERN_ERR "rdma_ucm: couldn't register sysctl paths\n");
ret = -ENOMEM;
Expand All @@ -1408,7 +1408,7 @@ static int __init ucma_init(void)

static void __exit ucma_cleanup(void)
{
unregister_sysctl_table(ucma_ctl_table_hdr);
unregister_net_sysctl_table(ucma_ctl_table_hdr);
device_remove_file(ucma_misc.this_device, &dev_attr_abi_version);
misc_deregister(&ucma_misc);
idr_destroy(&ctx_idr);
Expand Down
2 changes: 1 addition & 1 deletion net/802/tr.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ static int __init rif_init(void)
setup_timer(&rif_timer, rif_check_expire, 0);
add_timer(&rif_timer);
#ifdef CONFIG_SYSCTL
register_sysctl_paths(tr_path, tr_table);
register_net_sysctl_table(&init_net, tr_path, tr_table);
#endif
proc_net_fops_create(&init_net, "tr_rif", S_IRUGO, &rif_seq_fops);
return 0;
Expand Down
4 changes: 2 additions & 2 deletions net/appletalk/sysctl_net_atalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ static struct ctl_table_header *atalk_table_header;

void atalk_register_sysctl(void)
{
atalk_table_header = register_sysctl_paths(atalk_path, atalk_table);
atalk_table_header = register_net_sysctl_table(&init_net, atalk_path, atalk_table);
}

void atalk_unregister_sysctl(void)
{
unregister_sysctl_table(atalk_table_header);
unregister_net_sysctl_table(atalk_table_header);
}
4 changes: 2 additions & 2 deletions net/ax25/sysctl_net_ax25.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ void ax25_register_sysctl(void)
}
spin_unlock_bh(&ax25_dev_lock);

ax25_table_header = register_sysctl_paths(ax25_path, ax25_table);
ax25_table_header = register_net_sysctl_table(&init_net, ax25_path, ax25_table);
}

void ax25_unregister_sysctl(void)
{
ctl_table *p;
unregister_sysctl_table(ax25_table_header);
unregister_net_sysctl_table(ax25_table_header);

for (p = ax25_table; p->procname; p++)
kfree(p->child);
Expand Down
4 changes: 2 additions & 2 deletions net/bridge/br_netfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ int __init br_netfilter_init(void)
return ret;
}
#ifdef CONFIG_SYSCTL
brnf_sysctl_header = register_sysctl_paths(brnf_path, brnf_table);
brnf_sysctl_header = register_net_sysctl_table(&init_net, brnf_path, brnf_table);
if (brnf_sysctl_header == NULL) {
printk(KERN_WARNING
"br_netfilter: can't register to sysctl.\n");
Expand All @@ -1047,7 +1047,7 @@ void br_netfilter_fini(void)
{
nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));
#ifdef CONFIG_SYSCTL
unregister_sysctl_table(brnf_sysctl_header);
unregister_net_sysctl_table(brnf_sysctl_header);
#endif
dst_entries_destroy(&fake_dst_ops);
}
2 changes: 1 addition & 1 deletion net/core/neighbour.c
Original file line number Diff line number Diff line change
Expand Up @@ -3017,7 +3017,7 @@ void neigh_sysctl_unregister(struct neigh_parms *p)
if (p->sysctl_table) {
struct neigh_sysctl_table *t = p->sysctl_table;
p->sysctl_table = NULL;
unregister_sysctl_table(t->sysctl_header);
unregister_net_sysctl_table(t->sysctl_header);
kfree(t->dev_name);
kfree(t);
}
Expand Down
2 changes: 1 addition & 1 deletion net/core/sysctl_net_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ static __init int sysctl_core_init(void)
{
static struct ctl_table empty[1];

kmemleak_not_leak(register_sysctl_paths(net_core_path, empty));
kmemleak_not_leak(register_net_sysctl_table(&init_net, net_core_path, empty));
register_net_sysctl(&init_net, "net/core", net_core_table);
return register_pernet_subsys(&sysctl_core_ops);
}
Expand Down
4 changes: 2 additions & 2 deletions net/dccp/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static struct ctl_table_header *dccp_table_header;

int __init dccp_sysctl_init(void)
{
dccp_table_header = register_sysctl_paths(dccp_path,
dccp_table_header = register_net_sysctl_table(&init_net, dccp_path,
dccp_default_table);

return dccp_table_header != NULL ? 0 : -ENOMEM;
Expand All @@ -118,7 +118,7 @@ int __init dccp_sysctl_init(void)
void dccp_sysctl_exit(void)
{
if (dccp_table_header != NULL) {
unregister_sysctl_table(dccp_table_header);
unregister_net_sysctl_table(dccp_table_header);
dccp_table_header = NULL;
}
}
4 changes: 2 additions & 2 deletions net/decnet/dn_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ static void dn_dev_sysctl_register(struct net_device *dev, struct dn_dev_parms *

t->dn_dev_vars[0].extra1 = (void *)dev;

t->sysctl_header = register_sysctl_paths(dn_ctl_path, t->dn_dev_vars);
t->sysctl_header = register_net_sysctl_table(&init_net, dn_ctl_path, t->dn_dev_vars);
if (t->sysctl_header == NULL)
kfree(t);
else
Expand All @@ -248,7 +248,7 @@ static void dn_dev_sysctl_unregister(struct dn_dev_parms *parms)
if (parms->sysctl) {
struct dn_dev_sysctl_table *t = parms->sysctl;
parms->sysctl = NULL;
unregister_sysctl_table(t->sysctl_header);
unregister_net_sysctl_table(t->sysctl_header);
kfree(t);
}
}
Expand Down
4 changes: 2 additions & 2 deletions net/decnet/sysctl_net_decnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,12 @@ static struct ctl_path dn_path[] = {

void dn_register_sysctl(void)
{
dn_table_header = register_sysctl_paths(dn_path, dn_table);
dn_table_header = register_net_sysctl_table(&init_net, dn_path, dn_table);
}

void dn_unregister_sysctl(void)
{
unregister_sysctl_table(dn_table_header);
unregister_net_sysctl_table(dn_table_header);
}

#else /* CONFIG_SYSCTL */
Expand Down
6 changes: 3 additions & 3 deletions net/ipv4/netfilter/ip_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ static int __init ip_queue_init(void)
#endif
register_netdevice_notifier(&ipq_dev_notifier);
#ifdef CONFIG_SYSCTL
ipq_sysctl_header = register_sysctl_paths(net_ipv4_ctl_path, ipq_table);
ipq_sysctl_header = register_net_sysctl_table(&init_net, net_ipv4_ctl_path, ipq_table);
#endif
status = nf_register_queue_handler(NFPROTO_IPV4, &nfqh);
if (status < 0) {
Expand All @@ -597,7 +597,7 @@ static int __init ip_queue_init(void)

cleanup_sysctl:
#ifdef CONFIG_SYSCTL
unregister_sysctl_table(ipq_sysctl_header);
unregister_net_sysctl_table(ipq_sysctl_header);
#endif
unregister_netdevice_notifier(&ipq_dev_notifier);
proc_net_remove(&init_net, IPQ_PROC_FS_NAME);
Expand All @@ -618,7 +618,7 @@ static void __exit ip_queue_fini(void)
ipq_flush(NULL, 0);

#ifdef CONFIG_SYSCTL
unregister_sysctl_table(ipq_sysctl_header);
unregister_net_sysctl_table(ipq_sysctl_header);
#endif
unregister_netdevice_notifier(&ipq_dev_notifier);
proc_net_remove(&init_net, IPQ_PROC_FS_NAME);
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -3515,6 +3515,6 @@ int __init ip_rt_init(void)
*/
void __init ip_static_sysctl_init(void)
{
kmemleak_not_leak(register_sysctl_paths(ipv4_path, ipv4_skeleton));
kmemleak_not_leak(register_net_sysctl_table(&init_net, ipv4_path, ipv4_skeleton));
}
#endif
4 changes: 2 additions & 2 deletions net/ipv4/sysctl_net_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,12 +857,12 @@ static __init int sysctl_ipv4_init(void)
if (!i->procname)
return -EINVAL;

hdr = register_sysctl_paths(net_ipv4_ctl_path, ipv4_table);
hdr = register_net_sysctl_table(&init_net, net_ipv4_ctl_path, ipv4_table);
if (hdr == NULL)
return -ENOMEM;

if (register_pernet_subsys(&ipv4_sysctl_ops)) {
unregister_sysctl_table(hdr);
unregister_net_sysctl_table(hdr);
return -ENOMEM;
}

Expand Down
6 changes: 3 additions & 3 deletions net/ipv6/netfilter/ip6_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ static int __init ip6_queue_init(void)
#endif
register_netdevice_notifier(&ipq_dev_notifier);
#ifdef CONFIG_SYSCTL
ipq_sysctl_header = register_sysctl_paths(net_ipv6_ctl_path, ipq_table);
ipq_sysctl_header = register_net_sysctl_table(&init_net, net_ipv6_ctl_path, ipq_table);
#endif
status = nf_register_queue_handler(NFPROTO_IPV6, &nfqh);
if (status < 0) {
Expand All @@ -599,7 +599,7 @@ static int __init ip6_queue_init(void)

cleanup_sysctl:
#ifdef CONFIG_SYSCTL
unregister_sysctl_table(ipq_sysctl_header);
unregister_net_sysctl_table(ipq_sysctl_header);
#endif
unregister_netdevice_notifier(&ipq_dev_notifier);
proc_net_remove(&init_net, IPQ_PROC_FS_NAME);
Expand All @@ -621,7 +621,7 @@ static void __exit ip6_queue_fini(void)
ipq_flush(NULL, 0);

#ifdef CONFIG_SYSCTL
unregister_sysctl_table(ipq_sysctl_header);
unregister_net_sysctl_table(ipq_sysctl_header);
#endif
unregister_netdevice_notifier(&ipq_dev_notifier);
proc_net_remove(&init_net, IPQ_PROC_FS_NAME);
Expand Down
4 changes: 2 additions & 2 deletions net/ipv6/netfilter/nf_conntrack_reasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ int nf_ct_frag6_init(void)
inet_frags_init(&nf_frags);

#ifdef CONFIG_SYSCTL
nf_ct_frag6_sysctl_header = register_sysctl_paths(nf_net_netfilter_sysctl_path,
nf_ct_frag6_sysctl_header = register_net_sysctl_table(&init_net, nf_net_netfilter_sysctl_path,
nf_ct_frag6_sysctl_table);
if (!nf_ct_frag6_sysctl_header) {
inet_frags_fini(&nf_frags);
Expand All @@ -640,7 +640,7 @@ int nf_ct_frag6_init(void)
void nf_ct_frag6_cleanup(void)
{
#ifdef CONFIG_SYSCTL
unregister_sysctl_table(nf_ct_frag6_sysctl_header);
unregister_net_sysctl_table(nf_ct_frag6_sysctl_header);
nf_ct_frag6_sysctl_header = NULL;
#endif
inet_frags_fini(&nf_frags);
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/sysctl_net_ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static struct ctl_table_header *ip6_base;

int ipv6_static_sysctl_register(void)
{
ip6_base = register_sysctl_paths(net_ipv6_ctl_path, ipv6_static_skeleton);
ip6_base = register_net_sysctl_table(&init_net, net_ipv6_ctl_path, ipv6_static_skeleton);
if (ip6_base == NULL)
return -ENOMEM;
return 0;
Expand Down
5 changes: 3 additions & 2 deletions net/ipx/sysctl_net_ipx.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <linux/mm.h>
#include <linux/sysctl.h>
#include <net/net_namespace.h>

#ifndef CONFIG_SYSCTL
#error This file should not be compiled without CONFIG_SYSCTL defined
Expand Down Expand Up @@ -37,10 +38,10 @@ static struct ctl_table_header *ipx_table_header;

void ipx_register_sysctl(void)
{
ipx_table_header = register_sysctl_paths(ipx_path, ipx_table);
ipx_table_header = register_net_sysctl_table(&init_net, ipx_path, ipx_table);
}

void ipx_unregister_sysctl(void)
{
unregister_sysctl_table(ipx_table_header);
unregister_net_sysctl_table(ipx_table_header);
}
4 changes: 2 additions & 2 deletions net/irda/irsysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ static struct ctl_table_header *irda_table_header;
*/
int __init irda_sysctl_register(void)
{
irda_table_header = register_sysctl_paths(irda_path, irda_table);
irda_table_header = register_net_sysctl_table(&init_net, irda_path, irda_table);
if (!irda_table_header)
return -ENOMEM;

Expand All @@ -266,7 +266,7 @@ int __init irda_sysctl_register(void)
*/
void irda_sysctl_unregister(void)
{
unregister_sysctl_table(irda_table_header);
unregister_net_sysctl_table(irda_table_header);
}


Expand Down
5 changes: 3 additions & 2 deletions net/llc/sysctl_net_llc.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <linux/mm.h>
#include <linux/init.h>
#include <linux/sysctl.h>
#include <net/net_namespace.h>
#include <net/llc.h>

#ifndef CONFIG_SYSCTL
Expand Down Expand Up @@ -89,15 +90,15 @@ static struct ctl_table_header *llc_table_header;

int __init llc_sysctl_init(void)
{
llc_table_header = register_sysctl_paths(llc_path, llc_table);
llc_table_header = register_net_sysctl_table(&init_net, llc_path, llc_table);

return llc_table_header ? 0 : -ENOMEM;
}

void llc_sysctl_exit(void)
{
if (llc_table_header) {
unregister_sysctl_table(llc_table_header);
unregister_net_sysctl_table(llc_table_header);
llc_table_header = NULL;
}
}
4 changes: 2 additions & 2 deletions net/netfilter/nf_conntrack_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ nf_ct_register_sysctl(struct ctl_table_header **header, struct ctl_path *path,
struct ctl_table *table, unsigned int *users)
{
if (*header == NULL) {
*header = register_sysctl_paths(path, table);
*header = register_net_sysctl_table(&init_net, path, table);
if (*header == NULL)
return -ENOMEM;
}
Expand All @@ -56,7 +56,7 @@ nf_ct_unregister_sysctl(struct ctl_table_header **header,
if (users != NULL && --*users > 0)
return;

unregister_sysctl_table(*header);
unregister_net_sysctl_table(*header);
*header = NULL;
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions net/netfilter/nf_conntrack_standalone.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net)

if (net_eq(net, &init_net)) {
nf_ct_netfilter_header =
register_sysctl_paths(nf_ct_path, nf_ct_netfilter_table);
register_net_sysctl_table(&init_net, nf_ct_path, nf_ct_netfilter_table);
if (!nf_ct_netfilter_header)
goto out;
}
Expand All @@ -505,7 +505,7 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net)
kfree(table);
out_kmemdup:
if (net_eq(net, &init_net))
unregister_sysctl_table(nf_ct_netfilter_header);
unregister_net_sysctl_table(nf_ct_netfilter_header);
out:
printk(KERN_ERR "nf_conntrack: can't register to sysctl.\n");
return -ENOMEM;
Expand All @@ -516,7 +516,7 @@ static void nf_conntrack_standalone_fini_sysctl(struct net *net)
struct ctl_table *table;

if (net_eq(net, &init_net))
unregister_sysctl_table(nf_ct_netfilter_header);
unregister_net_sysctl_table(nf_ct_netfilter_header);
table = net->ct.sysctl_header->ctl_table_arg;
unregister_net_sysctl_table(net->ct.sysctl_header);
kfree(table);
Expand Down
2 changes: 1 addition & 1 deletion net/netfilter/nf_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ static __init int netfilter_log_sysctl_init(void)
nf_log_sysctl_table[i].extra1 = (void *)(unsigned long) i;
}

nf_log_dir_header = register_sysctl_paths(nf_log_sysctl_path,
nf_log_dir_header = register_net_sysctl_table(&init_net, nf_log_sysctl_path,
nf_log_sysctl_table);
if (!nf_log_dir_header)
return -ENOMEM;
Expand Down
4 changes: 2 additions & 2 deletions net/netrom/sysctl_net_netrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ static struct ctl_path nr_path[] = {

void __init nr_register_sysctl(void)
{
nr_table_header = register_sysctl_paths(nr_path, nr_table);
nr_table_header = register_net_sysctl_table(&init_net, nr_path, nr_table);
}

void nr_unregister_sysctl(void)
{
unregister_sysctl_table(nr_table_header);
unregister_net_sysctl_table(nr_table_header);
}
4 changes: 2 additions & 2 deletions net/phonet/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ static struct ctl_path phonet_ctl_path[] = {

int __init phonet_sysctl_init(void)
{
phonet_table_hrd = register_sysctl_paths(phonet_ctl_path, phonet_table);
phonet_table_hrd = register_net_sysctl_table(&init_net, phonet_ctl_path, phonet_table);
return phonet_table_hrd == NULL ? -ENOMEM : 0;
}

void phonet_sysctl_exit(void)
{
unregister_sysctl_table(phonet_table_hrd);
unregister_net_sysctl_table(phonet_table_hrd);
}
Loading

0 comments on commit 5dd3df1

Please sign in to comment.