summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2017-08-16 15:44:24 +0200
committerLubomir Rintel <lkundrak@v3.sk>2017-08-24 11:27:14 +0200
commit5c5f483b84305fda1f1eb104206cc9e505e82850 (patch)
treefc42596484bdb802bff5208e41eb6d43f0091af9
parent9481bda93958565082efc87fccab5946f83efbc9 (diff)
downloadNetworkManager-5c5f483b84305fda1f1eb104206cc9e505e82850.tar.gz
manager: always update the device when the plink comes and goes
For some software devices, the platform link appears only after they've been realized. Update their properties and let them know that the link has changed so they can eventually proceed with activation. Also, reset the properties (udi, iface, driver) that are set from the platform link when the link goes away. At that point they don't reflect reality anymore. Removes some code duplication too.
-rw-r--r--src/devices/nm-device.c84
-rw-r--r--src/devices/nm-device.h3
-rw-r--r--src/nm-manager.c3
3 files changed, 45 insertions, 45 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 006d4e9227..69efbffb1c 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -2561,7 +2561,6 @@ device_link_changed (NMDevice *self)
NMDeviceClass *klass = NM_DEVICE_GET_CLASS (self);
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
gboolean ip_ifname_changed = FALSE;
- const char *udi;
NMPlatformLink info;
const NMPlatformLink *pllink;
int ifindex;
@@ -2576,29 +2575,9 @@ device_link_changed (NMDevice *self)
if (!pllink)
return G_SOURCE_REMOVE;
- info = *pllink;
-
- udi = nm_platform_link_get_udi (nm_device_get_platform (self), info.ifindex);
- if (udi && !nm_streq0 (udi, priv->udi)) {
- /* Update UDI to what udev gives us */
- g_free (priv->udi);
- priv->udi = g_strdup (udi);
- _notify (self, PROP_UDI);
- }
-
- if (!nm_streq0 (info.driver, priv->driver)) {
- g_free (priv->driver);
- priv->driver = g_strdup (info.driver);
- _notify (self, PROP_DRIVER);
- }
-
- if (priv->mtu != info.mtu) {
- priv->mtu = info.mtu;
- _notify (self, PROP_MTU);
- }
+ nm_device_update_from_platform_link (self, pllink);
- if (ifindex == nm_device_get_ip_ifindex (self))
- _stats_update_counters_from_pllink (self, &info);
+ info = *pllink;
had_hw_addr = (priv->hw_addr != NULL);
nm_device_update_hw_address (self);
@@ -2965,38 +2944,56 @@ nm_device_create_and_realize (NMDevice *self,
return TRUE;
}
-static void
-update_device_from_platform_link (NMDevice *self, const NMPlatformLink *plink)
+void
+nm_device_update_from_platform_link (NMDevice *self, const NMPlatformLink *plink)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
- const char *udi;
+ const char *str;
+ int num;
- g_return_if_fail (plink != NULL);
+ g_return_if_fail (plink == NULL || link_type_compatible (self, plink->type, NULL, NULL));
- udi = nm_platform_link_get_udi (nm_device_get_platform (self), plink->ifindex);
- if (udi && !nm_streq0 (udi, priv->udi)) {
+ str = plink ? nm_platform_link_get_udi (nm_device_get_platform (self), plink->ifindex) : NULL;
+ if (g_strcmp0 (str, priv->udi)) {
g_free (priv->udi);
- priv->udi = g_strdup (udi);
+ priv->udi = g_strdup (str);
_notify (self, PROP_UDI);
}
- if (!g_strcmp0 (plink->name, priv->iface)) {
+ str = plink ? plink->name : NULL;
+ if (str && g_strcmp0 (str, priv->iface)) {
g_free (priv->iface);
- priv->iface = g_strdup (plink->name);
+ priv->iface = g_strdup (str);
_notify (self, PROP_IFACE);
}
- if (priv->ifindex != plink->ifindex) {
- priv->ifindex = plink->ifindex;
- _notify (self, PROP_IFINDEX);
- }
-
- priv->up = NM_FLAGS_HAS (plink->n_ifi_flags, IFF_UP);
- if (plink->driver && g_strcmp0 (plink->driver, priv->driver) != 0) {
+ str = plink ? plink->driver : NULL;
+ if (g_strcmp0 (str, priv->driver) != 0) {
g_free (priv->driver);
- priv->driver = g_strdup (plink->driver);
+ priv->driver = g_strdup (str);
_notify (self, PROP_DRIVER);
}
+
+ if (plink) {
+ priv->up = NM_FLAGS_HAS (plink->n_ifi_flags, IFF_UP);
+ if (plink->ifindex == nm_device_get_ip_ifindex (self))
+ _stats_update_counters_from_pllink (self, plink);
+ } else {
+ priv->up = FALSE;
+ }
+
+ num = plink ? plink->mtu : 0;
+ if (priv->mtu != num) {
+ priv->mtu = num;
+ _notify (self, PROP_MTU);
+ }
+
+ num = plink ? plink->ifindex : 0;
+ if (priv->ifindex != num) {
+ priv->ifindex = num;
+ _notify (self, PROP_IFINDEX);
+ NM_DEVICE_GET_CLASS (self)->link_changed (self, plink);
+ }
}
static void
@@ -3110,11 +3107,8 @@ realize_start_setup (NMDevice *self,
nm_device_sys_iface_state_set (self, NM_DEVICE_SYS_IFACE_STATE_EXTERNAL);
- if (plink) {
- g_return_if_fail (link_type_compatible (self, plink->type, NULL, NULL));
- update_device_from_platform_link (self, plink);
- _stats_update_counters_from_pllink (self, plink);
- }
+ if (plink)
+ nm_device_update_from_platform_link (self, plink);
if (priv->ifindex > 0) {
priv->physical_port_id = nm_platform_link_get_physical_port_id (nm_device_get_platform (self), priv->ifindex);
diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h
index 358b59af20..07d84076cb 100644
--- a/src/devices/nm-device.h
+++ b/src/devices/nm-device.h
@@ -652,6 +652,9 @@ gboolean nm_device_unrealize (NMDevice *device,
gboolean remove_resources,
GError **error);
+void nm_device_update_from_platform_link (NMDevice *self,
+ const NMPlatformLink *plink);
+
gboolean nm_device_get_autoconnect (NMDevice *device);
void nm_device_set_autoconnect_intern (NMDevice *device, gboolean autoconnect);
void nm_device_emit_recheck_auto_activate (NMDevice *device);
diff --git a/src/nm-manager.c b/src/nm-manager.c
index f058396c33..3ded9a5942 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -2331,6 +2331,7 @@ platform_link_added (NMManager *self,
/* Ignore the link added event since there's already a realized
* device with the link's name.
*/
+ nm_device_update_from_platform_link (candidate, plink);
return;
} else if (nm_device_realize_start (candidate,
plink,
@@ -2458,6 +2459,8 @@ _platform_link_cb_idle (PlatformLinkCbData *data)
_LOG2W (LOGD_DEVICE, device, "failed to unrealize: %s", error->message);
g_clear_error (&error);
remove_device (self, device, FALSE, TRUE);
+ } else {
+ nm_device_update_from_platform_link (device, NULL);
}
} else {
/* Hardware and external devices always get removed when their kernel link is gone */