-/* $OpenBSD: bgpctl.c,v 1.266 2021/04/15 14:12:05 claudio Exp $ */
+/* $OpenBSD: bgpctl.c,v 1.267 2021/05/03 14:01:56 claudio Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
return (0);
}
+time_t
+get_monotime(time_t t)
+{
+ struct timespec ts;
+
+ if (t == 0)
+ return -1;
+ 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 (ts.tv_sec - t);
+}
+
char *
fmt_peer(const char *descr, const struct bgpd_addr *remote_addr,
int masklen)
const char *
fmt_monotime(time_t t)
{
- struct timespec ts;
+ t = get_monotime(t);
- if (t == 0)
+ if (t == -1)
return ("Never");
- 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));
+ return (fmt_timeframe(t));
}
const char *
-/* $OpenBSD: output_json.c,v 1.9 2021/04/15 14:12:05 claudio Exp $ */
+/* $OpenBSD: output_json.c,v 1.10 2021/05/03 14:01:56 claudio Exp $ */
/*
* Copyright (c) 2020 Claudio Jeker <claudio@openbsd.org>
{
json_do_object("stats");
json_do_printf("last_read", "%s", fmt_monotime(p->stats.last_read));
+ json_do_int("last_read_sec", get_monotime(p->stats.last_read));
json_do_printf("last_write", "%s", fmt_monotime(p->stats.last_write));
+ json_do_int("last_write_sec", get_monotime(p->stats.last_write));
json_do_object("prefixes");
json_do_uint("sent", p->stats.prefix_out_cnt);
}
json_do_printf("state", "%s", statenames[p->state]);
json_do_printf("last_updown", "%s", fmt_monotime(p->stats.last_updown));
+ json_do_int("last_updown_sec", get_monotime(p->stats.last_updown));
switch (res->action) {
case SHOW:
json_do_uint("localpref", r->local_pref);
json_do_uint("weight", r->weight);
json_do_printf("last_update", "%s", fmt_timeframe(r->age));
+ json_do_int("last_update_sec", r->age);
/* keep the object open for communities and attribuites */
}
json_do_printf("name", "%s", set->name);
json_do_printf("type", "%s", fmt_set_type(set));
json_do_printf("last_change", "%s", fmt_monotime(set->lastchange));
+ json_do_int("last_change_sec", get_monotime(set->lastchange));
if (set->type == ASNUM_SET) {
json_do_uint("num_ASnum", set->as_cnt);
} else {