From 682d9ea89659c1711f3455c7be15e8d381ad5fb5 Mon Sep 17 00:00:00 2001 From: Jordan Whited Date: Mon, 11 Dec 2023 17:18:06 -0800 Subject: [PATCH] wgengine/magicsock: debug knob to override preferred derp region Signed-off-by: Jordan Whited --- wgengine/magicsock/debugknobs.go | 3 ++- wgengine/magicsock/debugknobs_stubs.go | 1 + wgengine/magicsock/magicsock.go | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/wgengine/magicsock/debugknobs.go b/wgengine/magicsock/debugknobs.go index 824c677f6..4f0d234a8 100644 --- a/wgengine/magicsock/debugknobs.go +++ b/wgengine/magicsock/debugknobs.go @@ -55,7 +55,8 @@ // sockets. debugEnablePMTUD = envknob.RegisterOptBool("TS_DEBUG_ENABLE_PMTUD") // debugPMTUD prints extra debugging about peer MTU path discovery. - debugPMTUD = envknob.RegisterBool("TS_DEBUG_PMTUD") + debugPMTUD = envknob.RegisterBool("TS_DEBUG_PMTUD") + debugPreferDERPRegion = envknob.RegisterInt("TS_DEBUG_PREFER_DERP_REGION") // Hey you! Adding a new debugknob? Make sure to stub it out in the // debugknobs_stubs.go file too. ) diff --git a/wgengine/magicsock/debugknobs_stubs.go b/wgengine/magicsock/debugknobs_stubs.go index de49865bf..de4999d4e 100644 --- a/wgengine/magicsock/debugknobs_stubs.go +++ b/wgengine/magicsock/debugknobs_stubs.go @@ -28,3 +28,4 @@ func debugEnablePMTUD() opt.Bool { return "" } func debugRingBufferMaxSizeBytes() int { return 0 } func inTest() bool { return false } func debugPeerMap() bool { return false } +func debugPreferDERPRegion() int { return 0 } diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 35755e03d..9fc80c2d4 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -649,6 +649,10 @@ func (c *Conn) updateNetInfo(ctx context.Context) (*netcheck.Report, error) { ni.WorkingUDP.Set(report.UDP) ni.WorkingICMPv4.Set(report.ICMPv4) ni.PreferredDERP = report.PreferredDERP + preferDERP := debugPreferDERPRegion() + if preferDERP > 0 { + ni.PreferredDERP = preferDERP + } if ni.PreferredDERP == 0 { // Perhaps UDP is blocked. Pick a deterministic but arbitrary