From 529e2cb31a11bdefac5c20dbeba7c4922bfbb1cf Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 9 May 2020 13:50:13 -0700 Subject: [PATCH] ipn: add AllowVersionSkew bool to Notify & Message For "tailscale status" on macOS (from separately downloaded cmd/tailscale binary against App Store IPNExtension). (This isn't all of it, but I've had this sitting around uncommitted.) --- cmd/tailscale/status.go | 2 ++ ipn/message.go | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cmd/tailscale/status.go b/cmd/tailscale/status.go index 2b465838f..9dc641064 100644 --- a/cmd/tailscale/status.go +++ b/cmd/tailscale/status.go @@ -48,6 +48,8 @@ func runStatus(ctx context.Context, args []string) error { c, bc, ctx, cancel := connect(ctx) defer cancel() + bc.AllowVersionSkew = true + ch := make(chan *ipnstate.Status, 1) bc.SetNotifyCallback(func(n ipn.Notify) { if n.ErrMessage != nil { diff --git a/ipn/message.go b/ipn/message.go index ea5fbaef7..3e1146247 100644 --- a/ipn/message.go +++ b/ipn/message.go @@ -35,9 +35,16 @@ type FakeExpireAfterArgs struct { // Command is a command message that is JSON encoded and sent by a // frontend to a backend. type Command struct { - _ structs.Incomparable + _ structs.Incomparable + + // Version is the binary version of the frontend (the client). Version string + // AllowVersionSkew controls whether it's permitted for the + // client and server to have a different version. The default + // (false) means to be strict. + AllowVersionSkew bool + // Exactly one of the following must be non-nil. Quit *NoArgs Start *StartArgs @@ -92,7 +99,7 @@ func (bs *BackendServer) GotFakeCommand(cmd *Command) error { } func (bs *BackendServer) GotCommand(cmd *Command) error { - if cmd.Version != version.LONG { + if cmd.Version != version.LONG && !cmd.AllowVersionSkew { vs := fmt.Sprintf("GotCommand: Version mismatch! frontend=%#v backend=%#v", cmd.Version, version.LONG) bs.logf("%s", vs) @@ -147,6 +154,10 @@ type BackendClient struct { logf logger.Logf sendCommandMsg func(jsonb []byte) notify func(Notify) + + // AllowVersionSkew controls whether to allow mismatched + // frontend & backend versions. + AllowVersionSkew bool } func NewBackendClient(logf logger.Logf, sendCommandMsg func(jsonb []byte)) *BackendClient { @@ -165,7 +176,7 @@ func (bc *BackendClient) GotNotifyMsg(b []byte) { if err := json.Unmarshal(b, &n); err != nil { log.Fatalf("BackendClient.Notify: cannot decode message (length=%d)\n%#v", len(b), string(b)) } - if n.Version != version.LONG { + if n.Version != version.LONG && !bc.AllowVersionSkew { vs := fmt.Sprintf("GotNotify: Version mismatch! frontend=%#v backend=%#v", version.LONG, n.Version) bc.logf("%s", vs) @@ -223,7 +234,7 @@ func (bc *BackendClient) RequestEngineStatus() { } func (bc *BackendClient) RequestStatus() { - bc.send(Command{RequestStatus: &NoArgs{}}) + bc.send(Command{AllowVersionSkew: true, RequestStatus: &NoArgs{}}) } func (bc *BackendClient) FakeExpireAfter(x time.Duration) {