mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-01 23:30:13 +01:00
platform: refactor the object comparison logic into a separate function
One from libnl is not good enough (see comment).
This commit is contained in:
parent
ed78d3b3dc
commit
85b811cc7c
1 changed files with 29 additions and 17 deletions
|
|
@ -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;
|
||||
if (!nm_nl_object_diff (type, kernel_object, cached_object))
|
||||
return NL_OK;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
/* Handle external change */
|
||||
nl_cache_remove (cached_object);
|
||||
nle = nl_cache_add (cache, kernel_object);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue