Fix in dhcpv4 rapid-commit code.

1) Cosmetic: don't log the tags twice.

2) Functional. If a host has an old lease for a different address,
   the rapid-commit will appear to work, but the old lease will
   not be removed and the new lease will not be recorded, so
   the client and server will have conflicting state, leading to
   problems later.
This commit is contained in:
Simon Kelley
2022-10-27 12:04:58 +01:00
parent fe9a134baf
commit 1bcad67806

View File

@@ -1153,15 +1153,22 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
tagif_netid = run_tag_if(&context->netid);
}
log_tags(tagif_netid, ntohl(mess->xid));
apply_delay(mess->xid, recvtime, tagif_netid);
if (option_bool(OPT_RAPID_COMMIT) && option_find(mess, sz, OPTION_RAPID_COMMIT, 0))
{
rapid_commit = 1;
/* If a lease exists for this host and another address, squash it. */
if (lease && lease->addr.s_addr != mess->yiaddr.s_addr)
{
lease_prune(lease, now);
lease = NULL;
}
goto rapid_commit;
}
log_tags(tagif_netid, ntohl(mess->xid));
daemon->metrics[METRIC_DHCPOFFER]++;
log_packet("DHCPOFFER" , &mess->yiaddr, emac, emac_len, iface_name, NULL, NULL, mess->xid);