mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-15 03:27:25 +00:00
bgpd: Refactor peer_uptime
peer_uptime was doing the same work unnecessarily. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com> Reviewed-by: Daniel Walton <dwalton@cumulusnetworks.com>
This commit is contained in:
parent
535c84b16b
commit
1d88934826
44
bgpd/bgpd.c
44
bgpd/bgpd.c
@ -6088,36 +6088,20 @@ peer_uptime (time_t uptime2, char *buf, size_t len, u_char use_json, json_object
|
|||||||
|
|
||||||
if (use_json)
|
if (use_json)
|
||||||
{
|
{
|
||||||
int time_store;
|
unsigned long time_store;
|
||||||
int day_msec = 86400000;
|
unsigned long day_msec = 86400000;
|
||||||
int hour_msec = 3600000;
|
unsigned long hour_msec = 3600000;
|
||||||
int minute_msec = 60000;
|
unsigned long minute_msec = 60000;
|
||||||
int sec_msec = 1000;
|
unsigned long sec_msec = 1000;
|
||||||
|
|
||||||
|
time_store =
|
||||||
|
day_msec * tm->tm_yday +
|
||||||
|
hour_msec * tm->tm_hour +
|
||||||
|
minute_msec * tm->tm_min +
|
||||||
|
sec_msec * tm->tm_sec;
|
||||||
|
json_object_int_add(json, "peerUptimeMsec", time_store);
|
||||||
|
}
|
||||||
|
|
||||||
if (uptime1 < ONE_DAY_SECOND)
|
|
||||||
{
|
|
||||||
time_store = hour_msec * tm->tm_hour + minute_msec * tm->tm_min + sec_msec * tm->tm_sec;
|
|
||||||
json_object_int_add(json, "peerUptimeMsec", time_store);
|
|
||||||
snprintf (buf, len, "%02d:%02d:%02d",
|
|
||||||
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
|
||||||
}
|
|
||||||
else if (uptime1 < ONE_WEEK_SECOND)
|
|
||||||
{
|
|
||||||
time_store = day_msec * tm->tm_yday + hour_msec * tm->tm_hour + minute_msec * tm->tm_min + sec_msec * tm->tm_sec;
|
|
||||||
json_object_int_add(json, "peerUptimeMsec", time_store);
|
|
||||||
snprintf (buf, len, "%dd%02dh%02dm",
|
|
||||||
tm->tm_yday, tm->tm_hour, tm->tm_min);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
time_store = day_msec * tm->tm_yday + hour_msec * tm->tm_hour + minute_msec * tm->tm_min + sec_msec * tm->tm_sec;
|
|
||||||
json_object_int_add(json, "peerUptimeMsec", time_store);
|
|
||||||
snprintf (buf, len, "%02dw%dd%02dh",
|
|
||||||
tm->tm_yday/7, tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (uptime1 < ONE_DAY_SECOND)
|
if (uptime1 < ONE_DAY_SECOND)
|
||||||
snprintf (buf, len, "%02d:%02d:%02d",
|
snprintf (buf, len, "%02d:%02d:%02d",
|
||||||
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
||||||
@ -6127,7 +6111,7 @@ peer_uptime (time_t uptime2, char *buf, size_t len, u_char use_json, json_object
|
|||||||
else
|
else
|
||||||
snprintf (buf, len, "%02dw%dd%02dh",
|
snprintf (buf, len, "%02dw%dd%02dh",
|
||||||
tm->tm_yday/7, tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
|
tm->tm_yday/7, tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
|
||||||
}
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user