device: support match.interface-name
Add support for matching a connection with the new match.interface-name property.
This commit is contained in:
@@ -5511,6 +5511,9 @@ check_connection_compatible (NMDevice *self, NMConnection *connection, GError **
|
|||||||
gs_free_error GError *local = NULL;
|
gs_free_error GError *local = NULL;
|
||||||
gs_free char *conn_iface = NULL;
|
gs_free char *conn_iface = NULL;
|
||||||
NMDeviceClass *klass;
|
NMDeviceClass *klass;
|
||||||
|
const char *const *patterns;
|
||||||
|
NMSettingMatch *s_match;
|
||||||
|
guint num_patterns;
|
||||||
|
|
||||||
klass = NM_DEVICE_GET_CLASS (self);
|
klass = NM_DEVICE_GET_CLASS (self);
|
||||||
if (klass->connection_type_check_compatible) {
|
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);
|
"cannot get interface name due to %s", local->message);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return TRUE;
|
} else if (!nm_streq0 (conn_iface, device_iface)) {
|
||||||
}
|
|
||||||
|
|
||||||
if (!nm_streq0 (conn_iface, device_iface)) {
|
|
||||||
nm_utils_error_set_literal (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
nm_utils_error_set_literal (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
||||||
"mismatching interface name");
|
"mismatching interface name");
|
||||||
return FALSE;
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <fnmatch.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -1730,6 +1731,33 @@ nm_match_spec_join (GSList *specs)
|
|||||||
return g_string_free (str, FALSE);
|
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 *
|
char *
|
||||||
|
@@ -215,6 +215,10 @@ NMMatchSpecMatchType nm_match_spec_config (const GSList *specs,
|
|||||||
GSList *nm_match_spec_split (const char *value);
|
GSList *nm_match_spec_split (const char *value);
|
||||||
char *nm_match_spec_join (GSList *specs);
|
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,
|
const char *nm_utils_get_ip_config_method (NMConnection *connection,
|
||||||
|
Reference in New Issue
Block a user