aboutsummaryrefslogtreecommitdiff
path: root/sbin/route/route.c
diff options
context:
space:
mode:
authorHiroki Sato <hrs@FreeBSD.org>2013-10-17 19:04:05 +0000
committerHiroki Sato <hrs@FreeBSD.org>2013-10-17 19:04:05 +0000
commitde109e29eff8e045cafbc6fcd3a3ff675c095b96 (patch)
tree7b830d70992f55594c7c473b7ec71218b7470f16 /sbin/route/route.c
parentfb93f5c47f1983aeabf4e9ec25df47d64ddda266 (diff)
downloadsrc-de109e29eff8e045cafbc6fcd3a3ff675c095b96.tar.gz
src-de109e29eff8e045cafbc6fcd3a3ff675c095b96.zip
- Add relative specification in expiration time.
- Add proto3 option for RTF_PROTO3. - Use %lu for members of struct rt_metrics.
Notes
Notes: svn path=/head/; revision=256695
Diffstat (limited to 'sbin/route/route.c')
-rw-r--r--sbin/route/route.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/sbin/route/route.c b/sbin/route/route.c
index 6c2bbe2084b2..a4a7469828b6 100644
--- a/sbin/route/route.c
+++ b/sbin/route/route.c
@@ -67,6 +67,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
+#include <time.h>
#include <unistd.h>
#include <ifaddrs.h>
@@ -723,6 +724,7 @@ static void
set_metric(char *value, int key)
{
int flag = 0;
+ char *endptr;
u_long noval, *valp = &noval;
switch (key) {
@@ -742,7 +744,18 @@ set_metric(char *value, int key)
rt_metrics.rmx_locks |= flag;
if (locking)
locking = 0;
- *valp = atoi(value);
+ errno = 0;
+ *valp = strtol(value, &endptr, 0);
+ if (errno == 0 && *endptr != '\0')
+ errno = EINVAL;
+ if (errno)
+ err(EX_USAGE, "%s", value);
+ if (flag & RTV_EXPIRE && (value[0] == '+' || value[0] == '-')) {
+ struct timespec ts;
+
+ clock_gettime(CLOCK_REALTIME_FAST, &ts);
+ *valp += ts.tv_sec;
+ }
}
#define F_ISHOST 0x01
@@ -827,6 +840,9 @@ newroute(int argc, char **argv)
case K_PROTO2:
flags |= RTF_PROTO2;
break;
+ case K_PROTO3:
+ flags |= RTF_PROTO3;
+ break;
case K_PROXY:
nrflags |= F_PROXY;
break;
@@ -1681,6 +1697,7 @@ static void
print_getmsg(struct rt_msghdr *rtm, int msglen, int fib)
{
struct sockaddr *sp[RTAX_MAX];
+ struct timespec ts;
char *cp;
int i;
@@ -1733,15 +1750,17 @@ print_getmsg(struct rt_msghdr *rtm, int msglen, int fib)
#define msec(u) (((u) + 500) / 1000) /* usec to msec */
printf("\n%9s %9s %9s %9s %9s %10s %9s\n", "recvpipe",
"sendpipe", "ssthresh", "rtt,msec", "mtu ", "weight", "expire");
- printf("%8ld%c ", rtm->rtm_rmx.rmx_recvpipe, lock(RPIPE));
- printf("%8ld%c ", rtm->rtm_rmx.rmx_sendpipe, lock(SPIPE));
- printf("%8ld%c ", rtm->rtm_rmx.rmx_ssthresh, lock(SSTHRESH));
- printf("%8ld%c ", msec(rtm->rtm_rmx.rmx_rtt), lock(RTT));
- printf("%8ld%c ", rtm->rtm_rmx.rmx_mtu, lock(MTU));
- printf("%8ld%c ", rtm->rtm_rmx.rmx_weight, lock(WEIGHT));
- if (rtm->rtm_rmx.rmx_expire)
- rtm->rtm_rmx.rmx_expire -= time(0);
- printf("%8ld%c\n", rtm->rtm_rmx.rmx_expire, lock(EXPIRE));
+ printf("%8lu%c ", rtm->rtm_rmx.rmx_recvpipe, lock(RPIPE));
+ printf("%8lu%c ", rtm->rtm_rmx.rmx_sendpipe, lock(SPIPE));
+ printf("%8lu%c ", rtm->rtm_rmx.rmx_ssthresh, lock(SSTHRESH));
+ printf("%8lu%c ", msec(rtm->rtm_rmx.rmx_rtt), lock(RTT));
+ printf("%8lu%c ", rtm->rtm_rmx.rmx_mtu, lock(MTU));
+ printf("%8lu%c ", rtm->rtm_rmx.rmx_weight, lock(WEIGHT));
+ if (rtm->rtm_rmx.rmx_expire > 0)
+ clock_gettime(CLOCK_REALTIME_FAST, &ts);
+ else
+ ts.tv_sec = 0;
+ printf("%8ld%c\n", rtm->rtm_rmx.rmx_expire - ts.tv_sec, lock(EXPIRE));
#undef lock
#undef msec
#define RTA_IGN (RTA_DST|RTA_GATEWAY|RTA_NETMASK|RTA_IFP|RTA_IFA|RTA_BRD)