From 130f118eba11a06e656a7ecdd123314b2b6f99d4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 23 Sep 2019 16:14:05 +0200 Subject: dhcp/nettools: don't trim the "expiry" timestamp to 32 bit The "expiry" is the Unix timestamp when the lease expires. This is not at all a useful parameter, in particular because the system's clock can be reset. Instead, we should expose the lease receive time stamp (in CLOCK_BOOTTIME), and the lease lifetime. Anyway. So, we somehow need to express infinite lifetimes. Previously, we would use the special value 4294967295 (2^32-1). However, that value does not seem so great, because it's also the Unix timestamp of 2106-02-07T06:28:15+0000. While that is quite far in the future, it's a valid timestamp still. Of course, the code worked around that by never setting a timestamp larger than 4294967295-1, but it still limits the range of what we can expose. Note that for the lifetime "dhcp_lease_time", we do express infinity with 4294967295. That's fine, it also does not contradict what we receive in the DHCP lease on the wire because the lifetime there is expressed by a 32 bit integer. Instead, for the "expiry" timestamp, don't perform such triming. The expiry timestamp is just the start timestamp plus the lease lifetime. If that is larger than 2106-02-07, so be it. Instead, express infinity by omitting the field. --- src/dhcp/nm-dhcp-nettools.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/dhcp/nm-dhcp-nettools.c b/src/dhcp/nm-dhcp-nettools.c index 89ab0ad30c..ee66b68451 100644 --- a/src/dhcp/nm-dhcp-nettools.c +++ b/src/dhcp/nm-dhcp-nettools.c @@ -371,7 +371,7 @@ lease_parse_address (NDhcp4ClientLease *lease, */ if (nettools_lifetime == G_MAXUINT64) { a_lifetime = NM_PLATFORM_LIFETIME_PERMANENT; - a_expiry = NM_PLATFORM_LIFETIME_PERMANENT; + a_expiry = -1; } else { gint64 ts_time = time (NULL); @@ -382,10 +382,7 @@ lease_parse_address (NDhcp4ClientLease *lease, else if (a_lifetime > NM_PLATFORM_LIFETIME_PERMANENT) a_lifetime = NM_PLATFORM_LIFETIME_PERMANENT - 1; - if (ts_time > NM_PLATFORM_LIFETIME_PERMANENT - a_lifetime) - a_expiry = NM_PLATFORM_LIFETIME_PERMANENT - 1; - else - a_expiry = ts_time + a_lifetime; + a_expiry = ts_time + a_lifetime; } if (!lease_get_in_addr (lease, NM_DHCP_OPTION_DHCP4_SUBNET_MASK, &a_netmask)) { @@ -410,10 +407,12 @@ lease_parse_address (NDhcp4ClientLease *lease, NM_DHCP_OPTION_DHCP4_IP_ADDRESS_LEASE_TIME, (guint64) a_lifetime); - nm_dhcp_option_add_option_u64 (options, - _nm_dhcp_option_dhcp4_options, - NM_DHCP_OPTION_DHCP4_NM_EXPIRY, - (guint64) a_expiry); + if (a_expiry != -1) { + nm_dhcp_option_add_option_u64 (options, + _nm_dhcp_option_dhcp4_options, + NM_DHCP_OPTION_DHCP4_NM_EXPIRY, + (guint64) a_expiry); + } nm_ip4_config_add_address (ip4_config, &((const NMPlatformIP4Address) { -- cgit v1.2.1