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:
Brad Fitzpatrick
2024-04-17 21:32:18 -07:00
committed by Brad Fitzpatrick
parent 22bd506129
commit 03d5d1f0f9
3 changed files with 14 additions and 5 deletions

View File

@@ -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 {