Skip to content

Commit

Permalink
[NET]: Make /proc/net per network namespace
Browse files Browse the repository at this point in the history
This patch makes /proc/net per network namespace.  It modifies the global
variables proc_net and proc_net_stat to be per network namespace.
The proc_net file helpers are modified to take a network namespace argument,
and all of their callers are fixed to pass &init_net for that argument.
This ensures that all of the /proc/net files are only visible and
usable in the initial network namespace until the code behind them
has been updated to be handle multiple network namespaces.

Making /proc/net per namespace is necessary as at least some files
in /proc/net depend upon the set of network devices which is per
network namespace, and even more files in /proc/net have contents
that are relevant to a single network namespace.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric W. Biederman authored and David S. Miller committed Oct 10, 2007
1 parent 07feaeb commit 457c4cb
Show file tree
Hide file tree
Showing 84 changed files with 342 additions and 261 deletions.
7 changes: 4 additions & 3 deletions drivers/isdn/divert/divert_procfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <linux/fs.h>
#endif
#include <linux/isdnif.h>
#include <net/net_namespace.h>
#include "isdn_divert.h"


Expand Down Expand Up @@ -284,12 +285,12 @@ divert_dev_init(void)
init_waitqueue_head(&rd_queue);

#ifdef CONFIG_PROC_FS
isdn_proc_entry = proc_mkdir("net/isdn", NULL);
isdn_proc_entry = proc_mkdir("isdn", init_net.proc_net);
if (!isdn_proc_entry)
return (-1);
isdn_divert_entry = create_proc_entry("divert", S_IFREG | S_IRUGO, isdn_proc_entry);
if (!isdn_divert_entry) {
remove_proc_entry("net/isdn", NULL);
remove_proc_entry("isdn", init_net.proc_net);
return (-1);
}
isdn_divert_entry->proc_fops = &isdn_fops;
Expand All @@ -309,7 +310,7 @@ divert_dev_deinit(void)

#ifdef CONFIG_PROC_FS
remove_proc_entry("divert", isdn_proc_entry);
remove_proc_entry("net/isdn", NULL);
remove_proc_entry("isdn", init_net.proc_net);
#endif /* CONFIG_PROC_FS */

return (0);
Expand Down
5 changes: 3 additions & 2 deletions drivers/isdn/hardware/eicon/diva_didd.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <net/net_namespace.h>

#include "platform.h"
#include "di_defs.h"
Expand Down Expand Up @@ -86,7 +87,7 @@ proc_read(char *page, char **start, off_t off, int count, int *eof,

static int DIVA_INIT_FUNCTION create_proc(void)
{
proc_net_eicon = proc_mkdir("net/eicon", NULL);
proc_net_eicon = proc_mkdir("eicon", init_net.proc_net);

if (proc_net_eicon) {
if ((proc_didd =
Expand All @@ -102,7 +103,7 @@ static int DIVA_INIT_FUNCTION create_proc(void)
static void remove_proc(void)
{
remove_proc_entry(DRIVERLNAME, proc_net_eicon);
remove_proc_entry("net/eicon", NULL);
remove_proc_entry("eicon", init_net.proc_net);
}

static int DIVA_INIT_FUNCTION divadidd_init(void)
Expand Down
5 changes: 3 additions & 2 deletions drivers/isdn/hysdn/hysdn_procconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <linux/proc_fs.h>
#include <linux/pci.h>
#include <linux/smp_lock.h>
#include <net/net_namespace.h>

#include "hysdn_defs.h"

Expand Down Expand Up @@ -392,7 +393,7 @@ hysdn_procconf_init(void)
hysdn_card *card;
unsigned char conf_name[20];

hysdn_proc_entry = proc_mkdir(PROC_SUBDIR_NAME, proc_net);
hysdn_proc_entry = proc_mkdir(PROC_SUBDIR_NAME, init_net.proc_net);
if (!hysdn_proc_entry) {
printk(KERN_ERR "HYSDN: unable to create hysdn subdir\n");
return (-1);
Expand Down Expand Up @@ -437,5 +438,5 @@ hysdn_procconf_release(void)
card = card->next; /* point to next card */
}

remove_proc_entry(PROC_SUBDIR_NAME, proc_net);
remove_proc_entry(PROC_SUBDIR_NAME, init_net.proc_net);
}
7 changes: 4 additions & 3 deletions drivers/net/bonding/bond_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include <linux/if_vlan.h>
#include <linux/if_bonding.h>
#include <net/route.h>
#include <net/net_namespace.h>
#include "bonding.h"
#include "bond_3ad.h"
#include "bond_alb.h"
Expand Down Expand Up @@ -3144,7 +3145,7 @@ static void bond_create_proc_dir(void)
{
int len = strlen(DRV_NAME);

for (bond_proc_dir = proc_net->subdir; bond_proc_dir;
for (bond_proc_dir = init_net.proc_net->subdir; bond_proc_dir;
bond_proc_dir = bond_proc_dir->next) {
if ((bond_proc_dir->namelen == len) &&
!memcmp(bond_proc_dir->name, DRV_NAME, len)) {
Expand All @@ -3153,7 +3154,7 @@ static void bond_create_proc_dir(void)
}

if (!bond_proc_dir) {
bond_proc_dir = proc_mkdir(DRV_NAME, proc_net);
bond_proc_dir = proc_mkdir(DRV_NAME, init_net.proc_net);
if (bond_proc_dir) {
bond_proc_dir->owner = THIS_MODULE;
} else {
Expand Down Expand Up @@ -3188,7 +3189,7 @@ static void bond_destroy_proc_dir(void)
bond_proc_dir->owner = NULL;
}
} else {
remove_proc_entry(DRV_NAME, proc_net);
remove_proc_entry(DRV_NAME, init_net.proc_net);
bond_proc_dir = NULL;
}
}
Expand Down
5 changes: 3 additions & 2 deletions drivers/net/hamradio/bpqether.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@

#include <net/ip.h>
#include <net/arp.h>
#include <net/net_namespace.h>

#include <linux/bpqether.h>

Expand Down Expand Up @@ -594,7 +595,7 @@ static int bpq_device_event(struct notifier_block *this,unsigned long event, voi
static int __init bpq_init_driver(void)
{
#ifdef CONFIG_PROC_FS
if (!proc_net_fops_create("bpqether", S_IRUGO, &bpq_info_fops)) {
if (!proc_net_fops_create(&init_net, "bpqether", S_IRUGO, &bpq_info_fops)) {
printk(KERN_ERR
"bpq: cannot create /proc/net/bpqether entry.\n");
return -ENOENT;
Expand All @@ -618,7 +619,7 @@ static void __exit bpq_cleanup_driver(void)

unregister_netdevice_notifier(&bpq_dev_notifier);

proc_net_remove("bpqether");
proc_net_remove(&init_net, "bpqether");

rtnl_lock();
while (!list_empty(&bpq_devices)) {
Expand Down
5 changes: 3 additions & 2 deletions drivers/net/hamradio/scc.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
#include <linux/seq_file.h>
#include <linux/bitops.h>

#include <net/net_namespace.h>
#include <net/ax25.h>

#include <asm/irq.h>
Expand Down Expand Up @@ -2114,7 +2115,7 @@ static int __init scc_init_driver (void)
}
rtnl_unlock();

proc_net_fops_create("z8530drv", 0, &scc_net_seq_fops);
proc_net_fops_create(&init_net, "z8530drv", 0, &scc_net_seq_fops);

return 0;
}
Expand Down Expand Up @@ -2169,7 +2170,7 @@ static void __exit scc_cleanup_driver(void)
if (Vector_Latch)
release_region(Vector_Latch, 1);

proc_net_remove("z8530drv");
proc_net_remove(&init_net, "z8530drv");
}

MODULE_AUTHOR("Joerg Reuter <jreuter@yaina.de>");
Expand Down
5 changes: 3 additions & 2 deletions drivers/net/hamradio/yam.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <net/net_namespace.h>

#include <asm/uaccess.h>
#include <linux/init.h>
Expand Down Expand Up @@ -1142,7 +1143,7 @@ static int __init yam_init_driver(void)
yam_timer.expires = jiffies + HZ / 100;
add_timer(&yam_timer);

proc_net_fops_create("yam", S_IRUGO, &yam_info_fops);
proc_net_fops_create(&init_net, "yam", S_IRUGO, &yam_info_fops);
return 0;
error:
while (--i >= 0) {
Expand Down Expand Up @@ -1174,7 +1175,7 @@ static void __exit yam_cleanup_driver(void)
kfree(p);
}

proc_net_remove("yam");
proc_net_remove(&init_net, "yam");
}

/* --------------------------------------------------------------------- */
Expand Down
7 changes: 4 additions & 3 deletions drivers/net/ibmveth.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <linux/mm.h>
#include <linux/ethtool.h>
#include <linux/proc_fs.h>
#include <net/net_namespace.h>
#include <asm/semaphore.h>
#include <asm/hvcall.h>
#include <asm/atomic.h>
Expand Down Expand Up @@ -97,7 +98,7 @@ static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter);
static struct kobj_type ktype_veth_pool;

#ifdef CONFIG_PROC_FS
#define IBMVETH_PROC_DIR "net/ibmveth"
#define IBMVETH_PROC_DIR "ibmveth"
static struct proc_dir_entry *ibmveth_proc_dir;
#endif

Expand Down Expand Up @@ -1091,15 +1092,15 @@ static int __devexit ibmveth_remove(struct vio_dev *dev)
#ifdef CONFIG_PROC_FS
static void ibmveth_proc_register_driver(void)
{
ibmveth_proc_dir = proc_mkdir(IBMVETH_PROC_DIR, NULL);
ibmveth_proc_dir = proc_mkdir(IBMVETH_PROC_DIR, init_net.proc_net);
if (ibmveth_proc_dir) {
SET_MODULE_OWNER(ibmveth_proc_dir);
}
}

static void ibmveth_proc_unregister_driver(void)
{
remove_proc_entry(IBMVETH_PROC_DIR, NULL);
remove_proc_entry(IBMVETH_PROC_DIR, init_net.proc_net);
}

static void *ibmveth_seq_start(struct seq_file *seq, loff_t *pos)
Expand Down
5 changes: 3 additions & 2 deletions drivers/net/pppoe.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
#include <linux/proc_fs.h>
#include <linux/seq_file.h>

#include <net/net_namespace.h>
#include <net/sock.h>

#include <asm/uaccess.h>
Expand Down Expand Up @@ -1042,7 +1043,7 @@ static int __init pppoe_proc_init(void)
{
struct proc_dir_entry *p;

p = create_proc_entry("net/pppoe", S_IRUGO, NULL);
p = create_proc_entry("pppoe", S_IRUGO, init_net.proc_net);
if (!p)
return -ENOMEM;

Expand Down Expand Up @@ -1113,7 +1114,7 @@ static void __exit pppoe_exit(void)
dev_remove_pack(&pppoes_ptype);
dev_remove_pack(&pppoed_ptype);
unregister_netdevice_notifier(&pppoe_notifier);
remove_proc_entry("net/pppoe", NULL);
remove_proc_entry("pppoe", init_net.proc_net);
proto_unregister(&pppoe_sk_proto);
}

Expand Down
5 changes: 3 additions & 2 deletions drivers/net/pppol2tp.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
#include <linux/hash.h>
#include <linux/sort.h>
#include <linux/proc_fs.h>
#include <net/net_namespace.h>
#include <net/dst.h>
#include <net/ip.h>
#include <net/udp.h>
Expand Down Expand Up @@ -2444,7 +2445,7 @@ static int __init pppol2tp_init(void)
goto out_unregister_pppol2tp_proto;

#ifdef CONFIG_PROC_FS
pppol2tp_proc = create_proc_entry("pppol2tp", 0, proc_net);
pppol2tp_proc = create_proc_entry("pppol2tp", 0, init_net.proc_net);
if (!pppol2tp_proc) {
err = -ENOMEM;
goto out_unregister_pppox_proto;
Expand All @@ -2469,7 +2470,7 @@ static void __exit pppol2tp_exit(void)
unregister_pppox_proto(PX_PROTO_OL2TP);

#ifdef CONFIG_PROC_FS
remove_proc_entry("pppol2tp", proc_net);
remove_proc_entry("pppol2tp", init_net.proc_net);
#endif
proto_unregister(&pppol2tp_sk_proto);
}
Expand Down
5 changes: 3 additions & 2 deletions drivers/net/tokenring/lanstreamer.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
#include <linux/bitops.h>
#include <linux/jiffies.h>

#include <net/net_namespace.h>
#include <net/checksum.h>

#include <asm/io.h>
Expand Down Expand Up @@ -250,7 +251,7 @@ static int __devinit streamer_init_one(struct pci_dev *pdev,
#if STREAMER_NETWORK_MONITOR
#ifdef CONFIG_PROC_FS
if (!dev_streamer)
create_proc_read_entry("net/streamer_tr", 0, 0,
create_proc_read_entry("streamer_tr", 0, init_net.proc_net,
streamer_proc_info, NULL);
streamer_priv->next = dev_streamer;
dev_streamer = streamer_priv;
Expand Down Expand Up @@ -423,7 +424,7 @@ static void __devexit streamer_remove_one(struct pci_dev *pdev)
}
}
if (!dev_streamer)
remove_proc_entry("net/streamer_tr", NULL);
remove_proc_entry("streamer_tr", init_net.proc_net);
}
#endif
#endif
Expand Down
9 changes: 5 additions & 4 deletions drivers/net/tokenring/olympic.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
#include <linux/jiffies.h>

#include <net/checksum.h>
#include <net/net_namespace.h>

#include <asm/io.h>
#include <asm/system.h>
Expand Down Expand Up @@ -268,9 +269,9 @@ static int __devinit olympic_probe(struct pci_dev *pdev, const struct pci_device
printk("Olympic: %s registered as: %s\n",olympic_priv->olympic_card_name,dev->name);
if (olympic_priv->olympic_network_monitor) { /* Must go after register_netdev as we need the device name */
char proc_name[20] ;
strcpy(proc_name,"net/olympic_") ;
strcpy(proc_name,"olympic_") ;
strcat(proc_name,dev->name) ;
create_proc_read_entry(proc_name,0,NULL,olympic_proc_info,(void *)dev) ;
create_proc_read_entry(proc_name,0,init_net.proc_net,olympic_proc_info,(void *)dev) ;
printk("Olympic: Network Monitor information: /proc/%s\n",proc_name);
}
return 0 ;
Expand Down Expand Up @@ -1752,9 +1753,9 @@ static void __devexit olympic_remove_one(struct pci_dev *pdev)

if (olympic_priv->olympic_network_monitor) {
char proc_name[20] ;
strcpy(proc_name,"net/olympic_") ;
strcpy(proc_name,"olympic_") ;
strcat(proc_name,dev->name) ;
remove_proc_entry(proc_name,NULL);
remove_proc_entry(proc_name,init_net.proc_net);
}
unregister_netdev(dev) ;
iounmap(olympic_priv->olympic_mmio) ;
Expand Down
7 changes: 4 additions & 3 deletions drivers/net/wireless/hostap/hostap_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <linux/rtnetlink.h>
#include <linux/wireless.h>
#include <linux/etherdevice.h>
#include <net/net_namespace.h>
#include <net/iw_handler.h>
#include <net/ieee80211.h>
#include <net/ieee80211_crypt.h>
Expand Down Expand Up @@ -1093,8 +1094,8 @@ struct proc_dir_entry *hostap_proc;

static int __init hostap_init(void)
{
if (proc_net != NULL) {
hostap_proc = proc_mkdir("hostap", proc_net);
if (init_net.proc_net != NULL) {
hostap_proc = proc_mkdir("hostap", init_net.proc_net);
if (!hostap_proc)
printk(KERN_WARNING "Failed to mkdir "
"/proc/net/hostap\n");
Expand All @@ -1109,7 +1110,7 @@ static void __exit hostap_exit(void)
{
if (hostap_proc != NULL) {
hostap_proc = NULL;
remove_proc_entry("hostap", proc_net);
remove_proc_entry("hostap", init_net.proc_net);
}
}

Expand Down
5 changes: 3 additions & 2 deletions drivers/net/wireless/strip.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ static const char StripVersion[] = "1.3A-STUART.CHESHIRE";
#include <linux/serialP.h>
#include <linux/rcupdate.h>
#include <net/arp.h>
#include <net/net_namespace.h>

#include <linux/ip.h>
#include <linux/tcp.h>
Expand Down Expand Up @@ -2787,7 +2788,7 @@ static int __init strip_init_driver(void)
/*
* Register the status file with /proc
*/
proc_net_fops_create("strip", S_IFREG | S_IRUGO, &strip_seq_fops);
proc_net_fops_create(&init_net, "strip", S_IFREG | S_IRUGO, &strip_seq_fops);

return status;
}
Expand All @@ -2809,7 +2810,7 @@ static void __exit strip_exit_driver(void)
}

/* Unregister with the /proc/net file here. */
proc_net_remove("strip");
proc_net_remove(&init_net, "strip");

if ((i = tty_unregister_ldisc(N_STRIP)))
printk(KERN_ERR "STRIP: can't unregister line discipline (err = %d)\n", i);
Expand Down
Loading

0 comments on commit 457c4cb

Please sign in to comment.