diff options
author | Thomas Haller <thaller@redhat.com> | 2014-06-07 11:32:40 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-06-07 11:35:22 +0200 |
commit | 63ef089f69f70a07c55764eb14fecb84984b9865 (patch) | |
tree | da95dc5b4bffb4c5d4e37b9f80dba597b243a076 | |
parent | b6337115726b3f58ddb77e5c231c11ec162809f7 (diff) | |
download | NetworkManager-63ef089f69f70a07c55764eb14fecb84984b9865.tar.gz |
platform: pass optional padding to _rebase_relative_time_on_now()
_rebase_relative_time_on_now() is used both by _address_get_lifetime()/nm_platform_ip[46]_address_sync()
and the to_string() functions.
In the latter case, we want to print the original value, without padding. Otherwise in
the addresses are printed in the logs with an additional 5 seconds
padding, which is confusing.
For adding addresses in platform however, we still want to keep the
padding. So pass it on as additional parameter.
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | src/platform/nm-platform.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 4885af14a6..6a3bbef6b1 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -1564,18 +1564,18 @@ array_contains_ip6_address (const GArray *addresses, const NMPlatformIP6Address * on the new timestamp @now. */ static guint32 -_rebase_relative_time_on_now (guint32 timestamp, guint32 duration, guint32 now) +_rebase_relative_time_on_now (guint32 timestamp, guint32 duration, guint32 now, guint32 padding) { gint64 t; if (duration == NM_PLATFORM_LIFETIME_PERMANENT) return NM_PLATFORM_LIFETIME_PERMANENT; - /* For timestamp>now, just accept it and calculate the expected(?) result. */ + /* For timestamp > now, just accept it and calculate the expected(?) result. */ t = (gint64) timestamp + (gint64) duration - (gint64) now; - /* Pad the timestamp by 5 seconds to avoid potential races. */ - t += 5; + /* Optional padding to avoid potential races. */ + t += (gint64) padding; if (t <= 0) return 0; @@ -1585,7 +1585,7 @@ _rebase_relative_time_on_now (guint32 timestamp, guint32 duration, guint32 now) } static gboolean -_address_get_lifetime (const NMPlatformIPAddress *address, guint32 now, guint32 *out_lifetime, guint32 *out_preferred) +_address_get_lifetime (const NMPlatformIPAddress *address, guint32 now, guint32 padding, guint32 *out_lifetime, guint32 *out_preferred) { gint32 lifetime, preferred; @@ -1593,10 +1593,10 @@ _address_get_lifetime (const NMPlatformIPAddress *address, guint32 now, guint32 *out_lifetime = NM_PLATFORM_LIFETIME_PERMANENT; *out_preferred = NM_PLATFORM_LIFETIME_PERMANENT; } else { - lifetime = _rebase_relative_time_on_now (address->timestamp, address->lifetime, now); + lifetime = _rebase_relative_time_on_now (address->timestamp, address->lifetime, now, padding); if (!lifetime) return FALSE; - preferred = _rebase_relative_time_on_now (address->timestamp, address->preferred, now); + preferred = _rebase_relative_time_on_now (address->timestamp, address->preferred, now, padding); if (preferred > lifetime) { g_warn_if_reached (); preferred = lifetime; @@ -1645,7 +1645,8 @@ nm_platform_ip4_address_sync (int ifindex, const GArray *known_addresses) const NMPlatformIP4Address *known_address = &g_array_index (known_addresses, NMPlatformIP4Address, i); guint32 lifetime, preferred; - if (!_address_get_lifetime ((NMPlatformIPAddress *) known_address, now, &lifetime, &preferred)) + /* add a padding of 5 seconds to avoid potential races. */ + if (!_address_get_lifetime ((NMPlatformIPAddress *) known_address, now, 5, &lifetime, &preferred)) continue; if (!nm_platform_ip4_address_add (ifindex, known_address->address, known_address->peer_address, known_address->plen, lifetime, preferred, known_address->label)) @@ -1696,7 +1697,8 @@ nm_platform_ip6_address_sync (int ifindex, const GArray *known_addresses) const NMPlatformIP6Address *known_address = &g_array_index (known_addresses, NMPlatformIP6Address, i); guint32 lifetime, preferred; - if (!_address_get_lifetime ((NMPlatformIPAddress *) known_address, now, &lifetime, &preferred)) + /* add a padding of 5 seconds to avoid potential races. */ + if (!_address_get_lifetime ((NMPlatformIPAddress *) known_address, now, 5, &lifetime, &preferred)) continue; if (!nm_platform_ip6_address_add (ifindex, known_address->address, @@ -2079,7 +2081,7 @@ _lifetime_to_string (guint32 timestamp, guint32 lifetime, gint32 now, char *buf, return "forever"; g_snprintf (buf, buf_size, "%usec", - _rebase_relative_time_on_now (timestamp, lifetime, now)); + _rebase_relative_time_on_now (timestamp, lifetime, now, 0)); return buf; } |