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: <20251117-param-defaults-v1-1-c99604175d09@gmail.com>
Date: Mon, 17 Nov 2025 16:40:02 -0800
From: Daniel Zahka <daniel.zahka@...il.com>
To: Jiri Pirko <jiri@...nulli.us>, "David S. Miller" <davem@...emloft.net>, 
 Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>, 
 Simon Horman <horms@...nel.org>, Donald Hunter <donald.hunter@...il.com>, 
 David Ahern <dsahern@...nel.org>
Cc: netdev@...r.kernel.org, linux-kernel@...r.kernel.org, 
 Daniel Zahka <daniel.zahka@...il.com>
Subject: [PATCH iproute2-next 1/2] devlink: Pull the value printing logic
 out of pr_out_param_value()

Split the type demux and value print out of pr_out_param_value() into
a new function pr_out_param_value_print(). This new function can be
re-used for printing additional kinds of values e.g., a default value
reported by the kernel.

Signed-off-by: Daniel Zahka <daniel.zahka@...il.com>
---
 devlink/devlink.c | 88 ++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 54 insertions(+), 34 deletions(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index fd9fac21..e1612b77 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -3518,33 +3518,14 @@ static const struct param_val_conv param_val_conv[] = {
 
 #define PARAM_VAL_CONV_LEN ARRAY_SIZE(param_val_conv)
 
-static void pr_out_param_value(struct dl *dl, const char *nla_name,
-			       int nla_type, struct nlattr *nl)
+static int pr_out_param_value_print(const char *nla_name, int nla_type,
+				     struct nlattr *val_attr, bool conv_exists,
+				     const char *label)
 {
-	struct nlattr *nla_value[DEVLINK_ATTR_MAX + 1] = {};
-	struct nlattr *val_attr;
+	char format_str[32];
 	const char *vstr;
-	bool conv_exists;
 	int err;
 
-	err = mnl_attr_parse_nested(nl, attr_cb, nla_value);
-	if (err != MNL_CB_OK)
-		return;
-
-	if (!nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE] ||
-	    (nla_type != MNL_TYPE_FLAG &&
-	     !nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA]))
-		return;
-
-	check_indent_newline(dl);
-	print_string(PRINT_ANY, "cmode", "cmode %s",
-		     param_cmode_name(mnl_attr_get_u8(nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE])));
-
-	val_attr = nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA];
-
-	conv_exists = param_val_conv_exists(param_val_conv, PARAM_VAL_CONV_LEN,
-					    nla_name);
-
 	switch (nla_type) {
 	case MNL_TYPE_U8:
 		if (conv_exists) {
@@ -3554,10 +3535,12 @@ static void pr_out_param_value(struct dl *dl, const char *nla_name,
 						     mnl_attr_get_u8(val_attr),
 						     &vstr);
 			if (err)
-				return;
-			print_string(PRINT_ANY, "value", " value %s", vstr);
+				return err;
+			snprintf(format_str, sizeof(format_str), " %s %%s", label);
+			print_string(PRINT_ANY, label, format_str, vstr);
 		} else {
-			print_uint(PRINT_ANY, "value", " value %u",
+			snprintf(format_str, sizeof(format_str), " %s %%u", label);
+			print_uint(PRINT_ANY, label, format_str,
 				   mnl_attr_get_u8(val_attr));
 		}
 		break;
@@ -3569,10 +3552,12 @@ static void pr_out_param_value(struct dl *dl, const char *nla_name,
 						     mnl_attr_get_u16(val_attr),
 						     &vstr);
 			if (err)
-				return;
-			print_string(PRINT_ANY, "value", " value %s", vstr);
+				return err;
+			snprintf(format_str, sizeof(format_str), " %s %%s", label);
+			print_string(PRINT_ANY, label, format_str, vstr);
 		} else {
-			print_uint(PRINT_ANY, "value", " value %u",
+			snprintf(format_str, sizeof(format_str), " %s %%u", label);
+			print_uint(PRINT_ANY, label, format_str,
 				   mnl_attr_get_u16(val_attr));
 		}
 		break;
@@ -3584,21 +3569,56 @@ static void pr_out_param_value(struct dl *dl, const char *nla_name,
 						     mnl_attr_get_u32(val_attr),
 						     &vstr);
 			if (err)
-				return;
-			print_string(PRINT_ANY, "value", " value %s", vstr);
+				return err;
+			snprintf(format_str, sizeof(format_str), " %s %%s", label);
+			print_string(PRINT_ANY, label, format_str, vstr);
 		} else {
-			print_uint(PRINT_ANY, "value", " value %u",
+			snprintf(format_str, sizeof(format_str), " %s %%u", label);
+			print_uint(PRINT_ANY, label, format_str,
 				   mnl_attr_get_u32(val_attr));
 		}
 		break;
 	case MNL_TYPE_STRING:
-		print_string(PRINT_ANY, "value", " value %s",
+		snprintf(format_str, sizeof(format_str), " %s %%s", label);
+		print_string(PRINT_ANY, label, format_str,
 			     mnl_attr_get_str(val_attr));
 		break;
 	case MNL_TYPE_FLAG:
-		print_bool(PRINT_ANY, "value", " value %s", val_attr);
+		snprintf(format_str, sizeof(format_str), " %s %%s", label);
+		print_bool(PRINT_ANY, label, format_str, val_attr);
 		break;
 	}
+
+	return 0;
+}
+
+static void pr_out_param_value(struct dl *dl, const char *nla_name,
+			       int nla_type, struct nlattr *nl)
+{
+	struct nlattr *nla_value[DEVLINK_ATTR_MAX + 1] = {};
+	struct nlattr *val_attr;
+	bool conv_exists;
+	int err;
+
+	err = mnl_attr_parse_nested(nl, attr_cb, nla_value);
+	if (err != MNL_CB_OK)
+		return;
+
+	if (!nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE] ||
+	    (nla_type != MNL_TYPE_FLAG &&
+	     !nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA]))
+		return;
+
+	check_indent_newline(dl);
+	print_string(PRINT_ANY, "cmode", "cmode %s",
+		     param_cmode_name(mnl_attr_get_u8(nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE])));
+
+	val_attr = nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA];
+
+	conv_exists = param_val_conv_exists(param_val_conv, PARAM_VAL_CONV_LEN,
+					    nla_name);
+
+	pr_out_param_value_print(nla_name, nla_type, val_attr, conv_exists, "value");
 }
 
 static void pr_out_param(struct dl *dl, struct nlattr **tb, bool array,

-- 
2.47.3


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ