summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-06-16 18:20:40 +0200
committerThomas Haller <thaller@redhat.com>2017-06-16 18:38:20 +0200
commit7fc80e6ca250320efaf7a64e1b975aaa2cca52cd (patch)
tree4a5f57578b0ccaf17b8395a1dbcfc589d3708728
parent6c8fe5754c0585e1837b037ab9266df59127d07a (diff)
downloadNetworkManager-th/connection-match-indicated.tar.gz
device: add "indicated" argument to nm_utils_match_connection()th/connection-match-indicated
The matching works fuzzy and is not reliable. That is why we store which connection should be assumed after restart in the state file of NetworkManager. In that case, we don't need to do a full check (with the possibility of a false-reject). Just check for the minimum required properties: the type and slave-type. Yes, if the user modifies the connection while restarting NM, then we might wrongly assume a connection that no longer would match. But NM should not read minds, it should do as indicated.
-rw-r--r--src/NetworkManagerUtils.c24
-rw-r--r--src/NetworkManagerUtils.h1
-rw-r--r--src/nm-manager.c2
-rw-r--r--src/tests/test-general.c2
4 files changed, 27 insertions, 2 deletions
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c
index ecb1d8ae7c..72926df1ef 100644
--- a/src/NetworkManagerUtils.c
+++ b/src/NetworkManagerUtils.c
@@ -708,6 +708,10 @@ check_possible_match (NMConnection *orig,
* @connections: a (optionally pre-sorted) list of connections from which to
* find a matching connection to @original based on "inferrable" properties
* @original: the #NMConnection to find a match for from @connections
+ * @indicated: whether the match is already hinted/indicated. That is the
+ * case when we found the connection in the state file from a previous run.
+ * In this case, we perform a relexed check, as we have a good hint
+ * that the connection actually matches.
* @device_has_carrier: pass %TRUE if the device that generated @original has
* a carrier, %FALSE if not
* @match_filter_func: a function to check whether each connection from @connections
@@ -727,6 +731,7 @@ check_possible_match (NMConnection *orig,
NMConnection *
nm_utils_match_connection (NMConnection *const*connections,
NMConnection *original,
+ gboolean indicated,
gboolean device_has_carrier,
gint64 default_v4_metric,
gint64 default_v6_metric,
@@ -747,7 +752,24 @@ nm_utils_match_connection (NMConnection *const*connections,
continue;
}
- if (!nm_connection_diff (original, candidate, NM_SETTING_COMPARE_FLAG_INFERRABLE, &diffs)) {
+ if (indicated) {
+ NMSettingConnection *s_orig, *s_cand;
+
+ s_orig = nm_connection_get_setting_connection (original);
+ s_cand = nm_connection_get_setting_connection (candidate);
+
+ /* It is indidcated that this connectin matches. Assume we have
+ * a match, but check for particular differences that let us
+ * reject the candidate. */
+ if (!nm_streq0 (nm_setting_connection_get_connection_type (s_orig),
+ nm_setting_connection_get_connection_type (s_cand)))
+ continue;
+ if (!nm_streq0 (nm_setting_connection_get_slave_type (s_orig),
+ nm_setting_connection_get_slave_type (s_cand)))
+ continue;
+
+ /* this is good enough for a match. */
+ } else if (!nm_connection_diff (original, candidate, NM_SETTING_COMPARE_FLAG_INFERRABLE, &diffs)) {
if (!best_match) {
best_match = check_possible_match (original, candidate, diffs, device_has_carrier,
default_v4_metric, default_v6_metric);
diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h
index c20f2439d4..e5f28b2729 100644
--- a/src/NetworkManagerUtils.h
+++ b/src/NetworkManagerUtils.h
@@ -41,6 +41,7 @@ typedef gboolean (NMUtilsMatchFilterFunc) (NMConnection *connection, gpointer us
NMConnection *nm_utils_match_connection (NMConnection *const*connections,
NMConnection *original,
+ gboolean indicated,
gboolean device_has_carrier,
gint64 default_v4_metric,
gint64 default_v6_metric,
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 3bc92f32aa..faabeb2b38 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -1804,6 +1804,7 @@ get_existing_connection (NMManager *self,
matched = NM_SETTINGS_CONNECTION (nm_utils_match_connection (connections,
connection,
+ TRUE,
nm_device_has_carrier (device),
nm_device_get_ip4_route_metric (device),
nm_device_get_ip6_route_metric (device),
@@ -1833,6 +1834,7 @@ get_existing_connection (NMManager *self,
matched = NM_SETTINGS_CONNECTION (nm_utils_match_connection ((NMConnection *const*) connections,
connection,
+ FALSE,
nm_device_has_carrier (device),
nm_device_get_ip4_route_metric (device),
nm_device_get_ip6_route_metric (device),
diff --git a/src/tests/test-general.c b/src/tests/test-general.c
index 37bbc5ca9b..a528147e41 100644
--- a/src/tests/test-general.c
+++ b/src/tests/test-general.c
@@ -333,7 +333,7 @@ _match_connection (GSList *connections,
}
list[i] = NULL;
- return nm_utils_match_connection (list, original, device_has_carrier, default_v4_metric, default_v6_metric, NULL, NULL);
+ return nm_utils_match_connection (list, original, FALSE, device_has_carrier, default_v4_metric, default_v6_metric, NULL, NULL);
}
static void