From 65771b80a6dbaa6dedb9edea9445bc00f9259da3 Mon Sep 17 00:00:00 2001 From: Francesco Giudici Date: Fri, 15 Jul 2016 14:38:00 +0200 Subject: [PATCH 1/4] cli: improve devices vs connection compatibility check report error message on device compatibility failures --- clients/cli/connections.c | 19 ++++++++++++------- libnm/nm-device-ethernet.c | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 09f0c00c3..46a386491 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -1927,17 +1927,22 @@ find_device_for_connection (NmCli *nmc, if (iface) { const char *dev_iface = nm_device_get_iface (dev); - if ( !g_strcmp0 (dev_iface, iface) - && nm_device_connection_compatible (dev, connection, NULL)) { - found_device = dev; + if (!nm_streq0 (dev_iface, iface)) + continue; + + if (!nm_device_connection_compatible (dev, connection, error)) { + g_prefix_error (error, _("device '%s' not compatible with connection '%s':"), + iface, nm_setting_connection_get_id (s_con)); + return FALSE; } + } else { - if (nm_device_connection_compatible (dev, connection, NULL)) { - found_device = dev; - } + if (!nm_device_connection_compatible (dev, connection, NULL)) + continue; } - if (found_device && ap && !strcmp (con_type, NM_SETTING_WIRELESS_SETTING_NAME) && NM_IS_DEVICE_WIFI (dev)) { + found_device = dev; + if (ap && !strcmp (con_type, NM_SETTING_WIRELESS_SETTING_NAME) && NM_IS_DEVICE_WIFI (dev)) { char *bssid_up = g_ascii_strup (ap, -1); const GPtrArray *aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (dev)); found_device = NULL; /* Mark as not found; set to the device again later, only if AP matches */ diff --git a/libnm/nm-device-ethernet.c b/libnm/nm-device-ethernet.c index 88a7c4324..65d28d033 100644 --- a/libnm/nm-device-ethernet.c +++ b/libnm/nm-device-ethernet.c @@ -228,8 +228,8 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro s_mac = nm_setting_wired_get_mac_address (s_wired); if (perm_addr) { if (!nm_utils_hwaddr_valid (perm_addr, ETH_ALEN)) { - g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, - _("Invalid device MAC address.")); + g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, + _("Invalid device MAC address %s."), perm_addr); return FALSE; } if (try_mac && s_mac && !nm_utils_hwaddr_matches (s_mac, -1, perm_addr, -1)) { From 55b9fd46eec0b18b8f93ae8bd3713641a9f02a4f Mon Sep 17 00:00:00 2001 From: Francesco Giudici Date: Thu, 21 Jul 2016 15:41:29 +0200 Subject: [PATCH 2/4] device: allow creation of default wired connection for virtual interfaces --- src/devices/nm-device-ethernet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 6efa4d99b..c077d020d 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -1421,7 +1421,7 @@ new_default_connection (NMDevice *self) if (nm_config_get_no_auto_default_for_device (nm_config_get (), self)) return NULL; - perm_hw_addr = nm_device_get_permanent_hw_address (self, FALSE); + perm_hw_addr = nm_device_get_permanent_hw_address (self, TRUE); if (!perm_hw_addr) return NULL; From ddc35f27eb2594d924755f2fc0ff39f4352a2a0c Mon Sep 17 00:00:00 2001 From: Francesco Giudici Date: Thu, 21 Jul 2016 18:12:37 +0200 Subject: [PATCH 3/4] device: enable checks against the MAC address of virtual devices enables (back) matching against 802-3-ethernet.mac-address and 802-3-ethenet.mac-address-blacklist connection parameters for MAC addresses belonging to virtual devices too. --- src/devices/nm-device-ethernet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index c077d020d..90d472da3 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -407,7 +407,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection) if (!match_subchans (self, s_wired, &try_mac)) return FALSE; - perm_hw_addr = nm_device_get_permanent_hw_address (device, FALSE); + perm_hw_addr = nm_device_get_permanent_hw_address (device, TRUE); mac = nm_setting_wired_get_mac_address (s_wired); if (perm_hw_addr) { if (try_mac && mac && !nm_utils_hwaddr_matches (mac, -1, perm_hw_addr, -1)) From 60a82e3ff27777c1fb5fc7e965d64138258df770 Mon Sep 17 00:00:00 2001 From: Francesco Giudici Date: Fri, 22 Jul 2016 14:49:31 +0200 Subject: [PATCH 4/4] device: enable MAC address check on virtual devices Virtual devices don't have a valid permanent hw address: when activating a connection against a specific interface, a check is performed on the device MAC address too: if it is an empty string, give a try to the currently assigned MAC address. --- libnm/nm-device-ethernet.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libnm/nm-device-ethernet.c b/libnm/nm-device-ethernet.c index 65d28d033..825ed7b39 100644 --- a/libnm/nm-device-ethernet.c +++ b/libnm/nm-device-ethernet.c @@ -227,6 +227,11 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro perm_addr = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (device)); s_mac = nm_setting_wired_get_mac_address (s_wired); if (perm_addr) { + /* Virtual devices will have empty permanent addr but they should not be excluded + * from the MAC address check specified in the connection */ + if (*perm_addr == 0) + perm_addr = nm_device_ethernet_get_hw_address (NM_DEVICE_ETHERNET (device)); + if (!nm_utils_hwaddr_valid (perm_addr, ETH_ALEN)) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, _("Invalid device MAC address %s."), perm_addr);