X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fodhcpd.git;a=blobdiff_plain;f=src%2Fdhcpv6-ia.c;h=e8b6e9fa07dae4dda39e1fb60c033e7506ad24e8;hp=f4bf044ba8f62fbff9081ed66d1fcdb4903d59c2;hb=e05553099c47b92420c21ff30b07709dfa40a84a;hpb=be6c5159a46bf2fb813456e53f217a415743ed4c diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c index f4bf044..e8b6e9f 100644 --- a/src/dhcpv6-ia.c +++ b/src/dhcpv6-ia.c @@ -83,7 +83,7 @@ int setup_dhcpv6_ia_interface(struct interface *iface, bool enable) syslog(LOG_ERR, "Calloc failed for border on interface %s", iface->ifname); return -1; } - + border->length = 64; list_add(&border->head, &iface->ia_assignments); } @@ -236,7 +236,7 @@ void dhcpv6_write_statefile(void) if (iface->dhcpv6 == RELAYD_SERVER && iface->ia_assignments.next) { struct dhcpv6_assignment *c; list_for_each_entry(c, &iface->ia_assignments, head) { - if (c->clid_len == 0 || c->managed_size < 0) + if (!(c->flags & OAF_BOUND) || c->managed_size < 0) continue; char ipbuf[INET6_ADDRSTRLEN]; @@ -282,9 +282,9 @@ void dhcpv6_write_statefile(void) fputs(ipbuf, fp); char b[256]; - if (dn_expand(iface->search, iface->search + iface->search_len, - iface->search, b, sizeof(b)) > 0) - fprintf(fp, "\t%s.%s", c->hostname, b); + if (dn_expand(iface->search, iface->search + iface->search_len, + iface->search, b, sizeof(b)) > 0) + fprintf(fp, "\t%s.%s", c->hostname, b); fprintf(fp, "\t%s\n", c->hostname); md5_hash(ipbuf, strlen(ipbuf), &md5); @@ -302,6 +302,9 @@ void dhcpv6_write_statefile(void) if (iface->dhcpv4 == RELAYD_SERVER && iface->dhcpv4_assignments.next) { struct dhcpv4_assignment *c; list_for_each_entry(c, &iface->dhcpv4_assignments, head) { + if (!(c->flags & OAF_BOUND)) + continue; + char ipbuf[INET6_ADDRSTRLEN]; char leasebuf[512]; char duidbuf[16]; @@ -323,9 +326,9 @@ void dhcpv6_write_statefile(void) fputs(ipbuf, fp); char b[256]; - if (dn_expand(iface->search, iface->search + iface->search_len, - iface->search, b, sizeof(b)) > 0) - fprintf(fp, "\t%s.%s", c->hostname, b); + if (dn_expand(iface->search, iface->search + iface->search_len, + iface->search, b, sizeof(b)) > 0) + fprintf(fp, "\t%s.%s", c->hostname, b); fprintf(fp, "\t%s\n", c->hostname); md5_hash(ipbuf, strlen(ipbuf), &md5); @@ -773,8 +776,10 @@ static size_t append_reply(uint8_t *buf, size_t buflen, uint16_t status, } } - /* UINT32_MAX is considered as infinite leasetime */ - a->valid_until = (valid == UINT32_MAX) ? 0 : valid + now; + if (!INFINITE_VALID(a->valid_until)) + /* UINT32_MAX is considered as infinite leasetime */ + a->valid_until = (valid == UINT32_MAX) ? 0 : valid + now; + out.t1 = htonl((pref == UINT32_MAX) ? pref : pref * 5 / 10); out.t2 = htonl((pref == UINT32_MAX) ? pref : pref * 8 / 10); @@ -1068,6 +1073,9 @@ ssize_t dhcpv6_handle_ia(uint8_t *buf, size_t buflen, struct interface *iface, a->length = reqlen; a->peer = *addr; a->assigned = reqhint; + // Set valid time to current time indicating + // assignment is not having infinite lifetime + a->valid_until = now; if (first) memcpy(a->key, first->key, sizeof(a->key)); @@ -1120,7 +1128,10 @@ ssize_t dhcpv6_handle_ia(uint8_t *buf, size_t buflen, struct interface *iface, // Was only a solicitation: mark binding for removal if (assigned && hdr->msg_type == DHCPV6_MSG_SOLICIT) { - a->valid_until = now; + a->flags &= ~OAF_BOUND; + + if (!INFINITE_VALID(a->valid_until)) + a->valid_until = now; } else if (assigned && hdr->msg_type == DHCPV6_MSG_REQUEST) { if (hostname_len > 0) { a->hostname = realloc(a->hostname, hostname_len + 1); @@ -1130,6 +1141,7 @@ ssize_t dhcpv6_handle_ia(uint8_t *buf, size_t buflen, struct interface *iface, } } a->accept_reconf = accept_reconf; + a->flags |= OAF_BOUND; apply_lease(iface, a, true); } else if (!assigned && a && a->managed_size == 0) { // Cleanup failed assignment free_dhcpv6_assignment(a); @@ -1144,14 +1156,23 @@ ssize_t dhcpv6_handle_ia(uint8_t *buf, size_t buflen, struct interface *iface, } else if (hdr->msg_type == DHCPV6_MSG_RENEW || hdr->msg_type == DHCPV6_MSG_REBIND) { ia_response_len = append_reply(buf, buflen, status, ia, a, iface, false); - if (a) + if (a) { + a->flags |= OAF_BOUND; apply_lease(iface, a, true); + } } else if (hdr->msg_type == DHCPV6_MSG_RELEASE) { - a->valid_until = now - 1; + if (!INFINITE_VALID(a->valid_until)) + a->valid_until = now - 1; + + a->flags &= ~OAF_BOUND; apply_lease(iface, a, false); } else if (hdr->msg_type == DHCPV6_MSG_DECLINE && a->length == 128) { - a->clid_len = 0; - a->valid_until = now + 3600; // Block address for 1h + a->flags &= ~OAF_BOUND; + + if (!INFINITE_VALID(a->valid_until)) { + a->clid_len = 0; + a->valid_until = now + 3600; // Block address for 1h + } } } else if (hdr->msg_type == DHCPV6_MSG_CONFIRM && ia_addr_present) { // Send NOTONLINK for CONFIRM with addr present so that clients restart connection