From: Denis Kenzior <denkenz@gmail.com>
To: linux-wireless@vger.kernel.org
Cc: Denis Kenzior <denkenz@gmail.com>
Subject: [PATCH v2] nl80211: Allow GET_INTERFACE dumps to be filtered
Date: Fri, 12 Aug 2016 11:12:37 -0500 [thread overview]
Message-ID: <1471018357-3047-1-git-send-email-denkenz@gmail.com> (raw)
This patch allows GET_INTERFACE dumps to be filtered based on
NL80211_ATTR_WIPHY or NL80211_ATTR_WDEV. The documentation for
GET_INTERFACE mentions that this is possible:
"Request an interface's configuration; either a dump request on
a %NL80211_ATTR_WIPHY or ..."
However, this behavior has not been implemented until now.
Signed-off-by: Denis Kenzior <denkenz@gmail.com>
---
net/wireless/nl80211.c | 63 +++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 55 insertions(+), 8 deletions(-)
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 4997857..aa85871 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -2519,27 +2519,74 @@ static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flag
return -EMSGSIZE;
}
+static int nl80211_dump_interface_parse(struct sk_buff *skb,
+ struct netlink_callback *cb,
+ int *filter_wiphy)
+{
+ struct nlattr **tb = nl80211_fam.attrbuf;
+ int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
+ tb, nl80211_fam.maxattr, nl80211_policy);
+
+ /* ignore parse errors for backward compatibility */
+ if (ret)
+ return 0;
+
+ if (tb[NL80211_ATTR_WIPHY])
+ *filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
+ if (tb[NL80211_ATTR_WDEV])
+ *filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
+
+ return 0;
+}
+
+struct dump_interface_context {
+ unsigned int wp_start;
+ unsigned int if_start;
+ int filter_wiphy;
+};
+
static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
{
- int wp_idx = 0;
- int if_idx = 0;
- int wp_start = cb->args[0];
- int if_start = cb->args[1];
struct cfg80211_registered_device *rdev;
struct wireless_dev *wdev;
+ unsigned int wp_idx = 0;
+ unsigned int if_idx;
+ static struct dump_interface_context static_ctx;
+ struct dump_interface_context *ctx = cb->args[0];
+
+ if (!ctx) {
+ int ret;
+
+ static_ctx.wp_start = 0;
+ static_ctx.if_start = 0;
+ static_ctx.filter_wiphy = -1;
+
+ ret = nl80211_dump_interface_parse(skb, cb,
+ &static_ctx.filter_wiphy);
+ if (ret)
+ return ret;
+
+ ctx = &static_ctx;
+ cb->args[0] = ctx;
+ }
rtnl_lock();
list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
continue;
- if (wp_idx < wp_start) {
+ if (wp_idx < ctx->wp_start) {
wp_idx++;
continue;
}
+
+ if (ctx->filter_wiphy != -1 &&
+ ctx->filter_wiphy != rdev->wiphy_idx)
+ continue;
+
if_idx = 0;
list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
- if (if_idx < if_start) {
+ if (if_idx < ctx->if_start) {
if_idx++;
continue;
}
@@ -2556,8 +2603,8 @@ static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *
out:
rtnl_unlock();
- cb->args[0] = wp_idx;
- cb->args[1] = if_idx;
+ ctx->wp_start = wp_idx;
+ ctx->if_start = if_idx;
return skb->len;
}
--
2.7.3
next reply other threads:[~2016-08-12 16:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-12 16:12 Denis Kenzior [this message]
2016-08-16 7:11 ` [PATCH v2] nl80211: Allow GET_INTERFACE dumps to be filtered Johannes Berg
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=1471018357-3047-1-git-send-email-denkenz@gmail.com \
--to=denkenz@gmail.com \
--cc=linux-wireless@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).