diff options
-rw-r--r-- | src/devices/nm-device.c | 65 | ||||
-rw-r--r-- | src/devices/nm-device.h | 2 | ||||
-rw-r--r-- | src/nm-manager.c | 1 |
3 files changed, 50 insertions, 18 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 0956135a97..f9333909d6 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -977,6 +977,22 @@ nm_device_release_one_slave (NMDevice *self, NMDevice *slave, gboolean configure return success; } +/** + * nm_device_finish_init: + * @self: the master device + * + * Whatever needs to be done post-initialization, when the device has a DBus + * object name. + */ +void +nm_device_finish_init (NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + + if (priv->master) + nm_device_enslave_slave (priv->master, self, NULL); +} + static void carrier_changed (NMDevice *self, gboolean carrier) { @@ -1138,6 +1154,27 @@ update_for_ip_ifname_change (NMDevice *self) } static void +device_set_master (NMDevice *self, int ifindex) +{ + NMDevice *master; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + + master = nm_manager_get_device_by_ifindex (nm_manager_get (), ifindex); + if (master && NM_DEVICE_GET_CLASS (master)->enslave_slave) { + g_clear_object (&priv->master); + priv->master = g_object_ref (master); + nm_device_master_add_slave (master, self, FALSE); + } else if (master) { + _LOGI (LOGD_DEVICE, "enslaved to non-master-type device %s; ignoring", + nm_device_get_iface (master)); + } else { + _LOGW (LOGD_DEVICE, "enslaved to unknown device %d %s", + ifindex, + nm_platform_link_get_name (ifindex)); + } +} + +static void device_link_changed (NMDevice *self, NMPlatformLink *info) { NMDeviceClass *klass = NM_DEVICE_GET_CLASS (self); @@ -1182,24 +1219,10 @@ device_link_changed (NMDevice *self, NMPlatformLink *info) /* Update slave status for external changes */ if (priv->enslaved && info->master != nm_device_get_ifindex (priv->master)) nm_device_release_one_slave (priv->master, self, FALSE, NM_DEVICE_STATE_REASON_NONE); - if (info->master && !priv->enslaved) { - NMDevice *master; - - master = nm_manager_get_device_by_ifindex (nm_manager_get (), info->master); - if (master && NM_DEVICE_GET_CLASS (master)->enslave_slave) { - g_clear_object (&priv->master); - priv->master = g_object_ref (master); - nm_device_master_add_slave (master, self, FALSE); - nm_device_enslave_slave (master, self, NULL); - } else if (master) { - _LOGI (LOGD_DEVICE, "enslaved to non-master-type device %s; ignoring", - nm_device_get_iface (master)); - } else { - _LOGW (LOGD_DEVICE, "enslaved to unknown device %d %s", - info->master, - nm_platform_link_get_name (info->master)); - } - } + if (info->master && !priv->enslaved) + device_set_master (self, info->master); + if (priv->master) + nm_device_enslave_slave (priv->master, self, NULL); if (klass->link_changed) klass->link_changed (self, info); @@ -7945,6 +7968,7 @@ constructed (GObject *object) { NMDevice *self = NM_DEVICE (object); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + int master; nm_device_update_hw_address (self); @@ -7977,6 +8001,11 @@ constructed (GObject *object) if (priv->is_software) priv->capabilities |= NM_DEVICE_CAP_IS_SOFTWARE; + /* Enslave ourselves */ + master = nm_platform_link_get_master (priv->ifindex); + if (master) + device_set_master (self, master); + priv->con_provider = nm_connection_provider_get (); g_assert (priv->con_provider); g_signal_connect (priv->con_provider, diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index ab54262623..38eddaa8df 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -216,6 +216,8 @@ GType nm_device_get_type (void); const char * nm_device_get_path (NMDevice *dev); void nm_device_dbus_export (NMDevice *device); +void nm_device_finish_init (NMDevice *device); + const char * nm_device_get_udi (NMDevice *dev); const char * nm_device_get_iface (NMDevice *dev); int nm_device_get_ifindex (NMDevice *dev); diff --git a/src/nm-manager.c b/src/nm-manager.c index 1c946ec41a..06f24abdb8 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -1819,6 +1819,7 @@ add_device (NMManager *self, NMDevice *device, gboolean try_assume) nm_device_set_initial_unmanaged_flag (device, NM_UNMANAGED_INTERNAL, sleeping); nm_device_dbus_export (device); + nm_device_finish_init (device); if (try_assume) { connection_assumed = recheck_assume_connection (device, self); |