Set bound flag for DHCPv4 and DHCPv6 assignments when the IPv6/IPv4 address
is leased to a client.
This will prevent the printing of leases and hostname/IPv4/IPv6 address
combinations in the state file for for which the IPv4/6 address has not
been assigned.
Also this will fix the printing of assignments which have been declined
by the clients
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
*leasetime = my_leasetime;
if (assigned) {
*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
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)));
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;
} else if (!assigned && a) { // Cleanup failed assignment
free(a);
a = NULL;
if (assigned && a)
lease = a;
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;
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();
}
dhcpv6_write_statefile();
time_t valid_until;
uint8_t hwaddr[6];
uint32_t leasetime;
time_t valid_until;
uint8_t hwaddr[6];
uint32_t leasetime;
syslog(LOG_ERR, "Calloc failed for border on interface %s", iface->ifname);
return -1;
}
syslog(LOG_ERR, "Calloc failed for border on interface %s", iface->ifname);
return -1;
}
border->length = 64;
list_add(&border->head, &iface->ia_assignments);
}
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 (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];
continue;
char ipbuf[INET6_ADDRSTRLEN];
fputs(ipbuf, fp);
char b[256];
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);
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 (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];
char ipbuf[INET6_ADDRSTRLEN];
char leasebuf[512];
char duidbuf[16];
fputs(ipbuf, fp);
char b[256];
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);
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) {
// 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) {
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->accept_reconf = accept_reconf;
apply_lease(iface, a, true);
} else if (!assigned && a && a->managed_size == 0) { // Cleanup failed assignment
free_dhcpv6_assignment(a);
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);
} 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) {
+ a->flags |= OAF_BOUND;
apply_lease(iface, a, true);
apply_lease(iface, a, true);
} else if (hdr->msg_type == DHCPV6_MSG_RELEASE) {
if (!INFINITE_VALID(a->valid_until))
a->valid_until = now - 1;
} 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);
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
}
} else if (hdr->msg_type == DHCPV6_MSG_CONFIRM && ia_addr_present) {
// Send NOTONLINK for CONFIRM with addr present so that clients restart connection
struct ustream_fd managed_sock;
uint32_t leasetime;
struct ustream_fd managed_sock;
uint32_t leasetime;
uint8_t clid_len;
uint8_t clid_data[];
uint8_t clid_len;
uint8_t clid_data[];
+enum odhcpd_assignment_flags {
+ OAF_BOUND = (1 << 0),
+};
+
struct config {
bool legacy;
char *dhcp_cb;
struct config {
bool legacy;
char *dhcp_cb;