diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2017-02-23 18:26:02 +0100 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2017-03-27 21:51:55 +0200 |
commit | 39d0559d9a7a2fe334d0f730f397fc7872a89faa (patch) | |
tree | 20187354e99e9614f0671b2031c9a7952f8df4ef | |
parent | 52b1f0415d558d02afb62f01c8abac75a2ee245b (diff) | |
download | NetworkManager-39d0559d9a7a2fe334d0f730f397fc7872a89faa.tar.gz |
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.
-rw-r--r-- | src/platform/nm-platform.c | 14 |
1 files 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); } /** |