summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/bgpctl/bgpctl.c29
-rw-r--r--usr.sbin/bgpctl/bgpctl.h1
-rw-r--r--usr.sbin/bgpctl/output.c13
3 files changed, 26 insertions, 17 deletions
diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c
index a4e12576d1c..37b34a92b55 100644
--- a/usr.sbin/bgpctl/bgpctl.c
+++ b/usr.sbin/bgpctl/bgpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpctl.c,v 1.255 2019/12/31 14:09:27 claudio Exp $ */
+/* $OpenBSD: bgpctl.c,v 1.256 2020/01/09 11:57:04 claudio Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -595,8 +595,8 @@ print_neighbor_msgstats(struct peer *p)
#define TF_BUFS 8
#define TF_LEN 9
-static const char *
-fmt_timeframe_core(time_t t)
+const char *
+fmt_timeframe(time_t t)
{
char *buf;
static char tfbuf[TF_BUFS][TF_LEN]; /* ring buffer */
@@ -630,17 +630,18 @@ fmt_timeframe_core(time_t t)
}
const char *
-fmt_timeframe(time_t t)
+fmt_monotime(time_t t)
{
- time_t now;
+ struct timespec ts;
if (t == 0)
return ("Never");
- now = time(NULL);
- if (t > now) /* time in the future is not possible */
- t = now;
- return (fmt_timeframe_core(now - t));
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
+ err(1, "clock_gettime");
+ if (t > ts.tv_sec) /* time in the future is not possible */
+ t = ts.tv_sec;
+ return (fmt_timeframe(ts.tv_sec - t));
}
void
@@ -1414,17 +1415,20 @@ show_mrt_dump(struct mrt_rib *mr, struct mrt_peer *mp, void *arg)
struct parse_result res;
struct ctl_show_rib_request *req = arg;
struct mrt_rib_entry *mre;
+ time_t now;
u_int16_t i, j;
memset(&res, 0, sizeof(res));
res.flags = req->flags;
+ now = time(NULL);
for (i = 0; i < mr->nentries; i++) {
mre = &mr->entries[i];
bzero(&ctl, sizeof(ctl));
ctl.prefix = mr->prefix;
ctl.prefixlen = mr->prefixlen;
- ctl.lastchange = mre->originated;
+ if (mre->originated <= now)
+ ctl.age = now - mre->originated;
ctl.true_nexthop = mre->nexthop;
ctl.exit_nexthop = mre->nexthop;
ctl.origin = mre->origin;
@@ -1490,14 +1494,17 @@ network_mrt_dump(struct mrt_rib *mr, struct mrt_peer *mp, void *arg)
struct ctl_show_rib_request *req = arg;
struct mrt_rib_entry *mre;
struct ibuf *msg;
+ time_t now;
u_int16_t i, j;
+ now = time(NULL);
for (i = 0; i < mr->nentries; i++) {
mre = &mr->entries[i];
bzero(&ctl, sizeof(ctl));
ctl.prefix = mr->prefix;
ctl.prefixlen = mr->prefixlen;
- ctl.lastchange = mre->originated;
+ if (mre->originated <= now)
+ ctl.age = now - mre->originated;
ctl.true_nexthop = mre->nexthop;
ctl.exit_nexthop = mre->nexthop;
ctl.origin = mre->origin;
diff --git a/usr.sbin/bgpctl/bgpctl.h b/usr.sbin/bgpctl/bgpctl.h
index 7f25ffd892e..d6090eb27d2 100644
--- a/usr.sbin/bgpctl/bgpctl.h
+++ b/usr.sbin/bgpctl/bgpctl.h
@@ -44,6 +44,7 @@ const char *print_auth_method(enum auth_method);
const char *fmt_mem(long long);
const char *fmt_timeframe(time_t);
+const char *fmt_monotime(time_t);
char *fmt_peer(const char *, const struct bgpd_addr *, int);
const char *get_errstr(u_int8_t, u_int8_t);
diff --git a/usr.sbin/bgpctl/output.c b/usr.sbin/bgpctl/output.c
index f18cb407775..e6ecafee456 100644
--- a/usr.sbin/bgpctl/output.c
+++ b/usr.sbin/bgpctl/output.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: output.c,v 1.2 2019/12/31 14:09:27 claudio Exp $ */
+/* $OpenBSD: output.c,v 1.3 2020/01/09 11:57:04 claudio Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -111,7 +111,7 @@ show_summary(struct peer *p)
p->stats.msg_sent_update + p->stats.msg_sent_keepalive +
p->stats.msg_sent_rrefresh,
p->wbuf.queued,
- fmt_timeframe(p->stats.last_updown));
+ fmt_monotime(p->stats.last_updown));
if (p->state == STATE_ESTABLISHED) {
printf("%6u", p->stats.prefix_cnt);
if (p->conf.max_prefix != 0)
@@ -182,11 +182,12 @@ show_neighbor_full(struct peer *p, struct parse_result *res)
if (p->stats.last_updown != 0)
printf(", %s for %s",
p->state == STATE_ESTABLISHED ? "up" : "down",
- fmt_timeframe(p->stats.last_updown));
+ fmt_monotime(p->stats.last_updown));
printf("\n");
printf(" Last read %s, holdtime %us, keepalive interval %us\n",
- fmt_timeframe(p->stats.last_read),
+ fmt_monotime(p->stats.last_read),
p->holdtime, p->holdtime/3);
+ printf(" Last write %s\n", fmt_monotime(p->stats.last_write));
for (i = 0; i < AID_MAX; i++)
if (p->capa.peer.mp[i])
hascapamp = 1;
@@ -288,7 +289,7 @@ show_timer(struct ctl_timer *t)
if (t->val <= 0)
printf("%-20s\n", "due");
else
- printf("due in %-13s\n", fmt_timeframe(time(NULL) - t->val));
+ printf("due in %-13s\n", fmt_timeframe(t->val));
}
void
@@ -432,7 +433,7 @@ show_rib_detail(struct ctl_show_rib *r, u_char *asdata, size_t aslen,
print_flags(r->flags, 0);
printf("%c Last update: %s ago%c", EOL0(flag0),
- fmt_timeframe(r->lastchange), EOL0(flag0));
+ fmt_timeframe(r->age), EOL0(flag0));
}
void