From: ebiederm@xmission.com (Eric W. Biederman)
To: <linux-kernel@vger.kernel.org>
Cc: Linux Containers <containers@lists.osdl.org>,
<netdev@vger.kernel.org>,
netfilter-devel@vger.kernel.org, <linux-fsdevel@vger.kernel.org>,
jamal <hadi@cyberus.ca>, Daniel Lezcano <daniel.lezcano@free.fr>,
Linus Torvalds <torvalds@linux-foundation.org>,
Michael Kerrisk <mtk.manpages@gmail.com>,
Ulrich Drepper <drepper@gmail.com>,
Al Viro <viro@ZenIV.linux.org.uk>,
David Miller <davem@davemloft.net>,
"Serge E. Hallyn" <serge@hallyn.com>,
Pavel Emelyanov <xemul@openvz.org>,
Pavel Emelyanov <xemul@parallels.com>,
Ben Greear <greearb@candelatech.com>,
Matt Helsley <matthltc@us.ibm.com>,
Jonathan Corbet <corbet@lwn.net>,
Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>,
Jan Engelhardt <jengelh@medozas.de>,
Patrick McHardy <kaber@trash.net>
Subject: [PATCH 7/8] net: Allow setting the network namespace by fd
Date: Thu, 23 Sep 2010 01:51:30 -0700 [thread overview]
Message-ID: <m1hbhgq1v1.fsf@fess.ebiederm.org> (raw)
In-Reply-To: <m1ocborgq7.fsf@fess.ebiederm.org> (Eric W. Biederman's message of "Thu, 23 Sep 2010 01:45:04 -0700")
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.
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
include/linux/if_link.h | 1 +
include/net/net_namespace.h | 1 +
net/core/net_namespace.c | 26 ++++++++++++++++++++++++++
net/core/rtnetlink.c | 4 +++-
4 files changed, 31 insertions(+), 1 deletions(-)
diff --git a/include/linux/if_link.h b/include/linux/if_link.h
index 2fc66dd..ae73d5e 100644
--- a/include/linux/if_link.h
+++ b/include/linux/if_link.h
@@ -116,6 +116,7 @@ enum {
IFLA_STATS64,
IFLA_VF_PORTS,
IFLA_PORT_SELF,
+ IFLA_NET_NS_FD,
__IFLA_MAX
};
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index bd10a79..68672ce 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -114,6 +114,7 @@ static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
extern struct list_head net_namespace_list;
extern struct net *get_net_ns_by_pid(pid_t pid);
+extern struct net *get_net_ns_by_fd(int pid);
#ifdef CONFIG_NET_NS
extern void __put_net(struct net *net);
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 581a088..a9b54a7 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>
@@ -341,6 +343,30 @@ 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;
+
+ file = NULL;
+ net = ERR_PTR(-EINVAL);
+ file = proc_ns_fget(fd);
+ if (!fd)
+ goto out;
+ return ERR_PTR(-EINVAL);
+
+ 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;
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index f78d821..771d8be 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1003,6 +1003,8 @@ struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[])
*/
if (tb[IFLA_NET_NS_PID])
net = get_net_ns_by_pid(nla_get_u32(tb[IFLA_NET_NS_PID]));
+ else if (tb[IFLA_NET_NS_FD])
+ net = get_net_ns_by_fd(nla_get_u32(tb[IFLA_NET_NS_FD]));
else
net = get_net(src_net);
return net;
@@ -1077,7 +1079,7 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
int send_addr_notify = 0;
int err;
- if (tb[IFLA_NET_NS_PID]) {
+ if (tb[IFLA_NET_NS_PID] || tb[IFLA_NET_NS_FD]) {
struct net *net = rtnl_link_get_net(dev_net(dev), tb);
if (IS_ERR(net)) {
err = PTR_ERR(net);
--
1.6.5.2.143.g8cc62
next prev parent reply other threads:[~2010-09-23 8:51 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-23 8:45 [ABI REVIEW][PATCH 0/8] Namespace file descriptors Eric W. Biederman
2010-09-23 8:46 ` [PATCH 1/8] ns: proc files for namespace naming policy Eric W. Biederman
2010-09-23 8:46 ` [PATCH 2/8] ns: Introduce the setns syscall Eric W. Biederman
2010-09-23 8:47 ` [PATCH 3/8] ns proc: Add support for the network namespace Eric W. Biederman
2010-09-23 11:27 ` Louis Rilling
2010-09-23 16:00 ` Eric W. Biederman
2010-09-23 8:48 ` [PATCH 4/8] ns proc: Add support for the uts namespace Eric W. Biederman
2010-09-23 8:49 ` [PATCH 5/8] ns proc: Add support for the ipc namespace Eric W. Biederman
2010-09-23 8:50 ` [PATCH 6/8] ns proc: Add support for the mount namespace Eric W. Biederman
2010-09-23 8:51 ` Eric W. Biederman [this message]
2010-09-23 9:41 ` [PATCH 7/8] net: Allow setting the network namespace by fd Eric Dumazet
2010-09-23 16:03 ` Eric W. Biederman
2010-09-23 11:22 ` jamal
2010-09-23 14:58 ` David Lamparter
2010-09-24 11:51 ` jamal
2010-09-24 12:57 ` David Lamparter
2010-09-24 13:32 ` jamal
2010-09-24 14:09 ` David Lamparter
2010-09-24 14:16 ` jamal
2010-09-23 15:14 ` Eric W. Biederman
2010-09-23 14:22 ` Brian Haley
2010-09-23 16:16 ` Eric W. Biederman
2010-09-24 13:46 ` Daniel Lezcano
2010-09-23 8:51 ` [PATCH 8/8] net: Implement socketat Eric W. Biederman
2010-09-23 8:56 ` Pavel Emelyanov
2010-09-23 11:19 ` jamal
2010-09-23 11:33 ` Pavel Emelyanov
2010-09-23 11:40 ` jamal
2010-09-23 11:53 ` Pavel Emelyanov
2010-09-23 12:11 ` jamal
2010-09-23 12:34 ` Pavel Emelyanov
2010-09-23 14:54 ` David Lamparter
2010-09-23 15:00 ` Eric W. Biederman
2010-10-02 21:13 ` Daniel Lezcano
2010-10-03 13:44 ` jamal
2010-10-04 10:13 ` Daniel Lezcano
2010-10-04 19:07 ` Eric W. Biederman
2010-10-15 12:30 ` netns patches WAS( " jamal
2010-10-26 20:52 ` jamal
2010-10-27 0:27 ` Eric W. Biederman
2010-09-23 15:18 ` [ABI REVIEW][PATCH 0/8] Namespace file descriptors David Lamparter
2010-09-23 16:32 ` Eric W. Biederman
2010-09-23 16:49 ` David Lamparter
2010-09-24 13:02 ` Andrew Lutomirski
2010-09-24 13:49 ` Daniel Lezcano
2010-09-24 17:06 ` Eric W. Biederman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1hbhgq1v1.fsf@fess.ebiederm.org \
--to=ebiederm@xmission.com \
--cc=containers@lists.osdl.org \
--cc=corbet@lwn.net \
--cc=daniel.lezcano@free.fr \
--cc=davem@davemloft.net \
--cc=drepper@gmail.com \
--cc=greearb@candelatech.com \
--cc=hadi@cyberus.ca \
--cc=jengelh@medozas.de \
--cc=kaber@trash.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matthltc@us.ibm.com \
--cc=mtk.manpages@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=serge@hallyn.com \
--cc=sukadev@linux.vnet.ibm.com \
--cc=torvalds@linux-foundation.org \
--cc=viro@ZenIV.linux.org.uk \
--cc=xemul@openvz.org \
--cc=xemul@parallels.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).