1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-06 01:57:47 +03:00

sd-netlink: append instead of prepend multipart message

Previously, e.g., networkd enumerated network interfaces with ifindex
in a decreasing order, as sd-netlink inverses the order of the received
multipart messages.
Let's keep the order of the multipart messages. Hopefully this changes
no behavior, as our code do not depend on the order of the received
multipart messages.

Before:
===
Nov 26 09:35:10 systemd[1]: Starting Network Configuration...
Nov 26 09:35:11 systemd-networkd[36185]: wlp59s0: Saved new link: ifindex=3, iftype=ETHER(1), kind=n/a
Nov 26 09:35:12 systemd-networkd[36185]: enp0s31f6: Saved new link: ifindex=2, iftype=ETHER(1), kind=n/a
Nov 26 09:35:12 systemd-networkd[36185]: lo: Saved new link: ifindex=1, iftype=LOOPBACK(772), kind=n/a

After:
===
Nov 26 09:45:18 systemd[1]: Starting Network Configuration...
Nov 26 09:45:19 systemd-networkd[38372]: lo: Saved new link: ifindex=1, iftype=LOOPBACK(772), kind=n/a
Nov 26 09:45:19 systemd-networkd[38372]: enp0s31f6: Saved new link: ifindex=2, iftype=ETHER(1), kind=n/a
Nov 26 09:45:19 systemd-networkd[38372]: wlp59s0: Saved new link: ifindex=3, iftype=ETHER(1), kind=n/a
This commit is contained in:
Yu Watanabe 2022-11-26 09:46:40 +09:00
parent a8ac052624
commit 52ceba53d3

View File

@ -429,16 +429,21 @@ int socket_read_message(sd_netlink *nl) {
} else {
sd_netlink_message *existing;
existing = hashmap_remove(nl->rqueue_partial_by_serial, UINT32_TO_PTR(hdr->nlmsg_seq));
if (existing)
/* push the message onto the multi-part message stack */
m->next = existing;
/* put it into the queue for partially received messages. */
existing = hashmap_get(nl->rqueue_partial_by_serial, UINT32_TO_PTR(hdr->nlmsg_seq));
if (existing) {
/* This is the continuation of the previously read messages.
* Let's append this message at the end. */
while (existing->next)
existing = existing->next;
existing->next = TAKE_PTR(m);
} else {
/* This is the first message. Put it into the queue for partially
* received messages. */
r = netlink_queue_partially_received_message(nl, m);
if (r < 0)
return r;
}
}
} else {
r = netlink_queue_received_message(nl, m);