netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, ebiederm@xmission.com,
	Nicolas Dichtel <nicolas.dichtel@6wind.com>
Subject: [PATCH net-next v2 3/3] netns: allow to dump netns ids
Date: Tue,  7 Apr 2015 11:51:54 +0200	[thread overview]
Message-ID: <1428400314-4472-4-git-send-email-nicolas.dichtel@6wind.com> (raw)
In-Reply-To: <1428400314-4472-1-git-send-email-nicolas.dichtel@6wind.com>

Which this patch, it's possible to dump the list of ids allocated for peer
netns.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 net/core/net_namespace.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index b3b5f22f0e90..a3abb719221f 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -616,6 +616,52 @@ out:
 	return err;
 }
 
+struct rtnl_net_dump_cb {
+	struct net *net;
+	struct sk_buff *skb;
+	struct netlink_callback *cb;
+	int idx;
+	int s_idx;
+};
+
+static int rtnl_net_dumpid_one(int id, void *peer, void *data)
+{
+	struct rtnl_net_dump_cb *net_cb = (struct rtnl_net_dump_cb *)data;
+	int ret;
+
+	if (net_cb->idx < net_cb->s_idx)
+		goto cont;
+
+	ret = rtnl_net_fill(net_cb->skb, NETLINK_CB(net_cb->cb->skb).portid,
+			    net_cb->cb->nlh->nlmsg_seq, NLM_F_MULTI,
+			    RTM_NEWNSID, net_cb->net, peer, id);
+	if (ret < 0)
+		return ret;
+
+cont:
+	net_cb->idx++;
+	return 0;
+}
+
+static int rtnl_net_dumpid(struct sk_buff *skb, struct netlink_callback *cb)
+{
+	struct net *net = sock_net(skb->sk);
+	struct rtnl_net_dump_cb net_cb = {
+		.net = net,
+		.skb = skb,
+		.cb = cb,
+		.idx = 0,
+		.s_idx = cb->args[0],
+	};
+
+	ASSERT_RTNL();
+
+	idr_for_each(&net->netns_ids, rtnl_net_dumpid_one, &net_cb);
+
+	cb->args[0] = net_cb.idx;
+	return skb->len;
+}
+
 static void rtnl_net_notifyid(struct net *net, struct net *peer, int cmd,
 			      int id)
 {
@@ -673,7 +719,8 @@ static int __init net_ns_init(void)
 	register_pernet_subsys(&net_ns_ops);
 
 	rtnl_register(PF_UNSPEC, RTM_NEWNSID, rtnl_net_newid, NULL, NULL);
-	rtnl_register(PF_UNSPEC, RTM_GETNSID, rtnl_net_getid, NULL, NULL);
+	rtnl_register(PF_UNSPEC, RTM_GETNSID, rtnl_net_getid, rtnl_net_dumpid,
+		      NULL);
 
 	return 0;
 }
-- 
2.2.2

  parent reply	other threads:[~2015-04-07  9:51 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-01 12:49 [PATCH net-next 0/4] netns: enhance netlink interface for nsid Nicolas Dichtel
2015-04-01 12:49 ` [PATCH net-next 1/4] netns: don't clear nsid too early on removal Nicolas Dichtel
2015-04-02 18:51   ` Eric W. Biederman
2015-04-03  9:56     ` Nicolas Dichtel
2015-04-03 10:02       ` [PATCH net 1/2] Revert "netns: don't clear nsid too early on removal" Nicolas Dichtel
2015-04-03 10:02         ` [PATCH net 2/2] netns: don't allocate an id for dead netns Nicolas Dichtel
2015-04-03 16:36           ` David Miller
2015-04-05  8:39             ` Nicolas Dichtel
2015-04-05 20:34               ` David Miller
2015-04-07  9:36                 ` Nicolas Dichtel
2015-04-03 16:36         ` [PATCH net 1/2] Revert "netns: don't clear nsid too early on removal" David Miller
2015-04-01 12:49 ` [PATCH net-next 2/4] netns: minor cleanup in rtnl_net_getid() Nicolas Dichtel
2015-04-01 12:49 ` [PATCH net-next 3/4] netns: notify netns id events Nicolas Dichtel
2015-04-01 12:49 ` [PATCH net-next 4/4] netns: allow to dump netns ids Nicolas Dichtel
2015-04-01 16:54 ` [PATCH net-next 0/4] netns: enhance netlink interface for nsid Cong Wang
2015-04-02  8:52   ` Nicolas Dichtel
2015-04-07  9:51 ` [PATCH net-next v2 0/3] " Nicolas Dichtel
2015-04-07  9:51   ` [PATCH net-next v2 1/3] netns: minor cleanup in rtnl_net_getid() Nicolas Dichtel
2015-04-07  9:51   ` [PATCH net-next v2 2/3] netns: notify netns id events Nicolas Dichtel
2015-04-07  9:51   ` Nicolas Dichtel [this message]
2015-04-07 21:30   ` [PATCH net-next v2 0/3] netns: enhance netlink interface for nsid David Miller

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=1428400314-4472-4-git-send-email-nicolas.dichtel@6wind.com \
    --to=nicolas.dichtel@6wind.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;
as well as URLs for NNTP newsgroup(s).