[RFC 3/3] ss: restore packet_raw/packet_dgram filtering
From: Stephen Hemminger <stephen@networkplumber.org>
Date: 2026-09-15 21:36:57
Subsystem:
the rest · Maintainer:
Linus Torvalds
The SOCK_RAW/SOCK_DGRAM type check only ever existed in the
/proc/net/packet parser, packet_show_line(), which commit a2b31976
("ss: drop the /proc parsers for packet and netlink sockets")
removed. The sock_diag path never had it.
packet_show_sock() populates stat.type from pdiag_type but nothing
tested it, and the dispatcher gates on PACKET_DBM, which is the OR of
both bits. So selecting either type ran an unfiltered dump and
displayed every AF_PACKET socket. Since packet_show() already
preferred the netlink path, "ss -A packet_raw" has been returning
dgram sockets on any kernel with packet_diag for a long time; the
/proc removal just made it unconditional.
Add packet_type_skip(), mirroring the existing unix_type_skip() and
vsock_type_skip(), and call it from packet_show_sock() once the type
is known. As before, a socket that is neither SOCK_RAW nor
SOCK_DGRAM falls through both tests and is still displayed.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
misc/ss.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/misc/ss.c b/misc/ss.c
index 7ec72c04..37ed73c4 100644
--- a/misc/ss.c
+++ b/misc/ss.c@@ -4713,6 +4713,15 @@ static int unix_show(struct filter *f) return 0; } +static bool packet_type_skip(struct sockstat *s, const struct filter *f) +{ + if (s->type == SOCK_RAW && !(f->dbs & (1 << PACKET_R_DB))) + return true; + if (s->type == SOCK_DGRAM && !(f->dbs & (1 << PACKET_DG_DB))) + return true; + return false; +} + static int packet_stats_print(struct sockstat *s, const struct filter *f) { const char *addr, *port;
@@ -4779,6 +4788,9 @@ static int packet_show_sock(struct nlmsghdr *nlh, void *arg) stat.state = SS_CLOSE; stat.sk = cookie_sk_get(&r->pdiag_cookie[0]); + if (packet_type_skip(&stat, f)) + return 0; + if (tb[PACKET_DIAG_MEMINFO]) { __u32 *skmeminfo = RTA_DATA(tb[PACKET_DIAG_MEMINFO]);
--
2.53.0