platform: rework nm_platform_link_get_unmanaged()

Split out the code to get udev properties. It will be reused in the next
commit.
This commit is contained in:
Beniamino Galvani 2020-06-11 14:59:33 +02:00
parent 2f21a52eeb
commit 3d9e2650c1

View file

@ -1412,6 +1412,27 @@ nm_platform_link_get_type_name (NMPlatform *self, int ifindex)
return obj->link.kind ?: "unknown";
}
static gboolean
link_get_udev_property (NMPlatform *self,
int ifindex,
const char *name,
const char **out_value)
{
struct udev_device *udevice = NULL;
const char *uproperty;
udevice = nm_platform_link_get_udev_device (self, ifindex);
if (!udevice)
return FALSE;
uproperty = udev_device_get_property_value (udevice, name);
if (!uproperty)
return FALSE;
NM_SET_OUT (out_value, uproperty);
return TRUE;
}
/**
* nm_platform_link_get_unmanaged:
* @self: platform instance
@ -1424,26 +1445,14 @@ nm_platform_link_get_type_name (NMPlatform *self, int ifindex)
gboolean
nm_platform_link_get_unmanaged (NMPlatform *self, int ifindex, gboolean *unmanaged)
{
const NMPObject *link;
struct udev_device *udevice = NULL;
const char *uproperty;
const char *value;
_CHECK_SELF (self, klass, FALSE);
if (link_get_udev_property (self, ifindex, "NM_UNMANAGED", &value)) {
NM_SET_OUT (unmanaged, nm_udev_utils_property_as_boolean (value));
return TRUE;
}
link = nmp_cache_lookup_link (nm_platform_get_cache (self), ifindex);
if (!link)
return FALSE;
udevice = link->_link.udev.device;
if (!udevice)
return FALSE;
uproperty = udev_device_get_property_value (udevice, "NM_UNMANAGED");
if (!uproperty)
return FALSE;
*unmanaged = nm_udev_utils_property_as_boolean (uproperty);
return TRUE;
return FALSE;
}
/**