From 6f013183e8265c8498d52d223c6ee1ce3cdf07d5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 9 Jun 2014 10:28:55 +0200 Subject: [PATCH] platform: extend nm_platform_ip_address_cmp_expiry() to handle addresses without timestamp If the timestamp is set to zero, the to_string() functions treat the lifetime as based on *now*. For nm_platform_ip_address_cmp_expiry() this makes no sense, because there is no absolute exiry to compare. Instead compare them as expire earlier then the other address. Signed-off-by: Thomas Haller --- src/platform/nm-platform.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index e15de984f7..542b0faab2 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -2506,31 +2506,32 @@ nm_platform_ip6_route_cmp (const NMPlatformIP6Route *a, const NMPlatformIP6Route int nm_platform_ip_address_cmp_expiry (const NMPlatformIPAddress *a, const NMPlatformIPAddress *b) { - gint64 ta, tb; + gint64 ta = 0, tb = 0; _CMP_POINTER (a, b); if (a->lifetime == NM_PLATFORM_LIFETIME_PERMANENT || a->lifetime == 0) ta = G_MAXINT64; - else + else if (a->timestamp) ta = ((gint64) a->timestamp) + a->lifetime; if (b->lifetime == NM_PLATFORM_LIFETIME_PERMANENT || b->lifetime == 0) tb = G_MAXINT64; - else + else if (b->timestamp) tb = ((gint64) b->timestamp) + b->lifetime; if (ta == tb) { /* if the lifetime is equal, compare the preferred time. */ + ta = tb = 0; if (a->preferred == NM_PLATFORM_LIFETIME_PERMANENT || a->lifetime == 0 /* liftime==0 means permanent! */) ta = G_MAXINT64; - else + else if (a->timestamp) ta = ((gint64) a->timestamp) + a->preferred; if (b->preferred == NM_PLATFORM_LIFETIME_PERMANENT|| b->lifetime == 0) tb = G_MAXINT64; - else + else if (b->timestamp) tb = ((gint64) b->timestamp) + b->preferred; if (ta == tb)