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. On the other hand, express infinity by omitting the "expiry" field.
This commit is contained in:
@@ -372,7 +372,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);
|
||||
|
||||
@@ -383,10 +383,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)) {
|
||||
@@ -411,10 +408,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);
|
||||
}
|
||||
|
||||
|
||||
n_dhcp4_client_lease_get_siaddr (lease, &a_next_server);
|
||||
|
Reference in New Issue
Block a user