Skip to contentSkip to conversation

tc_util: fix breakage from clang changes

PATCH Applied Stephen Hemminger 2 participants 3 messages Feb 1, 2022 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CA+NMeC-uzWxn182SfF57e7xjXUdLmJV7fV0VN2a681LCh95R5g@mail.gmail.com

#1 lore raw

PATCH 1/2 tc_util: fix breakage from clang changes

This fixes the indentation of types with newline flag.

---
The clang changes merged an earlier version of the changes to print_masked_type.

 tc/tc_util.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)
tc/tc_util.c +10 -15
index 67960d2c03d7..78cb9901f7b9 100644
@@ -784,8 +784,6 @@ static void print_masked_type(__u32 type_max,
 			      struct rtattr *mask_attr, bool newline)
 {
 	__u32 value, mask;
-	SPRINT_BUF(out);
-	size_t done;
 
 	if (!attr)
 		return;
@@ -793,21 +791,18 @@ static void print_masked_type(__u32 type_max,
 	value = rta_getattr_type(attr);
 	mask = mask_attr ? rta_getattr_type(mask_attr) : type_max;
 
-	if (is_json_context()) {
-		print_hu(PRINT_JSON, name, NULL, value);
-		if (mask != type_max) {
-			char mask_name[SPRINT_BSIZE-6];
+	if (newline)
+		print_string(PRINT_FP, NULL, "%s  ", _SL_);
+	else
+		print_string(PRINT_FP, NULL, " ", _SL_);
 
-			sprintf(mask_name, "%s_mask", name);
-			print_hu(PRINT_JSON, mask_name, NULL, mask);
-		}
-	} else {
-		done = sprintf(out, "%u", value);
-		if (mask != type_max)
-			sprintf(out + done, "/0x%x", mask);
+	print_uint_name_value(name, value);
+
+	if (mask != type_max) {
+		char mask_name[SPRINT_BSIZE-6];
 
-		print_nl();
-		print_string_name_value(name, out);
+		snprintf(mask_name, sizeof(mask_name), "%s_mask", name);
+		print_hex(PRINT_ANY, mask_name, "/0x%x", mask);
 	}
 }
 
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/2 tc/f_flower: fix indentation

Introduce print_indent_name_value to do the indented style used in flower.

---
This was in second version of clang patches but missed during merge.

 tc/f_flower.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
tc/f_flower.c +12 -10
index 674e0d0384db..d3f79bdf4252 100644
@@ -102,6 +102,13 @@ static void explain(void)
 		"	to specify different mask, he has to use different prio.\n");
 }
 
+/* prints newline, two spaces, name/value */
+static void print_indent_name_value(const char *name, const char *value)
+{
+	print_string(PRINT_FP, NULL, "%s  ", _SL_);
+	print_string_name_value(name, value);
+}
+
 static int flower_parse_eth_addr(char *str, int addr_type, int mask_type,
 				 struct nlmsghdr *n)
 {
@@ -1945,8 +1952,7 @@ static void flower_print_eth_addr(const char *name, struct rtattr *addr_attr,
 			sprintf(out + done, "/%d", bits);
 	}
 
-	print_nl();
-	print_string_name_value(name, out);
+	print_indent_name_value(name, out);
 }
 
 static void flower_print_eth_type(__be16 *p_eth_type,
@@ -2089,8 +2095,7 @@ static void flower_print_ip_addr(char *name, __be16 eth_type,
 	else if (bits < len * 8)
 		sprintf(out + done, "/%d", bits);
 
-	print_nl();
-	print_string_name_value(name, out);
+	print_indent_name_value(name, out);
 }
 
 static void flower_print_ip4_addr(char *name, struct rtattr *addr_attr,
@@ -2123,8 +2128,7 @@ static void flower_print_port_range(char *name, struct rtattr *min_attr,
 
 		done = sprintf(out, "%u", rta_getattr_be16(min_attr));
 		sprintf(out + done, "-%u", rta_getattr_be16(max_attr));
-		print_nl();
-		print_string_name_value(name, out);
+		print_indent_name_value(name, out);
 	}
 }
 
@@ -2141,8 +2145,7 @@ static void flower_print_tcp_flags(const char *name, struct rtattr *flags_attr,
 	if (mask_attr)
 		sprintf(out + done, "/%x", rta_getattr_be16(mask_attr));
 
-	print_nl();
-	print_string_name_value(name, out);
+	print_indent_name_value(name, out);
 }
 
 static void flower_print_ct_state(struct rtattr *flags_attr,
@@ -2438,8 +2441,7 @@ static void flower_print_masked_u8(const char *name, struct rtattr *attr,
 	if (mask != UINT8_MAX)
 		sprintf(out + done, "/%d", mask);
 
-	print_nl();
-	print_string_name_value(name, out);
+	print_indent_name_value(name, out);
 }
 
 static void flower_print_u8(const char *name, struct rtattr *attr)
Signature · 1 line
2.34.1
#3 lore raw
In reply to Stephen Hemminger
This series was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:

Hello:

This series was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:

Quoted 8 lines · On Mon, 31 Jan 2022 20:28:18 -0800 you wrote:

This fixes the indentation of types with newline flag.

---
The clang changes merged an earlier version of the changes to print_masked_type.

[...]

Here is the summary with links:
- [iproute2-next,1/2] tc_util: fix breakage from clang changes

    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=9948b6cb92c5
  - [iproute2-next,2/2] tc/f_flower: fix indentation
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=5f44590ddec5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html