Merge pull request #1090 from weaveworks/1076-ignore-iface
Don't complain about weave bridge routes clashing Fixes #1076.
This commit is contained in:
commit
6cc566fd3e
3 files changed
+46
-18
No files matched your search
+21
-11
@@ -9,17 +9,13 @@ import (
|
|||||||
|
|
||||||
// A network is considered free if it does not overlap any existing
|
// A network is considered free if it does not overlap any existing
|
||||||
// routes on this host. This is the same approach taken by Docker.
|
// routes on this host. This is the same approach taken by Docker.
|
||||||
func CheckNetworkFree(subnet *net.IPNet) error {
|
func CheckNetworkFree(subnet *net.IPNet, ignoreIfaceNames map[string]struct{}) error {
|
||||||
routes, err := netlink.RouteList(nil, netlink.FAMILY_V4)
|
return forEachRoute(ignoreIfaceNames, func(route netlink.Route) error {
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, route := range routes {
|
|
||||||
if route.Dst != nil && overlaps(route.Dst, subnet) {
|
if route.Dst != nil && overlaps(route.Dst, subnet) {
|
||||||
return fmt.Errorf("Network %s overlaps with existing route %s on host.", subnet, route.Dst)
|
return fmt.Errorf("Network %s overlaps with existing route %s on host.", subnet, route.Dst)
|
||||||
}
|
}
|
||||||
}
|
return nil
|
||||||
return nil
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Two networks overlap if the start-point of one is inside the other.
|
// Two networks overlap if the start-point of one is inside the other.
|
||||||
@@ -29,14 +25,28 @@ func overlaps(n1, n2 *net.IPNet) bool {
|
|||||||
|
|
||||||
// For a specific address, we only care if it is actually *inside* an
|
// For a specific address, we only care if it is actually *inside* an
|
||||||
// existing route, because weave-local traffic never hits IP routing.
|
// existing route, because weave-local traffic never hits IP routing.
|
||||||
func CheckAddressOverlap(addr net.IP) error {
|
func CheckAddressOverlap(addr net.IP, ignoreIfaceNames map[string]struct{}) error {
|
||||||
|
return forEachRoute(ignoreIfaceNames, func(route netlink.Route) error {
|
||||||
|
if route.Dst != nil && route.Dst.Contains(addr) {
|
||||||
|
return fmt.Errorf("Address %s overlaps with existing route %s on host.", addr, route.Dst)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func forEachRoute(ignoreIfaceNames map[string]struct{}, check func(netlink.Route) error) error {
|
||||||
routes, err := netlink.RouteList(nil, netlink.FAMILY_V4)
|
routes, err := netlink.RouteList(nil, netlink.FAMILY_V4)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
if route.Dst != nil && route.Dst.Contains(addr) {
|
if link, err := netlink.LinkByIndex(route.LinkIndex); err == nil {
|
||||||
return fmt.Errorf("Address %s overlaps with existing route %s on host.", addr, route.Dst)
|
if _, found := ignoreIfaceNames[link.Attrs().Name]; found {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := check(route); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/mflag"
|
||||||
weavenet "github.com/weaveworks/weave/net"
|
weavenet "github.com/weaveworks/weave/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,20 +15,37 @@ func fatal(err error) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type stringList map[string]struct{}
|
||||||
|
|
||||||
|
func (ss *stringList) Set(value string) error {
|
||||||
|
(*ss)[value] = struct{}{}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ss *stringList) String() string {
|
||||||
|
return fmt.Sprintf("%v", *ss)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) <= 1 {
|
ignoreIfaceNames := make(stringList)
|
||||||
os.Exit(0)
|
|
||||||
|
mflag.Var(&ignoreIfaceNames, []string{"-ignore-iface"}, "name of interface to ignore)")
|
||||||
|
mflag.Parse()
|
||||||
|
|
||||||
|
if len(mflag.Args()) < 1 {
|
||||||
|
fmt.Fprintln(os.Stderr, "usage: netcheck [--ignore-iface <iface-name>] network-cidr")
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
cidrStr := os.Args[1]
|
cidrStr := mflag.Args()[0]
|
||||||
addr, ipnet, err := net.ParseCIDR(cidrStr)
|
addr, ipnet, err := net.ParseCIDR(cidrStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
}
|
}
|
||||||
if ipnet.IP.Equal(addr) {
|
if ipnet.IP.Equal(addr) {
|
||||||
err = weavenet.CheckNetworkFree(ipnet)
|
err = weavenet.CheckNetworkFree(ipnet, ignoreIfaceNames)
|
||||||
} else {
|
} else {
|
||||||
err = weavenet.CheckAddressOverlap(addr)
|
err = weavenet.CheckAddressOverlap(addr, ignoreIfaceNames)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
|
|||||||
@@ -860,7 +860,7 @@ ipam_cidrs() {
|
|||||||
ALL_CIDRS="$ALL_CIDRS $CIDR"
|
ALL_CIDRS="$ALL_CIDRS $CIDR"
|
||||||
else
|
else
|
||||||
# This is a plain IP address; warn if it clashes but carry on
|
# This is a plain IP address; warn if it clashes but carry on
|
||||||
command_exists netcheck && netcheck $1 || true
|
command_exists netcheck && netcheck --ignore-iface=$BRIDGE $1 || true
|
||||||
ALL_CIDRS="$ALL_CIDRS $1"
|
ALL_CIDRS="$ALL_CIDRS $1"
|
||||||
fi
|
fi
|
||||||
shift 1
|
shift 1
|
||||||
@@ -1018,7 +1018,7 @@ launch_router() {
|
|||||||
eval "set -- $ARGS"
|
eval "set -- $ARGS"
|
||||||
if [ -z "$IPRANGE_SPECIFIED" ] ; then
|
if [ -z "$IPRANGE_SPECIFIED" ] ; then
|
||||||
IPRANGE="10.32.0.0/12"
|
IPRANGE="10.32.0.0/12"
|
||||||
if command_exists netcheck && ! netcheck $IPRANGE ; then
|
if command_exists netcheck && ! netcheck --ignore-iface=$BRIDGE $IPRANGE ; then
|
||||||
echo "Default --ipalloc-range $IPRANGE overlaps with existing route on host." >&2
|
echo "Default --ipalloc-range $IPRANGE overlaps with existing route on host." >&2
|
||||||
echo "Please pick another range and set it on all hosts." >&2
|
echo "Please pick another range and set it on all hosts." >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
Reference in new issue
Block a user