wgengine: flesh out some docs, minor cleanups

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2020-02-11 15:21:24 -08:00 committed by Brad Fitzpatrick
parent 819daf10e2
commit 7e5e32775a
4 changed files with 24 additions and 13 deletions

View File

@ -16,11 +16,10 @@ type fakeRouter struct {
} }
func NewFakeRouter(logf logger.Logf, tunname string, dev *device.Device, tuntap tun.Device, netChanged func()) Router { func NewFakeRouter(logf logger.Logf, tunname string, dev *device.Device, tuntap tun.Device, netChanged func()) Router {
r := fakeRouter{ return &fakeRouter{
logf: logf, logf: logf,
tunname: tunname, tunname: tunname,
} }
return &r
} }
func (r *fakeRouter) Up() error { func (r *fakeRouter) Up() error {
@ -33,6 +32,7 @@ func (r *fakeRouter) SetRoutes(rs RouteSettings) error {
return nil return nil
} }
func (r *fakeRouter) Close() { func (r *fakeRouter) Close() error {
r.logf("Warning: fakeRouter.Close: not implemented.\n") r.logf("Warning: fakeRouter.Close: not implemented.\n")
return nil
} }

View File

@ -57,6 +57,8 @@ func cmd(args ...string) *exec.Cmd {
func (r *linuxRouter) Up() error { func (r *linuxRouter) Up() error {
out, err := cmd("ip", "link", "set", r.tunname, "up").CombinedOutput() out, err := cmd("ip", "link", "set", r.tunname, "up").CombinedOutput()
if err != nil { if err != nil {
// TODO: this should return an error; why is it calling log.Fatalf?
// Audit callers to make sure they're handling errors.
log.Fatalf("running ip link failed: %v\n%s", err, out) log.Fatalf("running ip link failed: %v\n%s", err, out)
} }
@ -154,6 +156,7 @@ func (r *linuxRouter) SetRoutes(rs RouteSettings) error {
r.local = rs.LocalAddr r.local = rs.LocalAddr
r.routes = newRoutes r.routes = newRoutes
// TODO: this:
if false { if false {
if err := r.replaceResolvConf(rs.DNS, rs.DNSDomains); err != nil { if err := r.replaceResolvConf(rs.DNS, rs.DNSDomains); err != nil {
errq = fmt.Errorf("replacing resolv.conf failed: %v", err) errq = fmt.Errorf("replacing resolv.conf failed: %v", err)
@ -162,12 +165,17 @@ func (r *linuxRouter) SetRoutes(rs RouteSettings) error {
return errq return errq
} }
func (r *linuxRouter) Close() { func (r *linuxRouter) Close() error {
var ret error
r.mon.Close() r.mon.Close()
if err := r.restoreResolvConf(); err != nil { if err := r.restoreResolvConf(); err != nil {
r.logf("failed to restore system resolv.conf: %v", err) r.logf("failed to restore system resolv.conf: %v", err)
if ret == nil {
ret = err
}
} }
// TODO(apenwarr): clean up iptables etc. // TODO(apenwarr): clean up iptables etc.
return ret
} }
const ( const (

View File

@ -205,7 +205,7 @@ func (e *userspaceEngine) Reconfig(cfg *wgcfg.Config, dnsDomains []string) error
e.peerSequence[i] = p.PublicKey e.peerSequence[i] = p.PublicKey
} }
// TODO(apenwarr): get rid of silly uapi stuff for in-process comms // TODO(apenwarr): get rid of uapi stuff for in-process comms
uapi, err := cfg.ToUAPI() uapi, err := cfg.ToUAPI()
if err != nil { if err != nil {
return err return err
@ -239,7 +239,7 @@ func (e *userspaceEngine) Reconfig(cfg *wgcfg.Config, dnsDomains []string) error
rs := RouteSettings{ rs := RouteSettings{
LocalAddr: cidr, LocalAddr: cidr,
Cfg: *cfg, Cfg: cfg,
DNS: cfg.Interface.Dns, DNS: cfg.Interface.Dns,
DNSDomains: dnsDomains, DNSDomains: dnsDomains,
} }

View File

@ -45,7 +45,7 @@ type RouteSettings struct {
LocalAddr wgcfg.CIDR // TODO: why is this here? how does it differ from wgcfg.Config's info? LocalAddr wgcfg.CIDR // TODO: why is this here? how does it differ from wgcfg.Config's info?
DNS []net.IP DNS []net.IP
DNSDomains []string DNSDomains []string
Cfg wgcfg.Config // TODO: value type here, but pointer below? Cfg *wgcfg.Config
} }
// OnlyRelevantParts returns a string minimally describing the route settings. // OnlyRelevantParts returns a string minimally describing the route settings.
@ -58,17 +58,20 @@ func (rs *RouteSettings) OnlyRelevantParts() string {
rs.LocalAddr, rs.DNS, rs.DNSDomains, peers) rs.LocalAddr, rs.DNS, rs.DNSDomains, peers)
} }
// Router is the TODO. // Router is responsible for managing the system route table.
//
// There's only one instance, and one per-OS implementation.
type Router interface { type Router interface {
// Up brings the router up. // Up brings the router up.
// TODO: more than once? after Close?
Up() error Up() error
// SetRoutes sets the routes.
// TODO: while running? // SetRoutes is called regularly on network map updates.
// It's how you kernel route table entries are populated for
// each peer.
SetRoutes(RouteSettings) error SetRoutes(RouteSettings) error
// Close closes the router. // Close closes the router.
// TODO: return an error? does this block? Close() error
Close()
} }
// Engine is the Tailscale WireGuard engine interface. // Engine is the Tailscale WireGuard engine interface.