diff --git a/ipam/allocator.go b/ipam/allocator.go index ae990444..6940bd5a 100644 --- a/ipam/allocator.go +++ b/ipam/allocator.go @@ -403,9 +403,9 @@ func (alloc *Allocator) AdminTakeoverRanges(peerNameOrNickname string) address.C return } - before := alloc.space.NumFreeAddressesInRange(alloc.universe) + before := alloc.space.NumFreeAddresses() alloc.space.AddRanges(newRanges) - after := alloc.space.NumFreeAddressesInRange(alloc.universe) + after := alloc.space.NumFreeAddresses() alloc.gossip.GossipBroadcast(alloc.Gossip()) diff --git a/ipam/space/space.go b/ipam/space/space.go index de7bc36b..80d99c97 100644 --- a/ipam/space/space.go +++ b/ipam/space/space.go @@ -88,6 +88,14 @@ func (s *Space) Claim(addr address.Address) error { return nil } +func (s *Space) NumFreeAddresses() address.Count { + res := address.Count(0) + for i := 0; i < len(s.free); i += 2 { + res += address.Length(s.free[i+1], s.free[i]) + } + return res +} + func (s *Space) NumFreeAddressesInRange(r address.Range) address.Count { res := address.Count(0) s.walkFree(r, func(chunk address.Range) bool { diff --git a/ipam/space/space_test.go b/ipam/space/space_test.go index 3b3290ac..295cfd57 100644 --- a/ipam/space/space_test.go +++ b/ipam/space/space_test.go @@ -19,16 +19,6 @@ func ip(s string) address.Address { return addr } -// Helper function to avoid 'NumFreeAddressesInRange(start, end)' -// dozens of times in tests -func (s *Space) NumFreeAddresses() address.Count { - res := address.Count(0) - for i := 0; i < len(s.free); i += 2 { - res += address.Length(s.free[i+1], s.free[i]) - } - return res -} - func TestLowlevel(t *testing.T) { a := []address.Address{} a = add(a, 100, 200)