Commit 6db04dc2 authored by Lubomir Rintel's avatar Lubomir Rintel 🥕

device: add link_type property

This is to make it possible for the device factories to indicate the desired
link type and make it possible to avoid matching the unrealized device to a
platform device of different link type.
parent 5201c3d8
......@@ -114,6 +114,7 @@ enum {
PROP_STATE_REASON,
PROP_ACTIVE_CONNECTION,
PROP_DEVICE_TYPE,
PROP_LINK_TYPE,
PROP_MANAGED,
PROP_AUTOCONNECT,
PROP_FIRMWARE_MISSING,
......@@ -215,6 +216,7 @@ typedef struct _NMDevicePrivate {
NMDeviceType type;
char * type_desc;
char * type_description;
NMLinkType link_type;
NMDeviceCapabilities capabilities;
char * driver;
char * driver_version;
......@@ -710,6 +712,14 @@ nm_device_get_device_type (NMDevice *self)
return NM_DEVICE_GET_PRIVATE (self)->type;
}
NMLinkType
nm_device_get_link_type (NMDevice *self)
{
g_return_val_if_fail (NM_IS_DEVICE (self), NM_LINK_TYPE_UNKNOWN);
return NM_DEVICE_GET_PRIVATE (self)->link_type;
}
/**
* nm_device_get_metered:
* @setting: the #NMDevice
......@@ -10064,12 +10074,25 @@ constructed (GObject *object)
NMDevice *self = NM_DEVICE (object);
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMPlatform *platform;
const NMPlatformLink *pllink;
platform = nm_platform_get ();
if (priv->iface) {
pllink = nm_platform_link_get_by_ifname (platform, priv->iface);
nm_assert (pllink->type != NM_LINK_TYPE_NONE);
if (pllink && link_type_compatible (self, pllink->type, NULL, NULL)) {
priv->ifindex = pllink->ifindex;
priv->up = NM_FLAGS_HAS (pllink->flags, IFF_UP);
}
}
if (NM_DEVICE_GET_CLASS (self)->get_generic_capabilities)
priv->capabilities |= NM_DEVICE_GET_CLASS (self)->get_generic_capabilities (self);
/* Watch for external IP config changes */
platform = nm_platform_get ();
g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, G_CALLBACK (device_ipx_changed), self);
g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, G_CALLBACK (device_ipx_changed), self);
g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, G_CALLBACK (device_ipx_changed), self);
......@@ -10214,7 +10237,6 @@ set_property (GObject *object, guint prop_id,
const char *hw_addr, *p;
guint count;
gboolean val_bool;
const NMPlatformLink *pllink;
switch (prop_id) {
case PROP_UDI:
......@@ -10224,20 +10246,9 @@ set_property (GObject *object, guint prop_id,
}
break;
case PROP_IFACE:
p = g_value_get_string (value);
if (p) {
g_free (priv->iface);
priv->iface = g_strdup (p);
pllink = nm_platform_link_get_by_ifname (NM_PLATFORM_GET, priv->iface);
if (pllink) {
if (link_type_compatible (self, pllink->type, NULL, NULL)) {
priv->ifindex = pllink->ifindex;
priv->up = nm_platform_link_is_up (NM_PLATFORM_GET, priv->ifindex);
}
}
}
/* construct only */
g_return_if_fail (!priv->iface);
priv->iface = g_value_dup_string (value);
break;
case PROP_DRIVER:
if (g_value_get_string (value)) {
......@@ -10280,6 +10291,11 @@ set_property (GObject *object, guint prop_id,
g_return_if_fail (priv->type == NM_DEVICE_TYPE_UNKNOWN);
priv->type = g_value_get_uint (value);
break;
case PROP_LINK_TYPE:
/* construct only */
g_return_if_fail (priv->link_type == NM_LINK_TYPE_NONE);
priv->link_type = g_value_get_uint (value);
break;
case PROP_TYPE_DESC:
g_free (priv->type_desc);
priv->type_desc = g_value_dup_string (value);
......@@ -10396,6 +10412,9 @@ get_property (GObject *object, guint prop_id,
case PROP_DEVICE_TYPE:
g_value_set_uint (value, priv->type);
break;
case PROP_LINK_TYPE:
g_value_set_uint (value, priv->link_type);
break;
case PROP_MANAGED:
g_value_set_boolean (value, nm_device_get_managed (self));
break;
......@@ -10648,6 +10667,13 @@ nm_device_class_init (NMDeviceClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property
(object_class, PROP_LINK_TYPE,
g_param_spec_uint (NM_DEVICE_LINK_TYPE, "", "",
0, G_MAXUINT32, NM_LINK_TYPE_NONE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property
(object_class, PROP_MANAGED,
g_param_spec_boolean (NM_DEVICE_MANAGED, "", "",
......
......@@ -49,6 +49,7 @@
#define NM_DEVICE_STATE_REASON "state-reason"
#define NM_DEVICE_ACTIVE_CONNECTION "active-connection"
#define NM_DEVICE_DEVICE_TYPE "device-type" /* ugh */
#define NM_DEVICE_LINK_TYPE "link-type"
#define NM_DEVICE_MANAGED "managed"
#define NM_DEVICE_AUTOCONNECT "autoconnect"
#define NM_DEVICE_FIRMWARE_MISSING "firmware-missing"
......@@ -372,6 +373,7 @@ const char * nm_device_get_driver_version (NMDevice *dev);
const char * nm_device_get_type_desc (NMDevice *dev);
const char * nm_device_get_type_description (NMDevice *dev);
NMDeviceType nm_device_get_device_type (NMDevice *dev);
NMLinkType nm_device_get_link_type (NMDevice *dev);
NMMetered nm_device_get_metered (NMDevice *dev);
int nm_device_get_priority (NMDevice *dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment