Skip to contentSkip to conversation

extensions: libebt_stp: Eliminate duplicate space in output

PATCH New Phil Sutter 1 participant 3 messages Oct 1, 2022 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/3 extensions: libebt_stp: Eliminate duplicate space in output

No need for print_range() to print a trailing whitespace, caller does this already.

Fixes fd8d7d7e5d911 ("ebtables-nft: add stp match")
---
 extensions/libebt_stp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
extensions/libebt_stp.c +2 -2
index 3e9e24474eb61..41059baae7078 100644
@@ -146,9 +146,9 @@ static int parse_range(const char *portstring, void *lower, void *upper,
 static void print_range(unsigned int l, unsigned int u)
 {
 	if (l == u)
-		printf("%u ", l);
+		printf("%u", l);
 	else
-		printf("%u:%u ", l, u);
+		printf("%u:%u", l, u);
 }
 
 static int
Signature · 1 line
2.34.1
author reviewer
#1 lore raw

PATCH 2/3 extensions: libip6t_dst: Fix output for empty options

If no --dst-opts were given, print_options() would print just a whitespace.

Fixes 73866357e4a7a ("iptables: do not print trailing whitespaces")
---
 extensions/libip6t_dst.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
extensions/libip6t_dst.c +3 -3
index bf0e3e436665d..baa010f56ac22 100644
@@ -125,15 +125,15 @@ static void
 print_options(unsigned int optsnr, uint16_t *optsp)
 {
 	unsigned int i;
+	char sep = ' ';
 
-	printf(" ");
 	for(i = 0; i < optsnr; i++) {
-		printf("%d", (optsp[i] & 0xFF00) >> 8);
+		printf("%c%d", sep, (optsp[i] & 0xFF00) >> 8);
 
 		if ((optsp[i] & 0x00FF) != 0x00FF)
 			printf(":%d", (optsp[i] & 0x00FF));
 
-		printf("%c", (i != optsnr - 1) ? ',' : ' ');
+		sep = ',';
 	}
 }
 
Signature · 1 line
2.34.1
author reviewer
#2 lore raw

PATCH 3/3 extensions: TCPOPTSTRIP: Do not print empty options

In reply to Phil Sutter

No point in printing anything if none of the bits are set.

Fixes aef4c1e727563 ("libxt_TCPOPTSTRIP")
---
 extensions/libxt_TCPOPTSTRIP.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
extensions/libxt_TCPOPTSTRIP.c +13 -0
index 6ea3489224602..ff873f98b3aaa 100644
@@ -142,6 +142,13 @@ tcpoptstrip_print_list(const struct xt_tcpoptstrip_target_info *info,
 	}
 }
 
+static bool tcpoptstrip_empty(const struct xt_tcpoptstrip_target_info *info)
+{
+	static const struct xt_tcpoptstrip_target_info empty = {};
+
+	return memcmp(info, &empty, sizeof(empty)) == 0;
+}
+
 static void
 tcpoptstrip_tg_print(const void *ip, const struct xt_entry_target *target,
                      int numeric)
@@ -149,6 +156,9 @@ tcpoptstrip_tg_print(const void *ip, const struct xt_entry_target *target,
 	const struct xt_tcpoptstrip_target_info *info =
 		(const void *)target->data;
 
+	if (tcpoptstrip_empty(info))
+		return;
+
 	printf(" TCPOPTSTRIP options ");
 	tcpoptstrip_print_list(info, numeric);
 }
@@ -159,6 +169,9 @@ tcpoptstrip_tg_save(const void *ip, const struct xt_entry_target *target)
 	const struct xt_tcpoptstrip_target_info *info =
 		(const void *)target->data;
 
+	if (tcpoptstrip_empty(info))
+		return;
+
 	printf(" --strip-options ");
 	tcpoptstrip_print_list(info, true);
 }
Signature · 1 line
2.34.1