mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-27 10:47:35 +00:00
wgengine: make Tun optional again, default to fake.
This makes setup more explicit in prod codepaths, without requiring a bunch of arguments or helpers for tests and userspace mode. Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
e18c3a7d84
commit
0fb738760f
@ -29,7 +29,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-multierror/multierror"
|
"github.com/go-multierror/multierror"
|
||||||
"github.com/tailscale/wireguard-go/tun"
|
|
||||||
"tailscale.com/ipn/ipnserver"
|
"tailscale.com/ipn/ipnserver"
|
||||||
"tailscale.com/logpolicy"
|
"tailscale.com/logpolicy"
|
||||||
"tailscale.com/net/socks5"
|
"tailscale.com/net/socks5"
|
||||||
@ -333,15 +332,13 @@ func tryEngine(logf logger.Logf, linkMon *monitor.Mon, name string) (e wgengine.
|
|||||||
LinkMonitor: linkMon,
|
LinkMonitor: linkMon,
|
||||||
}
|
}
|
||||||
isUserspace = name == "userspace-networking"
|
isUserspace = name == "userspace-networking"
|
||||||
var dev tun.Device
|
if !isUserspace {
|
||||||
if isUserspace {
|
dev, err := tstun.New(logf, name)
|
||||||
dev = tstun.NewFake()
|
|
||||||
} else {
|
|
||||||
dev, err = tstun.New(logf, name)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tstun.Diagnose(logf, name)
|
tstun.Diagnose(logf, name)
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
conf.Tun = dev
|
||||||
r, err := router.New(logf, dev)
|
r, err := router.New(logf, dev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dev.Close()
|
dev.Close()
|
||||||
@ -349,7 +346,7 @@ func tryEngine(logf logger.Logf, linkMon *monitor.Mon, name string) (e wgengine.
|
|||||||
}
|
}
|
||||||
conf.Router = r
|
conf.Router = r
|
||||||
}
|
}
|
||||||
e, err = wgengine.NewUserspaceEngine(logf, dev, conf)
|
e, err = wgengine.NewUserspaceEngine(logf, conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, isUserspace, err
|
return nil, isUserspace, err
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,8 @@ func startIPNServer(ctx context.Context, logid string) error {
|
|||||||
dev.Close()
|
dev.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
eng, err := wgengine.NewUserspaceEngine(logf, dev, wgengine.Config{
|
eng, err := wgengine.NewUserspaceEngine(logf, wgengine.Config{
|
||||||
|
Tun: dev,
|
||||||
Router: r,
|
Router: r,
|
||||||
ListenPort: 41641,
|
ListenPort: 41641,
|
||||||
})
|
})
|
||||||
|
@ -133,6 +133,11 @@ func (e *userspaceEngine) GetInternals() (*tstun.Wrapper, *magicsock.Conn) {
|
|||||||
|
|
||||||
// Config is the engine configuration.
|
// Config is the engine configuration.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
// Tun is the device used by the Engine to exchange packets with
|
||||||
|
// the OS.
|
||||||
|
// If nil, a fake Device that does nothing is used.
|
||||||
|
Tun tun.Device
|
||||||
|
|
||||||
// Router interfaces the Engine to the OS network stack.
|
// Router interfaces the Engine to the OS network stack.
|
||||||
// If nil, a fake Router that does nothing is used.
|
// If nil, a fake Router that does nothing is used.
|
||||||
Router router.Router
|
Router router.Router
|
||||||
@ -152,7 +157,7 @@ type Config struct {
|
|||||||
|
|
||||||
func NewFakeUserspaceEngine(logf logger.Logf, listenPort uint16) (Engine, error) {
|
func NewFakeUserspaceEngine(logf logger.Logf, listenPort uint16) (Engine, error) {
|
||||||
logf("Starting userspace wireguard engine (with fake TUN device)")
|
logf("Starting userspace wireguard engine (with fake TUN device)")
|
||||||
return NewUserspaceEngine(logf, tstun.NewFake(), Config{
|
return NewUserspaceEngine(logf, Config{
|
||||||
ListenPort: listenPort,
|
ListenPort: listenPort,
|
||||||
Fake: true,
|
Fake: true,
|
||||||
})
|
})
|
||||||
@ -160,15 +165,18 @@ func NewFakeUserspaceEngine(logf logger.Logf, listenPort uint16) (Engine, error)
|
|||||||
|
|
||||||
// NewUserspaceEngine creates the named tun device and returns a
|
// NewUserspaceEngine creates the named tun device and returns a
|
||||||
// Tailscale Engine running on it.
|
// Tailscale Engine running on it.
|
||||||
func NewUserspaceEngine(logf logger.Logf, dev tun.Device, conf Config) (_ Engine, reterr error) {
|
func NewUserspaceEngine(logf logger.Logf, conf Config) (_ Engine, reterr error) {
|
||||||
var closePool closeOnErrorPool
|
var closePool closeOnErrorPool
|
||||||
defer closePool.closeAllIfError(&reterr)
|
defer closePool.closeAllIfError(&reterr)
|
||||||
|
|
||||||
|
if conf.Tun == nil {
|
||||||
|
conf.Tun = tstun.NewFake()
|
||||||
|
}
|
||||||
if conf.Router == nil {
|
if conf.Router == nil {
|
||||||
conf.Router = router.NewFake(logf)
|
conf.Router = router.NewFake(logf)
|
||||||
}
|
}
|
||||||
|
|
||||||
tsTUNDev := tstun.Wrap(logf, dev)
|
tsTUNDev := tstun.Wrap(logf, conf.Tun)
|
||||||
closePool.add(tsTUNDev)
|
closePool.add(tsTUNDev)
|
||||||
|
|
||||||
e := &userspaceEngine{
|
e := &userspaceEngine{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user