Skip to contentSkip to conversation

ss: remove /proc fallback paths

RFC In review Stephen Hemminger 2 participants 3 messages Sep 1 – Oct 19

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 ss: remove /proc fallback paths

This patch removes the old /proc/net fallback code in ss command. The sock_diag netlink interfaces were all in 3.10, over 13 years ago. No longer need to carry all the additional text parsing code. Having less code also reduces the potential for AI scavenging of bugs.

---
 man/man8/ss.8 |   2 +-
 misc/ss.c     | 568 ++------------------------------------------------
 2 files changed, 18 insertions(+), 552 deletions(-)
man/man8/ss.8 +1 -1
index 3871612d..0e934c40 100644
@@ -317,7 +317,7 @@ closing. It supports IPv4 and IPv6 sockets only.
 .B \-s, \-\-summary
 Print summary statistics. This option does not parse socket lists obtaining
 summary from various sources. It is useful when amount of sockets is so huge
-that parsing /proc/net/tcp is painful.
+that dumping the full socket list is painful.
 .TP
 .B \-E, \-\-events
 Continually display sockets as they are destroyed
misc/ss.c +17 -551

685 lines not on this page · raw message

Signature · 1 line
2.53.0
#1 lore raw
Quoted 3 lines · Stephen Hemminger

This patch removes the old /proc/net fallback code in ss command. The sock_diag netlink interfaces were all in 3.10, over 13 years ago. No longer need to carry all the additional text parsing code.

I tested this on top of iproute2-next (204a7210). It builds with no new warnings, testsuite/tests/ss/ssfilter.t passes, and on a WSL2 6.18 kernel the output of ss -tan, -uan, -xan, -s and -tanpie is identical with and without the patch (ss -a -A netlink too, apart from the line for ss's own netlink socket).

One concern: the diag interfaces are in the kernel, but each one is a separate Kconfig option. INET_DIAG defaults to y, while UNIX_DIAG, PACKET_DIAG, NETLINK_DIAG, INET_UDP_DIAG and INET_RAW_DIAG are all "default n", and common configs leave some of them off:
x86_64_defconfig has "# CONFIG_INET_DIAG is not set", arm64 defconfig sets none of the five, and Android's gki_defconfig enables only INET_UDP_DIAG among them.

When the interface for a socket type is missing, ss currently falls back to /proc/net/*. With this patch it prints only the header and exits 0, so those sockets silently disappear. I reproduced this for raw, unix and packet sockets (ss_before/ss_after are ss built without/with this patch). Raw sockets, on a kernel without INET_RAW_DIAG (the stock WSL2 kernel), with one ICMP and one ICMPv6 raw socket open:

  # uname -r
  6.18.54.1-microsoft-standard-WSL2
  # zcat /proc/config.gz | grep INET_RAW_DIAG
  # CONFIG_INET_RAW_DIAG is not set
  # ss_before -wa
  State  Recv-Q Send-Q Local Address:Port      Peer Address:Port
  UNCONN 0      0            0.0.0.0:icmp           0.0.0.0:*
  UNCONN 0      0                  *:ipv6-icmp            *:*
  # ss_after -wa
  State Recv-Q Send-Q Local Address:Port Peer Address:Port
  # echo $?
  0

Unix and packet sockets, on a kernel where unix_diag and packet_diag are modules that cannot be loaded (a WSL 6.6 kernel booted without its modules), with one packet socket open:

  # zcat /proc/config.gz | grep -E 'CONFIG_(UNIX_DIAG|PACKET_DIAG)='
  CONFIG_PACKET_DIAG=m
  CONFIG_UNIX_DIAG=m
  # modprobe unix_diag
  modprobe: FATAL: Module unix_diag not found in directory /lib/modules/6.6.114.1-microsoft-standard-WSL2-destroy+
  # tail -n +2 /proc/net/unix | wc -l
  171
  # ss_before -xa | tail -n +2 | wc -l
  171
  # ss_after -xa | tail -n +2 | wc -l
  0
  # ss_before -0a
  Netid State  Recv-Q Send-Q Local Address:Port Peer Address:Port
  p_raw UNCONN 896    0                  *:*                *
  # ss_after -0a
  Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port

Distribution kernels such as Ubuntu's 6.8.0-147-generic and Arch's linux package build all of them as modules, so they are not affected. I did not boot an x86_64_defconfig kernel; I would expect ss -t to show nothing there for the same reason, since INET_DIAG is off.

I may be missing context on how much these configurations matter for ss, so please take this only as a data point. If it is useful, I would be glad to help test any further changes in this area.

Thanks,
Gopal Malaviya

#2 lore raw
Quoted 19 lines · On Sun, 18 Oct 2026 20:07:12 +0000 Gopal Malaviya <[email protected]>…
Quoted 3 lines · Stephen Hemminger

This patch removes the old /proc/net fallback code in ss command. The sock_diag netlink interfaces were all in 3.10, over 13 years ago. No longer need to carry all the additional text parsing code.

I tested this on top of iproute2-next (204a7210). It builds with no new warnings, testsuite/tests/ss/ssfilter.t passes, and on a WSL2 6.18 kernel the output of ss -tan, -uan, -xan, -s and -tanpie is identical with and without the patch (ss -a -A netlink too, apart from the line for ss's own netlink socket).

One concern: the diag interfaces are in the kernel, but each one is a separate Kconfig option. INET_DIAG defaults to y, while UNIX_DIAG, PACKET_DIAG, NETLINK_DIAG, INET_UDP_DIAG and INET_RAW_DIAG are all "default n", and common configs leave some of them off:
x86_64_defconfig has "# CONFIG_INET_DIAG is not set", arm64 defconfig sets none of the five, and Android's gki_defconfig enables only INET_UDP_DIAG among them.

Quoted 7 lines

When the interface for a socket type is missing, ss currently falls back to /proc/net/*. With this patch it prints only the header and exits 0, so those sockets silently disappear. I reproduced this for raw, unix and packet sockets (ss_before/ss_after are ss built without/with this patch). Raw sockets, on a kernel without INET_RAW_DIAG (the stock WSL2 kernel), with one ICMP and one ICMPv6 raw socket open:

I am ok with forcing use of inet_diag for this.
If users turn it off, like Android, they are in embedded envrionments where ss doesn't make lot of sense.