moby/libnetwork/ipam
Cory Snider 7257c77e19 libnetwork/ipam: refactor prefix-overlap checks
I am finally convinced that, given two netip.Prefix values a and b, the
expression

    a.Contains(b.Addr()) || b.Contains(a.Addr())

is functionally equivalent to

    a.Overlaps(b)

The (netip.Prefix).Contains method works by masking the address with the
prefix's mask and testing whether the remaining most-significant bits
are equal to the same bits in the prefix. The (netip.Prefix).Overlaps
method works by masking the longer prefix to the length of the shorter
prefix and testing whether the remaining most-significant bits are
equal. This is equivalent to
shorterPrefix.Contains(longerPrefix.Addr()), therefore applying Contains
symmetrically to two prefixes will always yield the same result as
applying Overlaps to the two prefixes in either order.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2023-11-01 11:44:24 -04:00
..
allocator.go libnetwork/ipam: refactor prefix-overlap checks 2023-11-01 11:44:24 -04:00
allocator_test.go libnetwork/ipam: move PoolID.FromString() to a PoolIDFromString() func 2023-08-08 15:57:24 +02:00
parallel_test.go libnet/ipam: drop vestiges of custom addrSpaces 2023-02-23 18:09:22 -05:00
structures.go libnetwork/ipam: refactor prefix-overlap checks 2023-11-01 11:44:24 -04:00
utils.go libnet/ipam: use netip types internally 2023-02-23 18:10:01 -05:00