summaryrefslogtreecommitdiff
path: root/libnm-core
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 18:58:53 +0200
commitf83e6b974324528a1d792b1d9c09fd8fb18446d3 (patch)
tree23042ddbfad91e82e76c83d3a98a1710adfe17ff /libnm-core
parentf05ebc426142090628b196438fb0a293fcd53c2e (diff)
downloadNetworkManager-f83e6b974324528a1d792b1d9c09fd8fb18446d3.tar.gz
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.
Diffstat (limited to 'libnm-core')
-rw-r--r--libnm-core/nm-setting-ip-config.c26
-rw-r--r--libnm-core/nm-setting-ip-config.h11
2 files changed, 28 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);