mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-21 22:21:41 +00:00
wgengine/magicsock: disable portmapper in tunchan-faked tests
Most of the magicsock tests fake the network, simulating packets going out and coming in. There's no reason to actually hit your router to do UPnP/NAT-PMP/PCP during in tests. But while debugging thousands of iterations of tests to deflake some things, I saw it slamming my router. This stops that. Updates #11762 Change-Id: I59b9f48f8f5aff1fa16b4935753d786342e87744 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
22bd506129
commit
03d5d1f0f9
@ -42,7 +42,9 @@ func (panicLogWriter) Write(b []byte) (int, error) {
|
|||||||
// interfaces.GetState & tshttpproxy code to allow pushing
|
// interfaces.GetState & tshttpproxy code to allow pushing
|
||||||
// down a Logger yet. TODO(bradfitz): do that refactoring once
|
// down a Logger yet. TODO(bradfitz): do that refactoring once
|
||||||
// 1.2.0 is out.
|
// 1.2.0 is out.
|
||||||
if bytes.Contains(b, []byte("tshttpproxy: ")) || bytes.Contains(b, []byte("runtime/panic.go:")) {
|
if bytes.Contains(b, []byte("tshttpproxy: ")) ||
|
||||||
|
bytes.Contains(b, []byte("runtime/panic.go:")) ||
|
||||||
|
bytes.Contains(b, []byte("XXX")) {
|
||||||
os.Stderr.Write(b)
|
os.Stderr.Write(b)
|
||||||
return len(b), nil
|
return len(b), nil
|
||||||
}
|
}
|
||||||
|
@ -384,6 +384,10 @@ type Options struct {
|
|||||||
// WireGuard state by its public key. If nil, it's not used.
|
// WireGuard state by its public key. If nil, it's not used.
|
||||||
// In regular use, this will be wgengine.(*userspaceEngine).PeerByKey.
|
// In regular use, this will be wgengine.(*userspaceEngine).PeerByKey.
|
||||||
PeerByKeyFunc func(key.NodePublic) (_ wgint.Peer, ok bool)
|
PeerByKeyFunc func(key.NodePublic) (_ wgint.Peer, ok bool)
|
||||||
|
|
||||||
|
// DisablePortMapper, if true, disables the portmapper.
|
||||||
|
// This is primarily useful in tests.
|
||||||
|
DisablePortMapper bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Options) logf() logger.Logf {
|
func (o *Options) logf() logger.Logf {
|
||||||
@ -452,7 +456,7 @@ func NewConn(opts Options) (*Conn, error) {
|
|||||||
c.testOnlyPacketListener = opts.TestOnlyPacketListener
|
c.testOnlyPacketListener = opts.TestOnlyPacketListener
|
||||||
c.noteRecvActivity = opts.NoteRecvActivity
|
c.noteRecvActivity = opts.NoteRecvActivity
|
||||||
portMapOpts := &portmapper.DebugKnobs{
|
portMapOpts := &portmapper.DebugKnobs{
|
||||||
DisableAll: func() bool { return c.onlyTCP443.Load() },
|
DisableAll: func() bool { return opts.DisablePortMapper || c.onlyTCP443.Load() },
|
||||||
}
|
}
|
||||||
c.portMapper = portmapper.NewClient(logger.WithPrefix(c.logf, "portmapper: "), opts.NetMon, portMapOpts, opts.ControlKnobs, c.onPortMapChanged)
|
c.portMapper = portmapper.NewClient(logger.WithPrefix(c.logf, "portmapper: "), opts.NetMon, portMapOpts, opts.ControlKnobs, c.onPortMapChanged)
|
||||||
if opts.NetMon != nil {
|
if opts.NetMon != nil {
|
||||||
|
@ -171,6 +171,7 @@ func newMagicStackWithKey(t testing.TB, logf logger.Logf, l nettype.PacketListen
|
|||||||
epCh := make(chan []tailcfg.Endpoint, 100) // arbitrary
|
epCh := make(chan []tailcfg.Endpoint, 100) // arbitrary
|
||||||
conn, err := NewConn(Options{
|
conn, err := NewConn(Options{
|
||||||
Logf: logf,
|
Logf: logf,
|
||||||
|
DisablePortMapper: true,
|
||||||
TestOnlyPacketListener: l,
|
TestOnlyPacketListener: l,
|
||||||
EndpointsFunc: func(eps []tailcfg.Endpoint) {
|
EndpointsFunc: func(eps []tailcfg.Endpoint) {
|
||||||
epCh <- eps
|
epCh <- eps
|
||||||
@ -377,6 +378,7 @@ func TestNewConn(t *testing.T) {
|
|||||||
port := pickPort(t)
|
port := pickPort(t)
|
||||||
conn, err := NewConn(Options{
|
conn, err := NewConn(Options{
|
||||||
Port: port,
|
Port: port,
|
||||||
|
DisablePortMapper: true,
|
||||||
EndpointsFunc: epFunc,
|
EndpointsFunc: epFunc,
|
||||||
Logf: t.Logf,
|
Logf: t.Logf,
|
||||||
})
|
})
|
||||||
@ -1242,6 +1244,7 @@ func newTestConn(t testing.TB) *Conn {
|
|||||||
t.Helper()
|
t.Helper()
|
||||||
port := pickPort(t)
|
port := pickPort(t)
|
||||||
conn, err := NewConn(Options{
|
conn, err := NewConn(Options{
|
||||||
|
DisablePortMapper: true,
|
||||||
Logf: t.Logf,
|
Logf: t.Logf,
|
||||||
Port: port,
|
Port: port,
|
||||||
TestOnlyPacketListener: localhostListener{},
|
TestOnlyPacketListener: localhostListener{},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user