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.
This commit is contained in:
@@ -2840,8 +2840,9 @@ ndisc_set_router_config (NMNDisc *ndisc, NMDevice *self)
|
|||||||
} else
|
} else
|
||||||
base = now;
|
base = now;
|
||||||
|
|
||||||
if (!nm_utils_lifetime_get (addr->timestamp, addr->lifetime, addr->preferred,
|
lifetime = nm_utils_lifetime_get (addr->timestamp, addr->lifetime, addr->preferred,
|
||||||
base, &lifetime, &preferred))
|
base, &preferred);
|
||||||
|
if (!lifetime)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
g_array_set_size (addresses, addresses->len+1);
|
g_array_set_size (addresses, addresses->len+1);
|
||||||
|
@@ -3891,12 +3891,11 @@ nm_utils_lifetime_rebase_relative_time_on_now (guint32 timestamp,
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
guint32
|
||||||
nm_utils_lifetime_get (guint32 timestamp,
|
nm_utils_lifetime_get (guint32 timestamp,
|
||||||
guint32 lifetime,
|
guint32 lifetime,
|
||||||
guint32 preferred,
|
guint32 preferred,
|
||||||
gint32 now,
|
gint32 now,
|
||||||
guint32 *out_lifetime,
|
|
||||||
guint32 *out_preferred)
|
guint32 *out_preferred)
|
||||||
{
|
{
|
||||||
guint32 t_lifetime, t_preferred;
|
guint32 t_lifetime, t_preferred;
|
||||||
@@ -3909,21 +3908,22 @@ nm_utils_lifetime_get (guint32 timestamp,
|
|||||||
* NM_PLATFORM_LIFETIME_PERMANENT). The real lifetime==0 addresses (E.g. DHCP6 telling us
|
* NM_PLATFORM_LIFETIME_PERMANENT). The real lifetime==0 addresses (E.g. DHCP6 telling us
|
||||||
* to drop an address will have timestamp set.
|
* 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);
|
NM_SET_OUT (out_preferred, NM_PLATFORM_LIFETIME_PERMANENT);
|
||||||
g_return_val_if_fail (preferred == 0, TRUE);
|
g_return_val_if_fail (preferred == 0, NM_PLATFORM_LIFETIME_PERMANENT);
|
||||||
} else {
|
return NM_PLATFORM_LIFETIME_PERMANENT;
|
||||||
|
}
|
||||||
|
|
||||||
if (now <= 0)
|
if (now <= 0)
|
||||||
now = nm_utils_get_monotonic_timestamp_s ();
|
now = nm_utils_get_monotonic_timestamp_s ();
|
||||||
|
|
||||||
t_lifetime = nm_utils_lifetime_rebase_relative_time_on_now (timestamp, lifetime, now);
|
t_lifetime = nm_utils_lifetime_rebase_relative_time_on_now (timestamp, lifetime, now);
|
||||||
if (!t_lifetime) {
|
if (!t_lifetime) {
|
||||||
NM_SET_OUT (out_lifetime, 0);
|
|
||||||
NM_SET_OUT (out_preferred, 0);
|
NM_SET_OUT (out_preferred, 0);
|
||||||
return FALSE;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
t_preferred = nm_utils_lifetime_rebase_relative_time_on_now (timestamp, preferred, now);
|
t_preferred = nm_utils_lifetime_rebase_relative_time_on_now (timestamp, preferred, now);
|
||||||
|
|
||||||
NM_SET_OUT (out_lifetime, t_lifetime);
|
|
||||||
NM_SET_OUT (out_preferred, MIN (t_preferred, t_lifetime));
|
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()
|
/* Assert that non-permanent addresses have a (positive) @timestamp. nm_utils_lifetime_rebase_relative_time_on_now()
|
||||||
@@ -3932,10 +3932,10 @@ nm_utils_lifetime_get (guint32 timestamp,
|
|||||||
*/
|
*/
|
||||||
g_return_val_if_fail ( timestamp != 0
|
g_return_val_if_fail ( timestamp != 0
|
||||||
|| ( lifetime == NM_PLATFORM_LIFETIME_PERMANENT
|
|| ( lifetime == NM_PLATFORM_LIFETIME_PERMANENT
|
||||||
&& preferred == NM_PLATFORM_LIFETIME_PERMANENT), TRUE);
|
&& preferred == NM_PLATFORM_LIFETIME_PERMANENT), t_lifetime);
|
||||||
g_return_val_if_fail (t_preferred <= t_lifetime, TRUE);
|
g_return_val_if_fail (t_preferred <= t_lifetime, t_lifetime);
|
||||||
}
|
|
||||||
return TRUE;
|
return t_lifetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
@@ -408,11 +408,10 @@ guint32 nm_utils_lifetime_rebase_relative_time_on_now (guint32 timestamp,
|
|||||||
guint32 duration,
|
guint32 duration,
|
||||||
gint32 now);
|
gint32 now);
|
||||||
|
|
||||||
gboolean nm_utils_lifetime_get (guint32 timestamp,
|
guint32 nm_utils_lifetime_get (guint32 timestamp,
|
||||||
guint32 lifetime,
|
guint32 lifetime,
|
||||||
guint32 preferred,
|
guint32 preferred,
|
||||||
gint32 now,
|
gint32 now,
|
||||||
guint32 *out_lifetime,
|
|
||||||
guint32 *out_preferred);
|
guint32 *out_preferred);
|
||||||
|
|
||||||
gboolean nm_utils_ip4_address_is_link_local (in_addr_t addr);
|
gboolean nm_utils_ip4_address_is_link_local (in_addr_t addr);
|
||||||
|
@@ -3145,7 +3145,6 @@ array_ip6_address_position (const GPtrArray *addresses,
|
|||||||
candidate->lifetime,
|
candidate->lifetime,
|
||||||
candidate->preferred,
|
candidate->preferred,
|
||||||
now,
|
now,
|
||||||
NULL,
|
|
||||||
NULL))
|
NULL))
|
||||||
return pos;
|
return pos;
|
||||||
|
|
||||||
@@ -3348,7 +3347,7 @@ nm_platform_ip4_address_sync (NMPlatform *self,
|
|||||||
known_address = NMP_OBJECT_CAST_IP4_ADDRESS (known_addresses->pdata[i]);
|
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,
|
if (!nm_utils_lifetime_get (known_address->timestamp, known_address->lifetime, known_address->preferred,
|
||||||
now, NULL, NULL))
|
now, NULL))
|
||||||
goto delete_and_next;
|
goto delete_and_next;
|
||||||
|
|
||||||
if (G_UNLIKELY (!known_addresses_idx)) {
|
if (G_UNLIKELY (!known_addresses_idx)) {
|
||||||
@@ -3466,8 +3465,9 @@ delete_and_next:
|
|||||||
|
|
||||||
known_address = NMP_OBJECT_CAST_IP4_ADDRESS (o);
|
known_address = NMP_OBJECT_CAST_IP4_ADDRESS (o);
|
||||||
|
|
||||||
if (!nm_utils_lifetime_get (known_address->timestamp, known_address->lifetime, known_address->preferred,
|
lifetime = nm_utils_lifetime_get (known_address->timestamp, known_address->lifetime, known_address->preferred,
|
||||||
now, &lifetime, &preferred))
|
now, &preferred);
|
||||||
|
if (!lifetime)
|
||||||
goto delete_and_next2;
|
goto delete_and_next2;
|
||||||
|
|
||||||
if (!nm_platform_ip4_address_add (self, ifindex, known_address->address, known_address->plen,
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nm_utils_lifetime_get (known_address->timestamp, known_address->lifetime, known_address->preferred,
|
lifetime = nm_utils_lifetime_get (known_address->timestamp, known_address->lifetime, known_address->preferred,
|
||||||
now, &lifetime, &preferred))
|
now, &preferred);
|
||||||
|
if (!lifetime)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!nm_platform_ip6_address_add (self, ifindex, known_address->address,
|
if (!nm_platform_ip6_address_add (self, ifindex, known_address->address,
|
||||||
|
Reference in New Issue
Block a user