wgengine: default Router to a no-op router.
Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
440effb21a
commit
93a4aa697c
|
@ -336,13 +336,18 @@ func tryEngine(logf logger.Logf, linkMon *monitor.Mon, name string) (e wgengine.
|
||||||
var dev tun.Device
|
var dev tun.Device
|
||||||
if isUserspace {
|
if isUserspace {
|
||||||
dev = tstun.NewFake()
|
dev = tstun.NewFake()
|
||||||
conf.Router = router.NewFake(logf)
|
|
||||||
} else {
|
} else {
|
||||||
dev, err = tstun.New(logf, name)
|
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
|
||||||
}
|
}
|
||||||
|
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)
|
e, err = wgengine.NewUserspaceEngine(logf, dev, conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -35,6 +35,7 @@ import (
|
||||||
"tailscale.com/types/logger"
|
"tailscale.com/types/logger"
|
||||||
"tailscale.com/version"
|
"tailscale.com/version"
|
||||||
"tailscale.com/wgengine"
|
"tailscale.com/wgengine"
|
||||||
|
"tailscale.com/wgengine/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
const serviceName = "Tailscale"
|
const serviceName = "Tailscale"
|
||||||
|
@ -164,10 +165,17 @@ func startIPNServer(ctx context.Context, logid string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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{
|
eng, err := wgengine.NewUserspaceEngine(logf, dev, wgengine.Config{
|
||||||
|
Router: r,
|
||||||
ListenPort: 41641,
|
ListenPort: 41641,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
r.Close()
|
||||||
dev.Close()
|
dev.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,8 +133,8 @@ func (e *userspaceEngine) GetInternals() (*tstun.Wrapper, *magicsock.Conn) {
|
||||||
|
|
||||||
// Config is the engine configuration.
|
// Config is the engine configuration.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// Router is the interface to OS networking APIs used to interface
|
// Router interfaces the Engine to the OS network stack.
|
||||||
// the OS with the Engine.
|
// If nil, a fake Router that does nothing is used.
|
||||||
Router router.Router
|
Router router.Router
|
||||||
|
|
||||||
// LinkMonitor optionally provides an existing link monitor to re-use.
|
// 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) {
|
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, tstun.NewFake(), Config{
|
||||||
Router: router.NewFake(logf),
|
|
||||||
ListenPort: listenPort,
|
ListenPort: listenPort,
|
||||||
Fake: true,
|
Fake: true,
|
||||||
})
|
})
|
||||||
|
@ -165,15 +164,8 @@ func NewUserspaceEngine(logf logger.Logf, dev tun.Device, conf Config) (_ Engine
|
||||||
var closePool closeOnErrorPool
|
var closePool closeOnErrorPool
|
||||||
defer closePool.closeAllIfError(&reterr)
|
defer closePool.closeAllIfError(&reterr)
|
||||||
|
|
||||||
// TODO: default to a no-op router, require caller to pass in
|
|
||||||
// effectful ones.
|
|
||||||
if conf.Router == nil {
|
if conf.Router == nil {
|
||||||
r, err := router.New(logf, dev)
|
conf.Router = router.NewFake(logf)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
conf.Router = r
|
|
||||||
closePool.add(r)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tsTUNDev := tstun.Wrap(logf, dev)
|
tsTUNDev := tstun.Wrap(logf, dev)
|
||||||
|
|
Loading…
Reference in New Issue