aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/net_namespace.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-05-25 21:10:16 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-05-25 21:10:16 -0400
commit14d74e0cab7a7779a7ff0c3863c04c8a8e507106 (patch)
tree5e27d7495f8f7ce178b637d588ec42bd7b4173d8 /net/core/net_namespace.c
parent49a78d085fa6b44d6ed791923c7172a6433589c2 (diff)
parent956c920786694f51601a0ef7ee12956fd6aa216e (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/linux-2.6-nsfd
* git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/linux-2.6-nsfd: net: fix get_net_ns_by_fd for !CONFIG_NET_NS ns proc: Return -ENOENT for a nonexistent /proc/self/ns/ entry. ns: Declare sys_setns in syscalls.h net: Allow setting the network namespace by fd ns proc: Add support for the ipc namespace ns proc: Add support for the uts namespace ns proc: Add support for the network namespace. ns: Introduce the setns syscall ns: proc files for namespace naming policy.
Diffstat (limited to 'net/core/net_namespace.c')
-rw-r--r--net/core/net_namespace.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 2e2dce6583e1..6c6b86d0da15 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -8,6 +8,8 @@
8#include <linux/idr.h> 8#include <linux/idr.h>
9#include <linux/rculist.h> 9#include <linux/rculist.h>
10#include <linux/nsproxy.h> 10#include <linux/nsproxy.h>
11#include <linux/proc_fs.h>
12#include <linux/file.h>
11#include <net/net_namespace.h> 13#include <net/net_namespace.h>
12#include <net/netns/generic.h> 14#include <net/netns/generic.h>
13 15
@@ -302,6 +304,28 @@ void __put_net(struct net *net)
302} 304}
303EXPORT_SYMBOL_GPL(__put_net); 305EXPORT_SYMBOL_GPL(__put_net);
304 306
307struct net *get_net_ns_by_fd(int fd)
308{
309 struct proc_inode *ei;
310 struct file *file;
311 struct net *net;
312
313 net = ERR_PTR(-EINVAL);
314 file = proc_ns_fget(fd);
315 if (!file)
316 goto out;
317
318 ei = PROC_I(file->f_dentry->d_inode);
319 if (ei->ns_ops != &netns_operations)
320 goto out;
321
322 net = get_net(ei->ns);
323out:
324 if (file)
325 fput(file);
326 return net;
327}
328
305#else 329#else
306struct net *copy_net_ns(unsigned long flags, struct net *old_net) 330struct net *copy_net_ns(unsigned long flags, struct net *old_net)
307{ 331{
@@ -309,6 +333,11 @@ struct net *copy_net_ns(unsigned long flags, struct net *old_net)
309 return ERR_PTR(-EINVAL); 333 return ERR_PTR(-EINVAL);
310 return old_net; 334 return old_net;
311} 335}
336
337struct net *get_net_ns_by_fd(int fd)
338{
339 return ERR_PTR(-EINVAL);
340}
312#endif 341#endif
313 342
314struct net *get_net_ns_by_pid(pid_t pid) 343struct net *get_net_ns_by_pid(pid_t pid)
@@ -561,3 +590,39 @@ void unregister_pernet_device(struct pernet_operations *ops)
561 mutex_unlock(&net_mutex); 590 mutex_unlock(&net_mutex);
562} 591}
563EXPORT_SYMBOL_GPL(unregister_pernet_device); 592EXPORT_SYMBOL_GPL(unregister_pernet_device);
593
594#ifdef CONFIG_NET_NS
595static void *netns_get(struct task_struct *task)
596{
597 struct net *net = NULL;
598 struct nsproxy *nsproxy;
599
600 rcu_read_lock();
601 nsproxy = task_nsproxy(task);
602 if (nsproxy)
603 net = get_net(nsproxy->net_ns);
604 rcu_read_unlock();
605
606 return net;
607}
608
609static void netns_put(void *ns)
610{
611 put_net(ns);
612}
613
614static int netns_install(struct nsproxy *nsproxy, void *ns)
615{
616 put_net(nsproxy->net_ns);
617 nsproxy->net_ns = get_net(ns);
618 return 0;
619}
620
621const struct proc_ns_operations netns_operations = {
622 .name = "net",
623 .type = CLONE_NEWNET,
624 .get = netns_get,
625 .put = netns_put,
626 .install = netns_install,
627};
628#endif