From 476a4c6ff174d46ce3b125c018c07c43713e1c10 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 10 Apr 2025 09:49:46 -0700 Subject: [PATCH] ipn/ipnstate: add home DERP to tailscale status JSON Fixes #15625 Change-Id: Ic20dad2dab4ac52c666057845bdc3cf5c0ffcd8f Signed-off-by: Brad Fitzpatrick --- ipn/ipnstate/ipnstate.go | 3 +++ wgengine/magicsock/magicsock.go | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ipn/ipnstate/ipnstate.go b/ipn/ipnstate/ipnstate.go index 89c6d7e24..4494afb67 100644 --- a/ipn/ipnstate/ipnstate.go +++ b/ipn/ipnstate/ipnstate.go @@ -53,6 +53,9 @@ type Status struct { // If nil, an exit node is not in use. ExitNodeStatus *ExitNodeStatus `json:"ExitNodeStatus,omitempty"` + // DERPHomeRegionID is the current home DERP region ID. + DERPHomeRegionID int + // Health contains health check problems. // Empty means everything is good. (or at least that no known // problems are detected) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index a32867f72..e7e65b6ee 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -2892,11 +2892,15 @@ func (c *Conn) UpdateStatus(sb *ipnstate.StatusBuilder) { }) } - c.foreachActiveDerpSortedLocked(func(node int, ad activeDerp) { - // TODO(bradfitz): add a method to ipnstate.StatusBuilder - // to include all the DERP connections we have open - // and add it here. See the other caller of foreachActiveDerpSortedLocked. + sb.MutateStatus(func(s *ipnstate.Status) { + s.DERPHomeRegionID = c.myDerp + c.foreachActiveDerpSortedLocked(func(node int, ad activeDerp) { + // TODO(bradfitz): add a method to ipnstate.StatusBuilder + // to include all the DERP connections we have open + // and add it here. See the other caller of foreachActiveDerpSortedLocked. + }) }) + } // SetStatistics specifies a per-connection statistics aggregator.