Skip to content

Commit

Permalink
Handle ip route showing mask-less IP addresses
Browse files Browse the repository at this point in the history
Sometimes `ip route` will show mask-less IPs, so net.ParseCIDR will fail. If it does we check if we can net.ParseIP, and fail only if we can't.
Fixes #1214
Fixes #362
  • Loading branch information
steeve authored and crosbymichael committed Aug 12, 2013
1 parent 6893487 commit 0ca133d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion network.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ func checkRouteOverlaps(dockerNetwork *net.IPNet) error {
continue
}
if _, network, err := net.ParseCIDR(strings.Split(line, " ")[0]); err != nil {
return fmt.Errorf("Unexpected ip route output: %s (%s)", err, line)
// is this a mask-less IP address?
if ip := net.ParseIP(strings.Split(line, " ")[0]); ip == nil {
// fail only if it's neither a network nor a mask-less IP address
return fmt.Errorf("Unexpected ip route output: %s (%s)", err, line)
}
} else if networkOverlaps(dockerNetwork, network) {
return fmt.Errorf("Network %s is already routed: '%s'", dockerNetwork.String(), line)
}
Expand Down

0 comments on commit 0ca133d

Please sign in to comment.