mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-30 20:10:10 +01:00
ip4-config: don't change order of addresses in the same subnet
When multiple address are assigned to an interface and the kernel must decide which one should be used to communicate with a given IP, it chooses the most specific one in the same subnet as the destination. In case there are multiple addresses in the same subnet, the primary address is choosen, which is basically the first one that was added. With commit7197425137("device: expose NMIP4Config:addresses in stable/defined sort order") we sorted all the addresses before committing the configuration, with the side effect that the order no longer respected the one in the user configuration. Instead, change the sort function to keep the subnet order unchanged. (cherry picked from commite02752c2ed)
This commit is contained in:
parent
8bcf1a6e3d
commit
56cebecd41
1 changed files with 11 additions and 4 deletions
|
|
@ -207,8 +207,9 @@ _addresses_sort_cmp_get_prio (in_addr_t addr)
|
|||
static gint
|
||||
_addresses_sort_cmp (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
gint p1, p2, c;
|
||||
gint p1, p2;
|
||||
const NMPlatformIP4Address *a1 = a, *a2 = b;
|
||||
guint32 n1, n2;
|
||||
|
||||
/* Sort by address type. For example link local will
|
||||
* be sorted *after* a global address. */
|
||||
|
|
@ -224,9 +225,15 @@ _addresses_sort_cmp (gconstpointer a, gconstpointer b)
|
|||
if ((a1->label[0] == '\0') != (a2->label[0] == '\0'))
|
||||
return (a1->label[0] == '\0') ? -1 : 1;
|
||||
|
||||
/* finally sort addresses lexically */
|
||||
c = memcmp (&a1->address, &a2->address, sizeof (a2->address));
|
||||
return c != 0 ? c : memcmp (a1, a2, sizeof (*a1));
|
||||
/* Finally, sort addresses lexically. We compare only the
|
||||
* network part so that the order of addresses in the same
|
||||
* subnet (and thus also the primary/secondary role) is
|
||||
* preserved.
|
||||
*/
|
||||
n1 = a1->address & nm_utils_ip4_prefix_to_netmask (a1->plen);
|
||||
n2 = a2->address & nm_utils_ip4_prefix_to_netmask (a2->plen);
|
||||
|
||||
return memcmp (&n1, &n2, sizeof (guint32));
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue