device: cleanup checking device avilability for ignoring carrier

The flags NMDeviceCheckConAvailableFlags and NMDeviceCheckDevAvailableFlags
both control whether a device appears available (either, available in
general, or related to a particular profile).

Also, both flag types strictly increase availability. Meaning: more flags,
more available.

There is some overlap between the flags, however they still have
their own distinct parts.

Improve the mapping from NMDeviceCheckConAvailableFlags to
NMDeviceCheckDevAvailableFlags, by picking exactly the flags
that are relevant.

(cherry picked from commit 5412fd389b)
This commit is contained in:
Thomas Haller 2018-10-17 12:02:51 +02:00
parent 0e2f08165d
commit 2c7f986b81

View file

@ -13544,6 +13544,19 @@ nm_device_update_metered (NMDevice *self)
}
}
static NMDeviceCheckDevAvailableFlags
_device_check_dev_available_flags_from_con (NMDeviceCheckConAvailableFlags con_flags)
{
NMDeviceCheckDevAvailableFlags dev_flags;
dev_flags = NM_DEVICE_CHECK_DEV_AVAILABLE_NONE;
if (NM_FLAGS_HAS (con_flags, _NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST_WAITING_CARRIER))
dev_flags |= _NM_DEVICE_CHECK_DEV_AVAILABLE_IGNORE_CARRIER;
return dev_flags;
}
static gboolean
_nm_device_check_connection_available (NMDevice *self,
NMConnection *connection,
@ -13601,18 +13614,15 @@ _nm_device_check_connection_available (NMDevice *self,
}
if ( state < NM_DEVICE_STATE_DISCONNECTED
&& !nm_device_is_software (self)) {
if (NM_FLAGS_ANY (flags, NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST)) {
if (!nm_device_is_available (self, NM_DEVICE_CHECK_DEV_AVAILABLE_FOR_USER_REQUEST)) {
if (!nm_device_is_available (self, _device_check_dev_available_flags_from_con (flags))) {
if (NM_FLAGS_HAS (flags, _NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST)) {
nm_utils_error_set_literal (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
"device is not available");
return FALSE;
}
} else {
if (!nm_device_is_available (self, NM_DEVICE_CHECK_DEV_AVAILABLE_NONE)) {
} else {
nm_utils_error_set_literal (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
"device is not available for internal request");
return FALSE;
}
return FALSE;
}
}