*leasetime = my_leasetime;
if (assigned) {
+ bool is_discover = (msg == DHCPV4_MSG_DISCOVER);
+
if (!INFINITE_VALID(a->valid_until))
// Was only a discover; mark binding for removal
- a->valid_until = ((msg == DHCPV4_MSG_DISCOVER) ? now : ((*leasetime == UINT32_MAX) ?
+ a->valid_until = (is_discover ? now : ((*leasetime == UINT32_MAX) ?
0 : (time_t)(now + *leasetime)));
+
+ /* Mark assignment as bound */
+ if (!is_discover)
+ a->flags |= OAF_BOUND;
+
} else if (!assigned && a) { // Cleanup failed assignment
free(a);
a = NULL;
if (assigned && a)
lease = a;
- } else if (msg == DHCPV4_MSG_RELEASE) {
- if (a && !INFINITE_VALID(a->valid_until))
+ } else if (msg == DHCPV4_MSG_RELEASE && a) {
+ a->flags &= ~OAF_BOUND;
+
+ if (!INFINITE_VALID(a->valid_until))
a->valid_until = now - 1;
- } else if (msg == DHCPV4_MSG_DECLINE && a && !INFINITE_VALID(a->valid_until)) {
- memset(a->hwaddr, 0, sizeof(a->hwaddr));
- a->valid_until = now + 3600; // Block address for 1h
+
+ } else if (msg == DHCPV4_MSG_DECLINE && a) {
+ a->flags &= ~OAF_BOUND;
+
+ if (!INFINITE_VALID(a->valid_until)) {
+ memset(a->hwaddr, 0, sizeof(a->hwaddr));
+ a->valid_until = now + 3600; // Block address for 1h
+ }
}
dhcpv6_write_statefile();
syslog(LOG_ERR, "Calloc failed for border on interface %s", iface->ifname);
return -1;
}
-
+
border->length = 64;
list_add(&border->head, &iface->ia_assignments);
}
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];
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);
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];
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);
// Was only a solicitation: mark binding for removal
if (assigned && hdr->msg_type == DHCPV6_MSG_SOLICIT) {
+ a->flags &= ~OAF_BOUND;
+
if (!INFINITE_VALID(a->valid_until))
a->valid_until = now;
} else if (assigned && hdr->msg_type == DHCPV6_MSG_REQUEST) {
}
}
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);
} 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) {
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 &&
- !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_DECLINE && a->length == 128) {
+ 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