iproute: fix unit conversion of rtt/rttvar/rto_min
Since July 2008 (2.6.27, c1e20f7c8b9), the kernel stores the values for
RTAX_{RTT{,VAR},RTO_MIN} in milliseconds. When using a kernel > 2.6.27 with
the current iproute2, conversion of these values is broken in either way.
This patch
* updates the code to pass and retrieve milliseconds;
* since values < 1msec would be rounded up, also drops the usec/nsec variants;
* since there is no way to query kernel HZ, also drops the jiffies variant.
Arguments such as
rtt 3.23sec
rto_min 0xff
rto_min 0.200s
rttvar 25ms
now all work as expected when reading back previously set values.
diff --git a/ip/iproute.c b/ip/iproute.c
index f3e7eb4..d48e743 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -85,7 +85,7 @@
fprintf(stderr, "MP_ALGO := { rr | drr | random | wrandom }\n");
fprintf(stderr, "NHFLAGS := [ onlink | pervasive ]\n");
fprintf(stderr, "RTPROTO := [ kernel | boot | static | NUMBER ]\n");
- fprintf(stderr, "TIME := NUMBER[s|ms|us|ns|j]\n");
+ fprintf(stderr, "TIME := NUMBER[s|ms]\n");
exit(-1);
}
@@ -526,8 +526,6 @@
if (mxrta[i] == NULL)
continue;
- if (!hz)
- hz = get_user_hz();
if (i < sizeof(mx_names)/sizeof(char*) && mx_names[i])
fprintf(fp, " %s", mx_names[i]);
@@ -549,18 +547,15 @@
case RTAX_RTT:
case RTAX_RTTVAR:
case RTAX_RTO_MIN:
- val *= 1000;
if (i == RTAX_RTT)
val /= 8;
else if (i == RTAX_RTTVAR)
val /= 4;
- if (val >= hz)
- fprintf(fp, " %llums",
- (unsigned long long) val / hz);
+ if (val >= 1000)
+ fprintf(fp, " %gs", val/1e3);
else
- fprintf(fp, " %.2fms",
- (double)val / hz);
+ fprintf(fp, " %ums", val);
}
}
}