summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-09-23 16:02:15 +0200
committerThomas Haller <thaller@redhat.com>2019-09-23 16:10:51 +0200
commit87680c4148679a0eb21cd601f919751986838ff0 (patch)
tree7cc4e8378bf4877eaf18b9653ad665b79dc6d6c4
parent3214841765ccf7901549d2e36153a06e3b3a5822 (diff)
downloadNetworkManager-87680c4148679a0eb21cd601f919751986838ff0.tar.gz
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.
-rw-r--r--src/dhcp/nm-dhcp-nettools.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/dhcp/nm-dhcp-nettools.c b/src/dhcp/nm-dhcp-nettools.c
index 86c3311f40..89ab0ad30c 100644
--- a/src/dhcp/nm-dhcp-nettools.c
+++ b/src/dhcp/nm-dhcp-nettools.c
@@ -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;