lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210803165140.172-4-alexandr.lobakin@intel.com>
Date:   Tue,  3 Aug 2021 18:51:38 +0200
From:   Alexander Lobakin <alexandr.lobakin@...el.com>
To:     Michal Kubecek <mkubecek@...e.cz>
Cc:     "David S. Miller" <davem@...emloft.net>,
        Jakub Kicinski <kuba@...nel.org>,
        Alexander Lobakin <alexandr.lobakin@...el.com>,
        Jesse Brandeburg <jesse.brandeburg@...el.com>,
        Lukasz Czapnik <lukasz.czapnik@...el.com>,
        Marcin Kubiak <marcin.kubiak@...el.com>,
        Michal Kubiak <michal.kubiak@...el.com>,
        Michal Swiatkowski <michal.swiatkowski@...el.com>,
        Jonathan Corbet <corbet@....net>,
        Netanel Belgazal <netanel@...zon.com>,
        Arthur Kiyanovski <akiyano@...zon.com>,
        Guy Tzalik <gtzalik@...zon.com>,
        Saeed Bishara <saeedb@...zon.com>,
        Ioana Ciornei <ioana.ciornei@....com>,
        Claudiu Manoil <claudiu.manoil@....com>,
        Thomas Petazzoni <thomas.petazzoni@...tlin.com>,
        Marcin Wojtas <mw@...ihalf.com>,
        Russell King <linux@...linux.org.uk>,
        Edward Cree <ecree.xilinx@...il.com>,
        Martin Habets <habetsm.xilinx@...il.com>,
        "Michael S. Tsirkin" <mst@...hat.com>,
        Jason Wang <jasowang@...hat.com>,
        Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Jesper Dangaard Brouer <hawk@...nel.org>,
        John Fastabend <john.fastabend@...il.com>,
        Andrii Nakryiko <andrii@...nel.org>,
        Martin KaFai Lau <kafai@...com>,
        Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
        KP Singh <kpsingh@...nel.org>,
        Shay Agroskin <shayagr@...zon.com>,
        Sameeh Jubran <sameehj@...zon.com>,
        Alexander Duyck <alexanderduyck@...com>,
        Danielle Ratson <danieller@...dia.com>,
        Ido Schimmel <idosch@...dia.com>, Andrew Lunn <andrew@...n.ch>,
        Vladyslav Tarasiuk <vladyslavt@...dia.com>,
        Arnd Bergmann <arnd@...db.de>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Jian Shen <shenjian15@...wei.com>,
        Petr Vorel <petr.vorel@...il.com>, Dan Murphy <dmurphy@...com>,
        Yangbo Lu <yangbo.lu@....com>,
        Zheng Yongjun <zhengyongjun3@...wei.com>,
        Heiner Kallweit <hkallweit1@...il.com>,
        YueHaibing <yuehaibing@...wei.com>,
        Johannes Berg <johannes@...solutions.net>,
        netdev@...r.kernel.org, linux-doc@...r.kernel.org,
        linux-kernel@...r.kernel.org,
        virtualization@...ts.linux-foundation.org, bpf@...r.kernel.org
Subject: [PATCH ethtool-next 3/5] stats: add support for per-channel statistics [blocks]

Treat ETHTOOL_A_STATS_GRP_STAT_BLOCK as a block of the standard
stats for one channel and print them prefixed with "channel%u-".
The index will be started from 0 and incremented automatically
for each new attr of that type.
This means that stats blocks should follow each other one by one
according to their channel number, otherwise the output can mess
up with the indices.

Signed-off-by: Alexander Lobakin <alexandr.lobakin@...el.com>
Reviewed-by: Jesse Brandeburg <jesse.brandeburg@...el.com>
---
 netlink/stats.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 63 insertions(+), 4 deletions(-)

diff --git a/netlink/stats.c b/netlink/stats.c
index 9d950b77d656..36a9dad97f15 100644
--- a/netlink/stats.c
+++ b/netlink/stats.c
@@ -87,8 +87,8 @@ err_close_rmon:
 	return 1;
 }
 
-static int parse_stat(const struct nlattr *attr, const char *grp_name,
-		      const struct stringset *stat_str)
+static int parse_stat(const struct nlattr *attr, const char *ch_name,
+		      const char *grp_name, const struct stringset *stat_str)
 {
 	const struct nlattr *stat;
 	unsigned long long val;
@@ -108,8 +108,12 @@ static int parse_stat(const struct nlattr *attr, const char *grp_name,
 	if (!name || !name[0])
 		return 0;
 
-	if (!is_json_context())
+	if (!is_json_context()) {
+		if (ch_name)
+			fprintf(stdout, "%s-", ch_name);
+
 		fprintf(stdout, "%s-%s: ", grp_name, name);
+	}
 
 	val = mnl_attr_get_u64(stat);
 	print_u64(PRINT_ANY, name, "%llu\n", val);
@@ -117,12 +121,62 @@ static int parse_stat(const struct nlattr *attr, const char *grp_name,
 	return 0;
 }
 
+static int parse_one_block(const struct nlattr *block, const char *grp_name,
+			   const struct stringset *stat_str,
+			   unsigned int channel)
+{
+	char ch_name[ETH_GSTRING_LEN];
+	const struct nlattr *attr;
+
+	snprintf(ch_name, sizeof(ch_name), "channel%u", channel);
+	open_json_object(ch_name);
+
+	mnl_attr_for_each_nested(attr, block) {
+		if (mnl_attr_get_type(attr) != ETHTOOL_A_STATS_GRP_STAT ||
+		    parse_stat(attr, ch_name, grp_name, stat_str))
+			goto err_close_block;
+	}
+
+	close_json_object();
+
+	return 0;
+
+err_close_block:
+	close_json_object();
+
+	return 1;
+}
+
+static int parse_blocks(const struct nlattr *grp, const char *grp_name,
+			const struct stringset *stat_str)
+{
+	const struct nlattr *attr;
+	unsigned int channel = 0;
+
+	open_json_array("per-channel", "");
+
+	mnl_attr_for_each_nested(attr, grp) {
+		if (mnl_attr_get_type(attr) == ETHTOOL_A_STATS_GRP_STAT_BLOCK &&
+		    parse_one_block(attr, grp_name, stat_str, channel++))
+			goto err_close_block;
+	}
+
+	close_json_array("");
+
+	return 0;
+
+err_close_block:
+	close_json_array("");
+
+	return 1;
+}
+
 static int parse_grp(struct nl_context *nlctx, const struct nlattr *grp,
 		     const struct stringset *std_str)
 {
 	const struct nlattr *tb[ETHTOOL_A_STATS_GRP_SS_ID + 1] = {};
 	DECLARE_ATTR_TB_INFO(tb);
-	bool hist_rx = false, hist_tx = false;
+	bool hist_rx = false, hist_tx = false, blocks = false;
 	const struct stringset *stat_str;
 	const struct nlattr *attr;
 	unsigned int ss_id, id;
@@ -156,6 +210,9 @@ static int parse_grp(struct nl_context *nlctx, const struct nlattr *grp,
 		case ETHTOOL_A_STATS_GRP_HIST_TX:
 			hist_tx = true;
 			continue;
+		case ETHTOOL_A_STATS_GRP_STAT_BLOCK:
+			blocks = true;
+			continue;
 		default:
 			continue;
 		}
@@ -170,6 +227,8 @@ static int parse_grp(struct nl_context *nlctx, const struct nlattr *grp,
 	if (hist_tx)
 		parse_rmon_hist(grp, std_name, "tx-pktsNtoM", "tx",
 				ETHTOOL_A_STATS_GRP_HIST_TX);
+	if (blocks)
+		parse_blocks(grp, std_name, stat_str);
 
 	close_json_object();
 
-- 
2.31.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ