Skip to contentSkip to conversation

ss: Filtering fixes for unix & netlink socks

PATCH Applied Vadim Kochan 2 participants 4 messages Feb 22, 2015 – Feb 25, 2015

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

cover ss: Filtering fixes for unix & netlink socks

Some fixes when filtering unix & netlink sockets.

Vadim Kochan (2):
ss: Add filter before printing unix stats from Netlink
ss: Skip filtered netlink sockets before detailed info

 misc/ss.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
Signature · 1 line
2.2.2
#1 lore raw

PATCH 1/2 ss: Add filter before printing unix stats from Netlink

From: Vadim Kochan <[email protected]>

Detailed info can be printed if filter should not pass the socket info.

---
 misc/ss.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
misc/ss.c +4 -1
index 2678033..5320d38 100644
@@ -2556,7 +2556,7 @@ static void unix_stats_print(struct sockstat *list, struct filter *f)
 			}
 		}
 
-		if (f->f) {
+		if (use_proc && f->f) {
 			if (strcmp(peer, "*") == 0)
 				memset(s->remote.data, 0, sizeof(char *));
 			else
@@ -2628,6 +2628,9 @@ static int unix_show_sock(const struct sockaddr_nl *addr, struct nlmsghdr *nlh,
 	if (tb[UNIX_DIAG_PEER])
 		stat.rport = rta_getattr_u32(tb[UNIX_DIAG_PEER]);
 
+	if (f->f && run_ssfilter(f->f, &stat) == 0)
+		return 0;
+
 	unix_stats_print(&stat, f);
 
 	if (show_mem) {
Signature · 1 line
2.2.2
#2 lore raw

PATCH 2/2 ss: Skip filtered netlink sockets before detailed info

In reply to Vadim Kochan

From: Vadim Kochan <[email protected]>

---
 misc/ss.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
misc/ss.c +7 -5
index 5320d38..5113d85 100644
@@ -2938,7 +2938,7 @@ static int packet_show(struct filter *f)
 	return 0;
 }
 
-static void netlink_show_one(struct filter *f,
+static int netlink_show_one(struct filter *f,
 				int prot, int pid, unsigned groups,
 				int state, int dst_pid, unsigned dst_group,
 				int rq, int wq,
@@ -2960,7 +2960,7 @@ static void netlink_show_one(struct filter *f,
 		st.lport = pid;
 		st.local.data[0] = prot;
 		if (run_ssfilter(f->f, &st) == 0)
-			return;
+			return 1;
 	}
 
 	sock_state_print(&st, "nl");
@@ -3032,7 +3032,7 @@ static void netlink_show_one(struct filter *f,
 	}
 	printf("\n");
 
-	return;
+	return 0;
 }
 
 static int netlink_show_sock(const struct sockaddr_nl *addr,
@@ -3058,9 +3058,11 @@ static int netlink_show_sock(const struct sockaddr_nl *addr,
 		wq = skmeminfo[SK_MEMINFO_WMEM_ALLOC];
 	}
 
-	netlink_show_one(f, r->ndiag_protocol, r->ndiag_portid, groups,
+	if (netlink_show_one(f, r->ndiag_protocol, r->ndiag_portid, groups,
 			 r->ndiag_state, r->ndiag_dst_portid, r->ndiag_dst_group,
-			 rq, wq, 0, 0);
+			 rq, wq, 0, 0)) {
+		return 0;
+	}
 
 	if (show_mem) {
 		printf("\t");
Signature · 1 line
2.2.2
#3 lore raw
In reply to Vadim Kochan
Quoted 9 lines · On Sun, 22 Feb 2015 22:23:09 +0200 Vadim Kochan <[email protected]> wrote:

Some fixes when filtering unix & netlink sockets.

Vadim Kochan (2):
ss: Add filter before printing unix stats from Netlink
ss: Skip filtered netlink sockets before detailed info

 misc/ss.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Applied