summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-03-15 17:29:58 +0100
committerThomas Haller <thaller@redhat.com>2016-03-15 18:28:43 +0100
commit6cb73224652e4b59f9c2d6e91e61b6e61a76c4a6 (patch)
tree42ba72285ace4875e7ce4a254319194ec60f35ca
parentca5da5d80f3a21847bb807021e2e40d25bca50d0 (diff)
downloadNetworkManager-6cb73224652e4b59f9c2d6e91e61b6e61a76c4a6.tar.gz
platform: remove padding for IP address lifetimes
We used to pad the lifetime since the beginning (commit f121995fad93eda886b2a34a8d79a45a5688b917). However, there is not race involved, since our platform cache is in sync with the messages from kernel (which didn't used to be the case). Also, when receiving a RA with a zero preferred time, we must not extend the address lifetime by 5 seconds, but instead deprecate the address immediately. https://bugzilla.gnome.org/show_bug.cgi?id=763513
-rw-r--r--src/nm-core-utils.c11
-rw-r--r--src/nm-core-utils.h4
-rw-r--r--src/platform/nm-platform.c20
3 files changed, 13 insertions, 22 deletions
diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c
index 52db9ced8e..0c557689fa 100644
--- a/src/nm-core-utils.c
+++ b/src/nm-core-utils.c
@@ -2976,8 +2976,7 @@ nm_utils_ip4_address_is_link_local (in_addr_t addr)
guint32
nm_utils_lifetime_rebase_relative_time_on_now (guint32 timestamp,
guint32 duration,
- guint32 now,
- guint32 padding)
+ guint32 now)
{
gint64 t;
@@ -2998,9 +2997,6 @@ nm_utils_lifetime_rebase_relative_time_on_now (guint32 timestamp,
/* For timestamp > now, just accept it and calculate the expected(?) result. */
t = (gint64) timestamp + (gint64) duration - (gint64) now;
- /* Optional padding to avoid potential races. */
- t += (gint64) padding;
-
if (t <= 0)
return 0;
if (t >= NM_PLATFORM_LIFETIME_PERMANENT)
@@ -3013,7 +3009,6 @@ nm_utils_lifetime_get (guint32 timestamp,
guint32 lifetime,
guint32 preferred,
guint32 now,
- guint32 padding,
guint32 *out_lifetime,
guint32 *out_preferred)
{
@@ -3030,13 +3025,13 @@ nm_utils_lifetime_get (guint32 timestamp,
} else {
if (!now)
now = nm_utils_get_monotonic_timestamp_s ();
- t_lifetime = nm_utils_lifetime_rebase_relative_time_on_now (timestamp, lifetime, now, padding);
+ t_lifetime = nm_utils_lifetime_rebase_relative_time_on_now (timestamp, lifetime, now);
if (!t_lifetime) {
*out_lifetime = 0;
*out_preferred = 0;
return FALSE;
}
- t_preferred = nm_utils_lifetime_rebase_relative_time_on_now (timestamp, preferred, now, padding);
+ t_preferred = nm_utils_lifetime_rebase_relative_time_on_now (timestamp, preferred, now);
*out_lifetime = t_lifetime;
*out_preferred = MIN (t_preferred, t_lifetime);
diff --git a/src/nm-core-utils.h b/src/nm-core-utils.h
index 7e1fdec470..15bc9014aa 100644
--- a/src/nm-core-utils.h
+++ b/src/nm-core-utils.h
@@ -402,14 +402,12 @@ void nm_utils_ifname_cpy (char *dst, const char *name);
guint32 nm_utils_lifetime_rebase_relative_time_on_now (guint32 timestamp,
guint32 duration,
- guint32 now,
- guint32 padding);
+ guint32 now);
gboolean nm_utils_lifetime_get (guint32 timestamp,
guint32 lifetime,
guint32 preferred,
guint32 now,
- guint32 padding,
guint32 *out_lifetime,
guint32 *out_preferred);
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 89f385ec96..6cc7e1e18f 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -49,8 +49,6 @@ const NMIPAddr nm_ip_addr_zero = NMIPAddrInit;
/*****************************************************************************/
-#define ADDRESS_LIFETIME_PADDING 5
-
G_STATIC_ASSERT (sizeof ( ((NMPlatformLink *) NULL)->addr.data ) == NM_UTILS_HWADDR_LEN_MAX);
G_STATIC_ASSERT (G_STRUCT_OFFSET (NMPlatformIPAddress, address_ptr) == G_STRUCT_OFFSET (NMPlatformIP4Address, address));
G_STATIC_ASSERT (G_STRUCT_OFFSET (NMPlatformIPAddress, address_ptr) == G_STRUCT_OFFSET (NMPlatformIP6Address, address));
@@ -2615,7 +2613,7 @@ nm_platform_ip6_address_get (NMPlatform *self, int ifindex, struct in6_addr addr
}
static gboolean
-array_contains_ip4_address (const GArray *addresses, const NMPlatformIP4Address *address, gint64 now, guint32 padding)
+array_contains_ip4_address (const GArray *addresses, const NMPlatformIP4Address *address, gint64 now)
{
guint len = addresses ? addresses->len : 0;
guint i;
@@ -2629,7 +2627,7 @@ array_contains_ip4_address (const GArray *addresses, const NMPlatformIP4Address
guint32 lifetime, preferred;
if (nm_utils_lifetime_get (candidate->timestamp, candidate->lifetime, candidate->preferred,
- now, padding, &lifetime, &preferred))
+ now, &lifetime, &preferred))
return TRUE;
}
}
@@ -2638,7 +2636,7 @@ array_contains_ip4_address (const GArray *addresses, const NMPlatformIP4Address
}
static gboolean
-array_contains_ip6_address (const GArray *addresses, const NMPlatformIP6Address *address, gint64 now, guint32 padding)
+array_contains_ip6_address (const GArray *addresses, const NMPlatformIP6Address *address, gint64 now)
{
guint len = addresses ? addresses->len : 0;
guint i;
@@ -2650,7 +2648,7 @@ array_contains_ip6_address (const GArray *addresses, const NMPlatformIP6Address
guint32 lifetime, preferred;
if (nm_utils_lifetime_get (candidate->timestamp, candidate->lifetime, candidate->preferred,
- now, padding, &lifetime, &preferred))
+ now, &lifetime, &preferred))
return TRUE;
}
}
@@ -2689,7 +2687,7 @@ nm_platform_ip4_address_sync (NMPlatform *self, int ifindex, const GArray *known
for (i = 0; i < addresses->len; i++) {
address = &g_array_index (addresses, NMPlatformIP4Address, i);
- if (!array_contains_ip4_address (known_addresses, address, now, ADDRESS_LIFETIME_PADDING))
+ if (!array_contains_ip4_address (known_addresses, address, now))
nm_platform_ip4_address_delete (self, ifindex, address->address, address->plen, address->peer_address);
}
g_array_free (addresses, TRUE);
@@ -2706,7 +2704,7 @@ nm_platform_ip4_address_sync (NMPlatform *self, int ifindex, const GArray *known
guint32 lifetime, preferred;
if (!nm_utils_lifetime_get (known_address->timestamp, known_address->lifetime, known_address->preferred,
- now, ADDRESS_LIFETIME_PADDING, &lifetime, &preferred))
+ now, &lifetime, &preferred))
continue;
if (!nm_platform_ip4_address_add (self, ifindex, known_address->address, known_address->plen,
@@ -2754,7 +2752,7 @@ nm_platform_ip6_address_sync (NMPlatform *self, int ifindex, const GArray *known
if (keep_link_local && IN6_IS_ADDR_LINKLOCAL (&address->address))
continue;
- if (!array_contains_ip6_address (known_addresses, address, now, ADDRESS_LIFETIME_PADDING))
+ if (!array_contains_ip6_address (known_addresses, address, now))
nm_platform_ip6_address_delete (self, ifindex, address->address, address->plen);
}
g_array_free (addresses, TRUE);
@@ -2768,7 +2766,7 @@ nm_platform_ip6_address_sync (NMPlatform *self, int ifindex, const GArray *known
guint32 lifetime, preferred;
if (!nm_utils_lifetime_get (known_address->timestamp, known_address->lifetime, known_address->preferred,
- now, ADDRESS_LIFETIME_PADDING, &lifetime, &preferred))
+ now, &lifetime, &preferred))
continue;
if (!nm_platform_ip6_address_add (self, ifindex, known_address->address,
@@ -3012,7 +3010,7 @@ _lifetime_to_string (guint32 timestamp, guint32 lifetime, gint32 now, char *buf,
return "forever";
g_snprintf (buf, buf_size, "%usec",
- nm_utils_lifetime_rebase_relative_time_on_now (timestamp, lifetime, now, 0));
+ nm_utils_lifetime_rebase_relative_time_on_now (timestamp, lifetime, now));
return buf;
}