a->addr = ntohl(lease->ipaddr.s_addr);
memcpy(a->hwaddr, lease->mac.ether_addr_octet, sizeof(a->hwaddr));
memcpy(a->hostname, lease->hostname, hostlen);
+ /* Static assignment */
+ a->flags |= OAF_STATIC;
/* Infinite valid */
a->valid_until = 0;
*leasetime = my_leasetime;
if (assigned) {
- bool is_discover = (msg == DHCPV4_MSG_DISCOVER);
+ if (msg == DHCPV4_MSG_DISCOVER) {
+ a->flags &= ~OAF_BOUND;
- if (!INFINITE_VALID(a->valid_until))
- // Was only a discover; mark binding for removal
- a->valid_until = (is_discover ? now : ((*leasetime == UINT32_MAX) ?
- 0 : (time_t)(now + *leasetime)));
-
- /* Mark assignment as bound */
- if (!is_discover)
+ if (!(a->flags & OAF_STATIC))
+ a->valid_until = now;
+ } else {
a->flags |= OAF_BOUND;
+ if (!(a->flags & OAF_STATIC))
+ a->valid_until = ((*leasetime == UINT32_MAX) ? 0 : (time_t)(now + *leasetime));
+ }
} else if (!assigned && a) { // Cleanup failed assignment
free(a);
a = NULL;
} else if (msg == DHCPV4_MSG_RELEASE && a) {
a->flags &= ~OAF_BOUND;
- if (!INFINITE_VALID(a->valid_until))
+ if (!(a->flags & OAF_STATIC))
a->valid_until = now - 1;
} else if (msg == DHCPV4_MSG_DECLINE && a) {
a->flags &= ~OAF_BOUND;
- if (!INFINITE_VALID(a->valid_until)) {
+ if (!(a->flags & OAF_STATIC)) {
memset(a->hwaddr, 0, sizeof(a->hwaddr));
a->valid_until = now + 3600; // Block address for 1h
}
odhcpd_urandom(a->key, sizeof(a->key));
memcpy(a->clid_data, lease->duid, lease->duid_len);
memcpy(a->mac, lease->mac.ether_addr_octet, sizeof(a->mac));
+ /* Static assignment */
+ a->flags |= OAF_STATIC;
/* Infinite valid */
a->valid_until = 0;
if (assigned && hdr->msg_type == DHCPV6_MSG_SOLICIT) {
a->flags &= ~OAF_BOUND;
- if (!INFINITE_VALID(a->valid_until))
+ if (!(a->flags & OAF_STATIC))
a->valid_until = now;
} else if (assigned && hdr->msg_type == DHCPV6_MSG_REQUEST) {
if (hostname_len > 0) {
apply_lease(iface, a, true);
}
} else if (hdr->msg_type == DHCPV6_MSG_RELEASE) {
- if (!INFINITE_VALID(a->valid_until))
+ if (!(a->flags & OAF_STATIC))
a->valid_until = now - 1;
a->flags &= ~OAF_BOUND;
} else if (hdr->msg_type == DHCPV6_MSG_DECLINE && a->length == 128) {
a->flags &= ~OAF_BOUND;
- if (!INFINITE_VALID(a->valid_until)) {
+ if (!(a->flags & OAF_STATIC)) {
a->clid_len = 0;
a->valid_until = now + 3600; // Block address for 1h
}