odhcpd: use proper struct msghdr initializers to fix build error on musl
[project/odhcpd.git] / src / dhcpv6-ia.c
index be6a245..d103ecb 100644 (file)
@@ -810,6 +810,10 @@ static size_t append_reply(uint8_t *buf, size_t buflen, uint16_t status,
                                        n.addr.s6_addr32[3] = htonl(a->assigned);
                                        size_t entrlen = sizeof(n) - 4;
 
+                                       if (!a->accept_reconf && iface->managed < RELAYD_MANAGED_NO_AFLAG &&
+                                                       addrs[i].prefix == 64)
+                                               n.preferred = htonl(1);
+
 #ifdef DHCPV6_OPT_PREFIX_CLASS
                                        if (iface->ia_addr[i].has_class) {
                                                entrlen += sizeof(pclass);
@@ -977,25 +981,28 @@ static void dhcpv6_log(uint8_t msgtype, struct interface *iface, time_t now,
                break;
        }
 
-       struct odhcpd_ipaddr *addrs = (a->managed) ? a->managed : iface->ia_addr;
-       size_t addrlen = (a->managed) ? (size_t)a->managed_size : iface->ia_addr_len;
        char leasebuf[256] = "";
-       size_t lbsize = 0;
-       char addrbuf[INET6_ADDRSTRLEN];
 
-       for (size_t i = 0; i < addrlen; ++i) {
-               if (addrs[i].prefix > 96 || addrs[i].preferred <= now)
-                       continue;
+       if (a) {
+               struct odhcpd_ipaddr *addrs = (a->managed) ? a->managed : iface->ia_addr;
+               size_t addrlen = (a->managed) ? (size_t)a->managed_size : iface->ia_addr_len;
+               size_t lbsize = 0;
+               char addrbuf[INET6_ADDRSTRLEN];
 
-               struct in6_addr addr = addrs[i].addr;
-               int prefix = a->managed ? addrs[i].prefix : a->length;
-               if (prefix == 128)
-                       addr.s6_addr32[3] = htonl(a->assigned);
-               else
-                       addr.s6_addr32[1] |= htonl(a->assigned);
+               for (size_t i = 0; i < addrlen; ++i) {
+                       if (addrs[i].prefix > 96 || addrs[i].preferred <= (uint32_t)now)
+                               continue;
+
+                       struct in6_addr addr = addrs[i].addr;
+                       int prefix = a->managed ? addrs[i].prefix : a->length;
+                       if (prefix == 128)
+                               addr.s6_addr32[3] = htonl(a->assigned);
+                       else
+                               addr.s6_addr32[1] |= htonl(a->assigned);
 
-               inet_ntop(AF_INET6, &addr, addrbuf, sizeof(addrbuf));
-               lbsize += snprintf(leasebuf + lbsize, sizeof(leasebuf) - lbsize, "%s/%d ", addrbuf, prefix);
+                       inet_ntop(AF_INET6, &addr, addrbuf, sizeof(addrbuf));
+                       lbsize += snprintf(leasebuf + lbsize, sizeof(leasebuf) - lbsize, "%s/%d ", addrbuf, prefix);
+               }
        }
 
        syslog(LOG_WARNING, "DHCPV6 %s %s from %s on %s: %s %s", type, (is_pd) ? "IA_PD" : "IA_NA",