From: Greg Rose <gregory.v.rose@intel.com>
To: netdev@vger.kernel.org
Cc: shemminger@vyatta.com, davem@davemloft.net
Subject: [RFC PATCH] iproute2: Add extended info mask to ifinfo dump requests
Date: Sun, 12 Feb 2012 11:16:31 -0800	[thread overview]
Message-ID: <20120212191630.2031.61073.stgit@gitlad.jf.intel.com> (raw)
Creates a new nlattr type IFLA_EXT_MASK which sends a u32 bit mask
along with the ifinfo dump request.  This mask can be used to filter
on types of extended interface information such as VFs.
Tested on 2.6.39 and 3.0.3 kernels to check for backward compatibility.
Signed-off-by: Greg Rose <gregory.v.rose@intel.com>
---
 include/linux/if_link.h   |    1 +
 include/linux/netlink.h   |    1 +
 include/linux/rtnetlink.h |   11 +++++++++--
 lib/libnetlink.c          |   14 +++++++++-----
 4 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/include/linux/if_link.h b/include/linux/if_link.h
index d3bc04c..06a3a47 100644
--- a/include/linux/if_link.h
+++ b/include/linux/if_link.h
@@ -137,6 +137,7 @@ enum {
 	IFLA_AF_SPEC,
 	IFLA_GROUP,		/* Group the device belongs to */
 	IFLA_NET_NS_FD,
+	IFLA_EXT_MASK,		/* Extended info mask, VFs, etc */
 	__IFLA_MAX
 };
 
diff --git a/include/linux/netlink.h b/include/linux/netlink.h
index 5c4f087..ca1f7fc 100644
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -59,6 +59,7 @@ struct nlmsghdr {
 #define NLM_F_MATCH	0x200	/* return all matching	*/
 #define NLM_F_ATOMIC	0x400	/* atomic GET		*/
 #define NLM_F_DUMP	(NLM_F_ROOT|NLM_F_MATCH)
+#define NLM_F_EXT	0x800	/* Get extended interface info such as VFs */
 
 /* Modifiers to NEW request */
 #define NLM_F_REPLACE	0x100	/* Override existing		*/
diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
index 12b19e6..ed0d85b 100644
--- a/include/linux/rtnetlink.h
+++ b/include/linux/rtnetlink.h
@@ -597,11 +597,18 @@ struct tcamsg {
 };
 #define TA_RTA(r)  ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcamsg))))
 #define TA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcamsg))
-#define TCA_ACT_TAB 1 /* attr type must be >=1 */	
+#define TCA_ACT_TAB 1 /* attr type must be >=1 */
 #define TCAA_MAX 1
 
-/* End of information exported to user level */
+struct rtnl_req_extended {
+	struct nlmsghdr nlh;
+	struct rtgenmsg g;
+	char ext[RTA_SPACE(sizeof(__u32))];
+};
 
+/* New extended info filters for IFLA_EXT_MASK */
+#define RTEXT_FILTER_VF		(1 << 0)
 
+/* End of information exported to user level */
 
 #endif	/* __LINUX_RTNETLINK_H */
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index c581e11..7d6966c 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -91,18 +91,22 @@ int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)
 
 int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
 {
-	struct {
-		struct nlmsghdr nlh;
-		struct rtgenmsg g;
-	} req;
+	struct rtnl_req_extended req;
+	struct rtattr *ext_req;
+	__u32 *ext_filter_mask;
 
 	memset(&req, 0, sizeof(req));
 	req.nlh.nlmsg_len = sizeof(req);
 	req.nlh.nlmsg_type = type;
-	req.nlh.nlmsg_flags = NLM_F_DUMP|NLM_F_REQUEST;
+	req.nlh.nlmsg_flags = NLM_F_DUMP|NLM_F_REQUEST|NLM_F_EXT;
 	req.nlh.nlmsg_pid = 0;
 	req.nlh.nlmsg_seq = rth->dump = ++rth->seq;
 	req.g.rtgen_family = family;
+	ext_req = (struct rtattr *)&req.ext;
+	ext_req->rta_type = IFLA_EXT_MASK;
+	ext_req->rta_len = RTA_LENGTH(sizeof(__u32));
+	ext_filter_mask = RTA_DATA(ext_req);
+	*ext_filter_mask = RTEXT_FILTER_VF;
 
 	return send(rth->fd, (void*)&req, sizeof(req), 0);
 }
                 reply	other threads:[~2012-02-12 19:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
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=20120212191630.2031.61073.stgit@gitlad.jf.intel.com \
    --to=gregory.v.rose@intel.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@vyatta.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).