diff options
author | Thomas Haller <thaller@redhat.com> | 2018-02-07 21:32:10 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-02-09 17:40:01 +0100 |
commit | 7459548f2351a11f00f19c26fa98dc19e88258cd (patch) | |
tree | 6280c430909ca01537f685d4ad07d9510168474e /src | |
parent | 1de10532f2b0bbd1fbe3a07d0315ccc90ae5c7a8 (diff) |
core: return remaining lifetime from nm_utils_lifetime_get()
nm_utils_lifetime_get() already has so many arguments.
Essentially, the function returned %TRUE if and only if the
lifetime was greater then zero.
Combine the return value and the output argument for the lifetime.
It also matches better the function name: to get the lifetime.
Diffstat (limited to 'src')
-rw-r--r-- | src/devices/nm-device.c | 5 | ||||
-rw-r--r-- | src/nm-core-utils.c | 52 | ||||
-rw-r--r-- | src/nm-core-utils.h | 11 | ||||
-rw-r--r-- | src/platform/nm-platform.c | 13 |
4 files changed, 41 insertions, 40 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 55252d58b3..4526765a92 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -2840,8 +2840,9 @@ ndisc_set_router_config (NMNDisc *ndisc, NMDevice *self) } else base = now; - if (!nm_utils_lifetime_get (addr->timestamp, addr->lifetime, addr->preferred, - base, &lifetime, &preferred)) + lifetime = nm_utils_lifetime_get (addr->timestamp, addr->lifetime, addr->preferred, + base, &preferred); + if (!lifetime) continue; g_array_set_size (addresses, addresses->len+1); diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index 3a5118508b..f3e9e5f75e 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -3891,12 +3891,11 @@ nm_utils_lifetime_rebase_relative_time_on_now (guint32 timestamp, return t; } -gboolean +guint32 nm_utils_lifetime_get (guint32 timestamp, guint32 lifetime, guint32 preferred, gint32 now, - guint32 *out_lifetime, guint32 *out_preferred) { guint32 t_lifetime, t_preferred; @@ -3904,38 +3903,39 @@ nm_utils_lifetime_get (guint32 timestamp, nm_assert (now >= 0); if (timestamp == 0 && lifetime == 0) { - /* We treat lifetime==0 && timestamp == 0 addresses as permanent addresses to allow easy + /* We treat lifetime==0 && timestamp==0 addresses as permanent addresses to allow easy * creation of such addresses (without requiring to set the lifetime fields to * NM_PLATFORM_LIFETIME_PERMANENT). The real lifetime==0 addresses (E.g. DHCP6 telling us * to drop an address will have timestamp set. */ - NM_SET_OUT (out_lifetime, NM_PLATFORM_LIFETIME_PERMANENT); NM_SET_OUT (out_preferred, NM_PLATFORM_LIFETIME_PERMANENT); - g_return_val_if_fail (preferred == 0, TRUE); - } else { - if (now <= 0) - now = nm_utils_get_monotonic_timestamp_s (); - t_lifetime = nm_utils_lifetime_rebase_relative_time_on_now (timestamp, lifetime, now); - if (!t_lifetime) { - NM_SET_OUT (out_lifetime, 0); - NM_SET_OUT (out_preferred, 0); - return FALSE; - } - t_preferred = nm_utils_lifetime_rebase_relative_time_on_now (timestamp, preferred, now); + g_return_val_if_fail (preferred == 0, NM_PLATFORM_LIFETIME_PERMANENT); + return NM_PLATFORM_LIFETIME_PERMANENT; + } - NM_SET_OUT (out_lifetime, t_lifetime); - NM_SET_OUT (out_preferred, MIN (t_preferred, t_lifetime)); + if (now <= 0) + now = nm_utils_get_monotonic_timestamp_s (); - /* Assert that non-permanent addresses have a (positive) @timestamp. nm_utils_lifetime_rebase_relative_time_on_now() - * treats addresses with timestamp 0 as *now*. Addresses passed to _address_get_lifetime() always - * should have a valid @timestamp, otherwise on every re-sync, their lifetime will be extended anew. - */ - g_return_val_if_fail ( timestamp != 0 - || ( lifetime == NM_PLATFORM_LIFETIME_PERMANENT - && preferred == NM_PLATFORM_LIFETIME_PERMANENT), TRUE); - g_return_val_if_fail (t_preferred <= t_lifetime, TRUE); + t_lifetime = nm_utils_lifetime_rebase_relative_time_on_now (timestamp, lifetime, now); + if (!t_lifetime) { + NM_SET_OUT (out_preferred, 0); + return 0; } - return TRUE; + + t_preferred = nm_utils_lifetime_rebase_relative_time_on_now (timestamp, preferred, now); + + NM_SET_OUT (out_preferred, MIN (t_preferred, t_lifetime)); + + /* Assert that non-permanent addresses have a (positive) @timestamp. nm_utils_lifetime_rebase_relative_time_on_now() + * treats addresses with timestamp 0 as *now*. Addresses passed to _address_get_lifetime() always + * should have a valid @timestamp, otherwise on every re-sync, their lifetime will be extended anew. + */ + g_return_val_if_fail ( timestamp != 0 + || ( lifetime == NM_PLATFORM_LIFETIME_PERMANENT + && preferred == NM_PLATFORM_LIFETIME_PERMANENT), t_lifetime); + g_return_val_if_fail (t_preferred <= t_lifetime, t_lifetime); + + return t_lifetime; } const char * diff --git a/src/nm-core-utils.h b/src/nm-core-utils.h index 2f6585e717..38f20b0522 100644 --- a/src/nm-core-utils.h +++ b/src/nm-core-utils.h @@ -408,12 +408,11 @@ guint32 nm_utils_lifetime_rebase_relative_time_on_now (guint32 timestamp, guint32 duration, gint32 now); -gboolean nm_utils_lifetime_get (guint32 timestamp, - guint32 lifetime, - guint32 preferred, - gint32 now, - guint32 *out_lifetime, - guint32 *out_preferred); +guint32 nm_utils_lifetime_get (guint32 timestamp, + guint32 lifetime, + guint32 preferred, + gint32 now, + guint32 *out_preferred); gboolean nm_utils_ip4_address_is_link_local (in_addr_t addr); diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index ec19835eee..c475d07a11 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -3145,7 +3145,6 @@ array_ip6_address_position (const GPtrArray *addresses, candidate->lifetime, candidate->preferred, now, - NULL, NULL)) return pos; @@ -3348,7 +3347,7 @@ nm_platform_ip4_address_sync (NMPlatform *self, known_address = NMP_OBJECT_CAST_IP4_ADDRESS (known_addresses->pdata[i]); if (!nm_utils_lifetime_get (known_address->timestamp, known_address->lifetime, known_address->preferred, - now, NULL, NULL)) + now, NULL)) goto delete_and_next; if (G_UNLIKELY (!known_addresses_idx)) { @@ -3466,8 +3465,9 @@ delete_and_next: known_address = NMP_OBJECT_CAST_IP4_ADDRESS (o); - if (!nm_utils_lifetime_get (known_address->timestamp, known_address->lifetime, known_address->preferred, - now, &lifetime, &preferred)) + lifetime = nm_utils_lifetime_get (known_address->timestamp, known_address->lifetime, known_address->preferred, + now, &preferred); + if (!lifetime) goto delete_and_next2; if (!nm_platform_ip4_address_add (self, ifindex, known_address->address, known_address->plen, @@ -3578,8 +3578,9 @@ nm_platform_ip6_address_sync (NMPlatform *self, continue; } - if (!nm_utils_lifetime_get (known_address->timestamp, known_address->lifetime, known_address->preferred, - now, &lifetime, &preferred)) + lifetime = nm_utils_lifetime_get (known_address->timestamp, known_address->lifetime, known_address->preferred, + now, &preferred); + if (!lifetime) continue; if (!nm_platform_ip6_address_add (self, ifindex, known_address->address, |