ipn/ipnlocal, wgengine/magicsock: move UpdateStatus stuff around

Upcoming work on incremental netmap change handling will require some
replumbing of which subsystems get notified about what. Done naively,
it could break "tailscale status --json" visibility later. To make sure
I understood the flow of all the updates I was rereading the status code
and realized parts of ipnstate.Status were being populated by the wrong
subsystems.

The engine (wireguard) and magicsock (data plane, NAT traveral) should
only populate the stuff that they uniquely know. The WireGuard bits
were fine but magicsock was populating stuff stuff that LocalBackend
could've better handled, so move it there.

Updates #1909

Change-Id: I6d1b95d19a2d1b70fbb3c875fac8ea1e169e8cb0
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2023-08-23 12:13:38 -07:00
committed by Brad Fitzpatrick
parent 74388a771f
commit ea4425d8a9
3 changed files with 34 additions and 29 deletions
+7 -3
View File
@@ -226,6 +226,8 @@ func (s *magicStack) Public() key.NodePublic {
return s.privateKey.Public()
}
// Status returns a subset of the ipnstate.Status, only involving
// the magicsock-specific parts.
func (s *magicStack) Status() *ipnstate.Status {
var sb ipnstate.StatusBuilder
sb.WantPeers = true
@@ -240,9 +242,11 @@ func (s *magicStack) Status() *ipnstate.Status {
// address. See meshStacks for one possible source of netmaps and IPs.
func (s *magicStack) IP() netip.Addr {
for deadline := time.Now().Add(5 * time.Second); time.Now().Before(deadline); time.Sleep(10 * time.Millisecond) {
st := s.Status()
if len(st.TailscaleIPs) > 0 {
return st.TailscaleIPs[0]
s.conn.mu.Lock()
nm := s.conn.netMap
s.conn.mu.Unlock()
if nm != nil && len(nm.Addresses) > 0 {
return nm.Addresses[0].Addr()
}
}
panic("timed out waiting for magicstack to get an IP assigned")