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.
This commit is contained in:
@@ -1594,7 +1594,6 @@ static gboolean
|
|||||||
have_connection_for_device (NMSettings *self, NMDevice *device)
|
have_connection_for_device (NMSettings *self, NMDevice *device)
|
||||||
{
|
{
|
||||||
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
|
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
|
||||||
NMSettingConnection *s_con;
|
|
||||||
NMSettingWired *s_wired;
|
NMSettingWired *s_wired;
|
||||||
const char *setting_hwaddr;
|
const char *setting_hwaddr;
|
||||||
const char *perm_hw_addr;
|
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 */
|
/* 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) {
|
c_list_for_each_entry (sett_conn, &priv->connections_lst_head, _connections_lst) {
|
||||||
NMConnection *connection = nm_settings_connection_get_connection (sett_conn);
|
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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
if (!nm_device_check_connection_compatible (device, connection, NULL))
|
if (!nm_device_check_connection_compatible (device, connection, NULL))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
s_con = nm_connection_get_setting_connection (connection);
|
|
||||||
|
|
||||||
iface = nm_setting_connection_get_interface_name (s_con);
|
iface = nm_setting_connection_get_interface_name (s_con);
|
||||||
if (iface && strcmp (iface, nm_device_get_iface (device)) != 0)
|
if (nm_streq0 (iface, nm_device_get_iface (device)))
|
||||||
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))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
s_wired = nm_connection_get_setting_wired (connection);
|
s_wired = nm_connection_get_setting_wired (connection);
|
||||||
|
|
||||||
if ( !s_wired
|
if ( !s_wired
|
||||||
&& nm_streq (ctype, NM_SETTING_PPPOE_SETTING_NAME)) {
|
&& nm_streq (ctype, NM_SETTING_PPPOE_SETTING_NAME)) {
|
||||||
/* No wired setting; therefore the PPPoE connection applies to any device */
|
/* No wired setting; therefore the PPPoE connection applies to any device */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
nm_assert (s_wired);
|
|
||||||
|
|
||||||
setting_hwaddr = nm_setting_wired_get_mac_address (s_wired);
|
setting_hwaddr = nm_setting_wired_get_mac_address (s_wired);
|
||||||
if (setting_hwaddr) {
|
if (setting_hwaddr) {
|
||||||
/* A connection mac-locked to this device */
|
/* A connection mac-locked to this device */
|
||||||
|
Reference in New Issue
Block a user