summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-05-21 10:06:10 +0200
committerThomas Haller <thaller@redhat.com>2019-06-13 09:44:23 +0200
commit2905f880132958c70b7f0eacefe1dfb319bd7e71 (patch)
tree8de7217a76b34fb98aee1d3db76e19117c76c991
parent658f5b84defd43647c661bbf84f9e4175afdba27 (diff)
downloadNetworkManager-2905f880132958c70b7f0eacefe1dfb319bd7e71.tar.gz
settings: in have_connection_for_device() first skip over irrelevant connection types
nm_device_check_connection_compatible() is potentially expensive. Check first whether the connection candidate is of a relevant type, hoping that this check is cheaper and thus shortcuts other checks early.
-rw-r--r--src/settings/nm-settings.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index f1d0ee9495..f342d6b446 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -1594,7 +1594,6 @@ static gboolean
have_connection_for_device (NMSettings *self, NMDevice *device)
{
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
- NMSettingConnection *s_con;
NMSettingWired *s_wired;
const char *setting_hwaddr;
const char *perm_hw_addr;
@@ -1607,32 +1606,29 @@ have_connection_for_device (NMSettings *self, NMDevice *device)
/* Find a wired connection locked to the given MAC address, if any */
c_list_for_each_entry (sett_conn, &priv->connections_lst_head, _connections_lst) {
NMConnection *connection = nm_settings_connection_get_connection (sett_conn);
- const char *ctype, *iface;
+ NMSettingConnection *s_con = nm_connection_get_setting_connection (connection);
+ const char *ctype;
+ const char *iface;
- if (!nm_device_check_connection_compatible (device, connection, NULL))
+ ctype = nm_setting_connection_get_connection_type (s_con);
+ if (!NM_IN_STRSET (ctype, NM_SETTING_WIRED_SETTING_NAME,
+ NM_SETTING_PPPOE_SETTING_NAME))
continue;
- 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)
+ if (!nm_device_check_connection_compatible (device, connection, NULL))
continue;
- ctype = nm_setting_connection_get_connection_type (s_con);
- if ( strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME)
- && strcmp (ctype, NM_SETTING_PPPOE_SETTING_NAME))
+ iface = nm_setting_connection_get_interface_name (s_con);
+ if (nm_streq0 (iface, nm_device_get_iface (device)))
continue;
s_wired = nm_connection_get_setting_wired (connection);
-
if ( !s_wired
&& nm_streq (ctype, NM_SETTING_PPPOE_SETTING_NAME)) {
/* No wired setting; therefore the PPPoE connection applies to any device */
return TRUE;
}
- nm_assert (s_wired);
-
setting_hwaddr = nm_setting_wired_get_mac_address (s_wired);
if (setting_hwaddr) {
/* A connection mac-locked to this device */