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] [day] [month] [year] [list]
Message-Id: <20210803165140.172-3-alexandr.lobakin@intel.com>
Date:   Tue,  3 Aug 2021 18:51:37 +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 2/5] stats: factor out one stat field printing

Move the code that takes one stat field nlattr, validates and prints
it in either stdout or JSON, into a separate function.
It will later be reused by per-channel statistics printing.

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

diff --git a/netlink/stats.c b/netlink/stats.c
index 9f609a4ec550..9d950b77d656 100644
--- a/netlink/stats.c
+++ b/netlink/stats.c
@@ -87,6 +87,36 @@ err_close_rmon:
 	return 1;
 }
 
+static int parse_stat(const struct nlattr *attr, const char *grp_name,
+		      const struct stringset *stat_str)
+{
+	const struct nlattr *stat;
+	unsigned long long val;
+	const char *name;
+	unsigned int s;
+	int ret;
+
+	stat = mnl_attr_get_payload(attr);
+	ret = mnl_attr_validate(stat, MNL_TYPE_U64);
+	if (ret) {
+		fprintf(stderr, "invalid kernel response - bad statistic entry\n");
+		return 1;
+	}
+
+	s = mnl_attr_get_type(stat);
+	name = get_string(stat_str, s);
+	if (!name || !name[0])
+		return 0;
+
+	if (!is_json_context())
+		fprintf(stdout, "%s-%s: ", grp_name, name);
+
+	val = mnl_attr_get_u64(stat);
+	print_u64(PRINT_ANY, name, "%llu\n", val);
+
+	return 0;
+}
+
 static int parse_grp(struct nl_context *nlctx, const struct nlattr *grp,
 		     const struct stringset *std_str)
 {
@@ -94,10 +124,9 @@ static int parse_grp(struct nl_context *nlctx, const struct nlattr *grp,
 	DECLARE_ATTR_TB_INFO(tb);
 	bool hist_rx = false, hist_tx = false;
 	const struct stringset *stat_str;
-	const struct nlattr *attr, *stat;
-	const char *std_name, *name;
-	unsigned int ss_id, id, s;
-	unsigned long long val;
+	const struct nlattr *attr;
+	unsigned int ss_id, id;
+	const char *std_name;
 	int ret;
 
 	ret = mnl_attr_parse_nested(grp, attr_cb, &tb_info);
@@ -131,22 +160,8 @@ static int parse_grp(struct nl_context *nlctx, const struct nlattr *grp,
 			continue;
 		}
 
-		stat = mnl_attr_get_payload(attr);
-		ret = mnl_attr_validate(stat, MNL_TYPE_U64);
-		if (ret) {
-			fprintf(stderr, "invalid kernel response - bad statistic entry\n");
+		if (parse_stat(attr, NULL, std_name, stat_str))
 			goto err_close_grp;
-		}
-		s = mnl_attr_get_type(stat);
-		name = get_string(stat_str, s);
-		if (!name || !name[0])
-			continue;
-
-		if (!is_json_context())
-			fprintf(stdout, "%s-%s: ", std_name, name);
-
-		val = mnl_attr_get_u64(stat);
-		print_u64(PRINT_ANY, name, "%llu\n", val);
 	}
 
 	if (hist_rx)
-- 
2.31.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ