ipam: Replace ChildSubnet with parent Subnet when its mask is bigger
Prior to moby/moby#44968, libnetwork would happily accept a ChildSubnet
with a bigger mask than its parent subnet. In such case, it was
producing IP addresses based on the parent subnet, and the child subnet
was not allocated from the address pool.
This commit automatically fixes invalid ChildSubnet for networks stored
in libnetwork's datastore.
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
(cherry picked from commit 3e8af0817a
)
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
parent
b81261f5c0
commit
58224457c3
1 changed files with 8 additions and 0 deletions
|
@ -106,6 +106,14 @@ func (a *Allocator) RequestPool(addressSpace, pool, subPool string, options map[
|
|||
}
|
||||
|
||||
k.Subnet, k.ChildSubnet = k.Subnet.Masked(), k.ChildSubnet.Masked()
|
||||
// Prior to https://github.com/moby/moby/pull/44968, libnetwork would happily accept a ChildSubnet with a bigger
|
||||
// mask than its parent subnet. In such case, it was producing IP addresses based on the parent subnet, and the
|
||||
// child subnet was not allocated from the address pool. Following condition take care of restoring this behavior
|
||||
// for networks created before upgrading to v24.0.
|
||||
if k.ChildSubnet.IsValid() && k.ChildSubnet.Bits() < k.Subnet.Bits() {
|
||||
k.ChildSubnet = k.Subnet
|
||||
}
|
||||
|
||||
err = aSpace.allocateSubnet(k.Subnet, k.ChildSubnet)
|
||||
if err != nil {
|
||||
return "", nil, nil, err
|
||||
|
|
Loading…
Reference in a new issue