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

Merge pull request #42598 from deepy/linux-routeoverlaps-link-only

Only check if route overlaps routes with scope: LINK
This commit is contained in:
Sebastiaan van Stijn 2021-08-26 09:58:35 +02:00 committed by GitHub
commit 2bb21b85c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View file

@ -31,7 +31,7 @@ func CheckRouteOverlaps(toCheck *net.IPNet) error {
return err
}
for _, network := range networks {
if network.Dst != nil && NetworkOverlaps(toCheck, network.Dst) {
if network.Dst != nil && network.Scope == netlink.SCOPE_LINK && NetworkOverlaps(toCheck, network.Dst) {
return ErrNetworkOverlaps
}
}

View file

@ -46,8 +46,11 @@ func TestCheckRouteOverlaps(t *testing.T) {
routes := []netlink.Route{}
for _, addr := range routesData {
_, netX, _ := net.ParseCIDR(addr)
routes = append(routes, netlink.Route{Dst: netX})
routes = append(routes, netlink.Route{Dst: netX, Scope: netlink.SCOPE_LINK})
}
// Add a route with a scope which should not overlap
_, netX, _ := net.ParseCIDR("10.0.5.0/24")
routes = append(routes, netlink.Route{Dst: netX, Scope: netlink.SCOPE_UNIVERSE})
return routes, nil
}
defer func() { networkGetRoutesFct = nil }()
@ -61,6 +64,11 @@ func TestCheckRouteOverlaps(t *testing.T) {
if err := CheckRouteOverlaps(netX); err == nil {
t.Fatal("10.0.2.0/24 and 10.0.2.0 should overlap but it doesn't")
}
_, netX, _ = net.ParseCIDR("10.0.5.0/24")
if err := CheckRouteOverlaps(netX); err != nil {
t.Fatal("10.0.5.0/24 and 10.0.5.0 with scope UNIVERSE should not overlap but it does")
}
}
func TestCheckNameserverOverlaps(t *testing.T) {