mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-06 20:10:17 +01:00
device: refactor how master device's set is_available()
Previously, master device types like bridge, bond, and team would overwrite is_available() and check_connection_available() and always return TRUE. The device already expresses via nm_device_is_master() that it is of a master kind. Refactor the code, so, instead of having these device types overwrite is_available() and check_connection_available(), let the parents implementation react on nm_device_is_master(). There is no change in behavior at all. Instead, the knowledge how to treat a master device moves from the device implementation to the parent class.
This commit is contained in:
parent
98651b90a1
commit
e9a917d619
4 changed files with 15 additions and 51 deletions
|
|
@ -57,24 +57,6 @@ get_generic_capabilities (NMDevice *dev)
|
|||
return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_available (NMDevice *dev, NMDeviceCheckDevAvailableFlags flags)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
check_connection_available (NMDevice *device,
|
||||
NMConnection *connection,
|
||||
NMDeviceCheckConAvailableFlags flags,
|
||||
const char *specific_object)
|
||||
{
|
||||
/* Connections are always available because the carrier state is determined
|
||||
* by the slave carrier states, not the bonds's state.
|
||||
*/
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
check_connection_compatible (NMDevice *device, NMConnection *connection)
|
||||
{
|
||||
|
|
@ -631,9 +613,7 @@ nm_device_bond_class_init (NMDeviceBondClass *klass)
|
|||
|
||||
parent_class->is_master = TRUE;
|
||||
parent_class->get_generic_capabilities = get_generic_capabilities;
|
||||
parent_class->is_available = is_available;
|
||||
parent_class->check_connection_compatible = check_connection_compatible;
|
||||
parent_class->check_connection_available = check_connection_available;
|
||||
parent_class->complete_connection = complete_connection;
|
||||
|
||||
parent_class->update_connection = update_connection;
|
||||
|
|
|
|||
|
|
@ -59,12 +59,6 @@ get_generic_capabilities (NMDevice *dev)
|
|||
return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_available (NMDevice *dev, NMDeviceCheckDevAvailableFlags flags)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
check_connection_available (NMDevice *device,
|
||||
NMConnection *connection,
|
||||
|
|
@ -73,6 +67,9 @@ check_connection_available (NMDevice *device,
|
|||
{
|
||||
NMSettingBluetooth *s_bt;
|
||||
|
||||
if (!NM_DEVICE_CLASS (nm_device_bridge_parent_class)->check_connection_available (device, connection, flags, specific_object))
|
||||
return FALSE;
|
||||
|
||||
s_bt = _nm_connection_get_setting_bluetooth_for_nap (connection);
|
||||
if (s_bt) {
|
||||
return nm_bt_vtable_network_server
|
||||
|
|
@ -80,9 +77,6 @@ check_connection_available (NMDevice *device,
|
|||
nm_setting_bluetooth_get_bdaddr (s_bt));
|
||||
}
|
||||
|
||||
/* Connections are always available because the carrier state is determined
|
||||
* by the bridge port carrier states, not the bridge's state.
|
||||
*/
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -490,7 +484,6 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass)
|
|||
|
||||
parent_class->is_master = TRUE;
|
||||
parent_class->get_generic_capabilities = get_generic_capabilities;
|
||||
parent_class->is_available = is_available;
|
||||
parent_class->check_connection_compatible = check_connection_compatible;
|
||||
parent_class->check_connection_available = check_connection_available;
|
||||
parent_class->complete_connection = complete_connection;
|
||||
|
|
|
|||
|
|
@ -3790,12 +3790,17 @@ is_available (NMDevice *self, NMDeviceCheckDevAvailableFlags flags)
|
|||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
||||
|
||||
if (priv->carrier || priv->ignore_carrier)
|
||||
if ( priv->carrier
|
||||
|| priv->ignore_carrier)
|
||||
return TRUE;
|
||||
|
||||
if (NM_FLAGS_HAS (flags, _NM_DEVICE_CHECK_DEV_AVAILABLE_IGNORE_CARRIER))
|
||||
return TRUE;
|
||||
|
||||
/* master types are always available even without carrier. */
|
||||
if (nm_device_is_master (self))
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -11681,6 +11686,12 @@ check_connection_available (NMDevice *self,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/* master types are always available even without carrier.
|
||||
* Making connection non-available would un-enslave slaves which
|
||||
* is not desired. */
|
||||
if (nm_device_is_master (self))
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -83,24 +83,6 @@ get_generic_capabilities (NMDevice *device)
|
|||
return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
check_connection_available (NMDevice *device,
|
||||
NMConnection *connection,
|
||||
NMDeviceCheckConAvailableFlags flags,
|
||||
const char *specific_object)
|
||||
{
|
||||
/* Connections are always available because the carrier state is determined
|
||||
* by the team port carrier states, not the team's state.
|
||||
*/
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
check_connection_compatible (NMDevice *device, NMConnection *connection)
|
||||
{
|
||||
|
|
@ -890,9 +872,7 @@ nm_device_team_class_init (NMDeviceTeamClass *klass)
|
|||
parent_class->is_master = TRUE;
|
||||
parent_class->create_and_realize = create_and_realize;
|
||||
parent_class->get_generic_capabilities = get_generic_capabilities;
|
||||
parent_class->is_available = is_available;
|
||||
parent_class->check_connection_compatible = check_connection_compatible;
|
||||
parent_class->check_connection_available = check_connection_available;
|
||||
parent_class->complete_connection = complete_connection;
|
||||
parent_class->update_connection = update_connection;
|
||||
parent_class->master_update_slave_connection = master_update_slave_connection;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue