summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2014-09-29 17:58:44 +0200
committerLubomir Rintel <lkundrak@v3.sk>2014-12-11 11:49:29 +0100
commit85b811cc7c83eea19020dbf2d03cf085f5fa2097 (patch)
treea318ecb34bc7b0d799da0609ff69c2f1ba147513
parented78d3b3dc1406f6a1186b482a160452527cba6e (diff)
downloadNetworkManager-85b811cc7c83eea19020dbf2d03cf085f5fa2097.tar.gz
platform: refactor the object comparison logic into a separate function
One from libnl is not good enough (see comment).
-rw-r--r--src/platform/nm-linux-platform.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 668acdb933..3cf4cc8306 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -1880,6 +1880,33 @@ _rtnl_addr_timestamps_equal_fuzzy (guint32 ts1, guint32 ts2)
return diff <= 2;
}
+static gboolean
+nm_nl_object_diff (ObjectType type, struct nl_object *_a, struct nl_object *_b)
+{
+ if (nl_object_diff (_a, _b)) {
+ /* libnl thinks objects are different*/
+ return TRUE;
+ }
+
+ if (type == OBJECT_TYPE_IP4_ADDRESS || type == OBJECT_TYPE_IP6_ADDRESS) {
+ struct rtnl_addr *a = (struct rtnl_addr *) _a;
+ struct rtnl_addr *b = (struct rtnl_addr *) _b;
+
+ /* libnl nl_object_diff() ignores differences in timestamp. Let's care about
+ * them (if they are large enough).
+ *
+ * Note that these valid and preferred timestamps are absolute, after
+ * _rtnl_addr_hack_lifetimes_rel_to_abs(). */
+ if ( !_rtnl_addr_timestamps_equal_fuzzy (rtnl_addr_get_preferred_lifetime (a),
+ rtnl_addr_get_preferred_lifetime (b))
+ || !_rtnl_addr_timestamps_equal_fuzzy (rtnl_addr_get_valid_lifetime (a),
+ rtnl_addr_get_valid_lifetime (b)))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
/* This function does all the magic to avoid race conditions caused
* by concurrent usage of synchronous commands and an asynchronous cache. This
* might be a nice future addition to libnl but it requires to do all operations
@@ -1985,24 +2012,9 @@ event_notification (struct nl_msg *msg, gpointer user_data)
* This also catches notifications for internal addition or change, unless
* another action occured very soon after it.
*/
- if (!nl_object_diff (kernel_object, cached_object)) {
- if (type == OBJECT_TYPE_IP4_ADDRESS || type == OBJECT_TYPE_IP6_ADDRESS) {
- struct rtnl_addr *c = (struct rtnl_addr *) cached_object;
- struct rtnl_addr *k = (struct rtnl_addr *) kernel_object;
-
- /* libnl nl_object_diff() ignores differences in timestamp. Let's care about
- * them (if they are large enough).
- *
- * Note that these valid and preferred timestamps are absolute, after
- * _rtnl_addr_hack_lifetimes_rel_to_abs(). */
- if ( _rtnl_addr_timestamps_equal_fuzzy (rtnl_addr_get_preferred_lifetime (c),
- rtnl_addr_get_preferred_lifetime (k))
- && _rtnl_addr_timestamps_equal_fuzzy (rtnl_addr_get_valid_lifetime (c),
- rtnl_addr_get_valid_lifetime (k)))
- return NL_OK;
- } else
- return NL_OK;
- }
+ if (!nm_nl_object_diff (type, kernel_object, cached_object))
+ return NL_OK;
+
/* Handle external change */
nl_cache_remove (cached_object);
nle = nl_cache_add (cache, kernel_object);