Skip to content

Commit

Permalink
Require IPv6 default route for IPv6 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsastrix committed Mar 8, 2024
1 parent 162f29a commit c088380
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
23 changes: 20 additions & 3 deletions client/internal/routemanager/systemops_nonandroid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package routemanager
import (
"bytes"
"fmt"
"github.com/google/gopacket/routing"
"github.com/netbirdio/netbird/client/firewall"
"net"
"net/netip"
Expand Down Expand Up @@ -57,8 +58,9 @@ func TestAddRemoveRoutes(t *testing.T) {
t.Run(testCase.name, func(t *testing.T) {

v6Addr := ""
hasV6DefaultRoute, err := EnvironmentHasIPv6DefaultRoute()
//goland:noinspection GoBoolExpressions
if (!iface.SupportsIPv6() || !firewall.SupportsIPv6()) && testCase.prefix.Addr().Is6() {
if (!iface.SupportsIPv6() || !firewall.SupportsIPv6() || !hasV6DefaultRoute || err != nil) && testCase.prefix.Addr().Is6() {
t.Skip("Platform does not support IPv6, skipping IPv6 test...")
} else if testCase.prefix.Addr().Is6() {
v6Addr = "2001:db8::4242:4711/128"
Expand Down Expand Up @@ -160,7 +162,9 @@ func TestGetExistingRIBRouteGateway(t *testing.T) {

func TestGetExistingRIBRouteGateway6(t *testing.T) {
//goland:noinspection GoBoolExpressions
if !iface.SupportsIPv6() {
hasV6DefaultRoute, err := EnvironmentHasIPv6DefaultRoute()
//goland:noinspection GoBoolExpressions
if !iface.SupportsIPv6() || !firewall.SupportsIPv6() || !hasV6DefaultRoute || err != nil {
t.Skip("Platform does not support IPv6, skipping IPv6 test...")
}

Expand Down Expand Up @@ -212,8 +216,9 @@ func TestAddExistAndRemoveRouteNonAndroid(t *testing.T) {
t.Fatal("shouldn't return error when fetching the gateway: ", err)
}
var defaultGateway6 net.IP
hasV6DefaultRoute, err := EnvironmentHasIPv6DefaultRoute()
//goland:noinspection GoBoolExpressions
if iface.SupportsIPv6() && firewall.SupportsIPv6() {
if iface.SupportsIPv6() && firewall.SupportsIPv6() && hasV6DefaultRoute && err == nil {
defaultGateway6, err = getExistingRIBRouteGateway(netip.MustParsePrefix("::/0"))
t.Log("defaultGateway6: ", defaultGateway6)
if err != nil {
Expand Down Expand Up @@ -418,3 +423,15 @@ func TestIsSubRange(t *testing.T) {
}
}
}

func EnvironmentHasIPv6DefaultRoute() (bool, error) {
router, err := routing.New()
if err != nil {
return false, nil

Check failure on line 430 in client/internal/routemanager/systemops_nonandroid_test.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

error is not nil (line 428) but it returns nil (nilerr)

Check failure on line 430 in client/internal/routemanager/systemops_nonandroid_test.go

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

error is not nil (line 428) but it returns nil (nilerr)

Check failure on line 430 in client/internal/routemanager/systemops_nonandroid_test.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

error is not nil (line 428) but it returns nil (nilerr)
}
routeIface, _, _, err := router.Route(netip.MustParsePrefix("::/0").Addr().AsSlice())
if err != nil {
return false, err
}
return routeIface != nil, nil
}
6 changes: 2 additions & 4 deletions iface/iface_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ package iface

import (
"fmt"
"github.com/netbirdio/netbird/iface/netstack"
"github.com/pion/transport/v3"
log "github.com/sirupsen/logrus"
"golang.org/x/net/nettest"

"github.com/pion/transport/v3"

"github.com/netbirdio/netbird/iface/netstack"
)

// NewWGIFace Creates a new WireGuard interface instance
Expand Down

0 comments on commit c088380

Please sign in to comment.