X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fodhcpd.git;a=blobdiff_plain;f=src%2Fdhcpv6-ia.c;h=7e8e53520036ebab024101705838877c958a04df;hp=7db4cee6be1cdec4028315053558a77260d85032;hb=33858d341fa7eff6e7245a2486fc42aee64c81ff;hpb=3b4e6d19b7ce0953efcd6d1c545b031b73e0ab6e;ds=sidebyside diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c index 7db4cee..7e8e535 100644 --- a/src/dhcpv6-ia.c +++ b/src/dhcpv6-ia.c @@ -219,7 +219,7 @@ void dhcpv6_write_statefile(void) return; lockf(fd, F_LOCK, 0); - ftruncate(fd, 0); + if (ftruncate(fd, 0) < 0) {} FILE *fp = fdopen(fd, "w"); if (!fp) { @@ -596,7 +596,10 @@ static void update(struct interface *iface) } struct dhcpv6_assignment *border = list_last_entry(&iface->ia_assignments, struct dhcpv6_assignment, head); - border->assigned = 1 << (64 - minprefix); + if (minprefix > 32 && minprefix <= 64) + border->assigned = 1U << (64 - minprefix); + else + border->assigned = 0; bool change = len != (int)iface->ia_addr_len; for (int i = 0; !change && i < len; ++i) @@ -728,13 +731,19 @@ static size_t append_reply(uint8_t *buf, size_t buflen, uint16_t status, m = i; for (size_t i = 0; i < addrlen; ++i) { - uint32_t prefix_pref = addrs[i].preferred - now; - uint32_t prefix_valid = addrs[i].valid - now; + uint32_t prefix_pref = addrs[i].preferred; + uint32_t prefix_valid = addrs[i].valid; if (addrs[i].prefix > 96 || addrs[i].preferred <= (uint32_t)now) continue; + if (prefix_pref != UINT32_MAX) + prefix_pref -= now; + + if (prefix_valid != UINT32_MAX) + prefix_valid -= now; + if (a->length < 128) { struct dhcpv6_ia_prefix p = { .type = htons(DHCPV6_OPT_IA_PREFIX),