ndp: keep an exact copy of IPv6 interface addresses
authorHans Dedecker <dedeckeh@gmail.com>
Wed, 29 Mar 2017 14:47:52 +0000 (16:47 +0200)
committerHans Dedecker <dedeckeh@gmail.com>
Wed, 29 Mar 2017 14:55:31 +0000 (16:55 +0200)
Don't reset the final 32 bit IPv6 host suffix when storing the IPv6 addresses
in the interface structure. This will allow exact lookup aand return of IPv6
addresses stored in the interface structure when needed.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
src/dhcpv6-ia.c
src/ndp.c
src/ubus.c

index fb50448844417311d40278a174bec0fc5115c200..09022a43a252cfa461c2de4e1b0f6fe2a49b3b22 100644 (file)
@@ -297,12 +297,12 @@ void dhcpv6_write_statefile(void)
                                                                continue;
 
                                                        addr.s6_addr32[3] = htonl(c->assigned);
-                                               }
-                                               else {
+                                               } else {
                                                        if (!valid_prefix_length(c, addrs[i].prefix))
                                                                continue;
 
                                                        addr.s6_addr32[1] |= htonl(c->assigned);
+                                                       addr.s6_addr32[2] = addr.s6_addr32[3] = 0;
                                                }
 
                                                inet_ntop(AF_INET6, &addr, ipbuf, sizeof(ipbuf) - 1);
@@ -399,6 +399,7 @@ static void apply_lease(struct interface *iface, struct dhcpv6_assignment *a, bo
        for (size_t i = 0; i < addrlen; ++i) {
                struct in6_addr prefix = addrs[i].addr;
                prefix.s6_addr32[1] |= htonl(a->assigned);
+               prefix.s6_addr32[2] = prefix.s6_addr32[3] = 0;
                odhcpd_setup_route(&prefix, (a->managed_size) ? addrs[i].prefix : a->length,
                                iface, &a->peer.sin6_addr, 1024, add);
        }
@@ -757,6 +758,7 @@ static size_t append_reply(uint8_t *buf, size_t buflen, uint16_t status,
                                                .addr = addrs[i].addr
                                        };
                                        p.addr.s6_addr32[1] |= htonl(a->assigned);
+                                       p.addr.s6_addr32[2] = p.addr.s6_addr32[3] = 0;
 
                                        size_t entrlen = sizeof(p) - 4;
 
@@ -833,6 +835,7 @@ static size_t append_reply(uint8_t *buf, size_t buflen, uint16_t status,
                                                struct in6_addr addr = addrs[i].addr;
                                                if (ia->type == htons(DHCPV6_OPT_IA_PD)) {
                                                        addr.s6_addr32[1] |= htonl(a->assigned);
+                                                       addr.s6_addr32[2] = addr.s6_addr32[3] = 0;
 
                                                        if (!memcmp(&p->addr, &addr, sizeof(addr)) &&
                                                                        p->prefix == ((a->managed) ? addrs[i].prefix : a->length))
@@ -965,6 +968,7 @@ static void dhcpv6_log(uint8_t msgtype, struct interface *iface, time_t now,
                                        continue;
 
                                addr.s6_addr32[1] |= htonl(a->assigned);
+                               addr.s6_addr32[2] = addr.s6_addr32[3] = 0;
                        }
 
                        inet_ntop(AF_INET6, &addr, addrbuf, sizeof(addrbuf));
index 3b472de84942587a1cfe3fb8a9ccaf1f27ef8adc..97a471338ca843a71f6a126379b8071e93fbe5d1 100644 (file)
--- a/src/ndp.c
+++ b/src/ndp.c
@@ -362,8 +362,6 @@ static void check_addr_updates(struct interface *iface)
        qsort(addr, len, sizeof(*addr), prefixcmp);
 
        for (int i = 0; i < len; ++i) {
-               addr[i].addr.s6_addr32[3] = 0;
-
                if (addr[i].preferred < UINT32_MAX - now)
                        addr[i].preferred += now;
 
index e9e2de386e53e170c076b4b413a34c03b2c7ef62..d562c0f85e26ae8cf89c10af196dc18e3a8e8b61 100644 (file)
@@ -107,8 +107,10 @@ static int handle_dhcpv6_leases(_unused struct ubus_context *ctx, _unused struct
                                addr = iface->ia_addr[i].addr;
                                if (lease->length == 128)
                                        addr.s6_addr32[3] = htonl(lease->assigned);
-                               else
+                               else {
                                        addr.s6_addr32[1] |= htonl(lease->assigned);
+                                       addr.s6_addr32[2] = addr.s6_addr32[3] = 0;
+                               }
 
                                char *c = blobmsg_alloc_string_buffer(&b, NULL, INET6_ADDRSTRLEN);
                                inet_ntop(AF_INET6, &addr, c, INET6_ADDRSTRLEN);