netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
To: netdev@vger.kernel.org
Cc: roopa@cumulusnetworks.com, davem@davemloft.net,
	stephen@networkplumber.org, jhs@mojatatu.com,
	Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Subject: [PATCH net-next 3/7] net: rtnetlink: add linkxstats callbacks and attribute
Date: Wed, 27 Apr 2016 18:18:18 +0200	[thread overview]
Message-ID: <1461773902-13528-4-git-send-email-nikolay@cumulusnetworks.com> (raw)
In-Reply-To: <1461773902-13528-1-git-send-email-nikolay@cumulusnetworks.com>

Add callbacks to calculate the size and fill link extended statistics
which can be split into multiple messages and are dumped via the new
rtnl stats API (RTM_GETSTATS) with the IFLA_STATS_LINK_XSTATS attribute.
Also add that attribute to the idx mask check since it is expected to
be able to save state and resume dumping (e.g. future bridge per-vlan
stats will be dumped via this attribute and callbacks).

Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
---
 include/net/rtnetlink.h      |  6 +++++-
 include/uapi/linux/if_link.h |  8 ++++++++
 net/core/rtnetlink.c         | 26 ++++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
index 3f3b0b1b8722..b449c1f3416f 100644
--- a/include/net/rtnetlink.h
+++ b/include/net/rtnetlink.h
@@ -95,6 +95,10 @@ struct rtnl_link_ops {
 						   const struct net_device *dev,
 						   const struct net_device *slave_dev);
 	struct net		*(*get_link_net)(const struct net_device *dev);
+	size_t			(*get_linkxstats_size)(const struct net_device *dev);
+	int			(*fill_linkxstats)(struct sk_buff *skb,
+						   const struct net_device *dev,
+						   int *lidx);
 };
 
 int __rtnl_link_register(struct rtnl_link_ops *ops);
@@ -154,6 +158,6 @@ int rtnl_nla_parse_ifla(struct nlattr **tb, const struct nlattr *head, int len);
  * IFLA_STATS_IDX_ATTR_MASK has all the idx saving attributes set and is
  * used to check if more than one is being requested
  */
-#define IFLA_STATS_IDX_ATTR_MASK 0
+#define IFLA_STATS_IDX_ATTR_MASK IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS)
 
 #endif
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index ba69d4447249..1b874e26b15b 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -798,6 +798,7 @@ struct if_stats_msg {
 enum {
 	IFLA_STATS_UNSPEC, /* also used as 64bit pad attribute */
 	IFLA_STATS_LINK_64,
+	IFLA_STATS_LINK_XSTATS,
 	__IFLA_STATS_MAX,
 };
 
@@ -805,4 +806,11 @@ enum {
 
 #define IFLA_STATS_FILTER_BIT(ATTR)	(1 << (ATTR - 1))
 
+/* These are embedded into IFLA_STATS_LINK_XSTATS */
+enum {
+	LINK_XSTATS_UNSPEC,
+	__LINK_XSTATS_MAX
+};
+#define LINK_XSTATS_MAX (__LINK_XSTATS_MAX - 1)
+
 #endif /* _UAPI_LINUX_IF_LINK_H */
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index ea03b6cd3d3c..9637618c408d 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -3477,6 +3477,23 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,
 		dev_get_stats(dev, sp);
 	}
 
+	if (filter_mask & IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS)) {
+		const struct rtnl_link_ops *ops = dev->rtnl_link_ops;
+
+		if (ops && ops->fill_linkxstats) {
+			int err;
+
+			attr = nla_nest_start(skb, IFLA_STATS_LINK_XSTATS);
+			if (!attr)
+				goto nla_put_failure;
+
+			err = ops->fill_linkxstats(skb, dev, lidx);
+			nla_nest_end(skb, attr);
+			if (err)
+				goto nla_put_failure;
+		}
+	}
+
 	nlmsg_end(skb, nlh);
 
 	return 0;
@@ -3503,6 +3520,15 @@ static size_t if_nlmsg_stats_size(const struct net_device *dev,
 	if (filter_mask & IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_64))
 		size += nla_total_size_64bit(sizeof(struct rtnl_link_stats64));
 
+	if (filter_mask & IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS)) {
+		const struct rtnl_link_ops *ops = dev->rtnl_link_ops;
+
+		if (ops && ops->get_linkxstats_size)
+			size += nla_total_size(ops->get_linkxstats_size(dev));
+		/* anything dumped is embedded in IFLA_STATS_LINK_XSTATS */
+		size += nla_total_size(0);
+	}
+
 	return size;
 }
 
-- 
2.4.11

  parent reply	other threads:[~2016-04-27 16:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-27 16:18 [PATCH net-next 0/7] bridge: per-vlan stats Nikolay Aleksandrov
2016-04-27 16:18 ` [PATCH net-next 1/7] net: rtnetlink: allow rtnl_fill_statsinfo to save private state counter Nikolay Aleksandrov
2016-04-27 16:18 ` [PATCH net-next 2/7] net: rtnetlink: allow only one idx saving stats attribute Nikolay Aleksandrov
2016-04-28  5:18   ` Roopa Prabhu
2016-04-28  8:40     ` Nikolay Aleksandrov
2016-04-27 16:18 ` Nikolay Aleksandrov [this message]
2016-04-27 16:18 ` [PATCH net-next 4/7] net: constify is_skb_forwardable's arguments Nikolay Aleksandrov
2016-04-27 16:18 ` [PATCH net-next 5/7] bridge: vlan: RCUify pvid Nikolay Aleksandrov
2016-04-27 16:18 ` [PATCH net-next 6/7] bridge: vlan: learn to count Nikolay Aleksandrov
2016-04-27 16:18 ` [PATCH net-next 7/7] bridge: netlink: export per-vlan stats Nikolay Aleksandrov
2016-04-27 17:06 ` [PATCH net-next 0/7] bridge: " Stephen Hemminger
2016-04-27 17:13   ` Nikolay Aleksandrov
2016-04-28  8:43 ` Nikolay Aleksandrov

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=1461773902-13528-4-git-send-email-nikolay@cumulusnetworks.com \
    --to=nikolay@cumulusnetworks.com \
    --cc=davem@davemloft.net \
    --cc=jhs@mojatatu.com \
    --cc=netdev@vger.kernel.org \
    --cc=roopa@cumulusnetworks.com \
    --cc=stephen@networkplumber.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).