diff options
author | Dan Winship <danw@redhat.com> | 2014-11-21 13:53:25 -0500 |
---|---|---|
committer | Dan Winship <danw@redhat.com> | 2014-11-24 10:52:56 -0500 |
commit | 9013fd42d6d3cf2ed458043744611c3a996b0c66 (patch) | |
tree | ce35e3f862de5c2dc0c236416365788907305162 | |
parent | 67d030a4f5c07eed48d6635d46bc85fb13882608 (diff) | |
download | NetworkManager-9013fd42d6d3cf2ed458043744611c3a996b0c66.tar.gz |
dhcp: fix expiry time logging/exporting
The previous nm-dhcp-systemd code for logging the lease expiry time,
and exporting that value to D-Bus was clamping the value to
G_MAXUINT32-1, but that's unnecessary on x86_64, and incorrect on x86
(since time_t is signed).
Correctly adding a value to the current time and not overflowing seems
to be more-or-less impossible without having separate cases for 4- and
8-byte time_t. Since this was basically just for logging purposes
anyway, just log the number of seconds rather than the timestamp, and
then we don't have to worry about sizeof(time_t).
-rw-r--r-- | src/dhcp-manager/nm-dhcp-systemd.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/dhcp-manager/nm-dhcp-systemd.c b/src/dhcp-manager/nm-dhcp-systemd.c index b475505c75..a20a089afa 100644 --- a/src/dhcp-manager/nm-dhcp-systemd.c +++ b/src/dhcp-manager/nm-dhcp-systemd.c @@ -181,6 +181,13 @@ add_option_u32 (GHashTable *options, const ReqOption *requests, guint option, gu } static void +add_option_u64 (GHashTable *options, const ReqOption *requests, guint option, guint64 value) +{ + if (options) + take_option (options, requests, option, g_strdup_printf ("%" G_GUINT64_FORMAT, value)); +} + +static void add_requests_to_options (GHashTable *options, const ReqOption *requests) { guint i; @@ -216,7 +223,7 @@ lease_to_ip4_config (sd_dhcp_lease *lease, struct sd_dhcp_route *routes; guint16 mtu; int r, num; - time_t end_time; + guint64 end_time; g_return_val_if_fail (lease != NULL, NULL); @@ -243,12 +250,12 @@ lease_to_ip4_config (sd_dhcp_lease *lease, sd_dhcp_lease_get_lifetime (lease, &lifetime); address.timestamp = nm_utils_get_monotonic_timestamp_s (); address.lifetime = address.preferred = lifetime; - end_time = MIN ((guint64) time (NULL) + lifetime, G_MAXUINT32 - 1); - LOG_LEASE (LOGD_DHCP4, " expires %s", ctime (&end_time)); - add_option_u32 (options, + end_time = (guint64) time (NULL) + lifetime; + LOG_LEASE (LOGD_DHCP4, " expires in %" G_GUINT64_FORMAT " seconds", lifetime); + add_option_u64 (options, dhcp4_requests, DHCP_OPTION_IP_ADDRESS_LEASE_TIME, - (guint32) end_time); + end_time); address.source = NM_IP_CONFIG_SOURCE_DHCP; nm_ip4_config_add_address (ip4_config, &address); |