Merge pull request #46482 from akerouanton/cp-24.0-3e8af081

[24.0 backport] ipam: Replace ChildSubnet with parent Subnet when its mask is bigger
This commit is contained in:
Sebastiaan van Stijn 2023-09-14 19:30:43 +02:00 committed by GitHub
commit 74e3528a5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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