mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-22 08:10:45 +02:00
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.
This commit is contained in:
parent
3214841765
commit
87680c4148
1 changed files with 1 additions and 1 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue