From ba3cc08b62b0bb3ee45d13887c12871bd79a9edb Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 1 Sep 2022 09:27:06 -0700 Subject: [PATCH] cmd/tailscale/cli: add backwards compatibility 'up' processing for legacy client Updates tailscale/corp#6781 Change-Id: I843fc810cbec0140d423d65db81e90179d6e0fa5 Signed-off-by: Brad Fitzpatrick --- cmd/tailscale/cli/cli_test.go | 3 +++ cmd/tailscale/cli/up.go | 7 ++++++- ipn/ipn_clone.go | 1 + ipn/ipnlocal/local.go | 10 +++++++++- ipn/prefs.go | 4 ++++ ipn/prefs_test.go | 1 + 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cmd/tailscale/cli/cli_test.go b/cmd/tailscale/cli/cli_test.go index 736f19058..f6825bf17 100644 --- a/cmd/tailscale/cli/cli_test.go +++ b/cmd/tailscale/cli/cli_test.go @@ -762,6 +762,9 @@ func TestPrefFlagMapping(t *testing.T) { case "NotepadURLs": // TODO(bradfitz): https://github.com/tailscale/tailscale/issues/1830 continue + case "Egg": + // Not applicable. + continue } t.Errorf("unexpected new ipn.Pref field %q is not handled by up.go (see addPrefFlagMapping and checkForAccidentalSettingReverts)", prefName) } diff --git a/cmd/tailscale/cli/up.go b/cmd/tailscale/cli/up.go index 6941fb880..5deaf96d7 100644 --- a/cmd/tailscale/cli/up.go +++ b/cmd/tailscale/cli/up.go @@ -406,8 +406,12 @@ func updatePrefs(prefs, curPrefs *ipn.Prefs, env upCheckEnv) (simpleUp bool, jus } func runUp(ctx context.Context, args []string) (retErr error) { + var egg bool if len(args) > 0 { - fatalf("too many non-flag arguments: %q", args) + egg = fmt.Sprint(args) == "[up down down left right left right b a]" + if !egg { + fatalf("too many non-flag arguments: %q", args) + } } st, err := localClient.Status(ctx) @@ -493,6 +497,7 @@ func runUp(ctx context.Context, args []string) (retErr error) { fatalf("%s", err) } if justEditMP != nil { + justEditMP.EggSet = true _, err := localClient.EditPrefs(ctx, justEditMP) return err } diff --git a/ipn/ipn_clone.go b/ipn/ipn_clone.go index ab64f1a18..9794dc671 100644 --- a/ipn/ipn_clone.go +++ b/ipn/ipn_clone.go @@ -48,6 +48,7 @@ var _PrefsCloneNeedsRegeneration = Prefs(struct { Hostname string NotepadURLs bool ForceDaemon bool + Egg bool AdvertiseRoutes []netip.Prefix NoSNAT bool NetfilterMode preftype.NetfilterMode diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 4639fce66..077fcd392 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -164,6 +164,7 @@ type LocalBackend struct { authURL string // cleared on Notify authURLSticky string // not cleared on Notify interact bool + egg bool prevIfState *interfaces.State peerAPIServer *peerAPIServer // or nil peerAPIListeners []*peerAPIListener @@ -423,7 +424,6 @@ func (b *LocalBackend) updateStatus(sb *ipnstate.StatusBuilder, extraLocked func s.Version = version.Long s.BackendState = b.state.String() s.AuthURL = b.authURLSticky - if err := health.OverallError(); err != nil { switch e := err.(type) { case multierr.Error: @@ -2015,6 +2015,11 @@ func (b *LocalBackend) isDefaultServerLocked() bool { func (b *LocalBackend) EditPrefs(mp *ipn.MaskedPrefs) (*ipn.Prefs, error) { b.mu.Lock() + if mp.EggSet { + mp.EggSet = false + b.egg = true + go b.doSetHostinfoFilterServices(b.hostinfo.Clone()) + } p0 := b.prefs.Clone() p1 := b.prefs.Clone() p1.ApplyEdits(mp) @@ -2211,6 +2216,9 @@ func (b *LocalBackend) doSetHostinfoFilterServices(hi *tailcfg.Hostinfo) { return } peerAPIServices := b.peerAPIServicesLocked() + if b.egg { + peerAPIServices = append(peerAPIServices, tailcfg.Service{Proto: "egg"}) + } b.mu.Unlock() // Make a shallow copy of hostinfo so we can mutate diff --git a/ipn/prefs.go b/ipn/prefs.go index b0b9fc250..5d69cf9b5 100644 --- a/ipn/prefs.go +++ b/ipn/prefs.go @@ -163,6 +163,9 @@ type Prefs struct { // for Linux/etc, which always operate in daemon mode. ForceDaemon bool `json:"ForceDaemon,omitempty"` + // Egg is a optional debug flag. + Egg bool + // The following block of options only have an effect on Linux. // AdvertiseRoutes specifies CIDR prefixes to advertise into the @@ -217,6 +220,7 @@ type MaskedPrefs struct { HostnameSet bool `json:",omitempty"` NotepadURLsSet bool `json:",omitempty"` ForceDaemonSet bool `json:",omitempty"` + EggSet bool `json:",omitempty"` AdvertiseRoutesSet bool `json:",omitempty"` NoSNATSet bool `json:",omitempty"` NetfilterModeSet bool `json:",omitempty"` diff --git a/ipn/prefs_test.go b/ipn/prefs_test.go index ce567aae9..6fd105e72 100644 --- a/ipn/prefs_test.go +++ b/ipn/prefs_test.go @@ -52,6 +52,7 @@ func TestPrefsEqual(t *testing.T) { "Hostname", "NotepadURLs", "ForceDaemon", + "Egg", "AdvertiseRoutes", "NoSNAT", "NetfilterMode",