From: Phil Sutter Date: Mon, 28 Aug 2017 17:31:22 +0000 (+0200) Subject: ss: Fix for added diag support check X-Git-Tag: v4.13.0~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c6bbc30f4e7fedc74381627f7ec86d26050b404;p=thirdparty%2Fiproute2.git ss: Fix for added diag support check Commit 9f66764e308e9 ("libnetlink: Add test for error code returned from netlink reply") changed rtnl_dump_filter_l() to return an error in case NLMSG_DONE would contain one, even if it was ENOENT. This in turn breaks ss when it tries to dump DCCP sockets on a system without support for it: The function tcp_show(), which is shared between TCP and DCCP, will start parsing /proc since inet_show_netlink() returns an error - yet it parses /proc/net/tcp which doesn't make sense for DCCP sockets at all. On my system, a call to 'ss' without further arguments prints the list of connected TCP sockets twice. Fix this by introducing a dedicated function dccp_show() which does not have a fallback to /proc, just like sctp_show(). And since tcp_show() is no longer "multi-purpose", drop it's socktype parameter. Fixes: 9f66764e308e9 ("libnetlink: Add test for error code returned from netlink reply") Signed-off-by: Phil Sutter --- diff --git a/misc/ss.c b/misc/ss.c index fcc3cf928..2c9e80e69 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -2753,7 +2753,7 @@ static int tcp_show_netlink_file(struct filter *f) return err; } -static int tcp_show(struct filter *f, int socktype) +static int tcp_show(struct filter *f) { FILE *fp = NULL; char *buf = NULL; @@ -2768,7 +2768,7 @@ static int tcp_show(struct filter *f, int socktype) return tcp_show_netlink_file(f); if (!getenv("PROC_NET_TCP") && !getenv("PROC_ROOT") - && inet_show_netlink(f, NULL, socktype) == 0) + && inet_show_netlink(f, NULL, IPPROTO_TCP) == 0) return 0; /* Sigh... We have to parse /proc/net/tcp... */ @@ -2836,6 +2836,18 @@ outerr: } while (0); } +static int dccp_show(struct filter *f) +{ + if (!filter_af_get(f, AF_INET) && !filter_af_get(f, AF_INET6)) + return 0; + + if (!getenv("PROC_NET_DCCP") && !getenv("PROC_ROOT") + && inet_show_netlink(f, NULL, IPPROTO_DCCP) == 0) + return 0; + + return 0; +} + static int sctp_show(struct filter *f) { if (!filter_af_get(f, AF_INET) && !filter_af_get(f, AF_INET6)) @@ -4390,9 +4402,9 @@ int main(int argc, char *argv[]) if (current_filter.dbs & (1<