diff options
author | Johannes Berg <johannes@sipsolutions.net> | 2009-07-10 13:51:35 +0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-07-13 01:03:28 +0400 |
commit | 30ffee8480c13fbcf8ab6c28e31f79dfff683117 (patch) | |
tree | ca86e974221761b813811047286142804f906ee2 /net/core/net_namespace.c | |
parent | 134e63756d5f3d0f7604dfcca847b09d1b14fd66 (diff) | |
download | linux-30ffee8480c13fbcf8ab6c28e31f79dfff683117.tar.xz |
net: move and export get_net_ns_by_pid
The function get_net_ns_by_pid(), to get a network
namespace from a pid_t, will be required in cfg80211
as well. Therefore, let's move it to net_namespace.c
and export it. We can't make it a static inline in
the !NETNS case because it needs to verify that the
given pid even exists (and return -ESRCH).
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/net_namespace.c')
-rw-r--r-- | net/core/net_namespace.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 5cd0b22e649d..ddd2cd2b1775 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -7,6 +7,7 @@ #include <linux/sched.h> #include <linux/idr.h> #include <linux/rculist.h> +#include <linux/nsproxy.h> #include <net/net_namespace.h> #include <net/netns/generic.h> @@ -201,6 +202,26 @@ struct net *copy_net_ns(unsigned long flags, struct net *old_net) } #endif +struct net *get_net_ns_by_pid(pid_t pid) +{ + struct task_struct *tsk; + struct net *net; + + /* Lookup the network namespace */ + net = ERR_PTR(-ESRCH); + rcu_read_lock(); + tsk = find_task_by_vpid(pid); + if (tsk) { + struct nsproxy *nsproxy; + nsproxy = task_nsproxy(tsk); + if (nsproxy) + net = get_net(nsproxy->net_ns); + } + rcu_read_unlock(); + return net; +} +EXPORT_SYMBOL_GPL(get_net_ns_by_pid); + static int __init net_ns_init(void) { struct net_generic *ng; |