From: Roy Marples Date: Wed, 31 Aug 2022 11:17:53 +0000 (+0100) Subject: inet6: Fix Tokenised IPv6 Identifiers X-Git-Tag: v10.0.0~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79c3ba7c2a5ac95647512ef58d8973aac206cb77;p=thirdparty%2Fdhcpcd.git inet6: Fix Tokenised IPv6 Identifiers Another one for #101. --- diff --git a/src/ipv6.c b/src/ipv6.c index d8e00de3..c7cb313a 100644 --- a/src/ipv6.c +++ b/src/ipv6.c @@ -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) {