aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2007-09-27 01:04:26 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:52:46 -0400
commit9dd776b6d7b0b85966b6ddd03e2b2aae59012ab1 (patch)
treeed92aee1f242bb31a0965a4156063eac916ae15e /net
parent8b41d1887db718be9a2cd9e18c58ce25a4c7fd93 (diff)
[NET]: Add network namespace clone & unshare support.
This patch allows you to create a new network namespace using sys_clone, or sys_unshare. As the network namespace is still experimental and under development clone and unshare support is only made available when CONFIG_NET_NS is selected at compile time. As this patch introduces network namespace support into code paths that exist when the CONFIG_NET is not selected there are a few additions made to net_namespace.h to allow a few more functions to be used when the networking stack is not compiled in. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/Kconfig8
-rw-r--r--net/core/net_namespace.c43
2 files changed, 49 insertions, 2 deletions
diff --git a/net/Kconfig b/net/Kconfig
index cdba08ca2efe..ab4e6da5012f 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -27,6 +27,14 @@ if NET
27 27
28menu "Networking options" 28menu "Networking options"
29 29
30config NET_NS
31 bool "Network namespace support"
32 default n
33 depends on EXPERIMENTAL && !SYSFS
34 help
35 Allow user space to create what appear to be multiple instances
36 of the network stack.
37
30source "net/packet/Kconfig" 38source "net/packet/Kconfig"
31source "net/unix/Kconfig" 39source "net/unix/Kconfig"
32source "net/xfrm/Kconfig" 40source "net/xfrm/Kconfig"
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 0e6cb02d7b77..e478e353ea6b 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -4,6 +4,7 @@
4#include <linux/slab.h> 4#include <linux/slab.h>
5#include <linux/list.h> 5#include <linux/list.h>
6#include <linux/delay.h> 6#include <linux/delay.h>
7#include <linux/sched.h>
7#include <net/net_namespace.h> 8#include <net/net_namespace.h>
8 9
9/* 10/*
@@ -32,12 +33,10 @@ void net_unlock(void)
32 mutex_unlock(&net_list_mutex); 33 mutex_unlock(&net_list_mutex);
33} 34}
34 35
35#if 0
36static struct net *net_alloc(void) 36static struct net *net_alloc(void)
37{ 37{
38 return kmem_cache_alloc(net_cachep, GFP_KERNEL); 38 return kmem_cache_alloc(net_cachep, GFP_KERNEL);
39} 39}
40#endif
41 40
42static void net_free(struct net *net) 41static void net_free(struct net *net)
43{ 42{
@@ -128,6 +127,46 @@ out_undo:
128 goto out; 127 goto out;
129} 128}
130 129
130struct net *copy_net_ns(unsigned long flags, struct net *old_net)
131{
132 struct net *new_net = NULL;
133 int err;
134
135 get_net(old_net);
136
137 if (!(flags & CLONE_NEWNET))
138 return old_net;
139
140#ifndef CONFIG_NET_NS
141 return ERR_PTR(-EINVAL);
142#endif
143
144 err = -ENOMEM;
145 new_net = net_alloc();
146 if (!new_net)
147 goto out;
148
149 mutex_lock(&net_mutex);
150 err = setup_net(new_net);
151 if (err)
152 goto out_unlock;
153
154 net_lock();
155 list_add_tail(&new_net->list, &net_namespace_list);
156 net_unlock();
157
158
159out_unlock:
160 mutex_unlock(&net_mutex);
161out:
162 put_net(old_net);
163 if (err) {
164 net_free(new_net);
165 new_net = ERR_PTR(err);
166 }
167 return new_net;
168}
169
131static int __init net_ns_init(void) 170static int __init net_ns_init(void)
132{ 171{
133 int err; 172 int err;