]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
inet6: Fix Tokenised IPv6 Identifiers
authorRoy Marples <roy@marples.name>
Wed, 31 Aug 2022 11:17:53 +0000 (12:17 +0100)
committerRoy Marples <roy@marples.name>
Wed, 31 Aug 2022 11:17:53 +0000 (12:17 +0100)
Another one for #101.

src/ipv6.c

index d8e00de3be56d728452631344141b3c34d2300d9..c7cb313aa1c3265345fd062a20ab1ebf60be9a69 100644 (file)
@@ -460,8 +460,21 @@ ipv6_makeaddr(struct in6_addr *addr, struct interface *ifp,
                        return -1;
                return dad;
        } else if (!IN6_IS_ADDR_UNSPECIFIED(&ifo->token)) {
+               int bytes = prefix_len / NBBY;
+               int bits = prefix_len % NBBY;
+
+               // Copy the token into the address.
                *addr = ifo->token;
-               return ipv6_makeprefix(addr, prefix, prefix_len);
+
+               // If we have any dangling bits, just copy that in also.
+               // XXX Can we preserve part of the token still?
+               if (bits != 0)
+                       bytes++;
+
+               // Copy the prefix in.
+               if (bytes > 0)
+                       memcpy(addr->s6_addr, prefix->s6_addr, (size_t)bytes);
+               return 0;
        }
 
        if (prefix_len > 64) {