netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ss: fix output of MD5 signature keys configured on TCP sockets
@ 2024-03-01 12:33 Lars Ellenberg
  2024-03-04 16:25 ` Stephen Hemminger
  2024-03-04 16:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Lars Ellenberg @ 2024-03-01 12:33 UTC (permalink / raw)
  To: netdev

da9cc6ab introduced printing of MD5 signature keys when found.
But when changing printf() to out() calls with 90351722,
the implicit printf call in print_escape_buf() was overlooked.
That results in a funny output in the first line:
"<all-your-tcp-signature-keys-concatenated>State"
and ambiguity as to which of those bytes belong to which socket.

Add a static void out_escape_buf() immediately before we use it.

da9cc6ab (ss: print MD5 signature keys configured on TCP sockets, 2017-10-06)
90351722 (ss: Replace printf() calls for "main" output by calls to helper, 2017-12-12)

Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
---
 misc/ss.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/misc/ss.c b/misc/ss.c
index 5296cabe..fb560a55 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -24,6 +24,7 @@
 #include <stdbool.h>
 #include <limits.h>
 #include <stdarg.h>
+#include <ctype.h>
 
 #include "ss_util.h"
 #include "utils.h"
@@ -2891,6 +2892,20 @@ static void print_skmeminfo(struct rtattr *tb[], int attrtype)
 	out(")");
 }
 
+/* like lib/utils.c print_escape_buf(), but use out(), not printf()! */
+static void out_escape_buf(const __u8 *buf, size_t len, const char *escape)
+{
+	size_t i;
+
+	for (i = 0; i < len; ++i) {
+		if (isprint(buf[i]) && buf[i] != '\\' &&
+		    !strchr(escape, buf[i]))
+			out("%c", buf[i]);
+		else
+			out("\\%03o", buf[i]);
+	}
+}
+
 static void print_md5sig(struct tcp_diag_md5sig *sig)
 {
 	out("%s/%d=",
@@ -2898,7 +2913,7 @@ static void print_md5sig(struct tcp_diag_md5sig *sig)
 			sig->tcpm_family == AF_INET6 ? 16 : 4,
 			&sig->tcpm_addr),
 	    sig->tcpm_prefixlen);
-	print_escape_buf(sig->tcpm_key, sig->tcpm_keylen, " ,");
+	out_escape_buf(sig->tcpm_key, sig->tcpm_keylen, " ,");
 }
 
 static void tcp_tls_version(struct rtattr *attr)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ss: fix output of MD5 signature keys configured on TCP sockets
  2024-03-01 12:33 [PATCH] ss: fix output of MD5 signature keys configured on TCP sockets Lars Ellenberg
@ 2024-03-04 16:25 ` Stephen Hemminger
  2024-03-04 16:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2024-03-04 16:25 UTC (permalink / raw)
  To: Lars Ellenberg; +Cc: netdev

On Fri, 1 Mar 2024 13:33:24 +0100
Lars Ellenberg <lars.ellenberg@linbit.com> wrote:

> da9cc6ab introduced printing of MD5 signature keys when found.
> But when changing printf() to out() calls with 90351722,
> the implicit printf call in print_escape_buf() was overlooked.
> That results in a funny output in the first line:
> "<all-your-tcp-signature-keys-concatenated>State"
> and ambiguity as to which of those bytes belong to which socket.
> 
> Add a static void out_escape_buf() immediately before we use it.
> 
> da9cc6ab (ss: print MD5 signature keys configured on TCP sockets, 2017-10-06)
> 90351722 (ss: Replace printf() calls for "main" output by calls to helper, 2017-12-12)
> 
> Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
> ---

Wonder if the out() method was really good idea in the first place.
Would have been easier to use openstream to redirect stdio buffer and count
bytes on the other side.

But will merge this. Eventually, ss needs a bit overhaul/rewrite to be not
one monolithic program and handle json.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ss: fix output of MD5 signature keys configured on TCP sockets
  2024-03-01 12:33 [PATCH] ss: fix output of MD5 signature keys configured on TCP sockets Lars Ellenberg
  2024-03-04 16:25 ` Stephen Hemminger
@ 2024-03-04 16:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-03-04 16:30 UTC (permalink / raw)
  To: Lars Ellenberg; +Cc: netdev

Hello:

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

On Fri, 1 Mar 2024 13:33:24 +0100 you wrote:
> da9cc6ab introduced printing of MD5 signature keys when found.
> But when changing printf() to out() calls with 90351722,
> the implicit printf call in print_escape_buf() was overlooked.
> That results in a funny output in the first line:
> "<all-your-tcp-signature-keys-concatenated>State"
> and ambiguity as to which of those bytes belong to which socket.
> 
> [...]

Here is the summary with links:
  - ss: fix output of MD5 signature keys configured on TCP sockets
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=857a328934a0

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-04 16:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-01 12:33 [PATCH] ss: fix output of MD5 signature keys configured on TCP sockets Lars Ellenberg
2024-03-04 16:25 ` Stephen Hemminger
2024-03-04 16:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).