summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-09-27 12:40:43 +0200
committerThomas Haller <thaller@redhat.com>2017-09-27 13:02:51 +0200
commit36f4418636d484e16a38ddfc4f2755ff4f0f8468 (patch)
treec584b97cb028a3e1acc319b2240b30bcaa704dd8
parent30747e31f3de89a92932c3ae99da8ed1e1bfa5ba (diff)
downloadNetworkManager-th/libnm-ip-route-equals.tar.gz
libnm: add nm_ip_route_equal_full() functionth/libnm-ip-route-equals
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.
-rw-r--r--libnm-core/nm-setting-ip-config.c26
-rw-r--r--libnm-core/nm-setting-ip-config.h11
-rw-r--r--libnm/libnm.ver1
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;