diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c index 790f00d44a..ef8fe1a519 100644 --- a/src/devices/nm-device-bond.c +++ b/src/devices/nm-device-bond.c @@ -413,6 +413,7 @@ release_slave (NMDevice *device, NMDeviceBond *self = NM_DEVICE_BOND (device); gboolean success; gs_free char *address = NULL; + int ifindex_slave; int ifindex; ifindex = nm_device_get_ifindex (device); @@ -420,22 +421,29 @@ release_slave (NMDevice *device, || !nm_platform_link_get (nm_device_get_platform (device), ifindex)) configure = FALSE; + ifindex_slave = nm_device_get_ip_ifindex (slave); + + if (ifindex_slave <= 0) + _LOGD (LOGD_TEAM, "bond slave %s is already released", nm_device_get_ip_iface (slave)); + if (configure) { /* When the last slave is released the bond MAC will be set to a random * value by kernel; remember the current one and restore it afterwards. */ address = g_strdup (nm_device_get_hw_address (device)); - success = nm_platform_link_release (nm_device_get_platform (device), - nm_device_get_ip_ifindex (device), - nm_device_get_ip_ifindex (slave)); + if (ifindex_slave > 0) { + success = nm_platform_link_release (nm_device_get_platform (device), + nm_device_get_ip_ifindex (device), + ifindex_slave); - if (success) { - _LOGI (LOGD_BOND, "released bond slave %s", - nm_device_get_ip_iface (slave)); - } else { - _LOGW (LOGD_BOND, "failed to release bond slave %s", - nm_device_get_ip_iface (slave)); + if (success) { + _LOGI (LOGD_BOND, "released bond slave %s", + nm_device_get_ip_iface (slave)); + } else { + _LOGW (LOGD_BOND, "failed to release bond slave %s", + nm_device_get_ip_iface (slave)); + } } nm_platform_process_events (nm_device_get_platform (device)); @@ -446,11 +454,15 @@ release_slave (NMDevice *device, * IFF_UP), so we must bring it back up here to ensure carrier changes and * other state is noticed by the now-released slave. */ - if (!nm_device_bring_up (slave, TRUE, NULL)) - _LOGW (LOGD_BOND, "released bond slave could not be brought up."); + if (ifindex_slave > 0) { + if (!nm_device_bring_up (slave, TRUE, NULL)) + _LOGW (LOGD_BOND, "released bond slave could not be brought up."); + } } else { - _LOGI (LOGD_BOND, "bond slave %s was released", - nm_device_get_ip_iface (slave)); + if (ifindex_slave > 0) { + _LOGI (LOGD_BOND, "bond slave %s was released", + nm_device_get_ip_iface (slave)); + } } } diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index e81bcd5d26..79e48e678b 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -625,6 +625,7 @@ release_slave (NMDevice *device, { NMDeviceBridge *self = NM_DEVICE_BRIDGE (device); gboolean success; + int ifindex_slave; int ifindex; ifindex = nm_device_get_ifindex (device); @@ -632,10 +633,17 @@ release_slave (NMDevice *device, || !nm_platform_link_get (nm_device_get_platform (device), ifindex)) configure = FALSE; + ifindex_slave = nm_device_get_ip_ifindex (slave); + + if (ifindex_slave <= 0) { + _LOGD (LOGD_TEAM, "bond slave %s is already released", nm_device_get_ip_iface (slave)); + return; + } + if (configure) { success = nm_platform_link_release (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), - nm_device_get_ip_ifindex (slave)); + ifindex_slave); if (success) { _LOGI (LOGD_BRIDGE, "detached bridge port %s", diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c index 7afd186064..876b48f821 100644 --- a/src/devices/team/nm-device-team.c +++ b/src/devices/team/nm-device-team.c @@ -774,6 +774,7 @@ release_slave (NMDevice *device, NMDeviceTeam *self = NM_DEVICE_TEAM (device); NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (self); gboolean success; + int ifindex_slave; int ifindex; ifindex = nm_device_get_ifindex (device); @@ -781,10 +782,17 @@ release_slave (NMDevice *device, || !nm_platform_link_get (nm_device_get_platform (device), ifindex)) configure = FALSE; + ifindex_slave = nm_device_get_ip_ifindex (slave); + + if (ifindex_slave <= 0) { + _LOGD (LOGD_TEAM, "team port %s is already released", nm_device_get_ip_iface (slave)); + return; + } + if (configure) { success = nm_platform_link_release (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), - nm_device_get_ip_ifindex (slave)); + ifindex_slave); if (success) _LOGI (LOGD_TEAM, "released team port %s", nm_device_get_ip_iface (slave)); @@ -795,9 +803,10 @@ release_slave (NMDevice *device, * IFF_UP), so we must bring it back up here to ensure carrier changes and * other state is noticed by the now-released port. */ - if (!nm_device_bring_up (slave, TRUE, NULL)) + if (!nm_device_bring_up (slave, TRUE, NULL)) { _LOGW (LOGD_TEAM, "released team port %s could not be brought up", nm_device_get_ip_iface (slave)); + } nm_clear_g_source (&priv->teamd_read_timeout); priv->teamd_read_timeout = g_timeout_add_seconds (5,