platform: sort links by name instead of ifindex
We should try to guarantee a stable activation order of connections across reboots; this is required, for example, for bonds because they get assigned the MAC address of the first device enslaved, and thus changing the activation order of slaves means also changing the MAC address of the bond. Since we activate connections in the order links are discovered, having a stable sorting of links returned by platform is enough. The ifindex of interfaces can change between reboots as it depends on the order in which kernel discover interfaces. Provided that the system uses a mechanism to enforce persistent interface naming (as udev rules or systemd-udevd predictable names), and that NM starts after all interfaces have been announced by udev, using the interface name instead of ifindex will guarantee a consistent order.
This commit is contained in:
@@ -444,11 +444,19 @@ _link_get_all_presort (gconstpointer p_a,
|
||||
const NMPlatformLink *a = p_a;
|
||||
const NMPlatformLink *b = p_b;
|
||||
|
||||
if (a->ifindex < b->ifindex)
|
||||
/* Loopback always first */
|
||||
if (a->ifindex == 1)
|
||||
return -1;
|
||||
if (a->ifindex > b->ifindex)
|
||||
if (b->ifindex == 1)
|
||||
return 1;
|
||||
return 0;
|
||||
|
||||
/* Initialized links first */
|
||||
if (a->initialized > b->initialized)
|
||||
return -1;
|
||||
if (a->initialized < b->initialized)
|
||||
return 1;
|
||||
|
||||
return strcmp (a->name, b->name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user