2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2020-08-06 22:57:03 +01:00
|
|
|
|
|
|
|
package wgengine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-07-26 04:55:44 +01:00
|
|
|
"net/netip"
|
2023-09-21 10:31:48 +01:00
|
|
|
"os"
|
2020-10-13 20:04:52 +01:00
|
|
|
"reflect"
|
2023-09-21 10:31:48 +01:00
|
|
|
"runtime"
|
2020-08-06 22:57:03 +01:00
|
|
|
"testing"
|
|
|
|
|
2020-10-13 20:04:52 +01:00
|
|
|
"go4.org/mem"
|
2023-01-19 14:42:58 +00:00
|
|
|
"tailscale.com/cmd/testwrapper/flakytest"
|
2023-09-11 20:03:39 +01:00
|
|
|
"tailscale.com/control/controlknobs"
|
2023-09-21 10:31:48 +01:00
|
|
|
"tailscale.com/envknob"
|
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 05:37:33 +01:00
|
|
|
"tailscale.com/health"
|
2021-04-02 08:34:32 +01:00
|
|
|
"tailscale.com/net/dns"
|
2022-07-25 04:08:42 +01:00
|
|
|
"tailscale.com/net/netaddr"
|
2021-03-27 05:14:08 +00:00
|
|
|
"tailscale.com/net/tstun"
|
2020-08-06 22:57:03 +01:00
|
|
|
"tailscale.com/tailcfg"
|
2021-09-07 23:17:39 +01:00
|
|
|
"tailscale.com/tstest"
|
2021-07-21 20:14:04 +01:00
|
|
|
"tailscale.com/tstime/mono"
|
2020-08-06 22:57:03 +01:00
|
|
|
"tailscale.com/types/key"
|
2021-09-01 03:06:04 +01:00
|
|
|
"tailscale.com/types/netmap"
|
2023-09-21 10:31:48 +01:00
|
|
|
"tailscale.com/types/opt"
|
2020-10-13 20:04:52 +01:00
|
|
|
"tailscale.com/wgengine/router"
|
2021-01-29 20:16:36 +00:00
|
|
|
"tailscale.com/wgengine/wgcfg"
|
2020-08-06 22:57:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNoteReceiveActivity(t *testing.T) {
|
2021-07-21 20:14:04 +01:00
|
|
|
now := mono.Time(123456)
|
2021-09-07 23:17:39 +01:00
|
|
|
var logBuf tstest.MemLogger
|
2020-08-06 22:57:03 +01:00
|
|
|
|
|
|
|
confc := make(chan bool, 1)
|
|
|
|
gotConf := func() bool {
|
|
|
|
select {
|
|
|
|
case <-confc:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e := &userspaceEngine{
|
2021-09-07 23:17:39 +01:00
|
|
|
timeNow: func() mono.Time { return now },
|
2021-11-02 01:21:48 +00:00
|
|
|
recvActivityAt: map[key.NodePublic]mono.Time{},
|
2021-09-07 23:17:39 +01:00
|
|
|
logf: logBuf.Logf,
|
2021-03-27 06:13:20 +00:00
|
|
|
tundev: new(tstun.Wrapper),
|
2020-08-06 22:57:03 +01:00
|
|
|
testMaybeReconfigHook: func() { confc <- true },
|
2021-11-02 01:21:48 +00:00
|
|
|
trimmedNodes: map[key.NodePublic]bool{},
|
2020-08-06 22:57:03 +01:00
|
|
|
}
|
|
|
|
ra := e.recvActivityAt
|
|
|
|
|
2021-11-02 00:53:40 +00:00
|
|
|
nk := key.NewNode().Public()
|
2020-08-06 22:57:03 +01:00
|
|
|
|
|
|
|
// Activity on an untracked key should do nothing.
|
2021-09-01 03:06:04 +01:00
|
|
|
e.noteRecvActivity(nk)
|
2020-08-06 22:57:03 +01:00
|
|
|
if len(ra) != 0 {
|
|
|
|
t.Fatalf("unexpected growth in map: now has %d keys; want 0", len(ra))
|
|
|
|
}
|
|
|
|
if logBuf.Len() != 0 {
|
|
|
|
t.Fatalf("unexpected log write (and thus activity): %s", logBuf.Bytes())
|
|
|
|
}
|
|
|
|
|
2020-08-26 20:20:09 +01:00
|
|
|
// Now track it, but don't mark it trimmed, so shouldn't update.
|
2021-11-02 01:21:48 +00:00
|
|
|
ra[nk] = 0
|
2021-09-01 03:06:04 +01:00
|
|
|
e.noteRecvActivity(nk)
|
2020-08-06 22:57:03 +01:00
|
|
|
if len(ra) != 1 {
|
|
|
|
t.Fatalf("unexpected growth in map: now has %d keys; want 1", len(ra))
|
|
|
|
}
|
2021-11-02 01:21:48 +00:00
|
|
|
if got := ra[nk]; got != now {
|
2020-08-06 22:57:03 +01:00
|
|
|
t.Fatalf("time in map = %v; want %v", got, now)
|
|
|
|
}
|
2020-08-26 20:20:09 +01:00
|
|
|
if gotConf() {
|
|
|
|
t.Fatalf("unexpected reconfig")
|
2020-08-06 22:57:03 +01:00
|
|
|
}
|
|
|
|
|
2020-08-26 20:20:09 +01:00
|
|
|
// Now mark it trimmed and expect an update.
|
2021-11-02 01:21:48 +00:00
|
|
|
e.trimmedNodes[nk] = true
|
2021-09-01 03:06:04 +01:00
|
|
|
e.noteRecvActivity(nk)
|
2020-08-26 20:20:09 +01:00
|
|
|
if len(ra) != 1 {
|
|
|
|
t.Fatalf("unexpected growth in map: now has %d keys; want 1", len(ra))
|
|
|
|
}
|
2021-11-02 01:21:48 +00:00
|
|
|
if got := ra[nk]; got != now {
|
2020-08-26 20:20:09 +01:00
|
|
|
t.Fatalf("time in map = %v; want %v", got, now)
|
|
|
|
}
|
2020-08-06 22:57:03 +01:00
|
|
|
if !gotConf() {
|
2020-08-26 20:20:09 +01:00
|
|
|
t.Fatalf("didn't get expected reconfig")
|
2020-08-06 22:57:03 +01:00
|
|
|
}
|
|
|
|
}
|
2020-10-13 20:04:52 +01:00
|
|
|
|
2023-08-18 15:57:44 +01:00
|
|
|
func nodeViews(v []*tailcfg.Node) []tailcfg.NodeView {
|
|
|
|
nv := make([]tailcfg.NodeView, len(v))
|
|
|
|
for i, n := range v {
|
|
|
|
nv[i] = n.View()
|
|
|
|
}
|
|
|
|
return nv
|
|
|
|
}
|
|
|
|
|
2020-10-13 20:04:52 +01:00
|
|
|
func TestUserspaceEngineReconfig(t *testing.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 05:37:33 +01:00
|
|
|
ht := new(health.Tracker)
|
|
|
|
e, err := NewFakeUserspaceEngine(t.Logf, 0, ht)
|
2020-10-13 20:04:52 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-09-15 19:48:49 +01:00
|
|
|
t.Cleanup(e.Close)
|
2020-10-13 20:04:52 +01:00
|
|
|
ue := e.(*userspaceEngine)
|
|
|
|
|
|
|
|
routerCfg := &router.Config{}
|
|
|
|
|
2021-09-01 03:06:04 +01:00
|
|
|
for _, nodeHex := range []string{
|
2020-10-13 20:04:52 +01:00
|
|
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
|
|
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
|
|
|
} {
|
2021-09-01 03:06:04 +01:00
|
|
|
nm := &netmap.NetworkMap{
|
2023-08-18 15:57:44 +01:00
|
|
|
Peers: nodeViews([]*tailcfg.Node{
|
2021-12-15 16:42:25 +00:00
|
|
|
{
|
2023-09-11 18:13:00 +01:00
|
|
|
ID: 1,
|
2021-11-02 03:55:52 +00:00
|
|
|
Key: nkFromHex(nodeHex),
|
2021-09-01 03:06:04 +01:00
|
|
|
},
|
2023-08-18 15:57:44 +01:00
|
|
|
}),
|
2021-09-01 03:06:04 +01:00
|
|
|
}
|
2021-10-28 01:42:33 +01:00
|
|
|
nk, err := key.ParseNodePublicUntyped(mem.S(nodeHex))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-10-13 20:04:52 +01:00
|
|
|
cfg := &wgcfg.Config{
|
|
|
|
Peers: []wgcfg.Peer{
|
|
|
|
{
|
2021-10-28 01:42:33 +01:00
|
|
|
PublicKey: nk,
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
AllowedIPs: []netip.Prefix{
|
|
|
|
netip.PrefixFrom(netaddr.IPv4(100, 100, 99, 1), 32),
|
2020-10-13 20:04:52 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-09-01 03:06:04 +01:00
|
|
|
e.SetNetworkMap(nm)
|
2023-08-18 01:29:15 +01:00
|
|
|
err = e.Reconfig(cfg, routerCfg, &dns.Config{})
|
2020-10-13 20:04:52 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-11-02 01:21:48 +00:00
|
|
|
wantRecvAt := map[key.NodePublic]mono.Time{
|
2021-09-01 03:06:04 +01:00
|
|
|
nkFromHex(nodeHex): 0,
|
2020-10-13 20:04:52 +01:00
|
|
|
}
|
|
|
|
if got := ue.recvActivityAt; !reflect.DeepEqual(got, wantRecvAt) {
|
|
|
|
t.Errorf("wrong recvActivityAt\n got: %v\nwant: %v\n", got, wantRecvAt)
|
|
|
|
}
|
|
|
|
|
2021-11-02 01:21:48 +00:00
|
|
|
wantTrimmedNodes := map[key.NodePublic]bool{
|
2021-09-01 03:06:04 +01:00
|
|
|
nkFromHex(nodeHex): true,
|
2020-10-13 20:04:52 +01:00
|
|
|
}
|
2021-09-01 03:06:04 +01:00
|
|
|
if got := ue.trimmedNodes; !reflect.DeepEqual(got, wantTrimmedNodes) {
|
|
|
|
t.Errorf("wrong wantTrimmedNodes\n got: %v\nwant: %v\n", got, wantTrimmedNodes)
|
2020-10-13 20:04:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-22 21:13:59 +01:00
|
|
|
func TestUserspaceEnginePortReconfig(t *testing.T) {
|
2023-01-19 14:42:58 +00:00
|
|
|
flakytest.Mark(t, "https://github.com/tailscale/tailscale/issues/2855")
|
2021-06-22 21:13:59 +01:00
|
|
|
const defaultPort = 49983
|
2023-09-11 20:03:39 +01:00
|
|
|
|
|
|
|
var knobs controlknobs.Knobs
|
|
|
|
|
2021-06-22 21:13:59 +01:00
|
|
|
// Keep making a wgengine until we find an unused port
|
|
|
|
var ue *userspaceEngine
|
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 05:37:33 +01:00
|
|
|
ht := new(health.Tracker)
|
2024-04-16 21:15:13 +01:00
|
|
|
for i := range 100 {
|
2021-06-22 21:13:59 +01:00
|
|
|
attempt := uint16(defaultPort + i)
|
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 05:37:33 +01:00
|
|
|
e, err := NewFakeUserspaceEngine(t.Logf, attempt, &knobs, ht)
|
2021-06-22 21:13:59 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
ue = e.(*userspaceEngine)
|
|
|
|
if ue.magicConn.LocalPort() == attempt {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
ue.Close()
|
|
|
|
ue = nil
|
|
|
|
}
|
|
|
|
if ue == nil {
|
|
|
|
t.Fatal("could not create a wgengine with a specific port")
|
|
|
|
}
|
2021-09-15 19:48:49 +01:00
|
|
|
t.Cleanup(ue.Close)
|
2021-06-22 21:13:59 +01:00
|
|
|
|
|
|
|
startingPort := ue.magicConn.LocalPort()
|
2021-10-28 01:42:33 +01:00
|
|
|
nodeKey, err := key.ParseNodePublicUntyped(mem.S("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-06-22 21:13:59 +01:00
|
|
|
cfg := &wgcfg.Config{
|
|
|
|
Peers: []wgcfg.Peer{
|
|
|
|
{
|
2021-10-28 01:42:33 +01:00
|
|
|
PublicKey: nodeKey,
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
AllowedIPs: []netip.Prefix{
|
|
|
|
netip.PrefixFrom(netaddr.IPv4(100, 100, 99, 1), 32),
|
2021-06-22 21:13:59 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
routerCfg := &router.Config{}
|
2023-08-18 01:29:15 +01:00
|
|
|
if err := ue.Reconfig(cfg, routerCfg, &dns.Config{}); err != nil {
|
2021-06-22 21:13:59 +01:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if got := ue.magicConn.LocalPort(); got != startingPort {
|
|
|
|
t.Errorf("no debug setting changed local port to %d from %d", got, startingPort)
|
|
|
|
}
|
2023-08-18 01:29:15 +01:00
|
|
|
|
2023-09-11 20:03:39 +01:00
|
|
|
knobs.RandomizeClientPort.Store(true)
|
2023-08-18 01:29:15 +01:00
|
|
|
if err := ue.Reconfig(cfg, routerCfg, &dns.Config{}); err != nil {
|
2021-06-22 21:13:59 +01:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if got := ue.magicConn.LocalPort(); got == startingPort {
|
|
|
|
t.Errorf("debug setting did not change local port from %d", startingPort)
|
|
|
|
}
|
|
|
|
|
|
|
|
lastPort := ue.magicConn.LocalPort()
|
2023-09-11 20:03:39 +01:00
|
|
|
knobs.RandomizeClientPort.Store(false)
|
2023-08-18 01:29:15 +01:00
|
|
|
if err := ue.Reconfig(cfg, routerCfg, &dns.Config{}); err != nil {
|
2021-06-22 21:13:59 +01:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if startingPort == defaultPort {
|
|
|
|
// Only try this if we managed to bind defaultPort the first time.
|
|
|
|
// Otherwise, assume someone else on the computer is using defaultPort
|
|
|
|
// and so Reconfig would have caused magicSockt to bind some other port.
|
|
|
|
if got := ue.magicConn.LocalPort(); got != defaultPort {
|
|
|
|
t.Errorf("debug setting did not change local port from %d to %d", startingPort, defaultPort)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if got := ue.magicConn.LocalPort(); got == lastPort {
|
|
|
|
t.Errorf("Reconfig did not change local port from %d", lastPort)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-21 10:31:48 +01:00
|
|
|
// Test that enabling and disabling peer path MTU discovery works correctly.
|
|
|
|
func TestUserspaceEnginePeerMTUReconfig(t *testing.T) {
|
|
|
|
if runtime.GOOS != "linux" && runtime.GOOS != "darwin" {
|
|
|
|
t.Skipf("skipping on %q; peer MTU not supported", runtime.GOOS)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer os.Setenv("TS_DEBUG_ENABLE_PMTUD", os.Getenv("TS_DEBUG_ENABLE_PMTUD"))
|
|
|
|
envknob.Setenv("TS_DEBUG_ENABLE_PMTUD", "")
|
|
|
|
// Turn on debugging to help diagnose problems.
|
|
|
|
defer os.Setenv("TS_DEBUG_PMTUD", os.Getenv("TS_DEBUG_PMTUD"))
|
|
|
|
envknob.Setenv("TS_DEBUG_PMTUD", "true")
|
|
|
|
|
|
|
|
var knobs controlknobs.Knobs
|
|
|
|
|
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 05:37:33 +01:00
|
|
|
ht := new(health.Tracker)
|
|
|
|
e, err := NewFakeUserspaceEngine(t.Logf, 0, &knobs, ht)
|
2023-09-21 10:31:48 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
t.Cleanup(e.Close)
|
|
|
|
ue := e.(*userspaceEngine)
|
|
|
|
|
|
|
|
if ue.magicConn.PeerMTUEnabled() != false {
|
|
|
|
t.Error("peer MTU enabled by default, should not be")
|
|
|
|
}
|
|
|
|
osDefaultDF, err := ue.magicConn.DontFragSetting()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("get don't fragment bit failed: %v", err)
|
|
|
|
}
|
|
|
|
t.Logf("Info: OS default don't fragment bit(s) setting: %v", osDefaultDF)
|
|
|
|
|
|
|
|
// Build a set of configs to use as we change the peer MTU settings.
|
|
|
|
nodeKey, err := key.ParseNodePublicUntyped(mem.S("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
cfg := &wgcfg.Config{
|
|
|
|
Peers: []wgcfg.Peer{
|
|
|
|
{
|
|
|
|
PublicKey: nodeKey,
|
|
|
|
AllowedIPs: []netip.Prefix{
|
|
|
|
netip.PrefixFrom(netaddr.IPv4(100, 100, 99, 1), 32),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
routerCfg := &router.Config{}
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
desc string // test description
|
|
|
|
wantP bool // desired value of PMTUD setting
|
|
|
|
wantDF bool // desired value of don't fragment bits
|
|
|
|
shouldP opt.Bool // if set, force peer MTU to this value
|
|
|
|
}{
|
|
|
|
{desc: "after_first_reconfig", wantP: false, wantDF: osDefaultDF, shouldP: ""},
|
|
|
|
{desc: "enabling_PMTUD_first_time", wantP: true, wantDF: true, shouldP: "true"},
|
|
|
|
{desc: "disabling_PMTUD", wantP: false, wantDF: false, shouldP: "false"},
|
|
|
|
{desc: "enabling_PMTUD_second_time", wantP: true, wantDF: true, shouldP: "true"},
|
|
|
|
{desc: "returning_to_default_PMTUD", wantP: false, wantDF: false, shouldP: ""},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.desc, func(t *testing.T) {
|
|
|
|
if v, ok := tt.shouldP.Get(); ok {
|
|
|
|
knobs.PeerMTUEnable.Store(v)
|
|
|
|
} else {
|
|
|
|
knobs.PeerMTUEnable.Store(false)
|
|
|
|
}
|
|
|
|
if err := ue.Reconfig(cfg, routerCfg, &dns.Config{}); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if v := ue.magicConn.PeerMTUEnabled(); v != tt.wantP {
|
|
|
|
t.Errorf("peer MTU set to %v, want %v", v, tt.wantP)
|
|
|
|
}
|
|
|
|
if v, err := ue.magicConn.DontFragSetting(); v != tt.wantDF || err != nil {
|
|
|
|
t.Errorf("don't fragment bit set to %v, want %v, err %v", v, tt.wantP, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-02 01:21:48 +00:00
|
|
|
func nkFromHex(hex string) key.NodePublic {
|
2020-10-13 20:04:52 +01:00
|
|
|
if len(hex) != 64 {
|
|
|
|
panic(fmt.Sprintf("%q is len %d; want 64", hex, len(hex)))
|
|
|
|
}
|
2021-10-29 22:57:32 +01:00
|
|
|
k, err := key.ParseNodePublicUntyped(mem.S(hex[:64]))
|
2020-10-13 20:04:52 +01:00
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("%q is not hex: %v", hex, err))
|
|
|
|
}
|
2021-11-02 01:21:48 +00:00
|
|
|
return k
|
2020-10-13 20:04:52 +01:00
|
|
|
}
|
2021-03-28 06:40:38 +01:00
|
|
|
|
|
|
|
// an experiment to see if genLocalAddrFunc was worth it. As of Go
|
|
|
|
// 1.16, it still very much is. (30-40x faster)
|
|
|
|
func BenchmarkGenLocalAddrFunc(b *testing.B) {
|
2022-07-26 04:55:44 +01:00
|
|
|
la1 := netip.MustParseAddr("1.2.3.4")
|
|
|
|
la2 := netip.MustParseAddr("::4")
|
|
|
|
lanot := netip.MustParseAddr("5.5.5.5")
|
2021-03-28 06:40:38 +01:00
|
|
|
var x bool
|
|
|
|
b.Run("map1", func(b *testing.B) {
|
2021-08-31 04:43:18 +01:00
|
|
|
b.ReportAllocs()
|
|
|
|
b.ResetTimer()
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
m := map[netip.Addr]bool{
|
2021-03-28 06:40:38 +01:00
|
|
|
la1: true,
|
|
|
|
}
|
2024-04-16 21:15:13 +01:00
|
|
|
for range b.N {
|
2021-03-28 06:40:38 +01:00
|
|
|
x = m[la1]
|
|
|
|
x = m[lanot]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
b.Run("map2", func(b *testing.B) {
|
2021-08-31 04:43:18 +01:00
|
|
|
b.ReportAllocs()
|
|
|
|
b.ResetTimer()
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
m := map[netip.Addr]bool{
|
2021-03-28 06:40:38 +01:00
|
|
|
la1: true,
|
|
|
|
la2: true,
|
|
|
|
}
|
2024-04-16 21:15:13 +01:00
|
|
|
for range b.N {
|
2021-03-28 06:40:38 +01:00
|
|
|
x = m[la1]
|
|
|
|
x = m[lanot]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
b.Run("or1", func(b *testing.B) {
|
2021-08-31 04:43:18 +01:00
|
|
|
b.ReportAllocs()
|
|
|
|
b.ResetTimer()
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
f := func(t netip.Addr) bool {
|
2021-03-28 06:40:38 +01:00
|
|
|
return t == la1
|
|
|
|
}
|
2024-04-16 21:15:13 +01:00
|
|
|
for range b.N {
|
2021-03-28 06:40:38 +01:00
|
|
|
x = f(la1)
|
|
|
|
x = f(lanot)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
b.Run("or2", func(b *testing.B) {
|
2021-08-31 04:43:18 +01:00
|
|
|
b.ReportAllocs()
|
|
|
|
b.ResetTimer()
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
f := func(t netip.Addr) bool {
|
2021-03-28 06:40:38 +01:00
|
|
|
return t == la1 || t == la2
|
|
|
|
}
|
2024-04-16 21:15:13 +01:00
|
|
|
for range b.N {
|
2021-03-28 06:40:38 +01:00
|
|
|
x = f(la1)
|
|
|
|
x = f(lanot)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
b.Logf("x = %v", x)
|
|
|
|
}
|