manager: set the right reason when managing device after realize

When managing a device after it is realized, we previously always set
the NOW_MANAGED reason, that makes the device fully-managed.

This works based on the assumption that initially an external device
has unmanaged flag EXTERNAL_DOWN set, and therefore the device stays
unmanaged during realization.

It is possible that an external device appears already with addresses
(or attached to a controller); we need to set reason
CONNECTION_ASSUMED if it's an external device, so that we don't set
sys-iface-state=managed.

Reproducer:

   ip link add br1 type bridge
   killall -STOP NetworkManager
   ip link add dummy1 type dummy
   ip link set dummy1 master br1
   ip link set dummy1 up
   sleep .5
   killall -CONT NetworkManager

After this, dummy1 is fully managed by NM while it shouldn't.

https://bugzilla.redhat.com/show_bug.cgi?id=2149012
This commit is contained in:
Beniamino Galvani 2023-05-27 15:46:08 +02:00 committed by Fernando Fernandez Mancera
parent 8bdb53f7f8
commit 9d18510437

View file

@ -3947,7 +3947,7 @@ _device_realize_finish(NMManager *self, NMDevice *device, const NMPlatformLink *
* is still unavailable. Set UNAVAILABLE state again, this time with NOW_MANAGED. */
nm_device_state_changed(device,
NM_DEVICE_STATE_UNAVAILABLE,
NM_DEVICE_STATE_REASON_NOW_MANAGED);
nm_device_get_manage_reason_external(device));
nm_manager_device_recheck_auto_activate_schedule(self, device);
}