From patchwork Tue Jan 28 06:24:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pavel Emelyanov X-Patchwork-Id: 314593 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41A672C007C for ; Tue, 28 Jan 2014 17:24:23 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751151AbaA1GYS (ORCPT ); Tue, 28 Jan 2014 01:24:18 -0500 Received: from relay.parallels.com ([195.214.232.42]:39242 "EHLO relay.parallels.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750816AbaA1GYR (ORCPT ); Tue, 28 Jan 2014 01:24:17 -0500 Received: from [10.30.3.11] (helo=mail.sw.ru) by relay.parallels.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.80.1) (envelope-from ) id 1W825o-0005Z8-2Y; Tue, 28 Jan 2014 10:24:16 +0400 Received: from [10.24.20.194] (10.24.20.194) by mail.sw.ru (10.30.3.11) with Microsoft SMTP Server (TLS) id 14.3.174.1; Tue, 28 Jan 2014 10:24:15 +0400 Message-ID: <52E74D0F.4050806@parallels.com> Date: Tue, 28 Jan 2014 10:24:15 +0400 From: Pavel Emelyanov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120605 Thunderbird/13.0 MIME-Version: 1.0 To: Stephen Hemminger , Linux Netdev List CC: =?ISO-8859-1?Q?Fran=E7ois-Xavier_Le_Bail?= Subject: [PATCH] iproute: Fix Netid value for multi-families output X-Originating-IP: [10.24.20.194] Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When requesting simultaneous output of TCP and UDP sockets the netid field shows "tcp" always. [root@xemvm1 iproute2]# ./misc/ss -a -tu Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port tcp UNCONN 0 0 *:32713 *:* tcp UNCONN 0 0 *:bootpc *:* tcp UNCONN 0 0 :::57879 :::* tcp LISTEN 0 128 *:ssh *:* tcp ESTAB 0 48 1.2.3.5:ssh 1.2.3.4:45826 tcp ESTAB 0 0 1.2.3.5:ssh 1.2.3.4:45814 tcp LISTEN 0 128 :::ssh :::* While the 1st 3 sockets are UDP ones: [root@xemvm1 iproute2]# ./misc/ss -a -u State Recv-Q Send-Q Local Address:Port Peer Address:Port UNCONN 0 0 *:32713 *:* UNCONN 0 0 *:bootpc *:* UNCONN 0 0 :::57879 :::* Reported-by: François-Xavier Le Bail Signed-off-by: Pavel Emelyanov Tested-by: François-Xavier Le Bail --- -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/misc/ss.c b/misc/ss.c index 764ffe2..37dcc11 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -1462,7 +1462,21 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r, } } -static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f) +static char *proto_name(int protocol) +{ + switch (protocol) { + case IPPROTO_UDP: + return "udp"; + case IPPROTO_TCP: + return "tcp"; + case IPPROTO_DCCP: + return "dccp"; + } + + return "???"; +} + +static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int protocol) { struct rtattr * tb[INET_DIAG_MAX+1]; struct inet_diag_msg *r = NLMSG_DATA(nlh); @@ -1487,7 +1501,7 @@ static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f) return 0; if (netid_width) - printf("%-*s ", netid_width, "tcp"); + printf("%-*s ", netid_width, proto_name(protocol)); if (state_width) printf("%-*s ", state_width, sstate_name[s.state]); @@ -1760,7 +1774,7 @@ again: h = NLMSG_NEXT(h, status); continue; } - err = inet_show_sock(h, NULL); + err = inet_show_sock(h, NULL, protocol); if (err < 0) { close(fd); return err; @@ -1839,7 +1853,7 @@ static int tcp_show_netlink_file(struct filter *f) return -1; } - err = inet_show_sock(h, f); + err = inet_show_sock(h, f, IPPROTO_TCP); if (err < 0) return err; }