dhcpv6-ia : Fix static DHCPv6 assignments becoming non static
authorHans Dedecker <dedeckeh@gmail.com>
Thu, 1 Dec 2016 13:24:24 +0000 (14:24 +0100)
committerFelix Fietkau <nbd@nbd.name>
Thu, 1 Dec 2016 13:26:36 +0000 (14:26 +0100)
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>
src/dhcpv6-ia.c

index f4bf044..20ef1f8 100644 (file)
@@ -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);
 
                        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;
                                        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));
 
                                        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) {
 
                        // 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);
                        } 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) {
                                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);
                                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
                        }
                                a->clid_len = 0;
                                a->valid_until = now + 3600; // Block address for 1h
                        }