From d575381c28f26ed46cfed97f3b332add28c6936f Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Tue, 11 Jun 2013 11:21:17 -0300 Subject: [PATCH] settings: fix unmanaging of InfiniBand devices ifcfg-rh didn't let you unmanage an InfiniBand device by hardware address because it was recording the hardware address with uppercase letters, while nm_match_spec_hwaddr() required lowercase. Fix this by making nm_match_spec_hwaddr() match case-insensitively (and remove the manual lowercasing that several other places were doing to work around this.) keyfile didn't let you unmanage an InfiniBand device by hardware address because it only accepted ARPHRD_ETHER hardware addresses. Fix that by using nm_utils_hwaddr_valid() instead. --- src/NetworkManagerUtils.c | 12 +++--------- src/settings/plugins/example/plugin.c | 13 +------------ src/settings/plugins/ifcfg-rh/plugin.c | 13 +++++++++++-- src/settings/plugins/keyfile/plugin.c | 10 +--------- 4 files changed, 16 insertions(+), 32 deletions(-) diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index f973c5b570..71513a4f70 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -369,7 +369,7 @@ nm_match_spec_string (const GSList *specs, const char *match) const GSList *iter; for (iter = specs; iter; iter = g_slist_next (iter)) { - if (!strcmp ((const char *) iter->data, match)) + if (!g_ascii_strcasecmp ((const char *) iter->data, match)) return TRUE; } @@ -379,18 +379,12 @@ nm_match_spec_string (const GSList *specs, const char *match) gboolean nm_match_spec_hwaddr (const GSList *specs, const char *hwaddr) { - char *hwaddr_match, *p; + char *hwaddr_match; gboolean matched; g_return_val_if_fail (hwaddr != NULL, FALSE); - p = hwaddr_match = g_strdup_printf ("mac:%s", hwaddr); - - while (*p) { - *p = g_ascii_tolower (*p); - p++; - } - + hwaddr_match = g_strdup_printf ("mac:%s", hwaddr); matched = nm_match_spec_string (specs, hwaddr_match); g_free (hwaddr_match); return matched; diff --git a/src/settings/plugins/example/plugin.c b/src/settings/plugins/example/plugin.c index 8d4b627705..c8c1bff770 100644 --- a/src/settings/plugins/example/plugin.c +++ b/src/settings/plugins/example/plugin.c @@ -559,18 +559,7 @@ get_unmanaged_specs (NMSystemConfigInterface *config) ids = g_strsplit (str, ";", -1); for (i = 0; ids[i] != NULL; i++) { /* Verify unmanaged specification and add it to the list */ - if (!strncmp (ids[i], "mac:", 4) && ether_aton (ids[i] + 4)) { - char *p = ids[i]; - - /* To accept uppercase MACs in configuration file, we have to - * convert values to lowercase here. Unmanaged MACs in specs are - * always in lowercase. - */ - while (*p) { - *p = g_ascii_tolower (*p); - p++; - } - + if (!strncmp (ids[i], "mac:", 4) && nm_utils_hwaddr_valid (ids[i] + 4)) { specs = g_slist_append (specs, ids[i]); } else if (!strncmp (ids[i], "interface-name:", 15) && nm_utils_iface_valid_name (ids[i] + 15)) { specs = g_slist_append (specs, ids[i]); diff --git a/src/settings/plugins/ifcfg-rh/plugin.c b/src/settings/plugins/ifcfg-rh/plugin.c index 13edfb17ea..e7494826e7 100644 --- a/src/settings/plugins/ifcfg-rh/plugin.c +++ b/src/settings/plugins/ifcfg-rh/plugin.c @@ -147,8 +147,17 @@ _internal_new_connection (SCPluginIfcfg *self, PLUGIN_PRINT (IFCFG_PLUGIN_NAME, " read connection '%s'", cid); if (nm_ifcfg_connection_get_unmanaged_spec (connection)) { - PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "Ignoring connection '%s' and its " - "device due to NM_CONTROLLED/BRIDGE/VLAN.", cid); + const char *spec; + const char *device_id; + + spec = nm_ifcfg_connection_get_unmanaged_spec (connection); + device_id = strchr (spec, ':'); + if (device_id) + device_id++; + else + device_id = spec; + PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "Ignoring connection '%s' / device '%s' " + "due to NM_CONTROLLED/BRIDGE/VLAN.", cid, device_id); } else { /* Wait for the connection to become unmanaged once it knows the * hardware IDs of its device, if/when the device gets plugged in. diff --git a/src/settings/plugins/keyfile/plugin.c b/src/settings/plugins/keyfile/plugin.c index b216eda246..52cb36d37b 100644 --- a/src/settings/plugins/keyfile/plugin.c +++ b/src/settings/plugins/keyfile/plugin.c @@ -412,15 +412,7 @@ get_unmanaged_specs (NMSystemConfigInterface *config) for (i = 0; udis[i] != NULL; i++) { /* Verify unmanaged specification and add it to the list */ - if (!strncmp (udis[i], "mac:", 4) && ether_aton (udis[i] + 4)) { - char *p = udis[i]; - - /* To accept uppercase MACs in configuration file, we have to convert values to lowercase here. - * Unmanaged MACs in specs are always in lowercase. */ - while (*p) { - *p = g_ascii_tolower (*p); - p++; - } + if (!strncmp (udis[i], "mac:", 4) && nm_utils_hwaddr_valid (udis[i] + 4)) { specs = g_slist_append (specs, udis[i]); } else if (!strncmp (udis[i], "interface-name:", 15) && nm_utils_iface_valid_name (udis[i] + 15)) { specs = g_slist_append (specs, udis[i]);