aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/net_namespace.c
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2011-05-04 17:51:50 -0700
committerEric W. Biederman <ebiederm@xmission.com>2011-05-10 14:36:03 -0700
commitf063052947f770845a6252f7fa24f6f624592a24 (patch)
tree17513dbd49d5a1a08443d76374d10dda6114b7a7 /net/core/net_namespace.c
parenta00eaf11a223c63fbb212369d6db69ce4c55a2d1 (diff)
downloadkernel_samsung_smdk4412-f063052947f770845a6252f7fa24f6f624592a24.zip
kernel_samsung_smdk4412-f063052947f770845a6252f7fa24f6f624592a24.tar.gz
kernel_samsung_smdk4412-f063052947f770845a6252f7fa24f6f624592a24.tar.bz2
net: Allow setting the network namespace by fd
Take advantage of the new abstraction and allow network devices to be placed in any network namespace that we have a fd to talk about. Acked-by: David S. Miller <davem@davemloft.net> Acked-by: Daniel Lezcano <daniel.lezcano@free.fr> Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Diffstat (limited to 'net/core/net_namespace.c')
-rw-r--r--net/core/net_namespace.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index bf7707e..b7403ff 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -8,6 +8,8 @@
#include <linux/idr.h>
#include <linux/rculist.h>
#include <linux/nsproxy.h>
+#include <linux/proc_fs.h>
+#include <linux/file.h>
#include <net/net_namespace.h>
#include <net/netns/generic.h>
@@ -343,6 +345,28 @@ struct net *get_net_ns_by_pid(pid_t pid)
}
EXPORT_SYMBOL_GPL(get_net_ns_by_pid);
+struct net *get_net_ns_by_fd(int fd)
+{
+ struct proc_inode *ei;
+ struct file *file;
+ struct net *net;
+
+ net = ERR_PTR(-EINVAL);
+ file = proc_ns_fget(fd);
+ if (!file)
+ goto out;
+
+ ei = PROC_I(file->f_dentry->d_inode);
+ if (ei->ns_ops != &netns_operations)
+ goto out;
+
+ net = get_net(ei->ns);
+out:
+ if (file)
+ fput(file);
+ return net;
+}
+
static int __init net_ns_init(void)
{
struct net_generic *ng;
@@ -577,10 +601,15 @@ EXPORT_SYMBOL_GPL(unregister_pernet_device);
#ifdef CONFIG_NET_NS
static void *netns_get(struct task_struct *task)
{
- struct net *net;
+ struct net *net = NULL;
+ struct nsproxy *nsproxy;
+
rcu_read_lock();
- net = get_net(task->nsproxy->net_ns);
+ nsproxy = task_nsproxy(task);
+ if (nsproxy)
+ net = get_net(nsproxy->net_ns);
rcu_read_unlock();
+
return net;
}