public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2] ss: print IPv6 zone identifier within the square backets
@ 2026-03-17 18:22 Jan Engelhardt
  2026-03-23  0:22 ` David Ahern
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Engelhardt @ 2026-03-17 18:22 UTC (permalink / raw)
  To: stephen; +Cc: netdev

ss was printing the zone identifier in the wrong place.
The zone identifier belongs to the address [1][2][3], and should thus
be enclosed within the square brackets, not outside of it.

[1] glibc (since about 2000) accepts "fe80::1%eth0" as an input to
    the `getaddrinfo` function.
[2] Zone architecture specification (drafted 2003; released 2005):
    RFC 4007 §4: "The scope of an address is encoded as part of the
    address".
[3] RFC 6874 §2 pg. 4: ABNF syntax showing where zones go in
    relation to square brackets.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
---
 misc/ss.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index b3566f6b..f242d761 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1484,10 +1484,23 @@ static void sock_details_print(struct sockstat *s)
 static void sock_addr_print(const char *addr, char *delim, const char *port,
 		const char *ifname)
 {
-	if (ifname)
-		out("%s" "%%" "%s%s", addr, ifname, delim);
-	else
-		out("%s%s", addr, delim);
+	/*
+	 * Numeric IPv6 addresses should be bracketed.
+	 * Come to think of it, any address with a port delimiter character
+	 * should be bracketed; otherwise, it would be impossible to tell if
+	 * ":N" is the port or part of the address.
+	 */
+	if (strpbrk(addr, delim) != NULL) {
+		if (ifname)
+			out("[%s" "%%" "%s]%s", addr, ifname, delim);
+		else
+			out("[%s]%s", addr, delim);
+	} else {
+		if (ifname)
+			out("%s" "%%" "%s%s", addr, ifname, delim);
+		else
+			out("%s%s", addr, delim);
+	}
 
 	field_next();
 	out("%s", port);
@@ -1725,13 +1738,6 @@ static void inet_addr_print(const inet_prefix *a, int port,
 			buf[1] = 0;
 		} else {
 			ap = format_host(a->family, 16, a->data);
-
-			/* Numeric IPv6 addresses should be bracketed */
-			if (strchr(ap, ':')) {
-				snprintf(buf, sizeof(buf),
-					 "[%s]", ap);
-				ap = buf;
-			}
 		}
 	}
 
-- 
2.53.0


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

* Re: [PATCH iproute2] ss: print IPv6 zone identifier within the square backets
  2026-03-17 18:22 [PATCH iproute2] ss: print IPv6 zone identifier within the square backets Jan Engelhardt
@ 2026-03-23  0:22 ` David Ahern
  2026-03-23  8:39   ` Jan Engelhardt
  0 siblings, 1 reply; 3+ messages in thread
From: David Ahern @ 2026-03-23  0:22 UTC (permalink / raw)
  To: Jan Engelhardt, stephen; +Cc: netdev

On 3/17/26 12:22 PM, Jan Engelhardt wrote:
> ss was printing the zone identifier in the wrong place.
> The zone identifier belongs to the address [1][2][3], and should thus
> be enclosed within the square brackets, not outside of it.
> 
> [1] glibc (since about 2000) accepts "fe80::1%eth0" as an input to
>     the `getaddrinfo` function.
> [2] Zone architecture specification (drafted 2003; released 2005):
>     RFC 4007 §4: "The scope of an address is encoded as part of the
>     address".
> [3] RFC 6874 §2 pg. 4: ABNF syntax showing where zones go in
>     relation to square brackets.
> 
> Signed-off-by: Jan Engelhardt <jengelh@inai.de>
> ---
>  misc/ss.c | 28 +++++++++++++++++-----------
>  1 file changed, 17 insertions(+), 11 deletions(-)
> 

This change is definitely going to break existing scripts handling ipv6
addresses. I do not see how this can be applied.


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

* Re: [PATCH iproute2] ss: print IPv6 zone identifier within the square backets
  2026-03-23  0:22 ` David Ahern
@ 2026-03-23  8:39   ` Jan Engelhardt
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Engelhardt @ 2026-03-23  8:39 UTC (permalink / raw)
  To: David Ahern; +Cc: stephen, netdev


On Monday 2026-03-23 01:22, David Ahern wrote:
>On 3/17/26 12:22 PM, Jan Engelhardt wrote:
>> ss was printing the zone identifier in the wrong place.
>> The zone identifier belongs to the address [1][2][3], and should thus
>> be enclosed within the square brackets, not outside of it.
>> 
>> [1] glibc (since about 2000) accepts "fe80::1%eth0" as an input to
>>     the `getaddrinfo` function.
>
>This change is definitely going to break existing scripts handling ipv6
>addresses. I do not see how this can be applied.

ss output is not reliably parsable at present anyway, so I think the
point is moot.
Unlike `lsblk -r`/`lsblk -P`, ss does not restrain what characters it
uses in column headers, does not to use a consistent character
separating address and port, and fails to do escaping of paths e.g.
in the case of AF_LOCAL socket. At the will of an unprivileged user,
any parser is immediately thrown off.

$ perl -e 'use Socket qw(:all);socket(my $s, AF_UNIX,SOCK_DGRAM,0);
  bind($s,sockaddr_un("/tmp/foo\x20"."bar\x3a"."13\x20"."49\x0a".
  "u_str ESTAB 0 0 ..."));sleep(600);'

# ss -x
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port    
u_dgr UNCONN 0 0 /tmp/foo bar:13 49
u_str ESTAB 0 0 ... 31267391 * 0       

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

end of thread, other threads:[~2026-03-23  8:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-17 18:22 [PATCH iproute2] ss: print IPv6 zone identifier within the square backets Jan Engelhardt
2026-03-23  0:22 ` David Ahern
2026-03-23  8:39   ` Jan Engelhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox