From 9fe5cc10b239b99113797712ca044af1163747d1 Mon Sep 17 00:00:00 2001 From: Abhinandan Prativadi Date: Thu, 10 May 2018 12:14:44 -0700 Subject: [PATCH] Add check for overlapping subnets Signed-off-by: Abhinandan Prativadi --- libnetwork/ipam/structures.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libnetwork/ipam/structures.go b/libnetwork/ipam/structures.go index 09a77695dd..455a16ca65 100644 --- a/libnetwork/ipam/structures.go +++ b/libnetwork/ipam/structures.go @@ -262,12 +262,13 @@ func (aSpace *addrSpace) updatePoolDBOnAdd(k SubnetKey, nw *net.IPNet, ipr *Addr defer aSpace.Unlock() // Check if already allocated - if p, ok := aSpace.subnets[k]; ok { + if _, ok := aSpace.subnets[k]; ok { if pdf { return nil, types.InternalMaskableErrorf("predefined pool %s is already reserved", nw) } - aSpace.incRefCount(p, 1) - return func() error { return nil }, nil + // This means the same pool is already allocated. updatePoolDBOnAdd is called when there + // is request for a pool/subpool. It should ensure there is no overlap with existing pools + return nil, ipamapi.ErrPoolOverlap } // If master pool, check for overlap