From: Yu Watanabe Date: Sat, 26 Nov 2022 00:46:40 +0000 (+0900) Subject: sd-netlink: append instead of prepend multipart message X-Git-Tag: v253-rc1~431^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F25536%2Fhead;p=thirdparty%2Fsystemd.git 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 --- diff --git a/src/libsystemd/sd-netlink/netlink-socket.c b/src/libsystemd/sd-netlink/netlink-socket.c index 2a9f6414190..96162963a75 100644 --- a/src/libsystemd/sd-netlink/netlink-socket.c +++ b/src/libsystemd/sd-netlink/netlink-socket.c @@ -429,15 +429,20 @@ 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. */ - r = netlink_queue_partially_received_message(nl, m); - if (r < 0) - return r; + 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 {