]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ndisc-option: sort options in sent message
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 17 Mar 2024 06:33:32 +0000 (15:33 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 26 Mar 2024 13:58:36 +0000 (13:58 +0000)
To make the sent message reproducible.

src/libsystemd-network/ndisc-option.c

index 7de83bcb12ec05b58b0425d8c58fd2fafcb17341..61c58d2971758c151c9b96a9689487115f99b69c 100644 (file)
@@ -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: