From 2b082959dbd79c6004e30474711d20a26fe25ca5 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 5 Nov 2021 14:05:13 -0700 Subject: [PATCH] safesocket: add WindowsLocalPort const Remove all the 41112 references. Change-Id: I2d7ed330d457e3bb91b7e6416cfb2667611e50c4 Signed-off-by: Brad Fitzpatrick --- client/tailscale/tailscale.go | 2 +- cmd/tailscale/cli/cli.go | 2 +- cmd/tailscale/cli/debug.go | 2 +- cmd/tailscaled/tailscaled.go | 3 ++- safesocket/safesocket.go | 4 ++++ tstest/integration/integration_test.go | 2 +- 6 files changed, 10 insertions(+), 5 deletions(-) diff --git a/client/tailscale/tailscale.go b/client/tailscale/tailscale.go index 33f5742e0..458b8652f 100644 --- a/client/tailscale/tailscale.go +++ b/client/tailscale/tailscale.go @@ -56,7 +56,7 @@ func defaultDialer(ctx context.Context, network, addr string) (net.Conn, error) return d.DialContext(ctx, "tcp", "localhost:"+strconv.Itoa(port)) } } - return safesocket.Connect(TailscaledSocket, 41112) + return safesocket.Connect(TailscaledSocket, safesocket.WindowsLocalPort) } var ( diff --git a/cmd/tailscale/cli/cli.go b/cmd/tailscale/cli/cli.go index 87e127b9f..d139c63a3 100644 --- a/cmd/tailscale/cli/cli.go +++ b/cmd/tailscale/cli/cli.go @@ -191,7 +191,7 @@ func fatalf(format string, a ...interface{}) { var gotSignal syncs.AtomicBool func connect(ctx context.Context) (net.Conn, *ipn.BackendClient, context.Context, context.CancelFunc) { - c, err := safesocket.Connect(rootArgs.socket, 41112) + c, err := safesocket.Connect(rootArgs.socket, safesocket.WindowsLocalPort) if err != nil { if runtime.GOOS != "windows" && rootArgs.socket == "" { fatalf("--socket cannot be empty") diff --git a/cmd/tailscale/cli/debug.go b/cmd/tailscale/cli/debug.go index 0d3d7e12b..f74243abd 100644 --- a/cmd/tailscale/cli/debug.go +++ b/cmd/tailscale/cli/debug.go @@ -94,7 +94,7 @@ func runDebug(ctx context.Context, args []string) error { return nil } if runtime.GOOS == "windows" { - printf("curl http://localhost:41112/localapi/v0/status\n") + printf("curl http://localhost:%v/localapi/v0/status\n", safesocket.WindowsLocalPort) return nil } printf("curl --unix-socket %s http://foo/localapi/v0/status\n", paths.DefaultTailscaledSocket()) diff --git a/cmd/tailscaled/tailscaled.go b/cmd/tailscaled/tailscaled.go index ddeb2ab6b..499c425ce 100644 --- a/cmd/tailscaled/tailscaled.go +++ b/cmd/tailscaled/tailscaled.go @@ -36,6 +36,7 @@ "tailscale.com/net/socks5/tssocks" "tailscale.com/net/tstun" "tailscale.com/paths" + "tailscale.com/safesocket" "tailscale.com/types/flagtype" "tailscale.com/types/logger" "tailscale.com/util/multierr" @@ -223,7 +224,7 @@ func ipnServerOpts() (o ipnserver.Options) { goos = runtime.GOOS } - o.Port = 41112 + o.Port = safesocket.WindowsLocalPort o.StatePath = statePathOrDefault() o.SocketPath = args.socketpath // even for goos=="windows", for tests o.VarRoot = args.statedir diff --git a/safesocket/safesocket.go b/safesocket/safesocket.go index 87fcc9d12..db51f0456 100644 --- a/safesocket/safesocket.go +++ b/safesocket/safesocket.go @@ -13,6 +13,10 @@ "time" ) +// WindowsLocalPort is the default localhost TCP port +// used by safesocket on Windows. +const WindowsLocalPort = 41112 + type closeable interface { CloseRead() error CloseWrite() error diff --git a/tstest/integration/integration_test.go b/tstest/integration/integration_test.go index 3a569ab5d..62f208ab1 100644 --- a/tstest/integration/integration_test.go +++ b/tstest/integration/integration_test.go @@ -755,7 +755,7 @@ func (n *testNode) MustDown() { // over its localhost IPC mechanism. (Unix socket, etc) func (n *testNode) AwaitListening(t testing.TB) { if err := tstest.WaitFor(20*time.Second, func() (err error) { - c, err := safesocket.Connect(n.sockFile, 41112) + c, err := safesocket.Connect(n.sockFile, safesocket.WindowsLocalPort) if err != nil { return err }