Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only check if route overlaps routes with scope: LINK #2656

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion netutils/utils_linux.go
Expand Up @@ -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
}
}
Expand Down
10 changes: 9 additions & 1 deletion netutils/utils_test.go
Expand Up @@ -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 }()
Expand All @@ -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) {
Expand Down