From 39d0559d9a7a2fe334d0f730f397fc7872a89faa Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Thu, 23 Feb 2017 18:26:02 +0100 Subject: [PATCH] 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. --- src/platform/nm-platform.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 4ab2cff20b..6eb4a1f807 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -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); } /**