Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/statd/iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ static time_t monotonic(void)
return ts.tv_sec;
}

/* CLOCK_REALTIME - CLOCK_MONOTONIC in whole seconds, floored */
static time_t clock_offset(void)
{
struct timespec rt, mono;

clock_gettime(CLOCK_REALTIME, &rt);
clock_gettime(CLOCK_MONOTONIC, &mono);
return rt.tv_sec - mono.tv_sec - (rt.tv_nsec < mono.tv_nsec);
}

static struct iface *iface_find(struct iface_ctx *ctx, const char *name)
{
struct iface *l;
Expand Down Expand Up @@ -263,12 +273,13 @@ void iface_ctx_exit(struct iface_ctx *ctx)
/* Add last-change to every interface in tree whose state changed since start */
void iface_annotate(struct iface_ctx *ctx, struct lyd_node *tree)
{
time_t now = time(NULL), mono = monotonic();
struct lyd_node *iface;
time_t off;

if (!tree)
return;

off = clock_offset();
LY_LIST_FOR(lyd_child(tree), iface) {
struct iface *l;
char buf[32];
Expand All @@ -277,7 +288,7 @@ void iface_annotate(struct iface_ctx *ctx, struct lyd_node *tree)
if (!l || !l->changed)
continue;

format_timestamp(now - (mono - l->changed), buf, sizeof(buf));
format_timestamp(l->changed + off, buf, sizeof(buf));
if (lyd_new_term(iface, NULL, "last-change", buf, 0, NULL))
WARN("Failed adding last-change to interface %s", l->name);
}
Expand Down
4 changes: 1 addition & 3 deletions src/statd/python/cli_pretty/cli_pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,7 @@ def from_yang(cls, ydate):
if not ydate:
return None

date, tz = ydate.split("+")
tz = tz.replace(":", "")
return cls.strptime(f"{date}+{tz}", "%Y-%m-%dT%H:%M:%S%z")
return cls.fromisoformat(ydate)

class Route:
def __init__(self, data, ip):
Expand Down
Loading