summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bgpd/bgp_labelpool.c4
-rw-r--r--bgpd/bgp_mplsvpn.c4
-rw-r--r--bgpd/bgp_nexthop.c4
-rw-r--r--bgpd/bgp_route.c4
-rw-r--r--bgpd/bgp_updgrp.c10
-rw-r--r--bgpd/bgpd.h8
-rw-r--r--lib/monotime.h16
-rw-r--r--pathd/path_pcep_debug.c3
8 files changed, 27 insertions, 26 deletions
diff --git a/bgpd/bgp_labelpool.c b/bgpd/bgp_labelpool.c
index 23e0c191dc..54a966e191 100644
--- a/bgpd/bgp_labelpool.c
+++ b/bgpd/bgp_labelpool.c
@@ -1125,7 +1125,6 @@ static void show_bgp_nexthop_label_afi(struct vty *vty, afi_t afi,
struct bgp_path_info *path;
struct bgp *bgp_path;
struct bgp_table *table;
- time_t tbuf;
vty_out(vty, "Current BGP label nexthop cache for %s, VRF %s\n",
afi2str(afi), bgp->name_pretty);
@@ -1146,8 +1145,7 @@ static void show_bgp_nexthop_label_afi(struct vty *vty, afi_t afi,
vty_out(vty, " if %s\n",
ifindex2ifname(iter->nh->ifindex,
iter->nh->vrf_id));
- tbuf = time(NULL) - (monotime(NULL) - iter->last_update);
- vty_out(vty, " Last update: %s", ctime_r(&tbuf, buf));
+ vty_out(vty, " Last update: %s", time_to_string(iter->last_update, buf));
if (!detail)
continue;
vty_out(vty, " Paths:\n");
diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c
index ecb78c1ce4..85cc8f3596 100644
--- a/bgpd/bgp_mplsvpn.c
+++ b/bgpd/bgp_mplsvpn.c
@@ -4395,7 +4395,6 @@ static void show_bgp_mplsvpn_nh_label_bind_internal(struct vty *vty,
struct bgp_path_info *path;
struct bgp *bgp_path;
struct bgp_table *table;
- time_t tbuf;
char buf[32];
vty_out(vty, "Current BGP mpls-vpn nexthop label bind cache, %s\n",
@@ -4413,8 +4412,7 @@ static void show_bgp_mplsvpn_nh_label_bind_internal(struct vty *vty,
vty_out(vty, " interface %s\n",
ifindex2ifname(iter->nh->ifindex,
iter->nh->vrf_id));
- tbuf = time(NULL) - (monotime(NULL) - iter->last_update);
- vty_out(vty, " Last update: %s", ctime_r(&tbuf, buf));
+ vty_out(vty, " Last update: %s", time_to_string(iter->last_update, buf));
if (!detail)
continue;
vty_out(vty, " Paths:\n");
diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c
index 1ef90a8e38..5fda5701f3 100644
--- a/bgpd/bgp_nexthop.c
+++ b/bgpd/bgp_nexthop.c
@@ -1079,14 +1079,14 @@ static void bgp_show_nexthop(struct vty *vty, struct bgp *bgp,
json_last_update = json_object_new_object();
json_object_int_add(json_last_update, "epoch", tbuf);
json_object_string_add(json_last_update, "string",
- ctime_r(&tbuf, timebuf));
+ time_to_string_json(bnc->last_update, timebuf));
json_object_object_add(json_nexthop, "lastUpdate",
json_last_update);
} else {
json_object_int_add(json_nexthop, "lastUpdate", tbuf);
}
} else {
- vty_out(vty, " Last update: %s", ctime_r(&tbuf, timebuf));
+ vty_out(vty, " Last update: %s", time_to_string(bnc->last_update, timebuf));
}
/* show paths dependent on nexthop, if needed. */
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index 5e6135e472..bd2fda56fc 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -11726,11 +11726,11 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
json_last_update = json_object_new_object();
json_object_int_add(json_last_update, "epoch", tbuf);
json_object_string_add(json_last_update, "string",
- ctime_r(&tbuf, timebuf));
+ time_to_string_json(path->uptime, timebuf));
json_object_object_add(json_path, "lastUpdate",
json_last_update);
} else
- vty_out(vty, " Last update: %s", ctime_r(&tbuf, timebuf));
+ vty_out(vty, " Last update: %s", time_to_string(path->uptime, timebuf));
/* Line 10 display PMSI tunnel attribute, if present */
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL))) {
diff --git a/bgpd/bgp_updgrp.c b/bgpd/bgp_updgrp.c
index ef03606707..35ddfc34ff 100644
--- a/bgpd/bgp_updgrp.c
+++ b/bgpd/bgp_updgrp.c
@@ -757,7 +757,7 @@ static int update_group_show_walkcb(struct update_group *updgrp, void *arg)
json_time = json_object_new_object();
json_object_int_add(json_time, "epoch", epoch_tbuf);
json_object_string_add(json_time, "epochString",
- ctime_r(&epoch_tbuf, timebuf));
+ time_to_string_json(updgrp->uptime, timebuf));
json_object_object_add(json_updgrp, "groupCreateTime",
json_time);
json_object_string_add(json_updgrp, "afi",
@@ -766,8 +766,7 @@ static int update_group_show_walkcb(struct update_group *updgrp, void *arg)
safi2str(updgrp->safi));
} else {
vty_out(vty, "Update-group %" PRIu64 ":\n", updgrp->id);
- vty_out(vty, " Created: %s",
- timestamp_string(updgrp->uptime, timebuf));
+ vty_out(vty, " Created: %s", time_to_string(updgrp->uptime, timebuf));
}
filter = &updgrp->conf->filter[updgrp->afi][updgrp->safi];
@@ -835,15 +834,14 @@ static int update_group_show_walkcb(struct update_group *updgrp, void *arg)
json_object_int_add(json_subgrp_time, "epoch",
epoch_tbuf);
json_object_string_add(json_subgrp_time, "epochString",
- ctime_r(&epoch_tbuf, timebuf));
+ time_to_string_json(subgrp->uptime, timebuf));
json_object_object_add(json_subgrp, "groupCreateTime",
json_subgrp_time);
} else {
vty_out(vty, "\n");
vty_out(vty, " Update-subgroup %" PRIu64 ":\n",
subgrp->id);
- vty_out(vty, " Created: %s",
- timestamp_string(subgrp->uptime, timebuf));
+ vty_out(vty, " Created: %s", time_to_string(subgrp->uptime, timebuf));
}
if (subgrp->split_from.update_group_id
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index 196193c4d2..2d7396ad6c 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -2714,14 +2714,6 @@ static inline int peer_group_af_configured(struct peer_group *group)
return 0;
}
-static inline char *timestamp_string(time_t ts, char *timebuf)
-{
- time_t tbuf;
-
- tbuf = time(NULL) - (monotime(NULL) - ts);
- return ctime_r(&tbuf, timebuf);
-}
-
static inline bool peer_established(struct peer_connection *connection)
{
return connection->status == Established;
diff --git a/lib/monotime.h b/lib/monotime.h
index f7ae1bbbe1..5e1bfe754e 100644
--- a/lib/monotime.h
+++ b/lib/monotime.h
@@ -129,6 +129,22 @@ static inline char *time_to_string(time_t ts, char *buf)
return ctime_r(&tbuf, buf);
}
+/* A wrapper for time_to_string() which removes newline at the end.
+ * This is needed for JSON outputs, where newline is not expected.
+ */
+static inline char *time_to_string_json(time_t ts, char *buf)
+{
+ size_t len;
+
+ time_to_string(ts, buf);
+ len = strlen(buf);
+
+ if (len && buf[len - 1] == '\n')
+ buf[len - 1] = '\0';
+
+ return buf;
+}
+
/* Convert interval to human-friendly string, used in cli output e.g. */
static inline const char *frrtime_to_interval(time_t t, char *buf,
size_t buflen)
diff --git a/pathd/path_pcep_debug.c b/pathd/path_pcep_debug.c
index 7bff9c7b9c..89e7574324 100644
--- a/pathd/path_pcep_debug.c
+++ b/pathd/path_pcep_debug.c
@@ -1321,8 +1321,7 @@ void _format_pcep_event(int ps, pcep_event *event)
PATHD_FORMAT("\n");
PATHD_FORMAT("%*sevent_type: %s\n", ps2, "",
pcep_event_type_name(event->event_type));
- PATHD_FORMAT("%*sevent_time: %s", ps2, "",
- ctime_r(&event->event_time, buf));
+ PATHD_FORMAT("%*sevent_time: %s", ps2, "", time_to_string(event->event_time, buf));
if (event->session == NULL) {
PATHD_FORMAT("%*ssession: NULL\n", ps2, "");
} else {