Skip to contentSkip to conversation

ss: Include -E option for socket destroy events

PATCH Superseded Craig Gallek 2 participants 3 messages Jun 16, 2015

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ss: Include -E option for socket destroy events

Use the IPv4/IPv6/TCP/UDP multicast groups of NETLINK_SOCK_DIAG to filter and display socket statistics as they are destroyed.

Kernel support patch series: 24029a3603cfa633e8bc2b3fb3e48e76c497831d

---
 include/linux/inet_diag.h |  3 +-
 include/linux/sock_diag.h | 10 +++++++
 misc/ss.c                 | 72 ++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 83 insertions(+), 2 deletions(-)
include/linux/inet_diag.h +2 -1
index 0fb76bb..e83340b 100644
@@ -111,9 +111,10 @@ enum {
 	INET_DIAG_SKMEMINFO,
 	INET_DIAG_SHUTDOWN,
 	INET_DIAG_DCTCPINFO,
+	INET_DIAG_PROTOCOL,  /* response attribute only */
 };
 
-#define INET_DIAG_MAX INET_DIAG_DCTCPINFO
+#define INET_DIAG_MAX INET_DIAG_PROTOCOL
 
 /* INET_DIAG_MEM */
 
include/linux/sock_diag.h +10 -0
index 78996e2..024e1f4 100644
@@ -23,4 +23,14 @@ enum {
 	SK_MEMINFO_VARS,
 };
 
+enum sknetlink_groups {
+	SKNLGRP_NONE,
+	SKNLGRP_INET_TCP_DESTROY,
+	SKNLGRP_INET_UDP_DESTROY,
+	SKNLGRP_INET6_TCP_DESTROY,
+	SKNLGRP_INET6_UDP_DESTROY,
+	__SKNLGRP_MAX,
+};
+#define SKNLGRP_MAX	(__SKNLGRP_MAX - 1)
+
 #endif /* __SOCK_DIAG_H__ */
misc/ss.c +71 -1

120 lines not on this page · raw message

Signature · 1 line
2.2.0.rc0.207.ga3a616c
#1 lore raw
Quoted 11 lines · Craig Gallek

Use the IPv4/IPv6/TCP/UDP multicast groups of NETLINK_SOCK_DIAG to filter and display socket statistics as they are destroyed.

Kernel support patch series: 24029a3603cfa633e8bc2b3fb3e48e76c497831d

---
 include/linux/inet_diag.h |  3 +-
 include/linux/sock_diag.h | 10 +++++++
 misc/ss.c                 | 72 ++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 83 insertions(+), 2 deletions(-)

I am not sure filter works, and apparently some fields are not properly reported ? (source port for example looks wrong)

(Note : you probably need to filter in user space, but ss should already have support for this)

lpaa23:~# ./ss -Eit dst 10.246.7.152
State       Recv-Q Send-Q Local Address:Port                 Peer Address:Port                
UNCONN      0      1         ::ffff:10.246.7.151:*                      ::ffff:10.126.178.16:14354                
	 wscale:7,7 rto:221 rtt:20.165/5.91 ato:40 mss:1448 cwnd:10 send 5.7Mbps lastsnd:21 lastrcv:15023 lastack:1 pacing_rate 11.5Mbps unacked:1 rcv_rtt:20 rcv_space:28960
UNCONN      0      1       127.0.0.1:*                     127.0.0.1:9551                 
	 rto:1000 mss:524 cwnd:10 lastsnd:67817 lastrcv:67817 lastack:67817 unacked:1
UNCONN      0      1       127.0.0.1:*                     127.0.0.1:9551                 
	 rto:1000 mss:524 cwnd:10 lastsnd:67818 lastrcv:67818 lastack:67818 unacked:1
UNCONN      0      1       127.0.0.1:*                     127.0.0.1:9551                 
	 rto:1000 mss:524 cwnd:10 lastsnd:68742 lastrcv:68742 lastack:68742 unacked:1
UNCONN      0      0      10.246.7.151:*                    10.246.7.152:50227                
	 wscale:7,7 rto:201 rtt:0.203/0.209 mss:1448 cwnd:254 ssthresh:251 send 14494.3Mbps lastsnd:1 lastrcv:71533 pacing_rate 28970.7Mbps retrans:0/5 rcv_space:29200
UNCONN      0      0      10.246.7.151:*                    10.246.7.152:12865                
	 wscale:7,7 rto:201 rtt:0.363/0.375 ato:40 mss:1448 cwnd:10 ssthresh:293 send 319.1Mbps lastsnd:1004 lastrcv:1 lastack:1 pacing_rate 636.7Mbps rcv_rtt:126.125 rcv_space:29200
UNCONN      0      1       127.0.0.1:*                     127.0.0.1:9551                 
	 rto:1000 mss:524 cwnd:10 lastsnd:73036 lastrcv:73036 lastack:73036 unacked:1
^C
#2 lore raw
Quoted 5 lines

I am not sure filter works, and apparently some fields are not properly reported ? (source port for example looks wrong)

(Note : you probably need to filter in user space, but ss should already have support for this)

Ah, good catch on the filter. It can be fixed by
- if ((err = inet_show_sock(h, NULL, diag_arg->protocol)) < 0)
+ if ((err = inet_show_sock(h, diag_arg->f, diag_arg->protocol)) < 0) in show_one_inet_sock. I believe this worked previously because the filter determined the parameters of the netlink request, effectively causing the filtering to happen in the kernel. However, if the ssfilter defined a parameter that could not be used select sockets via the netlink request (either because it is a concept not available in the request structure or because the multicast groups have no request concept), this user space filtering parameter would be necessary. Perhaps this was an optimization to not do userspace filtering when we know we won't need it? In that case, my updated version of this patch should probably set the filter parameter of inet_diag_arg to NULL in the case of a get request and to the actual userspace filter in the case of monitoring the broadcast data.

The source port issue is a harder problem (related to the kernel patches, not this one). The point at which socket information is broadcast happens after the unhash callback of the appropriate protocol (called in sk_common_release). This process sets the source port of the socket to zero (via __inet_put_port for tcp and udp_lib_unhash for udp). If we want the source port to be returned, I believe the only options are broadcasting earlier in the destruction path (potentially missing any activity that may happen after that point) or to store the source port in an additional location for later use...