From f1d31e36da79ae9676fa0ed6b91665f2fb213227 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Thu, 11 Apr 2013 10:41:49 -0400 Subject: [PATCH] settings: consider :interface-name in default wired connection matching The code to check if an ethernet device had a matching connection was not taking NMSettingConnection:interface-name into account, meaning it might think a device had a matching connection when that connection actually only matched a different device. Fix this by calling nm_setting_connection_get_interface_name() rather than nm_connection_get_virtual_iface_name() (which would always be NULL for ethernet connections anyway). Also, simplify the code a bit. https://bugzilla.gnome.org/show_bug.cgi?id=696722 --- src/settings/nm-settings.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 4c9203eb6f..0afe100ecf 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -1307,7 +1307,6 @@ have_connection_for_device (NMSettings *self, NMDevice *device) const GByteArray *setting_mac; const guint8 *hwaddr; guint hwaddr_len = 0; - gboolean ret = FALSE; g_return_val_if_fail (NM_IS_SETTINGS (self), FALSE); @@ -1320,27 +1319,21 @@ have_connection_for_device (NMSettings *self, NMDevice *device) const char *ctype, *iface; s_con = nm_connection_get_setting_connection (connection); + + iface = nm_setting_connection_get_interface_name (s_con); + if (iface && strcmp (iface, nm_device_get_iface (device)) != 0) + continue; + ctype = nm_setting_connection_get_connection_type (s_con); - - iface = nm_connection_get_virtual_iface_name (connection); - if (iface) { - if (!strcmp (iface, nm_device_get_iface (device))) { - ret = TRUE; - break; - } else - continue; - } - if ( strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME) && strcmp (ctype, NM_SETTING_PPPOE_SETTING_NAME)) continue; s_wired = nm_connection_get_setting_wired (connection); - /* No wired setting; therefore the PPPoE connection applies to any device */ if (!s_wired && !strcmp (ctype, NM_SETTING_PPPOE_SETTING_NAME)) { - ret = TRUE; - break; + /* No wired setting; therefore the PPPoE connection applies to any device */ + return TRUE; } g_assert (s_wired != NULL); @@ -1349,18 +1342,15 @@ have_connection_for_device (NMSettings *self, NMDevice *device) if (setting_mac) { /* A connection mac-locked to this device */ if (hwaddr_len == setting_mac->len && - !memcmp (setting_mac->data, hwaddr, hwaddr_len)) { - ret = TRUE; - break; - } + !memcmp (setting_mac->data, hwaddr, hwaddr_len)) + return TRUE; } else { /* A connection that applies to any wired device */ - ret = TRUE; - break; + return TRUE; } } - return ret; + return FALSE; } #define DEFAULT_WIRED_TAG "default-wired"