core: accept unmanaged parent if it's unrealized

find_parent_device_for_connection() must return a parent device even
if it's unrealized. In fact, callers already handle the unrealized
case; in specific:

 - _internal_activate_device() will try to autoactivate a connection
   on the unrealized parent to realize it;

 - system_create_virtual_device()'s goal is to create a NMDevice
   object, so it doesn't matter whether the parent is realized or not.

Relax the condition about managed-ness, since any unrealized
device is also unmanaged.

This change fixes the following scenario, where all profiles have
autoconnect=no and autoconnect-slaves=yes:

                   vrf0
       -------------^----------------
       |            |               |
       |         bridge0        bond0.4000
       |                            .
     bond0    <......................
    ---^---
    |     |
  veth0  veth1

    ----> = controller
    ....> = VLAN parent

When profiles are added, unrealized devices are created for bond0 and
bridge0, but not for bond0.4000 becase its parent is unrealized. Then
the autoconnect-slaves machinery for vrf0 tries to activate all ports
but fails for bond0.4000 because it can't find a device for it.

https://bugzilla.redhat.com/show_bug.cgi?id=2101317
This commit is contained in:
Beniamino Galvani 2022-09-09 17:34:15 +02:00
parent ee0f3f6242
commit 952f6a3787

View file

@ -1887,8 +1887,11 @@ find_parent_device_for_connection(NMManager *self,
* with some known device.
*/
c_list_for_each_entry (candidate, &priv->devices_lst_head, devices_lst) {
/* Unmanaged devices are not compatible with any connection */
if (!nm_device_get_managed(candidate, FALSE))
/* For a realized device, check that it's managed; otherwise it's not
* compatible with any connection. If the device is unrealized then
* the managed state is meaningless.
*/
if (nm_device_is_real(candidate) && !nm_device_get_managed(candidate, FALSE))
continue;
if (nm_device_get_settings_connection(candidate) == parent_connection)