diff options
author | Hans Dedecker <dedeckeh@gmail.com> | 2016-12-01 14:24:24 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@nbd.name> | 2016-12-01 14:26:36 +0100 |
commit | 41b52688403016017eca812315a7206b6d27c097 (patch) | |
tree | 8775658bab8e95e946dfce3cb3dd312af805275b /src/dhcpv6-ia.c | |
parent | be6c5159a46bf2fb813456e53f217a415743ed4c (diff) |
dhcpv6-ia : Fix static DHCPv6 assignments becoming non static
The valid_until parameter which is set to 0 for static DHCPv6
assignments was overwritten depending on the received DHCPv6 message
which turned the assignment into having a finite lifetime and thus not
static anymore.
Fix this by checking if the valid_until parameter holds infinite
lifetime before updating it.
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'src/dhcpv6-ia.c')
-rw-r--r-- | src/dhcpv6-ia.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c index f4bf044..20ef1f8 100644 --- a/src/dhcpv6-ia.c +++ b/src/dhcpv6-ia.c @@ -773,8 +773,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 +1070,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 +1125,8 @@ 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; + 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); @@ -1147,9 +1153,12 @@ ssize_t dhcpv6_handle_ia(uint8_t *buf, size_t buflen, struct interface *iface, if (a) 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; + apply_lease(iface, a, false); - } else if (hdr->msg_type == DHCPV6_MSG_DECLINE && a->length == 128) { + } else if (hdr->msg_type == DHCPV6_MSG_DECLINE && a->length == 128 && + !INFINITE_VALID(a->valid_until)) { a->clid_len = 0; a->valid_until = now + 3600; // Block address for 1h } |