From 2c7f986b81c045ba4637ee09f8cf64eb7e67a80d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 17 Oct 2018 12:02:51 +0200 Subject: [PATCH] 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 5412fd389b051bc3598c08b9d0eb63db4f2af45d) --- src/devices/nm-device.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 1845c8bccb..28ad98326e 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -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; } }