@@ -14,6 +14,7 @@ import (
14
14
15
15
"github.com/cenkalti/backoff/v4"
16
16
"github.com/google/uuid"
17
+ "github.com/tailscale/wireguard-go/tun"
17
18
"golang.org/x/xerrors"
18
19
"google.golang.org/protobuf/types/known/durationpb"
19
20
"google.golang.org/protobuf/types/known/wrapperspb"
@@ -113,6 +114,8 @@ type Options struct {
113
114
DNSConfigurator dns.OSConfigurator
114
115
// Router is optional, and is passed to the underlying wireguard engine.
115
116
Router router.Router
117
+ // TUNDev is optional, and is passed to the underlying wireguard engine.
118
+ TUNDev tun.Device
116
119
}
117
120
118
121
// TelemetrySink allows tailnet.Conn to send network telemetry to the Coder
@@ -143,6 +146,8 @@ func NewConn(options *Options) (conn *Conn, err error) {
143
146
return nil , xerrors .New ("At least one IP range must be provided" )
144
147
}
145
148
149
+ netns .SetEnabled (options .TUNDev != nil )
150
+
146
151
var telemetryStore * TelemetryStore
147
152
if options .TelemetrySink != nil {
148
153
var err error
@@ -187,6 +192,7 @@ func NewConn(options *Options) (conn *Conn, err error) {
187
192
SetSubsystem : sys .Set ,
188
193
DNS : options .DNSConfigurator ,
189
194
Router : options .Router ,
195
+ Tun : options .TUNDev ,
190
196
})
191
197
if err != nil {
192
198
return nil , xerrors .Errorf ("create wgengine: %w" , err )
@@ -197,11 +203,14 @@ func NewConn(options *Options) (conn *Conn, err error) {
197
203
}
198
204
}()
199
205
wireguardEngine .InstallCaptureHook (options .CaptureHook )
200
- dialer .UseNetstackForIP = func (ip netip.Addr ) bool {
201
- _ , ok := wireguardEngine .PeerForIP (ip )
202
- return ok
206
+ if options .TUNDev == nil {
207
+ dialer .UseNetstackForIP = func (ip netip.Addr ) bool {
208
+ _ , ok := wireguardEngine .PeerForIP (ip )
209
+ return ok
210
+ }
203
211
}
204
212
213
+ wireguardEngine = wgengine .NewWatchdog (wireguardEngine )
205
214
sys .Set (wireguardEngine )
206
215
207
216
magicConn := sys .MagicSock .Get ()
@@ -244,11 +253,12 @@ func NewConn(options *Options) (conn *Conn, err error) {
244
253
return nil , xerrors .Errorf ("create netstack: %w" , err )
245
254
}
246
255
247
- dialer .NetstackDialTCP = func (ctx context.Context , dst netip.AddrPort ) (net.Conn , error ) {
248
- return netStack .DialContextTCP (ctx , dst )
256
+ if options .TUNDev == nil {
257
+ dialer .NetstackDialTCP = func (ctx context.Context , dst netip.AddrPort ) (net.Conn , error ) {
258
+ return netStack .DialContextTCP (ctx , dst )
259
+ }
260
+ netStack .ProcessLocalIPs = true
249
261
}
250
- netStack .ProcessLocalIPs = true
251
- wireguardEngine = wgengine .NewWatchdog (wireguardEngine )
252
262
253
263
cfgMaps := newConfigMaps (
254
264
options .Logger ,
0 commit comments