ipn/ipnlocal: add basic support for netmap caching (#18530)
This commit is based on ff0978ab, and extends #18497 to connect network map caching to the LocalBackend. As implemented, only "whole" netmap values are stored, and we do not yet handle incremental updates. As-written, the feature must be explicitly enabled via the TS_USE_CACHED_NETMAP envknob, and must be considered experimental. Updates #12639 Co-Authored-by: Brad Fitzpatrick <bradfitz@tailscale.com> Change-Id: I48a1e92facfbf7fb3a8e67cff7f2c9ab4ed62c83 Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
This commit is contained in:
+30
-8
@@ -271,6 +271,7 @@ type LocalBackend struct {
|
||||
// of [LocalBackend]'s own state that is not tied to the node context.
|
||||
currentNodeAtomic atomic.Pointer[nodeBackend]
|
||||
|
||||
diskCache diskCache
|
||||
conf *conffile.Config // latest parsed config, or nil if not in declarative mode
|
||||
pm *profileManager // mu guards access
|
||||
lastFilterInputs *filterInputs
|
||||
@@ -1573,7 +1574,13 @@ func (b *LocalBackend) SetControlClientStatus(c controlclient.Client, st control
|
||||
}
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
b.setControlClientStatusLocked(c, st)
|
||||
}
|
||||
|
||||
// setControlClientStatusLocked is the locked version of SetControlClientStatus.
|
||||
//
|
||||
// b.mu must be held.
|
||||
func (b *LocalBackend) setControlClientStatusLocked(c controlclient.Client, st controlclient.Status) {
|
||||
if b.cc != c {
|
||||
b.logf("Ignoring SetControlClientStatus from old client")
|
||||
return
|
||||
@@ -2414,6 +2421,14 @@ func (b *LocalBackend) initOnce() {
|
||||
b.extHost.Init()
|
||||
}
|
||||
|
||||
func (b *LocalBackend) controlDebugFlags() []string {
|
||||
debugFlags := controlDebugFlags
|
||||
if b.sys.IsNetstackRouter() {
|
||||
return append([]string{"netstack"}, debugFlags...)
|
||||
}
|
||||
return debugFlags
|
||||
}
|
||||
|
||||
// Start applies the configuration specified in opts, and starts the
|
||||
// state machine.
|
||||
//
|
||||
@@ -2570,14 +2585,18 @@ func (b *LocalBackend) startLocked(opts ipn.Options) error {
|
||||
persistv = new(persist.Persist)
|
||||
}
|
||||
|
||||
discoPublic := b.MagicConn().DiscoPublicKey()
|
||||
|
||||
isNetstack := b.sys.IsNetstackRouter()
|
||||
debugFlags := controlDebugFlags
|
||||
if isNetstack {
|
||||
debugFlags = append([]string{"netstack"}, debugFlags...)
|
||||
if envknob.Bool("TS_USE_CACHED_NETMAP") {
|
||||
if nm, ok := b.loadDiskCacheLocked(); ok {
|
||||
logf("loaded netmap from disk cache; %d peers", len(nm.Peers))
|
||||
b.setControlClientStatusLocked(nil, controlclient.Status{
|
||||
NetMap: nm,
|
||||
LoggedIn: true, // sure
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
discoPublic := b.MagicConn().DiscoPublicKey()
|
||||
|
||||
var ccShutdownCbs []func()
|
||||
ccShutdown := func() {
|
||||
for _, cb := range ccShutdownCbs {
|
||||
@@ -2603,7 +2622,7 @@ func (b *LocalBackend) startLocked(opts ipn.Options) error {
|
||||
Hostinfo: b.hostInfoWithServicesLocked(),
|
||||
HTTPTestClient: httpTestClient,
|
||||
DiscoPublicKey: discoPublic,
|
||||
DebugFlags: debugFlags,
|
||||
DebugFlags: b.controlDebugFlags(),
|
||||
HealthTracker: b.health,
|
||||
PolicyClient: b.sys.PolicyClientOrDefault(),
|
||||
Pinger: b,
|
||||
@@ -2619,7 +2638,7 @@ func (b *LocalBackend) startLocked(opts ipn.Options) error {
|
||||
|
||||
// Don't warn about broken Linux IP forwarding when
|
||||
// netstack is being used.
|
||||
SkipIPForwardingCheck: isNetstack,
|
||||
SkipIPForwardingCheck: b.sys.IsNetstackRouter(),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -6248,6 +6267,9 @@ func (b *LocalBackend) setNetMapLocked(nm *netmap.NetworkMap) {
|
||||
var login string
|
||||
if nm != nil {
|
||||
login = cmp.Or(profileFromView(nm.UserProfiles[nm.User()]).LoginName, "<missing-profile>")
|
||||
if err := b.writeNetmapToDiskLocked(nm); err != nil {
|
||||
b.logf("write netmap to cache: %v", err)
|
||||
}
|
||||
}
|
||||
b.currentNode().SetNetMap(nm)
|
||||
if ms, ok := b.sys.MagicSock.GetOK(); ok {
|
||||
|
||||
Reference in New Issue
Block a user