Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions net/netcheck/netcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package netcheck
import (
"bufio"
"context"
"crypto/tls"
"encoding/hex"
"errors"
"fmt"
Expand Down Expand Up @@ -207,6 +208,9 @@ type Client struct {
// probes.
GetDERPHeaders func() http.Header

// DERPTLSConfig is an optional TLS config for DERP connections.
DERPTLSConfig *tls.Config

// For tests
testEnoughRegions int
testCaptivePortalDelay time.Duration
Expand Down Expand Up @@ -1301,6 +1305,9 @@ func (c *Client) measureHTTPLatency(ctx context.Context, reg *tailcfg.DERPRegion

dc := derphttp.NewNetcheckClient(c.logf)
dc.Header = derpHeaders
if c.DERPTLSConfig != nil {
dc.TLSConfig = c.DERPTLSConfig
}
defer dc.Close()

var hasForceHTTPNode = false
Expand Down
3 changes: 3 additions & 0 deletions wgengine/magicsock/derp.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ func (c *Conn) derpWriteChanOfAddr(addr netip.AddrPort, peer key.NodePublic) cha
dc.SetAddressFamilySelector(derpAddrFamSelector{c})
dc.SetForcedWebsocketCallback(c.derpForcedWebsocketFunc)
dc.DNSCache = dnscache.Get()
if tlsCfg := c.derpTLSConfig.Load(); tlsCfg != nil {
dc.TLSConfig = tlsCfg
}
header := c.derpHeader.Load()
if header != nil {
dc.Header = header.Clone()
Expand Down
8 changes: 8 additions & 0 deletions wgengine/magicsock/magicsock.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package magicsock
import (
"bufio"
"context"
"crypto/tls"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -176,6 +177,9 @@ type Conn struct {
// derpRegionDialer is passed to the DERP client
derpRegionDialer atomic.Pointer[func(ctx context.Context, region *tailcfg.DERPRegion) net.Conn]

// derpTLSConfig is an optional TLS config for DERP connections.
derpTLSConfig atomic.Pointer[tls.Config]

// stats maintains per-connection counters.
stats atomic.Pointer[connstats.Statistics]

Expand Down Expand Up @@ -1759,6 +1763,10 @@ func (c *Conn) SetDERPForceWebsockets(v bool) {
c.derpForceWebsockets.Store(v)
}

func (c *Conn) SetDERPTLSConfig(cfg *tls.Config) {
c.derpTLSConfig.Store(cfg)
}

func (c *Conn) SetDERPRegionDialer(dialer func(ctx context.Context, region *tailcfg.DERPRegion) net.Conn) {
c.derpRegionDialer.Store(&dialer)
c.mu.Lock()
Expand Down
Loading