dhcp4d: don’t incorrectly _offer_ reused addresses

Turns out a5d9e03dd3212f7f0c11dd856b308a16a58a3cdf was not entirely sufficient:
even though reused addresses would not be handed out anymore, they would still
be offered, which results in the client not being able to obtain an address.
This commit is contained in:
Michael Stapelberg 2019-01-01 10:41:29 +01:00
parent ddcdd39737
commit b923f145a5
2 changed files with 9 additions and 1 deletions

View File

@ -210,7 +210,7 @@ func (h *Handler) leaseHW(hwAddr string) (*Lease, bool) {
return nil, false
}
l, ok := h.leasesIP[num]
return l, ok
return l, ok && l.HardwareAddr == hwAddr
}
// TODO: is ServeDHCP always run from the same goroutine, or do we need locking?

View File

@ -403,6 +403,14 @@ func TestRequestExpired(t *testing.T) {
t.Errorf("DHCPREQUEST resulted in unexpected message type: got %v, want %v", got, want)
}
})
t.Run("mbp requests any", func(t *testing.T) {
p := request(addr, hardwareAddr["mbp"])
resp := handler.serveDHCP(p, dhcp4.Discover, p.ParseOptions())
if got, want := resp.YIAddr().To4(), addr.To4(); bytes.Equal(got, want) {
t.Errorf("DHCPOFFER for wrong IP: got offered %v (in use!)", got)
}
})
}
func TestServerID(t *testing.T) {