device: fix queued activation failure due to link disconnected

When activating a connection, it may fail with nmcli reporting:
  $ nmcli connection up id "Wired Connection 1"
  Error: Connection activation failed: Active connection removed before it was initialized

This should be easily reproducible by having a connection "Wired Connection 1" with
cloned-mac-address set to random. When the connection is already active on a device,
re-activating with
  $ nmcli connection up id "Wired Connection 1"
fails.

We first create a queued-activation and tear down the existing
connection:
   device (enp0s25): state change: deactivating -> disconnected (reason 'new-activation')
Shortly after we see:
   device[0x557d02cdb0c0] (enp0s25): set-hw-addr: setting MAC address to 'AA:BB:CC:DD:EE:FF' (reset, deactivate)...
   device[0x557d02cdb0c0] (enp0s25): taking down device
later, we get:
   device (enp0s25): link disconnected
   device[0x557d02cdb0c0] (enp0s25): queued state change to unavailable due to carrier-changed (id 17290)
in the meantime, the queued activation request starts:
   device (enp0s25): Activation: starting connection 'my-wired' (ca058ec5-8a47-4e1e-b38e-962b71c4699e)
but the device already transitions to unavailable
   device[0x557d02cdb0c0] (enp0s25): running queued state change to unavailable (id 17290)
   device (enp0s25): state change: disconnected -> unavailable (reason 'carrier-changed') [30 20 40]
which kills the new activation request:
   active-connection[0x557d02c10e40]: set state deactivated (was unknown)

Just delay a carrier-lost handling if we have any queued activation
requests.

(cherry picked from commit d4e9b30320)
This commit is contained in:
Thomas Haller
2016-08-22 17:37:20 +02:00
parent 6c4447520d
commit f392da2c78

View File

@@ -1726,7 +1726,8 @@ nm_device_set_carrier (NMDevice *self, gboolean carrier)
nm_device_remove_pending_action (self, "carrier wait", TRUE);
_carrier_wait_check_queued_act_request (self);
}
} else if (state <= NM_DEVICE_STATE_DISCONNECTED) {
} else if ( state <= NM_DEVICE_STATE_DISCONNECTED
&& !priv->queued_act_request) {
_LOGI (LOGD_DEVICE, "link disconnected");
klass->carrier_changed (self, FALSE);
} else {