All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [RFC 3/3] ss: restore packet_raw/packet_dgram filtering
Date: Tue, 15 Sep 2026 14:36:04 -0700	[thread overview]
Message-ID: <20260915213646.116214-4-stephen@networkplumber.org> (raw)
In-Reply-To: <20260915213646.116214-1-stephen@networkplumber.org>

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


      parent reply	other threads:[~2026-09-15 21:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02  3:56 [PATCH iproute2 v2] ss: drop the /proc parsers for packet and netlink sockets Prabhakar Pujeri
2026-09-15 21:34 ` Stephen Hemminger
2026-09-15 21:36 ` [RFC PATCH iproute2 0/3] ss: follow-ups to the packet/netlink /proc removal Stephen Hemminger
2026-09-15 21:36   ` [RFC 1/3] ss: drop the dead /proc fallback trigger in packet_show_sock() Stephen Hemminger
2026-09-15 21:36   ` [RFC 2/3] ss: warn when packet socket diag is unavailable Stephen Hemminger
2026-09-15 21:36   ` Stephen Hemminger [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260915213646.116214-4-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.