2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2021-04-01 16:35:41 +00:00
|
|
|
|
|
|
|
package wgengine_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-12-09 23:12:20 +00:00
|
|
|
"github.com/tailscale/wireguard-go/tun"
|
2021-04-01 16:35:41 +00:00
|
|
|
"tailscale.com/net/tstun"
|
2023-05-03 20:57:17 +00:00
|
|
|
"tailscale.com/tsd"
|
2024-03-19 22:32:34 +00:00
|
|
|
"tailscale.com/tstest"
|
2021-04-01 16:35:41 +00:00
|
|
|
"tailscale.com/types/logger"
|
|
|
|
"tailscale.com/wgengine"
|
|
|
|
"tailscale.com/wgengine/router"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIsNetstack(t *testing.T) {
|
2023-05-03 20:57:17 +00:00
|
|
|
sys := new(tsd.System)
|
2024-03-19 22:32:34 +00:00
|
|
|
e, err := wgengine.NewUserspaceEngine(
|
|
|
|
tstest.WhileTestRunningLogger(t),
|
ipn/ipnlocal, all: plumb health trackers in tests
I saw some panics in CI, like:
2024-05-08T04:30:25.9553518Z ## WARNING: (non-fatal) nil health.Tracker (being strict in CI):
2024-05-08T04:30:25.9554043Z goroutine 801 [running]:
2024-05-08T04:30:25.9554489Z tailscale.com/health.(*Tracker).nil(0x0)
2024-05-08T04:30:25.9555086Z tailscale.com/health/health.go:185 +0x70
2024-05-08T04:30:25.9555688Z tailscale.com/health.(*Tracker).SetUDP4Unbound(0x0, 0x0)
2024-05-08T04:30:25.9556373Z tailscale.com/health/health.go:532 +0x2f
2024-05-08T04:30:25.9557296Z tailscale.com/wgengine/magicsock.(*Conn).bindSocket(0xc0003b4808, 0xc0003b4878, {0x1fbca53, 0x4}, 0x0)
2024-05-08T04:30:25.9558301Z tailscale.com/wgengine/magicsock/magicsock.go:2481 +0x12c5
2024-05-08T04:30:25.9559026Z tailscale.com/wgengine/magicsock.(*Conn).rebind(0xc0003b4808, 0x0)
2024-05-08T04:30:25.9559874Z tailscale.com/wgengine/magicsock/magicsock.go:2510 +0x16f
2024-05-08T04:30:25.9561038Z tailscale.com/wgengine/magicsock.NewConn({0xc000063c80, 0x0, 0xc000197930, 0xc000197950, 0xc000197960, {0x0, 0x0}, 0xc000197970, 0xc000198ee0, 0x0, ...})
2024-05-08T04:30:25.9562402Z tailscale.com/wgengine/magicsock/magicsock.go:476 +0xd5f
2024-05-08T04:30:25.9563779Z tailscale.com/wgengine.NewUserspaceEngine(0xc000063c80, {{0x22c8750, 0xc0001976b0}, 0x0, {0x22c3210, 0xc000063c80}, {0x22c31d8, 0x2d3c900}, 0x0, 0x0, ...})
2024-05-08T04:30:25.9564982Z tailscale.com/wgengine/userspace.go:389 +0x159d
2024-05-08T04:30:25.9565529Z tailscale.com/ipn/ipnlocal.newTestBackend(0xc000358b60)
2024-05-08T04:30:25.9566086Z tailscale.com/ipn/ipnlocal/serve_test.go:675 +0x2a5
2024-05-08T04:30:25.9566612Z ta
Updates #11874
Change-Id: I3432ed52d670743e532be4642f38dbd6e3763b1b
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-05-08 04:37:33 +00:00
|
|
|
wgengine.Config{
|
|
|
|
SetSubsystem: sys.Set,
|
|
|
|
HealthTracker: sys.HealthTracker(),
|
2024-09-23 16:34:00 +00:00
|
|
|
Metrics: sys.UserMetricsRegistry(),
|
ipn/ipnlocal, all: plumb health trackers in tests
I saw some panics in CI, like:
2024-05-08T04:30:25.9553518Z ## WARNING: (non-fatal) nil health.Tracker (being strict in CI):
2024-05-08T04:30:25.9554043Z goroutine 801 [running]:
2024-05-08T04:30:25.9554489Z tailscale.com/health.(*Tracker).nil(0x0)
2024-05-08T04:30:25.9555086Z tailscale.com/health/health.go:185 +0x70
2024-05-08T04:30:25.9555688Z tailscale.com/health.(*Tracker).SetUDP4Unbound(0x0, 0x0)
2024-05-08T04:30:25.9556373Z tailscale.com/health/health.go:532 +0x2f
2024-05-08T04:30:25.9557296Z tailscale.com/wgengine/magicsock.(*Conn).bindSocket(0xc0003b4808, 0xc0003b4878, {0x1fbca53, 0x4}, 0x0)
2024-05-08T04:30:25.9558301Z tailscale.com/wgengine/magicsock/magicsock.go:2481 +0x12c5
2024-05-08T04:30:25.9559026Z tailscale.com/wgengine/magicsock.(*Conn).rebind(0xc0003b4808, 0x0)
2024-05-08T04:30:25.9559874Z tailscale.com/wgengine/magicsock/magicsock.go:2510 +0x16f
2024-05-08T04:30:25.9561038Z tailscale.com/wgengine/magicsock.NewConn({0xc000063c80, 0x0, 0xc000197930, 0xc000197950, 0xc000197960, {0x0, 0x0}, 0xc000197970, 0xc000198ee0, 0x0, ...})
2024-05-08T04:30:25.9562402Z tailscale.com/wgengine/magicsock/magicsock.go:476 +0xd5f
2024-05-08T04:30:25.9563779Z tailscale.com/wgengine.NewUserspaceEngine(0xc000063c80, {{0x22c8750, 0xc0001976b0}, 0x0, {0x22c3210, 0xc000063c80}, {0x22c31d8, 0x2d3c900}, 0x0, 0x0, ...})
2024-05-08T04:30:25.9564982Z tailscale.com/wgengine/userspace.go:389 +0x159d
2024-05-08T04:30:25.9565529Z tailscale.com/ipn/ipnlocal.newTestBackend(0xc000358b60)
2024-05-08T04:30:25.9566086Z tailscale.com/ipn/ipnlocal/serve_test.go:675 +0x2a5
2024-05-08T04:30:25.9566612Z ta
Updates #11874
Change-Id: I3432ed52d670743e532be4642f38dbd6e3763b1b
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-05-08 04:37:33 +00:00
|
|
|
},
|
2024-03-19 22:32:34 +00:00
|
|
|
)
|
2021-04-01 16:35:41 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer e.Close()
|
2023-05-03 20:57:17 +00:00
|
|
|
if !sys.IsNetstack() {
|
2021-04-01 16:35:41 +00:00
|
|
|
t.Errorf("IsNetstack = false; want true")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsNetstackRouter(t *testing.T) {
|
|
|
|
tests := []struct {
|
2023-05-03 20:57:17 +00:00
|
|
|
name string
|
|
|
|
conf wgengine.Config
|
|
|
|
setNetstackRouter bool
|
|
|
|
want bool
|
2021-04-01 16:35:41 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "no_netstack",
|
|
|
|
conf: wgengine.Config{
|
|
|
|
Tun: newFakeOSTUN(),
|
|
|
|
Router: newFakeOSRouter(),
|
|
|
|
},
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "netstack",
|
|
|
|
conf: wgengine.Config{},
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "hybrid_netstack",
|
|
|
|
conf: wgengine.Config{
|
|
|
|
Tun: newFakeOSTUN(),
|
2023-10-11 17:49:01 +00:00
|
|
|
Router: newFakeOSRouter(),
|
2021-04-01 16:35:41 +00:00
|
|
|
},
|
2023-05-03 20:57:17 +00:00
|
|
|
setNetstackRouter: true,
|
|
|
|
want: true,
|
2021-04-01 16:35:41 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2023-05-03 20:57:17 +00:00
|
|
|
sys := &tsd.System{}
|
|
|
|
if tt.setNetstackRouter {
|
|
|
|
sys.NetstackRouter.Set(true)
|
|
|
|
}
|
|
|
|
conf := tt.conf
|
|
|
|
conf.SetSubsystem = sys.Set
|
ipn/ipnlocal, all: plumb health trackers in tests
I saw some panics in CI, like:
2024-05-08T04:30:25.9553518Z ## WARNING: (non-fatal) nil health.Tracker (being strict in CI):
2024-05-08T04:30:25.9554043Z goroutine 801 [running]:
2024-05-08T04:30:25.9554489Z tailscale.com/health.(*Tracker).nil(0x0)
2024-05-08T04:30:25.9555086Z tailscale.com/health/health.go:185 +0x70
2024-05-08T04:30:25.9555688Z tailscale.com/health.(*Tracker).SetUDP4Unbound(0x0, 0x0)
2024-05-08T04:30:25.9556373Z tailscale.com/health/health.go:532 +0x2f
2024-05-08T04:30:25.9557296Z tailscale.com/wgengine/magicsock.(*Conn).bindSocket(0xc0003b4808, 0xc0003b4878, {0x1fbca53, 0x4}, 0x0)
2024-05-08T04:30:25.9558301Z tailscale.com/wgengine/magicsock/magicsock.go:2481 +0x12c5
2024-05-08T04:30:25.9559026Z tailscale.com/wgengine/magicsock.(*Conn).rebind(0xc0003b4808, 0x0)
2024-05-08T04:30:25.9559874Z tailscale.com/wgengine/magicsock/magicsock.go:2510 +0x16f
2024-05-08T04:30:25.9561038Z tailscale.com/wgengine/magicsock.NewConn({0xc000063c80, 0x0, 0xc000197930, 0xc000197950, 0xc000197960, {0x0, 0x0}, 0xc000197970, 0xc000198ee0, 0x0, ...})
2024-05-08T04:30:25.9562402Z tailscale.com/wgengine/magicsock/magicsock.go:476 +0xd5f
2024-05-08T04:30:25.9563779Z tailscale.com/wgengine.NewUserspaceEngine(0xc000063c80, {{0x22c8750, 0xc0001976b0}, 0x0, {0x22c3210, 0xc000063c80}, {0x22c31d8, 0x2d3c900}, 0x0, 0x0, ...})
2024-05-08T04:30:25.9564982Z tailscale.com/wgengine/userspace.go:389 +0x159d
2024-05-08T04:30:25.9565529Z tailscale.com/ipn/ipnlocal.newTestBackend(0xc000358b60)
2024-05-08T04:30:25.9566086Z tailscale.com/ipn/ipnlocal/serve_test.go:675 +0x2a5
2024-05-08T04:30:25.9566612Z ta
Updates #11874
Change-Id: I3432ed52d670743e532be4642f38dbd6e3763b1b
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-05-08 04:37:33 +00:00
|
|
|
conf.HealthTracker = sys.HealthTracker()
|
2024-09-23 16:34:00 +00:00
|
|
|
conf.Metrics = sys.UserMetricsRegistry()
|
2023-05-03 20:57:17 +00:00
|
|
|
e, err := wgengine.NewUserspaceEngine(logger.Discard, conf)
|
2021-04-01 16:35:41 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer e.Close()
|
2023-05-03 20:57:17 +00:00
|
|
|
if got := sys.IsNetstackRouter(); got != tt.want {
|
2021-04-01 16:35:41 +00:00
|
|
|
t.Errorf("IsNetstackRouter = %v; want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFakeOSRouter() router.Router {
|
|
|
|
return someRandoOSRouter{router.NewFake(logger.Discard)}
|
|
|
|
}
|
|
|
|
|
|
|
|
type someRandoOSRouter struct {
|
|
|
|
router.Router
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFakeOSTUN() tun.Device {
|
|
|
|
return someRandoOSTUN{tstun.NewFake()}
|
|
|
|
}
|
|
|
|
|
|
|
|
type someRandoOSTUN struct {
|
|
|
|
tun.Device
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name returns something that is not FakeTUN.
|
|
|
|
func (t someRandoOSTUN) Name() (string, error) { return "some_os_tun0", nil }
|