diff options
author | Thomas Haller <thaller@redhat.com> | 2019-05-21 10:06:10 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-06-13 16:10:53 +0200 |
commit | be0018382d4d60a1b550651e623f0186e729363b (patch) | |
tree | 2917804ce6e22dfd07d7ea3b122317fd41840738 | |
parent | 179134bbdce4ba0a92ea9f6573f47f42dca6b231 (diff) | |
download | NetworkManager-be0018382d4d60a1b550651e623f0186e729363b.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.c | 22 |
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 */ |