diff mbox series

[v2,iproute2,1/2] tc/taprio: don't print netlink attributes which weren't reported by the kernel

Message ID 20230807220936.4164355-1-vladimir.oltean@nxp.com (mailing list archive)
State Accepted
Commit a5f695cbb1308b085ca2ff898f2d25c04a48265a
Delegated to: Stephen Hemminger
Headers show
Series [v2,iproute2,1/2] tc/taprio: don't print netlink attributes which weren't reported by the kernel | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Vladimir Oltean Aug. 7, 2023, 10:09 p.m. UTC
When an admin schedule is pending and hasn't yet become operational, the
kernel will report only the parameters of the admin schedule in a nested
TCA_TAPRIO_ATTR_ADMIN_SCHED attribute.

However, we default to printing zeroes even for the parameters of the
operational base time, when that doesn't exist.

Link: https://lore.kernel.org/netdev/87il9w0xx7.fsf@intel.com/
Fixes: 0dd16449356f ("tc: Add support for configuring the taprio scheduler")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Acked-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
v1->v2:
- move variable declarations to their respective "if" blocks
- use "nla" instead of "tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME]"


 tc/q_taprio.c | 89 +++++++++++++++++++++++++++++++--------------------
 1 file changed, 54 insertions(+), 35 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org Aug. 9, 2023, 8:50 p.m. UTC | #1
Hello:

This series was applied to iproute2/iproute2.git (main)
by Stephen Hemminger <stephen@networkplumber.org>:

On Tue,  8 Aug 2023 01:09:35 +0300 you wrote:
> When an admin schedule is pending and hasn't yet become operational, the
> kernel will report only the parameters of the admin schedule in a nested
> TCA_TAPRIO_ATTR_ADMIN_SCHED attribute.
> 
> However, we default to printing zeroes even for the parameters of the
> operational base time, when that doesn't exist.
> 
> [...]

Here is the summary with links:
  - [v2,iproute2,1/2] tc/taprio: don't print netlink attributes which weren't reported by the kernel
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=a5f695cbb130
  - [v2,iproute2,2/2] tc/taprio: fix JSON output when TCA_TAPRIO_ATTR_ADMIN_SCHED is present
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=f848310a7279

You are awesome, thank you!
diff mbox series

Patch

diff --git a/tc/q_taprio.c b/tc/q_taprio.c
index 913197f68caa..6250871fb5f2 100644
--- a/tc/q_taprio.c
+++ b/tc/q_taprio.c
@@ -416,14 +416,11 @@  static int taprio_parse_opt(struct qdisc_util *qu, int argc,
 	return 0;
 }
 
-static int print_sched_list(FILE *f, struct rtattr *list)
+static void print_sched_list(FILE *f, struct rtattr *list)
 {
-	struct rtattr *item;
+	struct rtattr *item, *nla;
 	int rem;
 
-	if (list == NULL)
-		return 0;
-
 	rem = RTA_PAYLOAD(list);
 
 	open_json_array(PRINT_JSON, "schedule");
@@ -432,60 +429,82 @@  static int print_sched_list(FILE *f, struct rtattr *list)
 
 	for (item = RTA_DATA(list); RTA_OK(item, rem); item = RTA_NEXT(item, rem)) {
 		struct rtattr *tb[TCA_TAPRIO_SCHED_ENTRY_MAX + 1];
-		__u32 index = 0, gatemask = 0, interval = 0;
-		__u8 command = 0;
 
 		parse_rtattr_nested(tb, TCA_TAPRIO_SCHED_ENTRY_MAX, item);
 
-		if (tb[TCA_TAPRIO_SCHED_ENTRY_INDEX])
-			index = rta_getattr_u32(tb[TCA_TAPRIO_SCHED_ENTRY_INDEX]);
+		open_json_object(NULL);
 
-		if (tb[TCA_TAPRIO_SCHED_ENTRY_CMD])
-			command = rta_getattr_u8(tb[TCA_TAPRIO_SCHED_ENTRY_CMD]);
+		nla = tb[TCA_TAPRIO_SCHED_ENTRY_INDEX];
+		if (nla) {
+			__u32 index = rta_getattr_u32(nla);
 
-		if (tb[TCA_TAPRIO_SCHED_ENTRY_GATE_MASK])
-			gatemask = rta_getattr_u32(tb[TCA_TAPRIO_SCHED_ENTRY_GATE_MASK]);
+			print_uint(PRINT_ANY, "index", "\tindex %u", index);
+		}
 
-		if (tb[TCA_TAPRIO_SCHED_ENTRY_INTERVAL])
-			interval = rta_getattr_u32(tb[TCA_TAPRIO_SCHED_ENTRY_INTERVAL]);
+		nla = tb[TCA_TAPRIO_SCHED_ENTRY_CMD];
+		if (nla) {
+			__u8 command = rta_getattr_u8(nla);
+
+			print_string(PRINT_ANY, "cmd", " cmd %s",
+				     entry_cmd_to_str(command));
+		}
+
+		nla = tb[TCA_TAPRIO_SCHED_ENTRY_GATE_MASK];
+		if (nla) {
+			__u32 gatemask = rta_getattr_u32(nla);
+
+			print_0xhex(PRINT_ANY, "gatemask", " gatemask %#llx",
+				    gatemask);
+		}
+
+		nla = tb[TCA_TAPRIO_SCHED_ENTRY_INTERVAL];
+		if (nla) {
+			__u32 interval = rta_getattr_u32(nla);
+
+			print_uint(PRINT_ANY, "interval", " interval %u",
+				   interval);
+		}
 
-		open_json_object(NULL);
-		print_uint(PRINT_ANY, "index", "\tindex %u", index);
-		print_string(PRINT_ANY, "cmd", " cmd %s", entry_cmd_to_str(command));
-		print_0xhex(PRINT_ANY, "gatemask", " gatemask %#llx", gatemask);
-		print_uint(PRINT_ANY, "interval", " interval %u", interval);
 		close_json_object();
 
 		print_nl();
 	}
 
 	close_json_array(PRINT_ANY, "");
-
-	return 0;
 }
 
 static int print_schedule(FILE *f, struct rtattr **tb)
 {
-	int64_t base_time = 0, cycle_time = 0, cycle_time_extension = 0;
+	struct rtattr *nla;
 
-	if (tb[TCA_TAPRIO_ATTR_SCHED_BASE_TIME])
-		base_time = rta_getattr_s64(tb[TCA_TAPRIO_ATTR_SCHED_BASE_TIME]);
+	nla = tb[TCA_TAPRIO_ATTR_SCHED_BASE_TIME];
+	if (nla) {
+		int64_t base_time = rta_getattr_s64(nla);
 
-	if (tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME])
-		cycle_time = rta_getattr_s64(tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME]);
+		print_lluint(PRINT_ANY, "base_time", "\tbase-time %lld",
+			     base_time);
+	}
 
-	if (tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION])
-		cycle_time_extension = rta_getattr_s64(
-			tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION]);
+	nla = tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME];
+	if (nla) {
+		int64_t cycle_time = rta_getattr_s64(nla);
 
-	print_lluint(PRINT_ANY, "base_time", "\tbase-time %lld", base_time);
+		print_lluint(PRINT_ANY, "cycle_time", " cycle-time %lld",
+			     cycle_time);
+	}
 
-	print_lluint(PRINT_ANY, "cycle_time", " cycle-time %lld", cycle_time);
+	nla = tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION];
+	if (nla) {
+		int64_t cycle_time_extension = rta_getattr_s64(nla);
 
-	print_lluint(PRINT_ANY, "cycle_time_extension",
-		     " cycle-time-extension %lld", cycle_time_extension);
+		print_lluint(PRINT_ANY, "cycle_time_extension",
+			     " cycle-time-extension %lld",
+			     cycle_time_extension);
+	}
 
-	print_sched_list(f, tb[TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST]);
+	nla = tb[TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST];
+	if (nla)
+		print_sched_list(f, nla);
 
 	return 0;
 }