From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, ebiederm@xmission.com, aatteka@nicira.com,
Nicolas Dichtel <nicolas.dichtel@6wind.com>
Subject: [RFC PATCH net-next 3/5] dev/netns: allow to get netns from nsindex in rtnl msg
Date: Wed, 12 Dec 2012 18:24:39 +0100 [thread overview]
Message-ID: <1355333081-4018-4-git-send-email-nicolas.dichtel@6wind.com> (raw)
In-Reply-To: <1355333081-4018-1-git-send-email-nicolas.dichtel@6wind.com>
This patch allows to move a netdevice to another netns by giving the nsindex.
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
include/net/net_namespace.h | 1 +
include/uapi/linux/if_link.h | 1 +
net/core/net_namespace.c | 14 ++++++++++++++
net/core/rtnetlink.c | 7 ++++++-
4 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index c373f2e..68e7a36 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -151,6 +151,7 @@ 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);
+extern struct net *get_net_ns_by_nsindex(int nsindex);
#ifdef CONFIG_NET_NS
extern void __put_net(struct net *net);
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 60f3b6b..6720a47 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -142,6 +142,7 @@ enum {
#define IFLA_PROMISCUITY IFLA_PROMISCUITY
IFLA_NUM_TX_QUEUES,
IFLA_NUM_RX_QUEUES,
+ IFLA_NET_NS_INDEX,
__IFLA_MAX
};
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 2ae22b0..18fc62f 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -399,6 +399,20 @@ struct net *get_net_ns_by_pid(pid_t pid)
}
EXPORT_SYMBOL_GPL(get_net_ns_by_pid);
+struct net *get_net_ns_by_nsindex(int nsindex)
+{
+ struct net *net;
+
+ ASSERT_RTNL();
+ for_each_net(net)
+ if (net->nsindex == nsindex) {
+ get_net(net);
+ break;
+ }
+ return net;
+}
+EXPORT_SYMBOL_GPL(get_net_ns_by_nsindex);
+
static struct genl_family netns_nl_family = {
.id = GENL_ID_GENERATE,
.name = NETNS_GENL_NAME,
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 1868625..e22954a 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1115,6 +1115,7 @@ const struct nla_policy ifla_policy[IFLA_MAX+1] = {
[IFLA_LINKINFO] = { .type = NLA_NESTED },
[IFLA_NET_NS_PID] = { .type = NLA_U32 },
[IFLA_NET_NS_FD] = { .type = NLA_U32 },
+ [IFLA_NET_NS_INDEX] = { .type = NLA_U32 },
[IFLA_IFALIAS] = { .type = NLA_STRING, .len = IFALIASZ-1 },
[IFLA_VFINFO_LIST] = {. type = NLA_NESTED },
[IFLA_VF_PORTS] = { .type = NLA_NESTED },
@@ -1171,6 +1172,8 @@ struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[])
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 if (tb[IFLA_NET_NS_INDEX])
+ net = get_net_ns_by_nsindex(nla_get_u32(tb[IFLA_NET_NS_INDEX]));
else
net = get_net(src_net);
return net;
@@ -1310,7 +1313,9 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
int send_addr_notify = 0;
int err;
- if (tb[IFLA_NET_NS_PID] || tb[IFLA_NET_NS_FD]) {
+ if (tb[IFLA_NET_NS_PID] ||
+ tb[IFLA_NET_NS_FD] ||
+ tb[IFLA_NET_NS_INDEX]) {
struct net *net = rtnl_link_get_net(dev_net(dev), tb);
if (IS_ERR(net)) {
err = PTR_ERR(net);
--
1.8.0.1
next prev parent reply other threads:[~2012-12-12 17:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-12 17:24 [RFC PATCH net-next 0/5] Ease netns management by userland Nicolas Dichtel
2012-12-12 17:24 ` [RFC PATCH net-next 1/5] netns: allocate an unique id to identify a netns Nicolas Dichtel
2012-12-12 17:24 ` [RFC PATCH net-next 2/5] netns: allow to dump netns with netlink Nicolas Dichtel
2012-12-12 17:24 ` Nicolas Dichtel [this message]
2012-12-12 17:24 ` [RFC PATCH net-next 4/5] netns: advertise netns activity " Nicolas Dichtel
2012-12-12 17:24 ` [RFC PATCH net-next 5/5] net/sock: add support of SO_NETNS Nicolas Dichtel
-- strict thread matches above, loose matches on Subject: below --
2012-12-12 17:17 [RFC PATCH net-next 0/5] Ease netns management for userland Nicolas Dichtel
2012-12-12 17:17 ` [RFC PATCH net-next 3/5] dev/netns: allow to get netns from nsindex in rtnl msg Nicolas Dichtel
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=1355333081-4018-4-git-send-email-nicolas.dichtel@6wind.com \
--to=nicolas.dichtel@6wind.com \
--cc=aatteka@nicira.com \
--cc=davem@davemloft.net \
--cc=ebiederm@xmission.com \
--cc=netdev@vger.kernel.org \
/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