Commit 87680c41 authored by Thomas Haller's avatar Thomas Haller

dhcp/nettools: round time difference when calculating the lease lifetime

nettools does not expose the original lease lifetime. It's a missing
API. Instead, it only exposes the timestamp when the lease will expire.

As a workaround, we calulate the timestamp by subtracting the current
timestamp from the expiration timestamp, assuming that the lease was
received just now. However, it was not received *exactly* now, but a
few milliseconds before. Hence, the calculated timestamp is not exact
here and likely a few milliseconds less then the actual (full integer)
value.

Account for that by rounding the value to the second.
parent 32148417
Pipeline #65597 passed with stages
in 132 minutes and 29 seconds
......@@ -375,7 +375,7 @@ lease_parse_address (NDhcp4ClientLease *lease,
} else {
gint64 ts_time = time (NULL);
a_lifetime = ((gint64) nettools_lifetime - ts_clock_boottime) / NM_UTILS_NS_PER_SECOND;
a_lifetime = ((gint64) nettools_lifetime - ts_clock_boottime + (NM_UTILS_NS_PER_SECOND / 2)) / NM_UTILS_NS_PER_SECOND;
/* A lease time of 0 is allowed on some dhcp servers, so, let's accept it. */
if (a_lifetime < 0)
a_lifetime = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment