From 0c55777fed7d9f8207611b920434968721f6e8d9 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 19 Feb 2020 23:23:34 -0800 Subject: [PATCH] ipn: temporary support for loading legacy relaynode configs. Signed-off-by: David Anderson --- cmd/tailscaled/tailscaled.go | 1 + ipn/backend.go | 8 ++++++++ ipn/ipnserver/server.go | 12 +++++++++++- ipn/local.go | 13 +++++++++---- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/cmd/tailscaled/tailscaled.go b/cmd/tailscaled/tailscaled.go index 821941a00..a25da36de 100644 --- a/cmd/tailscaled/tailscaled.go +++ b/cmd/tailscaled/tailscaled.go @@ -80,6 +80,7 @@ func main() { SocketPath: *socketpath, StatePath: *statepath, AutostartStateKey: globalStateKey, + LegacyConfigPath: "/var/lib/tailscale/relay.conf", SurviveDisconnects: true, } err = ipnserver.Run(context.Background(), logf, pol.PublicID.String(), opts, e) diff --git a/ipn/backend.go b/ipn/backend.go index da5f17592..8988115f1 100644 --- a/ipn/backend.go +++ b/ipn/backend.go @@ -82,6 +82,14 @@ type Options struct { // an initial overwrite of backend state with Prefs. StateKey StateKey Prefs *Prefs + // LegacyConfigPath optionally specifies the old-style relaynode + // relay.conf location. If both LegacyConfigPath and StateKey are + // specified and the requested state doesn't exist in the backend + // store, the backend migrates the config from LegacyConfigPath. + // + // TODO(danderson): remove some time after the transition to + // tailscaled is done. + LegacyConfigPath string // Notify is called when backend events happen. Notify func(Notify) `json:"-"` } diff --git a/ipn/ipnserver/server.go b/ipn/ipnserver/server.go index 0809ad6fd..6e70b9dfa 100644 --- a/ipn/ipnserver/server.go +++ b/ipn/ipnserver/server.go @@ -43,6 +43,15 @@ type Options struct { // using the given StateKey. If empty, the agent stays idle and // waits for a frontend to start it. AutostartStateKey ipn.StateKey + // LegacyConfigPath optionally specifies the old-style relaynode + // relay.conf location. If both LegacyConfigPath and + // AutostartStateKey are specified and the requested state doesn't + // exist in the backend store, the backend migrates the config + // from LegacyConfigPath. + // + // TODO(danderson): remove some time after the transition to + // tailscaled is done. + LegacyConfigPath string // SurviveDisconnects specifies how the server reacts to its // frontend disconnecting. If true, the server keeps running on // its existing state, and accepts new frontend connections. If @@ -114,7 +123,8 @@ func Run(rctx context.Context, logf logger.Logf, logid string, opts Options, e w Version: version.LONG, Start: &ipn.StartArgs{ Opts: ipn.Options{ - StateKey: opts.AutostartStateKey, + StateKey: opts.AutostartStateKey, + LegacyConfigPath: opts.LegacyConfigPath, }, }, }) diff --git a/ipn/local.go b/ipn/local.go index 065b24f81..459df9492 100644 --- a/ipn/local.go +++ b/ipn/local.go @@ -150,7 +150,7 @@ func (b *LocalBackend) Start(opts Options) error { b.hiCache = hi b.state = NoState - if err := b.loadStateWithLock(opts.StateKey, opts.Prefs); err != nil { + if err := b.loadStateWithLock(opts.StateKey, opts.Prefs, opts.LegacyConfigPath); err != nil { b.mu.Unlock() return fmt.Errorf("loading requested state: %v", err) } @@ -360,7 +360,7 @@ func (b *LocalBackend) popBrowserAuthNow() { } } -func (b *LocalBackend) loadStateWithLock(key StateKey, prefs *Prefs) error { +func (b *LocalBackend) loadStateWithLock(key StateKey, prefs *Prefs, legacyPath string) error { if prefs == nil && key == "" { panic("state key and prefs are both unset") } @@ -386,9 +386,14 @@ func (b *LocalBackend) loadStateWithLock(key StateKey, prefs *Prefs) error { bs, err := b.store.ReadState(key) if err != nil { if err == ErrStateNotExist { - b.prefs = NewPrefs() + if legacyPath != "" { + b.prefs = *LoadPrefs(legacyPath, true) + b.logf("Imported state from relaynode for %q", key) + } else { + b.prefs = NewPrefs() + b.logf("Created empty state for %q", key) + } b.stateKey = key - b.logf("Created empty state for %q", key) return nil } return fmt.Errorf("store.ReadState(%q): %v", key, err)