diff options
author | Johannes Berg <johannes@sipsolutions.net> | 2009-07-10 05:51:35 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-07-12 17:03:28 -0400 |
commit | 30ffee8480c13fbcf8ab6c28e31f79dfff683117 (patch) | |
tree | ca86e974221761b813811047286142804f906ee2 /net/core | |
parent | 134e63756d5f3d0f7604dfcca847b09d1b14fd66 (diff) |
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')
-rw-r--r-- | net/core/net_namespace.c | 21 | ||||
-rw-r--r-- | net/core/rtnetlink.c | 21 |
2 files changed, 22 insertions, 20 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 @@ | |||
7 | #include <linux/sched.h> | 7 | #include <linux/sched.h> |
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 <net/net_namespace.h> | 11 | #include <net/net_namespace.h> |
11 | #include <net/netns/generic.h> | 12 | #include <net/netns/generic.h> |
12 | 13 | ||
@@ -201,6 +202,26 @@ struct net *copy_net_ns(unsigned long flags, struct net *old_net) | |||
201 | } | 202 | } |
202 | #endif | 203 | #endif |
203 | 204 | ||
205 | struct net *get_net_ns_by_pid(pid_t pid) | ||
206 | { | ||
207 | struct task_struct *tsk; | ||
208 | struct net *net; | ||
209 | |||
210 | /* Lookup the network namespace */ | ||
211 | net = ERR_PTR(-ESRCH); | ||
212 | rcu_read_lock(); | ||
213 | tsk = find_task_by_vpid(pid); | ||
214 | if (tsk) { | ||
215 | struct nsproxy *nsproxy; | ||
216 | nsproxy = task_nsproxy(tsk); | ||
217 | if (nsproxy) | ||
218 | net = get_net(nsproxy->net_ns); | ||
219 | } | ||
220 | rcu_read_unlock(); | ||
221 | return net; | ||
222 | } | ||
223 | EXPORT_SYMBOL_GPL(get_net_ns_by_pid); | ||
224 | |||
204 | static int __init net_ns_init(void) | 225 | static int __init net_ns_init(void) |
205 | { | 226 | { |
206 | struct net_generic *ng; | 227 | struct net_generic *ng; |
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index d78030f88bd0..b44775f9f2bf 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c | |||
@@ -35,7 +35,6 @@ | |||
35 | #include <linux/security.h> | 35 | #include <linux/security.h> |
36 | #include <linux/mutex.h> | 36 | #include <linux/mutex.h> |
37 | #include <linux/if_addr.h> | 37 | #include <linux/if_addr.h> |
38 | #include <linux/nsproxy.h> | ||
39 | 38 | ||
40 | #include <asm/uaccess.h> | 39 | #include <asm/uaccess.h> |
41 | #include <asm/system.h> | 40 | #include <asm/system.h> |
@@ -52,6 +51,7 @@ | |||
52 | #include <net/pkt_sched.h> | 51 | #include <net/pkt_sched.h> |
53 | #include <net/fib_rules.h> | 52 | #include <net/fib_rules.h> |
54 | #include <net/rtnetlink.h> | 53 | #include <net/rtnetlink.h> |
54 | #include <net/net_namespace.h> | ||
55 | 55 | ||
56 | struct rtnl_link | 56 | struct rtnl_link |
57 | { | 57 | { |
@@ -725,25 +725,6 @@ static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = { | |||
725 | [IFLA_INFO_DATA] = { .type = NLA_NESTED }, | 725 | [IFLA_INFO_DATA] = { .type = NLA_NESTED }, |
726 | }; | 726 | }; |
727 | 727 | ||
728 | static struct net *get_net_ns_by_pid(pid_t pid) | ||
729 | { | ||
730 | struct task_struct *tsk; | ||
731 | struct net *net; | ||
732 | |||
733 | /* Lookup the network namespace */ | ||
734 | net = ERR_PTR(-ESRCH); | ||
735 | rcu_read_lock(); | ||
736 | tsk = find_task_by_vpid(pid); | ||
737 | if (tsk) { | ||
738 | struct nsproxy *nsproxy; | ||
739 | nsproxy = task_nsproxy(tsk); | ||
740 | if (nsproxy) | ||
741 | net = get_net(nsproxy->net_ns); | ||
742 | } | ||
743 | rcu_read_unlock(); | ||
744 | return net; | ||
745 | } | ||
746 | |||
747 | static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[]) | 728 | static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[]) |
748 | { | 729 | { |
749 | if (dev) { | 730 | if (dev) { |