summaryrefslogtreecommitdiff
path: root/libnm-core
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-06-27 17:00:55 +0200
committerThomas Haller <thaller@redhat.com>2018-07-24 09:39:09 +0200
commit2a242d39463cfe88b2a509c801eba07f9c778df5 (patch)
tree59474d55dc74ba39274a103fc2e8e3780023ceff /libnm-core
parent33dd520668c75dd5573b9bced7b6379bb4a98d77 (diff)
core: give better error reason why device is incompatible with profile
Note the special error codes NM_UTILS_ERROR_CONNECTION_AVAILABLE_*. This will be used to determine, whether the profile is fundamentally incompatible with the device, or whether just some other properties mismatch. That information will be importand during a plain `nmcli connection up`, where NetworkManager searches all devices for a device to activate. If no device is found (and multiple errors happened), we want to show the error that is most likely relevant for the user. Also note, how NMDevice's check_connection_compatible() uses the new class field "device_class->connection_type_check_compatible" to simplify checks for compatible profiles. The error reason is still unused.
Diffstat (limited to 'libnm-core')
-rw-r--r--libnm-core/nm-connection.c34
-rw-r--r--libnm-core/nm-core-internal.h4
2 files changed, 38 insertions, 0 deletions
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c
index 2f8cb4e90..29fdd9790 100644
--- a/libnm-core/nm-connection.c
+++ b/libnm-core/nm-connection.c
@@ -225,6 +225,40 @@ nm_connection_get_setting_by_name (NMConnection *connection, const char *name)
return type ? _connection_get_setting (connection, type) : NULL;
}
+/*****************************************************************************/
+
+gpointer /* (NMSetting *) */
+_nm_connection_check_main_setting (NMConnection *connection,
+ const char *setting_name,
+ GError **error)
+{
+ NMSetting *setting;
+
+ nm_assert (NM_IS_CONNECTION (connection));
+ nm_assert (setting_name);
+
+ if (!nm_connection_is_type (connection, setting_name)) {
+ nm_utils_error_set (error,
+ NM_UTILS_ERROR_CONNECTION_AVAILABLE_INCOMPATIBLE,
+ "connection type is not \"%s\"",
+ setting_name);
+ return NULL;
+ }
+
+ setting = nm_connection_get_setting_by_name (connection, setting_name);
+ if (!setting) {
+ nm_utils_error_set (error,
+ NM_UTILS_ERROR_CONNECTION_AVAILABLE_INCOMPATIBLE,
+ "connection misses \"%s\" settings",
+ setting_name);
+ return NULL;
+ }
+
+ return setting;
+}
+
+/*****************************************************************************/
+
static gboolean
validate_permissions_type (GVariant *variant, GError **error)
{
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h
index 3808a9e61..4945118ff 100644
--- a/libnm-core/nm-core-internal.h
+++ b/libnm-core/nm-core-internal.h
@@ -140,6 +140,10 @@ gboolean _nm_connection_replace_settings (NMConnection *connection,
NMSettingParseFlags parse_flags,
GError **error);
+gpointer _nm_connection_check_main_setting (NMConnection *connection,
+ const char *setting_name,
+ GError **error);
+
/**
* NMSettingVerifyResult:
* @NM_SETTING_VERIFY_SUCCESS: the setting verifies successfully