Merge pull request #116 from mavenugo/master

Incorrect assumption with golang net package causes Overlapping IP
This commit is contained in:
Jana Radhakrishnan 2015-05-04 22:42:05 -07:00
commit 288a6b8c49
2 changed files with 4 additions and 2 deletions

View file

@ -35,7 +35,7 @@ func init() {
log.Errorf("Failed to parse address %s", addr) log.Errorf("Failed to parse address %s", addr)
continue continue
} }
net.IP = ip net.IP = ip.To4()
bridgeNetworks = append(bridgeNetworks, net) bridgeNetworks = append(bridgeNetworks, net)
} }
} }

View file

@ -192,7 +192,9 @@ func CheckRouteOverlaps(toCheck *net.IPNet) error {
// NetworkOverlaps detects overlap between one IPNet and another // NetworkOverlaps detects overlap between one IPNet and another
func NetworkOverlaps(netX *net.IPNet, netY *net.IPNet) bool { func NetworkOverlaps(netX *net.IPNet, netY *net.IPNet) bool {
if len(netX.IP) == len(netY.IP) { // 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) { if firstIP, _ := NetworkRange(netX); netY.Contains(firstIP) {
return true return true
} }