health: don't report a warning in DERP homeless mode

Updates #3363
Updates tailscale/corp#396

Change-Id: Ibfb0496821cb58a78399feb88d4206d81e95ca0f
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2023-11-16 13:43:36 -08:00 committed by Brad Fitzpatrick
parent cca27ef96a
commit 4d196c12d9
2 changed files with 20 additions and 12 deletions

View File

@ -37,6 +37,7 @@
lastMapPollEndedAt time.Time lastMapPollEndedAt time.Time
lastStreamedMapResponse time.Time lastStreamedMapResponse time.Time
derpHomeRegion int derpHomeRegion int
derpHomeless bool
derpRegionConnected = map[int]bool{} derpRegionConnected = map[int]bool{}
derpRegionHealthProblem = map[int]string{} derpRegionHealthProblem = map[int]string{}
derpRegionLastFrame = map[int]time.Time{} derpRegionLastFrame = map[int]time.Time{}
@ -315,10 +316,14 @@ func GetInPollNetMap() bool {
} }
// SetMagicSockDERPHome notes what magicsock's view of its home DERP is. // SetMagicSockDERPHome notes what magicsock's view of its home DERP is.
func SetMagicSockDERPHome(region int) { //
// The homeless parameter is whether magicsock is running in DERP-disconnected
// mode, without discovering and maintaining a connection to its home DERP.
func SetMagicSockDERPHome(region int, homeless bool) {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
derpHomeRegion = region derpHomeRegion = region
derpHomeless = homeless
selfCheckLocked() selfCheckLocked()
} }
@ -447,15 +452,17 @@ func overallErrorLocked() error {
if d := now.Sub(lastStreamedMapResponse).Round(time.Second); d > tooIdle { if d := now.Sub(lastStreamedMapResponse).Round(time.Second); d > tooIdle {
return fmt.Errorf("no map response in %v", d) return fmt.Errorf("no map response in %v", d)
} }
rid := derpHomeRegion if !derpHomeless {
if rid == 0 { rid := derpHomeRegion
return errors.New("no DERP home") if rid == 0 {
} return errors.New("no DERP home")
if !derpRegionConnected[rid] { }
return fmt.Errorf("not connected to home DERP region %v", rid) if !derpRegionConnected[rid] {
} return fmt.Errorf("not connected to home DERP region %v", rid)
if d := now.Sub(derpRegionLastFrame[rid]).Round(time.Second); d > tooIdle { }
return fmt.Errorf("haven't heard from home DERP region %v in %v", rid, d) if d := now.Sub(derpRegionLastFrame[rid]).Round(time.Second); d > tooIdle {
return fmt.Errorf("haven't heard from home DERP region %v in %v", rid, d)
}
} }
if udp4Unbound { if udp4Unbound {
return errors.New("no udp4 bind") return errors.New("no udp4 bind")

View File

@ -141,11 +141,12 @@ func (c *Conn) setNearestDERP(derpNum int) (wantDERP bool) {
defer c.mu.Unlock() defer c.mu.Unlock()
if !c.wantDerpLocked() { if !c.wantDerpLocked() {
c.myDerp = 0 c.myDerp = 0
health.SetMagicSockDERPHome(0) health.SetMagicSockDERPHome(0, c.homeless)
return false return false
} }
if c.homeless { if c.homeless {
c.myDerp = 0 c.myDerp = 0
health.SetMagicSockDERPHome(0, c.homeless)
return false return false
} }
if derpNum == c.myDerp { if derpNum == c.myDerp {
@ -156,7 +157,7 @@ func (c *Conn) setNearestDERP(derpNum int) (wantDERP bool) {
metricDERPHomeChange.Add(1) metricDERPHomeChange.Add(1)
} }
c.myDerp = derpNum c.myDerp = derpNum
health.SetMagicSockDERPHome(derpNum) health.SetMagicSockDERPHome(derpNum, c.homeless)
if c.privateKey.IsZero() { if c.privateKey.IsZero() {
// No private key yet, so DERP connections won't come up anyway. // No private key yet, so DERP connections won't come up anyway.