diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 908a0b5359..f2a9f3fa52 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -5511,6 +5511,9 @@ check_connection_compatible (NMDevice *self, NMConnection *connection, GError ** gs_free_error GError *local = NULL; gs_free char *conn_iface = NULL; NMDeviceClass *klass; + const char *const *patterns; + NMSettingMatch *s_match; + guint num_patterns; klass = NM_DEVICE_GET_CLASS (self); if (klass->connection_type_check_compatible) { @@ -5534,15 +5537,23 @@ check_connection_compatible (NMDevice *self, NMConnection *connection, GError ** "cannot get interface name due to %s", local->message); return FALSE; } - return TRUE; - } - - if (!nm_streq0 (conn_iface, device_iface)) { + } else if (!nm_streq0 (conn_iface, device_iface)) { nm_utils_error_set_literal (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY, "mismatching interface name"); return FALSE; } + s_match = (NMSettingMatch *) nm_connection_get_setting (connection, + NM_TYPE_SETTING_MATCH); + if (s_match) { + patterns = nm_setting_match_get_interface_names (s_match, &num_patterns); + if (!nm_wildcard_match_check (device_iface, patterns, num_patterns)) { + nm_utils_error_set_literal (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY, + "device does not satisfy match.interface-name property"); + return FALSE; + } + } + return TRUE; } diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index 51caf8bdfc..9aab919ebf 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -1730,6 +1731,33 @@ nm_match_spec_join (GSList *specs) return g_string_free (str, FALSE); } +gboolean +nm_wildcard_match_check (const char *str, + const char *const *patterns, + guint num_patterns) +{ + guint i, neg = 0; + + for (i = 0; i < num_patterns; i++) { + if (patterns[i][0] == '!') { + neg++; + if (!fnmatch (patterns[i] + 1, str, 0)) + return FALSE; + } + } + + if (neg == num_patterns) + return TRUE; + + for (i = 0; i < num_patterns; i++) { + if ( patterns[i][0] != '!' + && !fnmatch (patterns[i], str, 0)) + return TRUE; + } + + return FALSE; +} + /*****************************************************************************/ char * diff --git a/src/nm-core-utils.h b/src/nm-core-utils.h index fe429a72e9..53c72e16f9 100644 --- a/src/nm-core-utils.h +++ b/src/nm-core-utils.h @@ -215,6 +215,10 @@ NMMatchSpecMatchType nm_match_spec_config (const GSList *specs, GSList *nm_match_spec_split (const char *value); char *nm_match_spec_join (GSList *specs); +gboolean nm_wildcard_match_check (const char *str, + const char *const *patterns, + guint num_patterns); + /*****************************************************************************/ const char *nm_utils_get_ip_config_method (NMConnection *connection,