[RFC 2/3] ss: warn when packet socket diag is unavailable
From: Stephen Hemminger <stephen@networkplumber.org>
Date: 2026-09-15 21:36:55
Subsystem:
the rest · Maintainer:
Linus Torvalds
Since the /proc/net/packet fallback went away, "ss -0" on a kernel
built without CONFIG_PACKET_DIAG prints a header and nothing else,
with no indication that anything went wrong.
AF_PACKET sockets are present on essentially every system, so an
empty listing reads as "no sockets" rather than "ss could not ask".
That is unlike tipc or vsock, where an empty result is unremarkable.
rtnl_dump_error() deliberately returns ENOENT and EOPNOTSUPP silently
for NETLINK_SOCK_DIAG, precisely because callers used to fall back to
/proc. With no fallback left, report those two at the call site.
Every other netlink error already gets perror("RTNETLINK answers"),
and rtnl_open_byproto() reports its own failures, so this does not
double up.
Only the diagnostic on stderr is new; the exit status is unchanged.
netlink_show() is left alone: CONFIG_NETLINK_DIAG is genuinely
optional and "ss -A netlink" is rarely the only thing a user asked
for.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
misc/ss.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/misc/ss.c b/misc/ss.c
index 0b7ba256..7ec72c04 100644
--- a/misc/ss.c
+++ b/misc/ss.c@@ -4913,7 +4913,17 @@ static int packet_show(struct filter *f) if (!filter_af_get(f, AF_PACKET) || !(f->states & (1 << SS_CLOSE))) return 0; - return packet_show_netlink(f); + if (packet_show_netlink(f)) { + /* + * rtnl_dump_error() swallows these two silently for + * NETLINK_SOCK_DIAG; anything else already perror'd. + */ + if (errno == ENOENT || errno == EOPNOTSUPP) + fprintf(stderr, "ss: no packet socket information available, kernel may lack CONFIG_PACKET_DIAG\n"); + return -1; + } + + return 0; } static int xdp_stats_print(struct sockstat *s, const struct filter *f)
--
2.53.0