File ip-support-of-usec-rtt-in-tcp_metrics.patch of Package iproute2

From: Eric Dumazet <edumazet@google.com>
Date: Fri, 5 Sep 2014 16:54:04 -0700
Subject: ip: support of usec rtt in tcp_metrics
Patch-mainline: v3.17.0
Git-commit: 9464a5f26cce2a7f7c54415dc3bb1238fdb71223
References: bsc#937086

Starting from linux-3.15, kernel supports new tcp metric attributes :
TCP_METRIC_RTT_US & TCP_METRIC_RTTVAR_US

Update ip command to detect their use.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Michal Kubecek <mkubecek@suse.cz>

---
 ip/tcp_metrics.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/ip/tcp_metrics.c b/ip/tcp_metrics.c
index c6be3c94415f..355bda4007f9 100644
--- a/ip/tcp_metrics.c
+++ b/ip/tcp_metrics.c
@@ -185,6 +185,7 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
 	a = attrs[TCP_METRICS_ATTR_VALS];
 	if (a) {
 		struct rtattr *m[TCP_METRIC_MAX + 1 + 1];
+		unsigned long rtt = 0, rttvar = 0;
 
 		parse_rtattr_nested(m, TCP_METRIC_MAX + 1, a);
 
@@ -194,18 +195,30 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
 			a = m[i + 1];
 			if (!a)
 				continue;
-			if (metric_name[i])
-				fprintf(fp, " %s ", metric_name[i]);
-			else
-				fprintf(fp, " metric_%d ", i);
-
+			if (i != TCP_METRIC_RTT &&
+			    i != TCP_METRIC_RTT_US &&
+			    i != TCP_METRIC_RTTVAR &&
+			    i != TCP_METRIC_RTTVAR_US) {
+				if (metric_name[i])
+					fprintf(fp, " %s ", metric_name[i]);
+				else
+					fprintf(fp, " metric_%d ", i);
+			}
 			val = rta_getattr_u32(a);
 			switch (i) {
 			case TCP_METRIC_RTT:
-				fprintf(fp, "%luus", (val * 1000UL) >> 3);
+				if (!rtt)
+					rtt = (val * 1000UL) >> 3;
 				break;
 			case TCP_METRIC_RTTVAR:
-				fprintf(fp, "%luus", (val * 1000UL) >> 2);
+				if (!rttvar)
+					rttvar = (val * 1000UL) >> 2;
+				break;
+			case TCP_METRIC_RTT_US:
+				rtt = val >> 3;
+				break;
+			case TCP_METRIC_RTTVAR_US:
+				rttvar = val >> 2;
 				break;
 			case TCP_METRIC_SSTHRESH:
 			case TCP_METRIC_CWND:
@@ -215,6 +228,10 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
 				break;
 			}
 		}
+		if (rtt)
+			fprintf(fp, " rtt %luus", rtt);
+		if (rttvar)
+			fprintf(fp, " rttvar %luus", rttvar);
 	}
 
 	a = attrs[TCP_METRICS_ATTR_FOPEN_MSS];
-- 
2.4.7

openSUSE Build Service is sponsored by