diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2015-12-08 14:49:50 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2015-12-08 18:11:52 +0100 |
commit | 6db04dc20664479fc71f102a536dbf2f4501c5a2 (patch) | |
tree | 4a3ca3753c552cc41353dc3ed452fab46d92717e | |
parent | 5201c3d8f96a03a8b8de1211ed9a10e59446c2ea (diff) | |
download | NetworkManager-6db04dc20664479fc71f102a536dbf2f4501c5a2.tar.gz |
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.
-rw-r--r-- | src/devices/nm-device.c | 58 | ||||
-rw-r--r-- | src/devices/nm-device.h | 2 |
2 files changed, 44 insertions, 16 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 7bf55a77f0..e08cb896c6 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -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; @@ -10649,6 +10668,13 @@ nm_device_class_init (NMDeviceClass *klass) 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, "", "", FALSE, diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 6f9e0462e0..48398faf05 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -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); |