config: move some spec-match-list handling from config to core
NMConfig accepted no-auto-default and ignore-carrier lists with untagged specs (ie, interface names not prefixed with "interface-name:" and hardware addresses not prefixed with "mac:"). Move that handling into nm_match_spec_interface_name() and nm_match_spec_hwaddr() instead.
This commit is contained in:
@@ -589,6 +589,9 @@ nm_match_spec_hwaddr (const GSList *specs, const char *hwaddr)
|
|||||||
|
|
||||||
g_return_val_if_fail (hwaddr != NULL, FALSE);
|
g_return_val_if_fail (hwaddr != NULL, FALSE);
|
||||||
|
|
||||||
|
if (nm_match_spec_string (specs, hwaddr))
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
hwaddr_match = g_strdup_printf ("mac:%s", hwaddr);
|
hwaddr_match = g_strdup_printf ("mac:%s", hwaddr);
|
||||||
matched = nm_match_spec_string (specs, hwaddr_match);
|
matched = nm_match_spec_string (specs, hwaddr_match);
|
||||||
g_free (hwaddr_match);
|
g_free (hwaddr_match);
|
||||||
@@ -603,6 +606,9 @@ nm_match_spec_interface_name (const GSList *specs, const char *interface_name)
|
|||||||
|
|
||||||
g_return_val_if_fail (interface_name != NULL, FALSE);
|
g_return_val_if_fail (interface_name != NULL, FALSE);
|
||||||
|
|
||||||
|
if (nm_match_spec_string (specs, interface_name))
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
iface_match = g_strdup_printf ("interface-name:%s", interface_name);
|
iface_match = g_strdup_printf ("interface-name:%s", interface_name);
|
||||||
matched = nm_match_spec_string (specs, iface_match);
|
matched = nm_match_spec_string (specs, iface_match);
|
||||||
g_free (iface_match);
|
g_free (iface_match);
|
||||||
|
@@ -38,7 +38,6 @@ nm_config_device_spec_match_list (NMConfigDevice *self, const char **config_spec
|
|||||||
{
|
{
|
||||||
GSList *specs = NULL;
|
GSList *specs = NULL;
|
||||||
gboolean match;
|
gboolean match;
|
||||||
char buf[NM_UTILS_HWADDR_LEN_MAX + 1], *tmp;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
g_return_val_if_fail (NM_IS_CONFIG_DEVICE (self), FALSE);
|
g_return_val_if_fail (NM_IS_CONFIG_DEVICE (self), FALSE);
|
||||||
@@ -46,28 +45,13 @@ nm_config_device_spec_match_list (NMConfigDevice *self, const char **config_spec
|
|||||||
if (!config_specs)
|
if (!config_specs)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* For compatibility, we allow an untagged MAC address, and for convenience,
|
for (i = 0; config_specs[i]; i++)
|
||||||
* we allow untagged interface names as well.
|
specs = g_slist_prepend (specs, (char *) config_specs[i]);
|
||||||
*/
|
|
||||||
for (i = 0; config_specs[i]; i++) {
|
|
||||||
if (g_strcmp0 (config_specs[i], "*") == 0)
|
|
||||||
specs = g_slist_prepend (specs, g_strdup (config_specs[i]));
|
|
||||||
else if (nm_utils_iface_valid_name (config_specs[i]))
|
|
||||||
specs = g_slist_prepend (specs, g_strdup_printf ("interface-name:%s", config_specs[i]));
|
|
||||||
else if ( nm_utils_hwaddr_aton (config_specs[i], ARPHRD_ETHER, buf)
|
|
||||||
|| nm_utils_hwaddr_aton (config_specs[i], ARPHRD_INFINIBAND, buf)) {
|
|
||||||
tmp = g_ascii_strdown (config_specs[i], -1);
|
|
||||||
specs = g_slist_prepend (specs, g_strdup_printf ("mac:%s", tmp));
|
|
||||||
g_free (tmp);
|
|
||||||
} else
|
|
||||||
specs = g_slist_prepend (specs, g_strdup (config_specs[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
specs = g_slist_reverse (specs);
|
specs = g_slist_reverse (specs);
|
||||||
|
|
||||||
match = NM_CONFIG_DEVICE_GET_INTERFACE (self)->spec_match_list (self, specs);
|
match = NM_CONFIG_DEVICE_GET_INTERFACE (self)->spec_match_list (self, specs);
|
||||||
|
|
||||||
g_slist_free_full (specs, g_free);
|
g_slist_free (specs);
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,6 +2,7 @@ AM_CPPFLAGS = \
|
|||||||
-I$(top_srcdir)/include \
|
-I$(top_srcdir)/include \
|
||||||
-I$(top_srcdir)/libnm-util \
|
-I$(top_srcdir)/libnm-util \
|
||||||
-I$(top_builddir)/libnm-util \
|
-I$(top_builddir)/libnm-util \
|
||||||
|
-I$(top_srcdir)/src/ \
|
||||||
-I$(top_srcdir)/src/config \
|
-I$(top_srcdir)/src/config \
|
||||||
-DG_LOG_DOMAIN=\""NetworkManager"\" \
|
-DG_LOG_DOMAIN=\""NetworkManager"\" \
|
||||||
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
|
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include "nm-test-device.h"
|
#include "nm-test-device.h"
|
||||||
#include "nm-config-device.h"
|
#include "nm-config-device.h"
|
||||||
#include "nm-utils.h"
|
#include "nm-utils.h"
|
||||||
|
#include "NetworkManagerUtils.h"
|
||||||
|
|
||||||
static void nm_test_device_config_device_interface_init (NMConfigDeviceInterface *iface);
|
static void nm_test_device_config_device_interface_init (NMConfigDeviceInterface *iface);
|
||||||
|
|
||||||
@@ -60,15 +61,8 @@ static gboolean
|
|||||||
spec_match_list (NMConfigDevice *device, const GSList *specs)
|
spec_match_list (NMConfigDevice *device, const GSList *specs)
|
||||||
{
|
{
|
||||||
NMTestDevice *self = NM_TEST_DEVICE (device);
|
NMTestDevice *self = NM_TEST_DEVICE (device);
|
||||||
const GSList *iter;
|
|
||||||
const char *spec;
|
|
||||||
|
|
||||||
for (iter = specs; iter; iter = iter->next) {
|
return nm_match_spec_hwaddr (specs, self->hwaddr);
|
||||||
spec = iter->data;
|
|
||||||
if (g_str_has_prefix (spec, "mac:") && !strcmp (spec + 4, self->hwaddr))
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const guint8 *
|
static const guint8 *
|
||||||
|
Reference in New Issue
Block a user