X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=src%2Fdhcpv6-ia.c;h=2fef6267225b39005419a2b990f80035e7d63be9;hb=f17f5711b277fd114c24d7e0861447a83cb85ef9;hp=25c11d756ff29a4fa05ca0f8c755ce18b359edb0;hpb=da2657472b642a266c8a80763a51868e2af6b050;p=project%2Fodhcpd.git diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c index 25c11d7..2fef626 100644 --- a/src/dhcpv6-ia.c +++ b/src/dhcpv6-ia.c @@ -258,6 +258,8 @@ void dhcpv6_write_statefile(void) for (size_t i = 0; i < addrlen; ++i) { if (addrs[i].prefix > 96) continue; + if (c->valid_until <= now) + continue; addr = addrs[i].addr; if (c->length == 128) @@ -267,7 +269,7 @@ void dhcpv6_write_statefile(void) inet_ntop(AF_INET6, &addr, ipbuf, sizeof(ipbuf) - 1); - if (c->length == 128 && c->hostname && i == 0) { + if (c->length == 128 && c->hostname) { fputs(ipbuf, fp); char b[256]; @@ -593,7 +595,7 @@ static void update(struct interface *iface) int minprefix = -1; for (int i = 0; i < len; ++i) { - if (addr[i].prefix > minprefix) + if (addr[i].preferred > 0 && addr[i].prefix > minprefix) minprefix = addr[i].prefix; addr[i].addr.s6_addr32[3] = 0; @@ -620,7 +622,7 @@ static void update(struct interface *iface) if (change) { struct dhcpv6_assignment *c; list_for_each_entry(c, &iface->ia_assignments, head) - if (c != border) + if (c != border && !iface->managed) apply_lease(iface, c, false); } @@ -718,8 +720,14 @@ static size_t append_reply(uint8_t *buf, size_t buflen, uint16_t status, datalen += sizeof(stat); } else { if (a) { - uint32_t pref = 3600; - uint32_t valid = 3600; + uint32_t leasetime = iface->dhcpv4_leasetime; + if (leasetime == 0) + leasetime = 3600; + else if (leasetime < 60) + leasetime = 60; + + uint32_t pref = leasetime; + uint32_t valid = leasetime; 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; @@ -968,7 +976,6 @@ ssize_t dhcpv6_handle_ia(uint8_t *buf, size_t buflen, struct interface *iface, goto out; update(iface); - bool update_state = false; struct dhcpv6_assignment *first = NULL; dhcpv6_for_each_option(start, end, otype, olen, odata) { @@ -1157,7 +1164,6 @@ ssize_t dhcpv6_handle_ia(uint8_t *buf, size_t buflen, struct interface *iface, } a->accept_reconf = accept_reconf; apply_lease(iface, a, true); - update_state = true; } else if (!assigned && a && a->managed_size == 0) { // Cleanup failed assignment free_dhcpv6_assignment(a); } @@ -1176,14 +1182,14 @@ ssize_t dhcpv6_handle_ia(uint8_t *buf, size_t buflen, struct interface *iface, } else if (hdr->msg_type == DHCPV6_MSG_RELEASE) { a->valid_until = 0; apply_lease(iface, a, false); - update_state = true; } else if (hdr->msg_type == DHCPV6_MSG_DECLINE && a->length == 128) { a->clid_len = 0; a->valid_until = now + 3600; // Block address for 1h - update_state = true; } } else if (hdr->msg_type == DHCPV6_MSG_CONFIRM && ia_addr_present) { // Send NOTONLINK for CONFIRM with addr present so that clients restart connection + status = DHCPV6_STATUS_NOTONLINK; + ia_response_len = append_reply(buf, buflen, status, ia, a, iface, true); notonlink = true; } @@ -1203,8 +1209,7 @@ ssize_t dhcpv6_handle_ia(uint8_t *buf, size_t buflen, struct interface *iface, response_len += 6; } - if (update_state) - dhcpv6_write_statefile(); + dhcpv6_write_statefile(); out: return response_len;