summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2007-09-26 22:10:56 -0700
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 16:52:49 -0700
commit2774c7aba6c97a2535be3309a2209770953780b3 (patch)
tree9327c795707f6d723c6395c31e1c060e70b5e0db /drivers
parent0cc217e16cb8ca8ef2544363571fce94259900e0 (diff)
[NET]: Make the loopback device per network namespace.
This patch makes loopback_dev per network namespace. Adding code to create a different loopback device for each network namespace and adding the code to free a loopback device when a network namespace exits. This patch modifies all users the loopback_dev so they access it as init_net.loopback_dev, keeping all of the code compiling and working. A later pass will be needed to update the users to use something other than the initial network namespace. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/loopback.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c
index f3018bb7570..0f9d8c60c96 100644
--- a/drivers/net/loopback.c
+++ b/drivers/net/loopback.c
@@ -57,6 +57,7 @@
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/percpu.h>
+#include <net/net_namespace.h>
struct pcpu_lstats {
unsigned long packets;
@@ -252,7 +253,7 @@ static void loopback_setup(struct net_device *dev)
}
/* Setup and register the loopback device. */
-static int __init loopback_init(void)
+static int loopback_net_init(struct net *net)
{
struct net_device *dev;
int err;
@@ -262,12 +263,13 @@ static int __init loopback_init(void)
if (!dev)
goto out;
+ dev->nd_net = net;
err = register_netdev(dev);
if (err)
goto out_free_netdev;
err = 0;
- loopback_dev = dev;
+ net->loopback_dev = dev;
out:
if (err)
@@ -279,7 +281,21 @@ out_free_netdev:
goto out;
}
-fs_initcall(loopback_init);
+static void loopback_net_exit(struct net *net)
+{
+ struct net_device *dev = net->loopback_dev;
+
+ unregister_netdev(dev);
+}
+
+static struct pernet_operations loopback_net_ops = {
+ .init = loopback_net_init,
+ .exit = loopback_net_exit,
+};
+
+static int __init loopback_init(void)
+{
+ return register_pernet_device(&loopback_net_ops);
+}
-struct net_device *loopback_dev;
-EXPORT_SYMBOL(loopback_dev);
+fs_initcall(loopback_init);