return -1;
}
- if (lease->dhcpv4_leasetime > 0)
- a->leasetime = lease->dhcpv4_leasetime;
+ a->leasetime = lease->dhcpv4_leasetime;
a->clid_len = duid_len;
a->length = 128;
free(c);
}
+static inline bool valid_prefix_length(const struct dhcpv6_assignment *a, const uint8_t prefix_length)
+{
+ return (a->managed_size || a->length > prefix_length);
+}
+
static inline bool valid_addr(const struct odhcpd_ipaddr *addr, time_t now)
{
return (addr->prefix <= 96 && addr->preferred > (uint32_t)now);
for (size_t i = 0; i < addrlen; ++i) {
if (!valid_addr(&addrs[i], now) ||
- (!INFINITE_VALID(c->valid_until) && c->valid_until <= now) ||
- !ADDR_ENTRY_VALID_IA_ADDR(iface, i, m, addrs))
+ (!INFINITE_VALID(c->valid_until) && c->valid_until <= now))
continue;
addr = addrs[i].addr;
- if (c->length == 128)
+ if (c->length == 128) {
+ if (!ADDR_ENTRY_VALID_IA_ADDR(iface, i, m, addrs))
+ continue;
+
addr.s6_addr32[3] = htonl(c->assigned);
- else
+ }
+ else {
+ if (!valid_prefix_length(c, addrs[i].prefix))
+ continue;
+
addr.s6_addr32[1] |= htonl(c->assigned);
+ }
inet_ntop(AF_INET6, &addr, ipbuf, sizeof(ipbuf) - 1);
if (assign->assigned >= current && assign->assigned + asize < c->assigned) {
list_add_tail(&assign->head, &c->head);
- apply_lease(iface, assign, true);
+
+ if (assign->flags & OAF_BOUND)
+ apply_lease(iface, assign, true);
+
return true;
}
if (current + asize < c->assigned) {
assign->assigned = current;
list_add_tail(&assign->head, &c->head);
- apply_lease(iface, assign, true);
+
+ if (assign->flags & OAF_BOUND)
+ apply_lease(iface, assign, true);
+
return true;
}
&iface->ia_assignments, struct dhcpv6_assignment, head);
list_for_each_entry(c, &iface->ia_assignments, head)
- if (c != border && !iface->managed)
+ if (c != border && !iface->managed && (c->flags & OAF_BOUND))
apply_lease(iface, c, false);
}
if (c->length < 128 && c->assigned >= border->assigned && c != border)
list_move(&c->head, &reassign);
- else if (c != border)
+ else if (c != border && (c->flags & OAF_BOUND))
apply_lease(iface, c, true);
if (c->accept_reconf && c->reconf_cnt == 0) {
} else {
if (a) {
uint32_t leasetime;
- if (a->leasetime > 0)
+ if (a->leasetime)
leasetime = a->leasetime;
else
leasetime = iface->dhcpv4_leasetime;
- if (leasetime == 0)
- leasetime = 3600;
- else if (leasetime < 60)
- leasetime = 60;
-
uint32_t pref = leasetime;
uint32_t valid = leasetime;
if (datalen + entrlen + 4 > buflen ||
(a->assigned == 0 && a->managed_size == 0) ||
- (!a->managed_size && a->length <= addrs[i].prefix))
+ !valid_prefix_length(a, addrs[i].prefix))
continue;
memcpy(buf + datalen, &p, sizeof(p));
addr.s6_addr32[3] = htonl(a->assigned);
}
- else
+ else {
+ if (!valid_prefix_length(a, addrs[i].prefix))
+ continue;
+
addr.s6_addr32[1] |= htonl(a->assigned);
+ }
inet_ntop(AF_INET6, &addr, addrbuf, sizeof(addrbuf));
lbsize += snprintf(leasebuf + lbsize, sizeof(leasebuf) - lbsize, "%s/%d ", addrbuf, prefix);
a = c;
/* Reset state */
- apply_lease(iface, a, false);
+ if (a->flags & OAF_BOUND)
+ apply_lease(iface, a, false);
+
memcpy(a->clid_data, clid_data, clid_len);
a->clid_len = clid_len;
a->iaid = ia->iaid;
if (!(a->flags & OAF_STATIC))
a->valid_until = now - 1;
- a->flags &= ~OAF_BOUND;
- apply_lease(iface, a, false);
+ if (a->flags & OAF_BOUND) {
+ apply_lease(iface, a, false);
+ a->flags &= ~OAF_BOUND;
+ }
} else if (hdr->msg_type == DHCPV6_MSG_DECLINE && a->length == 128) {
a->flags &= ~OAF_BOUND;