diff options
| author | Maisem Ali <maisem@tailscale.com> | 2023-10-23 14:20:15 -0700 |
|---|---|---|
| committer | Maisem Ali <maisem@tailscale.com> | 2023-10-23 14:20:15 -0700 |
| commit | b2cd13146c3650ef05fba06712465a4301196479 (patch) | |
| tree | 8dd3858cc98c6e122f1d2548173816c8a7b0a41d /control | |
| parent | cc43f4d1de78267dd2eb6734c2a89f05a3cc0372 (diff) | |
| download | tailscale-maisem/ni.tar.xz tailscale-maisem/ni.zip | |
ipn/ipnlocal: move tailcfg.Netinfo ownership to LocalBackendmaisem/ni
The only thing place which owned the copy of Netinfo was the controlclient,
which meant that we had another place where we were modifying the hostinfo
and blending fields in. This moves all of that logic to now occur solely
in LocalBackend.
Updates #cleanup
Signed-off-by: Maisem Ali <maisem@tailscale.com>
Diffstat (limited to 'control')
| -rw-r--r-- | control/controlclient/auto.go | 12 | ||||
| -rw-r--r-- | control/controlclient/client.go | 6 | ||||
| -rw-r--r-- | control/controlclient/direct.go | 41 |
3 files changed, 4 insertions, 55 deletions
diff --git a/control/controlclient/auto.go b/control/controlclient/auto.go index fa5e2e106..10f5a3781 100644 --- a/control/controlclient/auto.go +++ b/control/controlclient/auto.go @@ -564,18 +564,6 @@ func (c *Auto) SetHostinfo(hi *tailcfg.Hostinfo) { c.updateControl() } -func (c *Auto) SetNetInfo(ni *tailcfg.NetInfo) { - if ni == nil { - panic("nil NetInfo") - } - if !c.direct.SetNetInfo(ni) { - return - } - - // Send new NetInfo to server - c.updateControl() -} - // SetTKAHead updates the TKA head hash that map-request infrastructure sends. func (c *Auto) SetTKAHead(headHash string) { if !c.direct.SetTKAHead(headHash) { diff --git a/control/controlclient/client.go b/control/controlclient/client.go index ef5af68c6..1bd087e29 100644 --- a/control/controlclient/client.go +++ b/control/controlclient/client.go @@ -65,12 +65,6 @@ type Client interface { // in a separate http request. It has nothing to do with the rest of // the state machine. SetHostinfo(*tailcfg.Hostinfo) - // SetNetinfo changes the NetIinfo structure that will be sent in - // subsequent node registration requests. - // TODO: a server-side change would let us simply upload this - // in a separate http request. It has nothing to do with the rest of - // the state machine. - SetNetInfo(*tailcfg.NetInfo) // SetTKAHead changes the TKA head hash value that will be sent in // subsequent netmap requests. SetTKAHead(headHash string) diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index 80f6e919b..1b1ed78f5 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -20,7 +20,6 @@ import ( "net/netip" "net/url" "os" - "reflect" "runtime" "slices" "strings" @@ -50,7 +49,6 @@ import ( "tailscale.com/types/logger" "tailscale.com/types/netmap" "tailscale.com/types/persist" - "tailscale.com/types/ptr" "tailscale.com/types/tkatype" "tailscale.com/util/clientmetric" "tailscale.com/util/multierr" @@ -93,8 +91,7 @@ type Direct struct { authKey string tryingNewKey key.NodePrivate expiry time.Time // or zero value if none/unknown - hostinfo *tailcfg.Hostinfo // always non-nil - netinfo *tailcfg.NetInfo + hostinfo *tailcfg.Hostinfo // always non-nil, never mutated only replaced endpoints []tailcfg.Endpoint tkaHead string lastPingURL string // last PingRequest.URL received, for dup suppression @@ -289,9 +286,6 @@ func NewDirect(opts Options) (*Direct, error) { c.SetHostinfo(hostinfo.New()) } else { c.SetHostinfo(opts.Hostinfo) - if ni := opts.Hostinfo.NetInfo; ni != nil { - c.SetNetInfo(ni) - } } if opts.NoiseTestClient != nil { c.noiseClient = &NoiseClient{ @@ -321,8 +315,6 @@ func (c *Direct) SetHostinfo(hi *tailcfg.Hostinfo) bool { if hi == nil { panic("nil Hostinfo") } - hi = ptr.To(*hi) - hi.NetInfo = nil c.mu.Lock() defer c.mu.Unlock() @@ -335,24 +327,7 @@ func (c *Direct) SetHostinfo(hi *tailcfg.Hostinfo) bool { return true } -// SetNetInfo clones the provided NetInfo and remembers it for the -// next update. It reports whether the NetInfo has changed. -func (c *Direct) SetNetInfo(ni *tailcfg.NetInfo) bool { - if ni == nil { - panic("nil NetInfo") - } - c.mu.Lock() - defer c.mu.Unlock() - - if reflect.DeepEqual(ni, c.netinfo) { - return false - } - c.netinfo = ni.Clone() - c.logf("NetInfo: %v", ni) - return true -} - -// SetNetInfo stores a new TKA head value for next update. +// SetTKAHead stores a new TKA head value for next update. // It reports whether the TKA head changed. func (c *Direct) SetTKAHead(tkaHead string) bool { c.mu.Lock() @@ -445,14 +420,6 @@ type httpClient interface { Do(req *http.Request) (*http.Response, error) } -// hostInfoLocked returns a Clone of c.hostinfo and c.netinfo. -// It must only be called with c.mu held. -func (c *Direct) hostInfoLocked() *tailcfg.Hostinfo { - hi := c.hostinfo.Clone() - hi.NetInfo = c.netinfo.Clone() - return hi -} - func (c *Direct) doLogin(ctx context.Context, opt loginOpt) (mustRegen bool, newURL string, nks tkatype.MarshaledSignature, err error) { c.mu.Lock() persist := c.persist.AsStruct() @@ -460,7 +427,7 @@ func (c *Direct) doLogin(ctx context.Context, opt loginOpt) (mustRegen bool, new serverKey := c.serverKey serverNoiseKey := c.serverNoiseKey authKey, isWrapped, wrappedSig, wrappedKey := decodeWrappedAuthkey(c.authKey, c.logf) - hi := c.hostInfoLocked() + hi := c.hostinfo backendLogID := hi.BackendLogID expired := !c.expiry.IsZero() && c.expiry.Before(c.clock.Now()) c.mu.Unlock() @@ -849,7 +816,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, isStreaming bool, nu Netmap serverURL := c.serverURL serverKey := c.serverKey serverNoiseKey := c.serverNoiseKey - hi := c.hostInfoLocked() + hi := c.hostinfo backendLogID := hi.BackendLogID var epStrs []string var eps []netip.AddrPort |
