wgengine: default Router to a no-op router.

Signed-off-by: David Anderson <danderson@tailscale.com>
pull/1603/head
David Anderson 4 years ago
parent 440effb21a
commit 93a4aa697c

@ -336,13 +336,18 @@ func tryEngine(logf logger.Logf, linkMon *monitor.Mon, name string) (e wgengine.
var dev tun.Device
if isUserspace {
dev = tstun.NewFake()
conf.Router = router.NewFake(logf)
} else {
dev, err = tstun.New(logf, name)
if err != nil {
tstun.Diagnose(logf, name)
return nil, false, err
}
r, err := router.New(logf, dev)
if err != nil {
dev.Close()
return nil, false, err
}
conf.Router = r
}
e, err = wgengine.NewUserspaceEngine(logf, dev, conf)
if err != nil {

@ -35,6 +35,7 @@ import (
"tailscale.com/types/logger"
"tailscale.com/version"
"tailscale.com/wgengine"
"tailscale.com/wgengine/router"
)
const serviceName = "Tailscale"
@ -164,10 +165,17 @@ func startIPNServer(ctx context.Context, logid string) error {
if err != nil {
return nil, err
}
r, err := router.New(logf, dev)
if err != nil {
dev.Close()
return nil, err
}
eng, err := wgengine.NewUserspaceEngine(logf, dev, wgengine.Config{
Router: r,
ListenPort: 41641,
})
if err != nil {
r.Close()
dev.Close()
return nil, err
}

@ -133,8 +133,8 @@ func (e *userspaceEngine) GetInternals() (*tstun.Wrapper, *magicsock.Conn) {
// Config is the engine configuration.
type Config struct {
// Router is the interface to OS networking APIs used to interface
// the OS with the Engine.
// Router interfaces the Engine to the OS network stack.
// If nil, a fake Router that does nothing is used.
Router router.Router
// LinkMonitor optionally provides an existing link monitor to re-use.
@ -153,7 +153,6 @@ type Config struct {
func NewFakeUserspaceEngine(logf logger.Logf, listenPort uint16) (Engine, error) {
logf("Starting userspace wireguard engine (with fake TUN device)")
return NewUserspaceEngine(logf, tstun.NewFake(), Config{
Router: router.NewFake(logf),
ListenPort: listenPort,
Fake: true,
})
@ -165,15 +164,8 @@ func NewUserspaceEngine(logf logger.Logf, dev tun.Device, conf Config) (_ Engine
var closePool closeOnErrorPool
defer closePool.closeAllIfError(&reterr)
// TODO: default to a no-op router, require caller to pass in
// effectful ones.
if conf.Router == nil {
r, err := router.New(logf, dev)
if err != nil {
return nil, err
}
conf.Router = r
closePool.add(r)
conf.Router = router.NewFake(logf)
}
tsTUNDev := tstun.Wrap(logf, dev)

Loading…
Cancel
Save