mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-12-26 21:36:50 +00:00
Merge pull request #17684 from opensourcerouting/fix/json_time_no_newline
bgpd, lib: Use frrstr_time() when using ctime_r()
This commit is contained in:
commit
e62c2f10bc
@ -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");
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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. */
|
||||
|
||||
@ -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))) {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user