Skip to content

Commit 020cacb

Browse files
committed
derp/derphttp: don't link websockets other than on GOOS=js
Or unless the new "ts_debug_websockets" build tag is set. Updates tailscale#1278 Change-Id: Ic4c4f81c1924250efd025b055585faec37a5491d Signed-off-by: Brad Fitzpatrick <[email protected]>
1 parent c3306bf commit 020cacb

File tree

11 files changed

+56
-26
lines changed

11 files changed

+56
-26
lines changed

cmd/derper/depaware.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa
116116
tailscale.com/net/tlsdial/blockblame from tailscale.com/net/tlsdial
117117
tailscale.com/net/tsaddr from tailscale.com/ipn+
118118
💣 tailscale.com/net/tshttpproxy from tailscale.com/derp/derphttp+
119-
tailscale.com/net/wsconn from tailscale.com/cmd/derper+
119+
tailscale.com/net/wsconn from tailscale.com/cmd/derper
120120
tailscale.com/paths from tailscale.com/client/tailscale
121121
💣 tailscale.com/safesocket from tailscale.com/client/tailscale
122122
tailscale.com/syncs from tailscale.com/cmd/derper+

cmd/k8s-operator/depaware.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ tailscale.com/cmd/k8s-operator dependencies: (generated by github.com/tailscale/
8080
github.com/beorn7/perks/quantile from github.com/prometheus/client_golang/prometheus
8181
github.com/bits-and-blooms/bitset from github.com/gaissmai/bart
8282
💣 github.com/cespare/xxhash/v2 from github.com/prometheus/client_golang/prometheus
83-
L github.com/coder/websocket from tailscale.com/derp/derphttp+
84-
L github.com/coder/websocket/internal/errd from github.com/coder/websocket
85-
L github.com/coder/websocket/internal/util from github.com/coder/websocket
86-
L github.com/coder/websocket/internal/xsync from github.com/coder/websocket
8783
L github.com/coreos/go-iptables/iptables from tailscale.com/util/linuxfw
8884
💣 github.com/davecgh/go-spew/spew from k8s.io/apimachinery/pkg/util/dump
8985
W 💣 github.com/dblohm7/wingoes from github.com/dblohm7/wingoes/com+
@@ -741,7 +737,6 @@ tailscale.com/cmd/k8s-operator dependencies: (generated by github.com/tailscale/
741737
tailscale.com/net/tsdial from tailscale.com/control/controlclient+
742738
💣 tailscale.com/net/tshttpproxy from tailscale.com/clientupdate/distsign+
743739
tailscale.com/net/tstun from tailscale.com/tsd+
744-
L tailscale.com/net/wsconn from tailscale.com/derp/derphttp
745740
tailscale.com/omit from tailscale.com/ipn/conffile
746741
tailscale.com/paths from tailscale.com/client/tailscale+
747742
💣 tailscale.com/portlist from tailscale.com/ipn/ipnlocal

cmd/tailscale/depaware.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep
55
W 💣 github.com/alexbrainman/sspi from github.com/alexbrainman/sspi/internal/common+
66
W github.com/alexbrainman/sspi/internal/common from github.com/alexbrainman/sspi/negotiate
77
W 💣 github.com/alexbrainman/sspi/negotiate from tailscale.com/net/tshttpproxy
8-
L github.com/coder/websocket from tailscale.com/derp/derphttp+
9-
L github.com/coder/websocket/internal/errd from github.com/coder/websocket
10-
L github.com/coder/websocket/internal/util from github.com/coder/websocket
11-
L github.com/coder/websocket/internal/xsync from github.com/coder/websocket
128
L github.com/coreos/go-iptables/iptables from tailscale.com/util/linuxfw
139
W 💣 github.com/dblohm7/wingoes from github.com/dblohm7/wingoes/pe+
1410
W 💣 github.com/dblohm7/wingoes/pe from tailscale.com/util/winutil/authenticode
@@ -125,7 +121,6 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep
125121
tailscale.com/net/tlsdial/blockblame from tailscale.com/net/tlsdial
126122
tailscale.com/net/tsaddr from tailscale.com/client/web+
127123
💣 tailscale.com/net/tshttpproxy from tailscale.com/clientupdate/distsign+
128-
L tailscale.com/net/wsconn from tailscale.com/derp/derphttp
129124
tailscale.com/paths from tailscale.com/client/tailscale+
130125
💣 tailscale.com/safesocket from tailscale.com/client/tailscale+
131126
tailscale.com/syncs from tailscale.com/cmd/tailscale/cli+
@@ -326,7 +321,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep
326321
reflect from archive/tar+
327322
regexp from github.com/coreos/go-iptables/iptables+
328323
regexp/syntax from regexp
329-
runtime/debug from github.com/coder/websocket/internal/xsync+
324+
runtime/debug from tailscale.com+
330325
slices from tailscale.com/client/web+
331326
sort from compress/flate+
332327
strconv from archive/tar+

cmd/tailscaled/depaware.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
7979
L github.com/aws/smithy-go/transport/http/internal/io from github.com/aws/smithy-go/transport/http
8080
L github.com/aws/smithy-go/waiter from github.com/aws/aws-sdk-go-v2/service/ssm
8181
github.com/bits-and-blooms/bitset from github.com/gaissmai/bart
82-
L github.com/coder/websocket from tailscale.com/derp/derphttp+
83-
L github.com/coder/websocket/internal/errd from github.com/coder/websocket
84-
L github.com/coder/websocket/internal/util from github.com/coder/websocket
85-
L github.com/coder/websocket/internal/xsync from github.com/coder/websocket
8682
L github.com/coreos/go-iptables/iptables from tailscale.com/util/linuxfw
8783
LD 💣 github.com/creack/pty from tailscale.com/ssh/tailssh
8884
W 💣 github.com/dblohm7/wingoes from github.com/dblohm7/wingoes/com+
@@ -328,7 +324,6 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
328324
tailscale.com/net/tsdial from tailscale.com/cmd/tailscaled+
329325
💣 tailscale.com/net/tshttpproxy from tailscale.com/clientupdate/distsign+
330326
tailscale.com/net/tstun from tailscale.com/cmd/tailscaled+
331-
L tailscale.com/net/wsconn from tailscale.com/derp/derphttp
332327
tailscale.com/omit from tailscale.com/ipn/conffile
333328
tailscale.com/paths from tailscale.com/client/tailscale+
334329
💣 tailscale.com/portlist from tailscale.com/ipn/ipnlocal

control/controlhttp/client_js.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/coder/websocket"
1414
"tailscale.com/control/controlbase"
15+
"tailscale.com/control/controlhttp/controlhttpcommon"
1516
"tailscale.com/net/wsconn"
1617
)
1718

@@ -42,11 +43,11 @@ func (d *Dialer) Dial(ctx context.Context) (*ClientConn, error) {
4243
// Can't set HTTP headers on the websocket request, so we have to to send
4344
// the handshake via an HTTP header.
4445
RawQuery: url.Values{
45-
handshakeHeaderName: []string{base64.StdEncoding.EncodeToString(init)},
46+
controlhttpcommon.HandshakeHeaderName: []string{base64.StdEncoding.EncodeToString(init)},
4647
}.Encode(),
4748
}
4849
wsConn, _, err := websocket.Dial(ctx, wsURL.String(), &websocket.DialOptions{
49-
Subprotocols: []string{upgradeHeaderValue},
50+
Subprotocols: []string{controlhttpcommon.UpgradeHeaderValue},
5051
})
5152
if err != nil {
5253
return nil, err

control/controlhttp/controlhttpserver/controlhttpserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
//go:build !ios
55

6-
// Packet controlhttpserver contains the HTTP server side of the ts2021 control protocol.
6+
// Package controlhttpserver contains the HTTP server side of the ts2021 control protocol.
77
package controlhttpserver
88

99
import (

derp/derphttp/derphttp_client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ func (c *Client) preferIPv6() bool {
313313
var dialWebsocketFunc func(ctx context.Context, urlStr string) (net.Conn, error)
314314

315315
func useWebsockets() bool {
316+
if !canWebsockets {
317+
return false
318+
}
316319
if runtime.GOOS == "js" {
317320
return true
318321
}
@@ -383,7 +386,7 @@ func (c *Client) connect(ctx context.Context, caller string) (client *derp.Clien
383386
var node *tailcfg.DERPNode // nil when using c.url to dial
384387
var idealNodeInRegion bool
385388
switch {
386-
case useWebsockets():
389+
case canWebsockets && useWebsockets():
387390
var urlStr string
388391
if c.url != nil {
389392
urlStr = c.url.String()

derp/derphttp/derphttp_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import (
1717

1818
"tailscale.com/derp"
1919
"tailscale.com/net/netmon"
20+
"tailscale.com/tstest/deptest"
2021
"tailscale.com/types/key"
22+
"tailscale.com/util/set"
2123
)
2224

2325
func TestSendRecv(t *testing.T) {
@@ -485,3 +487,23 @@ func TestProbe(t *testing.T) {
485487
}
486488
}
487489
}
490+
491+
func TestDeps(t *testing.T) {
492+
deptest.DepChecker{
493+
GOOS: "darwin",
494+
GOARCH: "arm64",
495+
BadDeps: map[string]string{
496+
"github.com/coder/websocket": "shouldn't link websockets except on js/wasm",
497+
},
498+
}.Check(t)
499+
500+
deptest.DepChecker{
501+
GOOS: "darwin",
502+
GOARCH: "arm64",
503+
Tags: "ts_debug_websockets",
504+
WantDeps: set.Of(
505+
"github.com/coder/websocket",
506+
),
507+
}.Check(t)
508+
509+
}

derp/derphttp/websocket.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Tailscale Inc & AUTHORS
22
// SPDX-License-Identifier: BSD-3-Clause
33

4-
//go:build linux || js
4+
//go:build js || ((linux || darwin) && ts_debug_websockets)
55

66
package derphttp
77

@@ -14,6 +14,8 @@ import (
1414
"tailscale.com/net/wsconn"
1515
)
1616

17+
const canWebsockets = true
18+
1719
func init() {
1820
dialWebsocketFunc = dialWebsocket
1921
}

derp/derphttp/websocket_stub.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) Tailscale Inc & AUTHORS
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
4+
//go:build !(js || ((linux || darwin) && ts_debug_websockets))
5+
6+
package derphttp
7+
8+
const canWebsockets = false

0 commit comments

Comments
 (0)