diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2011-05-04 20:51:50 -0400 |
---|---|---|
committer | Eric W. Biederman <ebiederm@xmission.com> | 2011-05-10 17:36:03 -0400 |
commit | f063052947f770845a6252f7fa24f6f624592a24 (patch) | |
tree | 17513dbd49d5a1a08443d76374d10dda6114b7a7 /net/core/net_namespace.c | |
parent | a00eaf11a223c63fbb212369d6db69ce4c55a2d1 (diff) |
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.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index bf7707e09a80..b7403ff4d6c6 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 | ||
@@ -343,6 +345,28 @@ struct net *get_net_ns_by_pid(pid_t pid) | |||
343 | } | 345 | } |
344 | EXPORT_SYMBOL_GPL(get_net_ns_by_pid); | 346 | EXPORT_SYMBOL_GPL(get_net_ns_by_pid); |
345 | 347 | ||
348 | struct net *get_net_ns_by_fd(int fd) | ||
349 | { | ||
350 | struct proc_inode *ei; | ||
351 | struct file *file; | ||
352 | struct net *net; | ||
353 | |||
354 | net = ERR_PTR(-EINVAL); | ||
355 | file = proc_ns_fget(fd); | ||
356 | if (!file) | ||
357 | goto out; | ||
358 | |||
359 | ei = PROC_I(file->f_dentry->d_inode); | ||
360 | if (ei->ns_ops != &netns_operations) | ||
361 | goto out; | ||
362 | |||
363 | net = get_net(ei->ns); | ||
364 | out: | ||
365 | if (file) | ||
366 | fput(file); | ||
367 | return net; | ||
368 | } | ||
369 | |||
346 | static int __init net_ns_init(void) | 370 | static int __init net_ns_init(void) |
347 | { | 371 | { |
348 | struct net_generic *ng; | 372 | struct net_generic *ng; |
@@ -577,10 +601,15 @@ EXPORT_SYMBOL_GPL(unregister_pernet_device); | |||
577 | #ifdef CONFIG_NET_NS | 601 | #ifdef CONFIG_NET_NS |
578 | static void *netns_get(struct task_struct *task) | 602 | static void *netns_get(struct task_struct *task) |
579 | { | 603 | { |
580 | struct net *net; | 604 | struct net *net = NULL; |
605 | struct nsproxy *nsproxy; | ||
606 | |||
581 | rcu_read_lock(); | 607 | rcu_read_lock(); |
582 | net = get_net(task->nsproxy->net_ns); | 608 | nsproxy = task_nsproxy(task); |
609 | if (nsproxy) | ||
610 | net = get_net(nsproxy->net_ns); | ||
583 | rcu_read_unlock(); | 611 | rcu_read_unlock(); |
612 | |||
584 | return net; | 613 | return net; |
585 | } | 614 | } |
586 | 615 | ||