core: refactor nm_platform_link_get_unmanaged() to return ternary value

It seems easier to understand this way and to implement.

Next, another udev property will be honored. In light of that, the
change makes more sense.
This commit is contained in:
Thomas Haller 2023-10-31 12:07:20 +01:00
parent 74cb240040
commit 175865c8d3
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
3 changed files with 28 additions and 22 deletions

View file

@ -15097,20 +15097,23 @@ nm_device_set_unmanaged_by_user_settings(NMDevice *self, gboolean now)
void
nm_device_set_unmanaged_by_user_udev(NMDevice *self)
{
int ifindex;
gboolean platform_unmanaged = FALSE;
NMOptionBool platform_unmanaged;
int ifindex;
ifindex = self->_priv->ifindex;
if (ifindex <= 0
|| !nm_platform_link_get_unmanaged(nm_device_get_platform(self),
ifindex,
&platform_unmanaged))
if (ifindex <= 0)
return;
platform_unmanaged = nm_platform_link_get_unmanaged(nm_device_get_platform(self), ifindex);
if (platform_unmanaged == NM_OPTION_BOOL_DEFAULT)
return;
nm_device_set_unmanaged_by_flags(self,
NM_UNMANAGED_USER_UDEV,
platform_unmanaged,
platform_unmanaged == NM_OPTION_BOOL_TRUE
? NM_UNMAN_FLAG_OP_SET_UNMANAGED
: NM_UNMAN_FLAG_OP_SET_MANAGED,
NM_DEVICE_STATE_REASON_USER_REQUESTED);
}

View file

@ -1636,7 +1636,7 @@ nm_platform_link_get_udev_property(NMPlatform *self,
const char *name,
const char **out_value)
{
struct udev_device *udevice = NULL;
struct udev_device *udevice;
const char *uproperty;
udevice = nm_platform_link_get_udev_device(self, ifindex);
@ -1655,22 +1655,25 @@ nm_platform_link_get_udev_property(NMPlatform *self,
* nm_platform_link_get_unmanaged:
* @self: platform instance
* @ifindex: interface index
* @unmanaged: management status (in case %TRUE is returned)
*
* Returns: %TRUE if platform overrides NM default-unmanaged status,
* %FALSE otherwise (with @unmanaged unmodified).
* Returns: %NM_OPTION_BOOL_DEFAULT if the udev property NM_UNMANAGED
* is not set. Otherwise, return NM_UNMANAGED as boolean.
*/
gboolean
nm_platform_link_get_unmanaged(NMPlatform *self, int ifindex, gboolean *unmanaged)
NMOptionBool
nm_platform_link_get_unmanaged(NMPlatform *self, int ifindex)
{
const char *value;
struct udev_device *udevice;
const char *val;
if (nm_platform_link_get_udev_property(self, ifindex, "NM_UNMANAGED", &value)) {
NM_SET_OUT(unmanaged, _nm_utils_ascii_str_to_bool(value, FALSE));
return TRUE;
}
udevice = nm_platform_link_get_udev_device(self, ifindex);
if (!udevice)
return NM_OPTION_BOOL_DEFAULT;
return FALSE;
val = udev_device_get_property_value(udevice, "NM_UNMANAGED");
if (val)
return _nm_utils_ascii_str_to_bool(val, FALSE);
return NM_OPTION_BOOL_DEFAULT;
}
/**

View file

@ -1941,9 +1941,9 @@ int nm_platform_link_get_master(NMPlatform *self, int slave);
gboolean nm_platform_link_can_assume(NMPlatform *self, int ifindex);
gboolean nm_platform_link_get_unmanaged(NMPlatform *self, int ifindex, gboolean *unmanaged);
gboolean nm_platform_link_supports_slaves(NMPlatform *self, int ifindex);
const char *nm_platform_link_get_type_name(NMPlatform *self, int ifindex);
NMOptionBool nm_platform_link_get_unmanaged(NMPlatform *self, int ifindex);
gboolean nm_platform_link_supports_slaves(NMPlatform *self, int ifindex);
const char *nm_platform_link_get_type_name(NMPlatform *self, int ifindex);
gboolean nm_platform_link_refresh(NMPlatform *self, int ifindex);
void nm_platform_process_events(NMPlatform *self);