Merge pull request #46755 from corhere/libn/netip-overlaps
libnetwork/ipam: refactor prefix-overlap checks
This commit is contained in:
commit
fb3cc5e716
2 changed files with 6 additions and 5 deletions
|
@ -214,7 +214,7 @@ func (aSpace *addrSpace) allocatePredefinedPool(ipV6 bool) (netip.Prefix, error)
|
|||
}
|
||||
// Shouldn't be necessary, but check prevents IP collisions should
|
||||
// predefined pools overlap for any reason.
|
||||
if !aSpace.contains(nw) {
|
||||
if !aSpace.overlaps(nw) {
|
||||
aSpace.updatePredefinedStartIndex(i + 1)
|
||||
err := aSpace.allocateSubnetL(nw, netip.Prefix{})
|
||||
if err != nil {
|
||||
|
|
|
@ -107,7 +107,7 @@ func (aSpace *addrSpace) allocateSubnet(nw, sub netip.Prefix) error {
|
|||
func (aSpace *addrSpace) allocateSubnetL(nw, sub netip.Prefix) error {
|
||||
// If master pool, check for overlap
|
||||
if sub == (netip.Prefix{}) {
|
||||
if aSpace.contains(nw) {
|
||||
if aSpace.overlaps(nw) {
|
||||
return ipamapi.ErrPoolOverlap
|
||||
}
|
||||
// This is a new master pool, add it along with corresponding bitmask
|
||||
|
@ -157,10 +157,11 @@ func (aSpace *addrSpace) releaseSubnet(nw, sub netip.Prefix) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// contains checks whether nw is a superset or subset of any of the existing subnets in this address space.
|
||||
func (aSpace *addrSpace) contains(nw netip.Prefix) bool {
|
||||
// overlaps reports whether nw contains any IP addresses in common with any of
|
||||
// the existing subnets in this address space.
|
||||
func (aSpace *addrSpace) overlaps(nw netip.Prefix) bool {
|
||||
for pool := range aSpace.subnets {
|
||||
if nw.Contains(pool.Addr()) || pool.Contains(nw.Addr()) {
|
||||
if pool.Overlaps(nw) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue