From b923f145a508f2d73d73ae6f748f2b223ea3c452 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 1 Jan 2019 10:41:29 +0100 Subject: [PATCH] =?UTF-8?q?dhcp4d:=20don=E2=80=99t=20incorrectly=20=5Foffe?= =?UTF-8?q?r=5F=20reused=20addresses?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- internal/dhcp4d/dhcp4d.go | 2 +- internal/dhcp4d/dhcp4d_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/dhcp4d/dhcp4d.go b/internal/dhcp4d/dhcp4d.go index a261c3e..feb2f8a 100644 --- a/internal/dhcp4d/dhcp4d.go +++ b/internal/dhcp4d/dhcp4d.go @@ -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? diff --git a/internal/dhcp4d/dhcp4d_test.go b/internal/dhcp4d/dhcp4d_test.go index 28098e1..517b72d 100644 --- a/internal/dhcp4d/dhcp4d_test.go +++ b/internal/dhcp4d/dhcp4d_test.go @@ -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) {