From 36f4418636d484e16a38ddfc4f2755ff4f0f8468 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 27 Sep 2017 12:40:43 +0200 Subject: libnm: add nm_ip_route_equal_full() function Expose previously internal function nm_ip_route_equal_full(). It's just useful API. However, add a @cmp_flags argument, so that in the future we could extend it. --- libnm-core/nm-setting-ip-config.c | 26 +++++++++++++++++--------- libnm-core/nm-setting-ip-config.h | 11 +++++++++++ libnm/libnm.ver | 1 + 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c index dd09baa62c..69dd91b40b 100644 --- a/libnm-core/nm-setting-ip-config.c +++ b/libnm-core/nm-setting-ip-config.c @@ -753,18 +753,22 @@ nm_ip_route_unref (NMIPRoute *route) } /** - * _nm_ip_route_equal: + * nm_ip_route_equal_full: * @route: the #NMIPRoute * @other: the #NMIPRoute to compare @route to. - * @consider_attributes: whether to compare attributes too + * @cmp_flags: tune how to compare attributes. Currently only + * NM_IP_ROUTE_EQUAL_CMP_FLAGS_NONE (0) and NM_IP_ROUTE_EQUAL_CMP_FLAGS_WITH_ATTRS (1) + * is supported. * * Determines if two #NMIPRoute objects contain the same destination, prefix, * next hop, and metric. * * Returns: %TRUE if the objects contain the same values, %FALSE if they do not. + * + * Since: 1.10 **/ -static gboolean -_nm_ip_route_equal (NMIPRoute *route, NMIPRoute *other, gboolean consider_attributes) +gboolean +nm_ip_route_equal_full (NMIPRoute *route, NMIPRoute *other, guint cmp_flags) { g_return_val_if_fail (route != NULL, FALSE); g_return_val_if_fail (route->refcount > 0, FALSE); @@ -772,12 +776,16 @@ _nm_ip_route_equal (NMIPRoute *route, NMIPRoute *other, gboolean consider_attrib g_return_val_if_fail (other != NULL, FALSE); g_return_val_if_fail (other->refcount > 0, FALSE); + g_return_val_if_fail (NM_IN_SET (cmp_flags, + NM_IP_ROUTE_EQUAL_CMP_FLAGS_NONE, + NM_IP_ROUTE_EQUAL_CMP_FLAGS_WITH_ATTRS), FALSE); + if ( route->prefix != other->prefix || route->metric != other->metric || strcmp (route->dest, other->dest) != 0 || g_strcmp0 (route->next_hop, other->next_hop) != 0) return FALSE; - if (consider_attributes) { + if (cmp_flags == NM_IP_ROUTE_EQUAL_CMP_FLAGS_WITH_ATTRS) { GHashTableIter iter; const char *key; GVariant *value, *value2; @@ -813,7 +821,7 @@ _nm_ip_route_equal (NMIPRoute *route, NMIPRoute *other, gboolean consider_attrib gboolean nm_ip_route_equal (NMIPRoute *route, NMIPRoute *other) { - return _nm_ip_route_equal (route, other, FALSE); + return nm_ip_route_equal_full (route, other, NM_IP_ROUTE_EQUAL_CMP_FLAGS_NONE); } /** @@ -2164,7 +2172,7 @@ nm_setting_ip_config_add_route (NMSettingIPConfig *setting, priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting); for (i = 0; i < priv->routes->len; i++) { - if (_nm_ip_route_equal (priv->routes->pdata[i], route, TRUE)) + if (nm_ip_route_equal_full (priv->routes->pdata[i], route, NM_IP_ROUTE_EQUAL_CMP_FLAGS_WITH_ATTRS)) return FALSE; } @@ -2217,7 +2225,7 @@ nm_setting_ip_config_remove_route_by_value (NMSettingIPConfig *setting, priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting); for (i = 0; i < priv->routes->len; i++) { - if (_nm_ip_route_equal (priv->routes->pdata[i], route, TRUE)) { + if (nm_ip_route_equal_full (priv->routes->pdata[i], route, NM_IP_ROUTE_EQUAL_CMP_FLAGS_WITH_ATTRS)) { g_ptr_array_remove_index (priv->routes, i); g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_ROUTES); return TRUE; @@ -2620,7 +2628,7 @@ compare_property (NMSetting *setting, if (a_priv->routes->len != b_priv->routes->len) return FALSE; for (i = 0; i < a_priv->routes->len; i++) { - if (!_nm_ip_route_equal (a_priv->routes->pdata[i], b_priv->routes->pdata[i], TRUE)) + if (!nm_ip_route_equal_full (a_priv->routes->pdata[i], b_priv->routes->pdata[i], NM_IP_ROUTE_EQUAL_CMP_FLAGS_WITH_ATTRS)) return FALSE; } return TRUE; diff --git a/libnm-core/nm-setting-ip-config.h b/libnm-core/nm-setting-ip-config.h index a3e4007c9e..16aa415684 100644 --- a/libnm-core/nm-setting-ip-config.h +++ b/libnm-core/nm-setting-ip-config.h @@ -92,6 +92,17 @@ void nm_ip_route_ref (NMIPRoute *route); void nm_ip_route_unref (NMIPRoute *route); gboolean nm_ip_route_equal (NMIPRoute *route, NMIPRoute *other); + +enum { + NM_IP_ROUTE_EQUAL_CMP_FLAGS_NONE = 0, + NM_IP_ROUTE_EQUAL_CMP_FLAGS_WITH_ATTRS = (1LL << 0), +}; + +NM_AVAILABLE_IN_1_10 +gboolean nm_ip_route_equal_full (NMIPRoute *route, + NMIPRoute *other, + guint cmp_flags); + NMIPRoute *nm_ip_route_dup (NMIPRoute *route); int nm_ip_route_get_family (NMIPRoute *route); diff --git a/libnm/libnm.ver b/libnm/libnm.ver index a2b8be52ef..5f3867c4f7 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -1185,6 +1185,7 @@ global: nm_client_connectivity_check_set_enabled; nm_device_dummy_get_hw_address; nm_device_ppp_get_type; + nm_ip_route_equal_full; nm_ip_route_table_sync_mode_get_type; nm_setting_bridge_get_group_forward_mask; nm_setting_ip_config_get_route_table_sync; -- cgit v1.2.1