diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c index d1f24bfce90..237133de927 100644 --- a/usr.sbin/bgpctl/bgpctl.c +++ b/usr.sbin/bgpctl/bgpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpctl.c,v 1.321 2026/05/18 18:37:22 claudio Exp $ */ +/* $OpenBSD: bgpctl.c,v 1.322 2026/05/21 14:48:58 claudio Exp $ */ /* * Copyright (c) 2003 Henning Brauer @@ -66,6 +66,7 @@ struct mrt_parser net_mrt = { network_mrt_dump, NULL, NULL }; const struct output *output = &show_output; int tableid; int nodescr; +int abs_time; __dead void usage(void) @@ -134,6 +135,7 @@ main(int argc, char *argv[]) if (pledge("stdio", NULL) == -1) err(1, "pledge"); + abs_time = 1; memset(&ribreq, 0, sizeof(ribreq)); if (res->as.type != AS_UNDEF) ribreq.as = res->as; @@ -588,14 +590,10 @@ show(struct imsg *imsg, struct parse_result *res) } time_t -get_rel_monotime(monotime_t t) +get_rel_monotime(monotime_t mt) { - monotime_t now; - - if (!monotime_valid(t)) - return 0; - now = getmonotime(); - return monotime_to_sec(monotime_sub(now, t)); + mt = monotime_sub(getmonotime(), mt); + return monotime_to_sec(mt); } char * @@ -644,7 +642,7 @@ fmt_auth_method(enum auth_method method) } } -#define TF_LEN 16 +#define TF_LEN 64 static const char * fmt_timeframe(time_t t) @@ -670,7 +668,7 @@ fmt_timeframe(time_t t) week /= 7; if (week >= 1000) - snprintf(buf, sizeof(buf), "%s%02lluw", due, week); + snprintf(buf, sizeof(buf), "%s%lluw", due, week); else if (week > 0) snprintf(buf, sizeof(buf), "%s%02lluw%01ud%02uh", due, week, day, hrs); @@ -688,12 +686,23 @@ const char * fmt_monotime(monotime_t mt) { time_t t; + monotime_t z = monotime_clear(); - if (!monotime_valid(mt)) - return ("Never"); + if (abs_time) { + struct tm *tm; + static char buf[TF_LEN]; - t = get_rel_monotime(mt); - return (fmt_timeframe(t)); + t = monotime_to_time(mt); + if ((tm = gmtime(&t)) == NULL) + return "invalid"; + strftime(buf, sizeof(buf), "%FT%TZ", tm); + return (buf); + } else { + if (monotime_cmp(mt, z) == 0) + return ("Never"); + t = get_rel_monotime(mt); + return (fmt_timeframe(t)); + } } const char * diff --git a/usr.sbin/bgpctl/output.c b/usr.sbin/bgpctl/output.c index 2adeb71c308..9aa38f6ba23 100644 --- a/usr.sbin/bgpctl/output.c +++ b/usr.sbin/bgpctl/output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output.c,v 1.76 2026/05/18 09:22:09 claudio Exp $ */ +/* $OpenBSD: output.c,v 1.77 2026/05/21 14:48:58 claudio Exp $ */ /* * Copyright (c) 2003 Henning Brauer @@ -1045,7 +1045,7 @@ show_rib_detail(struct ctl_show_rib *r, struct ibuf *asbuf, int flag0) printf("avs %s, %s", fmt_avs(r->aspa_validation_state, 0), fmt_flags(r->flags, 0)); - printf("%c Last update: %s ago%c", EOL0(flag0), + printf("%c Last update: %s%c", EOL0(flag0), fmt_monotime(r->lastchange), EOL0(flag0)); }