From 073f4383657b7811b3b6934cdcdb94732d5723c8 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 17 Mar 2024 15:33:32 +0900 Subject: [PATCH] ndisc-option: sort options in sent message To make the sent message reproducible. --- src/libsystemd-network/ndisc-option.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/libsystemd-network/ndisc-option.c b/src/libsystemd-network/ndisc-option.c index 7de83bcb12..61c58d2971 100644 --- a/src/libsystemd-network/ndisc-option.c +++ b/src/libsystemd-network/ndisc-option.c @@ -1177,11 +1177,17 @@ int ndisc_send(int fd, const struct sockaddr_in6 *dst, const struct icmp6_hdr *h assert(dst); assert(hdr); + size_t n; + _cleanup_free_ sd_ndisc_option **list = NULL; + r = set_dump_sorted(options, (void***) &list, &n); + if (r < 0) + return r; + struct iovec *iov = NULL; size_t n_iov = 0; CLEANUP_ARRAY(iov, n_iov, iovec_array_free); - iov = new(struct iovec, 1 + set_size(options)); + iov = new(struct iovec, 1 + n); if (!iov) return -ENOMEM; @@ -1196,9 +1202,9 @@ int ndisc_send(int fd, const struct sockaddr_in6 *dst, const struct icmp6_hdr *h iov[n_iov++] = IOVEC_MAKE(TAKE_PTR(copy), hdr_size); - const sd_ndisc_option *option; - SET_FOREACH(option, options) { + FOREACH_ARRAY(p, list, n) { _cleanup_free_ uint8_t *buf = NULL; + sd_ndisc_option *option = *p; switch (option->type) { case 0: