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]
Date:   Mon, 19 Oct 2020 23:32:40 +0200 (CEST)
From:   Michal Kubecek <mkubecek@...e.cz>
To:     netdev@...r.kernel.org
Cc:     Jakub Kicinski <kuba@...nel.org>
Subject: [PATCH ethtool 1/4] netlink: support u32 enumerated types in pretty
 printing

Some numeric attributes take values from a short list/range with symbolic
names. Showing the symbolic names instead of numeric values will make the
pretty printed netlink messages easier to read. If the value is too big for
provided names array (e.g. running on newer kernel) or the name is omitted,
numeric attribute value is shown.

Signed-off-by: Michal Kubecek <mkubecek@...e.cz>
---
 netlink/prettymsg.c |  9 +++++++++
 netlink/prettymsg.h | 18 ++++++++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/netlink/prettymsg.c b/netlink/prettymsg.c
index f992dcaf071f..d5d999fddfbb 100644
--- a/netlink/prettymsg.c
+++ b/netlink/prettymsg.c
@@ -137,6 +137,15 @@ static int pretty_print_attr(const struct nlattr *attr,
 	case NLA_BOOL:
 		printf("%s", mnl_attr_get_u8(attr) ? "on" : "off");
 		break;
+	case NLA_U32_ENUM: {
+		uint32_t val = mnl_attr_get_u32(attr);
+
+		if (adesc && val < adesc->n_names && adesc->names[val])
+			printf("%s", adesc->names[val]);
+		else
+			printf("%u", val);
+		break;
+	}
 	default:
 		if (alen <= __DUMP_LINE)
 			__print_binary_short(adata, alen);
diff --git a/netlink/prettymsg.h b/netlink/prettymsg.h
index b5e5f735ac8a..6987c6ec5bca 100644
--- a/netlink/prettymsg.h
+++ b/netlink/prettymsg.h
@@ -28,13 +28,20 @@ enum pretty_nla_format {
 	NLA_BOOL,
 	NLA_NESTED,
 	NLA_ARRAY,
+	NLA_U32_ENUM,
 };
 
 struct pretty_nla_desc {
 	enum pretty_nla_format		format;
 	const char			*name;
-	const struct pretty_nla_desc	*children;
-	unsigned int			n_children;
+	union {
+		const struct pretty_nla_desc	*children;
+		const char			*const *names;
+	};
+	union {
+		unsigned int			n_children;
+		unsigned int			n_names;
+	};
 };
 
 struct pretty_nlmsg_desc {
@@ -81,6 +88,13 @@ struct pretty_nlmsg_desc {
 		.children = __ ## _children_desc ## _desc, \
 		.n_children = 1, \
 	}
+#define NLATTR_DESC_U32_ENUM(_name, _names_table) \
+	[_name] = { \
+		.format = NLA_U32_ENUM, \
+		.name = #_name, \
+		.names = __ ## _names_table ## _names, \
+		.n_children = ARRAY_SIZE(__ ## _names_table ## _names), \
+	}
 
 #define NLMSG_DESC(_name, _attrs) \
 	[_name] = { \
-- 
2.28.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ