Added --ignore-iface option to netcheck and use it to ignore weave bridge route

This commit is contained in:
Bryan Boreham committed 2015-07-07 12:52:29 +01:00
1 parent 3e7c20b4ee
commit e621aca77e
3 files changed
+23 -9

No files matched your search

+9 -2
View File
@@ -9,13 +9,17 @@ import (
// A network is considered free if it does not overlap any existing
// routes on this host. This is the same approach taken by Docker.
func CheckNetworkFree(subnet *net.IPNet) error {
func CheckNetworkFree(subnet *net.IPNet, ignoreIfName string) error {
routes, err := netlink.RouteList(nil, netlink.FAMILY_V4)
if err != nil {
return err
}
for _, route := range routes {
if route.Dst != nil && overlaps(route.Dst, subnet) {
if link, err := netlink.LinkByIndex(route.LinkIndex); err == nil && link.Attrs().Name == ignoreIfName {
continue
}
return fmt.Errorf("Network %s overlaps with existing route %s on host.", subnet, route.Dst)
}
}
@@ -29,13 +33,16 @@ func overlaps(n1, n2 *net.IPNet) bool {
// For a specific address, we only care if it is actually *inside* an
// existing route, because weave-local traffic never hits IP routing.
func CheckAddressOverlap(addr net.IP) error {
func CheckAddressOverlap(addr net.IP, ignoreIfName string) error {
routes, err := netlink.RouteList(nil, netlink.FAMILY_V4)
if err != nil {
return err
}
for _, route := range routes {
if route.Dst != nil && route.Dst.Contains(addr) {
if link, err := netlink.LinkByIndex(route.LinkIndex); err == nil && link.Attrs().Name == ignoreIfName {
continue
}
return fmt.Errorf("Address %s overlaps with existing route %s on host.", addr, route.Dst)
}
}