Do not manipulate bitseq length to reserve broadcast address
Signed-off-by: Alessandro Boch <aboch@docker.com>
This commit is contained in:
parent
15871f32fc
commit
115d2ec7d8
|
@ -250,11 +250,6 @@ func (a *Allocator) insertBitMask(key SubnetKey, pool *net.IPNet) error {
|
||||||
ones, bits := pool.Mask.Size()
|
ones, bits := pool.Mask.Size()
|
||||||
numAddresses := uint64(1 << uint(bits-ones))
|
numAddresses := uint64(1 << uint(bits-ones))
|
||||||
|
|
||||||
if ipVer == v4 {
|
|
||||||
// Do not let broadcast address be reserved
|
|
||||||
numAddresses--
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allow /64 subnet
|
// Allow /64 subnet
|
||||||
if ipVer == v6 && numAddresses == 0 {
|
if ipVer == v6 && numAddresses == 0 {
|
||||||
numAddresses--
|
numAddresses--
|
||||||
|
@ -270,6 +265,11 @@ func (a *Allocator) insertBitMask(key SubnetKey, pool *net.IPNet) error {
|
||||||
// Do the same for IPv6 so that bridge ip starts with XXXX...::1
|
// Do the same for IPv6 so that bridge ip starts with XXXX...::1
|
||||||
h.Set(0)
|
h.Set(0)
|
||||||
|
|
||||||
|
// Do not let broadcast address be reserved
|
||||||
|
if ipVer == v4 {
|
||||||
|
h.Set(numAddresses - 1)
|
||||||
|
}
|
||||||
|
|
||||||
a.Lock()
|
a.Lock()
|
||||||
a.addresses[key] = h
|
a.addresses[key] = h
|
||||||
a.Unlock()
|
a.Unlock()
|
||||||
|
|
|
@ -575,6 +575,23 @@ func TestGetSameAddress(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetAddressSubPoolEqualPool(t *testing.T) {
|
||||||
|
a, err := getAllocator()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// Requesting a subpool of same size of the master pool should not cause any problem on ip allocation
|
||||||
|
pid, _, _, err := a.RequestPool(localAddressSpace, "172.18.0.0/16", "172.18.0.0/16", nil, false)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, err = a.RequestAddress(pid, nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRequestReleaseAddressFromSubPool(t *testing.T) {
|
func TestRequestReleaseAddressFromSubPool(t *testing.T) {
|
||||||
a, err := getAllocator()
|
a, err := getAllocator()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue