All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Emelyanov <xemul@parallels.com>
To: Stephen Hemminger <shemminger@linux-foundation.org>,
	Linux Netdev List <netdev@vger.kernel.org>
Cc: "François-Xavier Le Bail" <fx.lebail@yahoo.com>
Subject: [PATCH] iproute: Fix Netid value for multi-families output
Date: Tue, 28 Jan 2014 10:24:15 +0400	[thread overview]
Message-ID: <52E74D0F.4050806@parallels.com> (raw)

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 <fx.lebail@yahoo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>

---

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;
 	}

             reply	other threads:[~2014-01-28  6:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-28  6:24 Pavel Emelyanov [this message]
2014-01-29 19:29 ` [PATCH] iproute: Fix Netid value for multi-families output François-Xavier Le Bail
2014-02-10 22:48 ` Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52E74D0F.4050806@parallels.com \
    --to=xemul@parallels.com \
    --cc=fx.lebail@yahoo.com \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.