Skip to contentSkip to conversation

ss: Use rtnl_dump_filter for inet_show_netlink

PATCH New Vadim Kochan 1 participant 1 message Dec 26, 2014

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

PATCH 1/1 ss: Use rtnl_dump_filter for inet_show_netlink

From: Vadim Kochan <[email protected]>

Just another refactoring for ss to use rtnl API from lib

---
It would be good to make better testing with opened different kind of sockets to test if ss behaves correctly and does not shows any errors.

 include/libnetlink.h |   1 +
 lib/libnetlink.c     |  17 +++++--
 misc/ss.c            | 139 ++++++++++++++-------------------------------------
 3 files changed, 50 insertions(+), 107 deletions(-)
include/libnetlink.h +1 -0
index 3794ef1..db04969 100644
@@ -19,6 +19,7 @@ struct rtnl_handle
 	__u32			seq;
 	__u32			dump;
 	int			proto;
+	FILE		       *dump_fp;
 };
 
 extern int rcvbuf;
lib/libnetlink.c +12 -5
index e3b7862..45ff90a 100644
@@ -220,12 +220,15 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth,
 			return -1;
 		}
 
+		if (rth->dump_fp)
+			fwrite(buf, 1, NLMSG_ALIGN(status), rth->dump_fp);
+
 		for (a = arg; a->filter; a++) {
 			struct nlmsghdr *h = (struct nlmsghdr*)buf;
 			msglen = status;
 
 			while (NLMSG_OK(h, msglen)) {
-				int err;
+				int err = 0;
 
 				if (nladdr.nl_pid != 0 ||
 				    h->nlmsg_pid != rth->local.nl_pid ||
@@ -247,16 +250,20 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth,
 					} else {
 						errno = -err->error;
 						if (rth->proto == NETLINK_SOCK_DIAG &&
-						    errno == ENOENT)
+						    (errno == ENOENT ||
+						     errno == EOPNOTSUPP))
 							return -1;
 
 						perror("RTNETLINK answers");
 					}
 					return -1;
 				}
-				err = a->filter(&nladdr, h, a->arg1);
-				if (err < 0)
-					return err;
+
+				if (!rth->dump_fp) {
+					err = a->filter(&nladdr, h, a->arg1);
+					if (err < 0)
+						return err;
+				}
 
 skip_it:
 				h = NLMSG_NEXT(h, msglen);
misc/ss.c +37 -102

159 lines not on this page · raw message

Signature · 1 line
2.1.3