Skip to contentSkip to conversation

tc: htb: Print default value in hex

PATCH Superseded Phil Sutter 2 participants 3 messages Oct 19, 2018 – Oct 23, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tc: htb: Print default value in hex

Value of 'default' is assumed to be hexadecimal when parsing, so consequently it should be printed in hex as well. This is a regression introduced when adding JSON output.

Fixes f354fa6aa5ff0 ("tc: jsonify htb qdisc")
---
 tc/q_htb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tc/q_htb.c +1 -1
index c8b2941d945b7..c69485db8ef7d 100644
@@ -332,7 +332,7 @@ static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 		if (RTA_PAYLOAD(tb[TCA_HTB_INIT])  < sizeof(*gopt)) return -1;
 
 		print_int(PRINT_ANY, "r2q", "r2q %d", gopt->rate2quantum);
-		print_uint(PRINT_ANY, "default", " default %u", gopt->defcls);
+		print_uint(PRINT_ANY, "default", " default %x", gopt->defcls);
 		print_uint(PRINT_ANY, "direct_packets_stat",
 			   " direct_packets_stat %u", gopt->direct_pkts);
 		if (show_details) {
Signature · 1 line
2.19.0
#1 lore raw
Quoted 15 lines · On Fri, 19 Oct 2018 17:42:55 +0200 Phil Sutter <[email protected]> wrote:

Value of 'default' is assumed to be hexadecimal when parsing, so consequently it should be printed in hex as well. This is a regression introduced when adding JSON output.

Fixes f354fa6aa5ff0 ("tc: jsonify htb qdisc")
---
 tc/q_htb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tc/q_htb.c +0 -0
index c8b2941d945b7..c69485db8ef7d 100644

tc/q_htb.c static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) · line 338

Quoted 8 lines
tc/q_htb.c +1 -1
@@ -332,7 +332,7 @@ static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 		if (RTA_PAYLOAD(tb[TCA_HTB_INIT])  < sizeof(*gopt)) return -1;
 
 		print_int(PRINT_ANY, "r2q", "r2q %d", gopt->rate2quantum);
-		print_uint(PRINT_ANY, "default", " default %u", gopt->defcls);
+		print_uint(PRINT_ANY, "default", " default %x", gopt->defcls);
 		print_uint(PRINT_ANY, "direct_packets_stat",
 			   " direct_packets_stat %u", gopt->direct_pkts);
 		if (show_details) {

The output should be in hex. Because you used print_uint it will still be in decimal in the JSON output. The correct fix here is to use print_0xhex instead.

Please fix that, test it, and resubmit.

#2 lore raw
Quoted 30 lines · Stephen Hemminger
Quoted 15 lines · On Fri, 19 Oct 2018 17:42:55 +0200 Phil Sutter <[email protected]> wrote:

Value of 'default' is assumed to be hexadecimal when parsing, so consequently it should be printed in hex as well. This is a regression introduced when adding JSON output.

Fixes f354fa6aa5ff0 ("tc: jsonify htb qdisc")
---
 tc/q_htb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tc/q_htb.c +0 -0
index c8b2941d945b7..c69485db8ef7d 100644

tc/q_htb.c static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) · line 338

Quoted 8 lines
tc/q_htb.c +1 -1
@@ -332,7 +332,7 @@ static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 		if (RTA_PAYLOAD(tb[TCA_HTB_INIT])  < sizeof(*gopt)) return -1;
 
 		print_int(PRINT_ANY, "r2q", "r2q %d", gopt->rate2quantum);
-		print_uint(PRINT_ANY, "default", " default %u", gopt->defcls);
+		print_uint(PRINT_ANY, "default", " default %x", gopt->defcls);
 		print_uint(PRINT_ANY, "direct_packets_stat",
 			   " direct_packets_stat %u", gopt->direct_pkts);
 		if (show_details) {

The output should be in hex. Because you used print_uint it will still be in decimal in the JSON output. The correct fix here is to use print_0xhex instead.

Quoted 1 line

Please fix that, test it, and resubmit.

I did test, but not JSON output. It is not a regression in the latter because it has been like this since JSON output was added to HTB. Assuming the output is programmatically parsed, it shouldn't matter too much as well.

Grepping through the code I found three more cases where print_uint() was used for data printed in %x. Should I fix those as well?

Thanks, Phil