diff --git a/tstest/log.go b/tstest/log.go index 86639357e..cb67c609a 100644 --- a/tstest/log.go +++ b/tstest/log.go @@ -42,7 +42,9 @@ func (panicLogWriter) Write(b []byte) (int, error) { // interfaces.GetState & tshttpproxy code to allow pushing // down a Logger yet. TODO(bradfitz): do that refactoring once // 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) return len(b), nil } diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index a6598291b..b9cb72d3f 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -384,6 +384,10 @@ type Options struct { // WireGuard state by its public key. If nil, it's not used. // In regular use, this will be wgengine.(*userspaceEngine).PeerByKey. 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 { @@ -452,7 +456,7 @@ func NewConn(opts Options) (*Conn, error) { c.testOnlyPacketListener = opts.TestOnlyPacketListener c.noteRecvActivity = opts.NoteRecvActivity 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) if opts.NetMon != nil { diff --git a/wgengine/magicsock/magicsock_test.go b/wgengine/magicsock/magicsock_test.go index 23f029eec..b009140b9 100644 --- a/wgengine/magicsock/magicsock_test.go +++ b/wgengine/magicsock/magicsock_test.go @@ -171,6 +171,7 @@ func newMagicStackWithKey(t testing.TB, logf logger.Logf, l nettype.PacketListen epCh := make(chan []tailcfg.Endpoint, 100) // arbitrary conn, err := NewConn(Options{ Logf: logf, + DisablePortMapper: true, TestOnlyPacketListener: l, EndpointsFunc: func(eps []tailcfg.Endpoint) { epCh <- eps @@ -376,9 +377,10 @@ func TestNewConn(t *testing.T) { port := pickPort(t) conn, err := NewConn(Options{ - Port: port, - EndpointsFunc: epFunc, - Logf: t.Logf, + Port: port, + DisablePortMapper: true, + EndpointsFunc: epFunc, + Logf: t.Logf, }) if err != nil { t.Fatal(err) @@ -1242,6 +1244,7 @@ func newTestConn(t testing.TB) *Conn { t.Helper() port := pickPort(t) conn, err := NewConn(Options{ + DisablePortMapper: true, Logf: t.Logf, Port: port, TestOnlyPacketListener: localhostListener{},