1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #442 from aboch/csb

Simplify NetworkOverlaps function
This commit is contained in:
Jana Radhakrishnan 2015-08-18 09:04:02 -07:00
commit 7f15aee70e

View file

@ -59,17 +59,7 @@ func CheckRouteOverlaps(toCheck *net.IPNet) error {
// NetworkOverlaps detects overlap between one IPNet and another
func NetworkOverlaps(netX *net.IPNet, netY *net.IPNet) bool {
// Check if both netX and netY are ipv4 or ipv6
if (netX.IP.To4() != nil && netY.IP.To4() != nil) ||
(netX.IP.To4() == nil && netY.IP.To4() == nil) {
if firstIP, _ := NetworkRange(netX); netY.Contains(firstIP) {
return true
}
if firstIP, _ := NetworkRange(netY); netX.Contains(firstIP) {
return true
}
}
return false
return netX.Contains(netY.IP) || netY.Contains(netX.IP)
}
// NetworkRange calculates the first and last IP addresses in an IPNet