wgengine/router: move DNS cleanup into the DNS package.

Signed-off-by: David Anderson <danderson@tailscale.com>
pull/1644/head
David Anderson 4 years ago
parent 15875ccc63
commit f77ba75d6c

@ -31,6 +31,7 @@ import (
"github.com/go-multierror/multierror" "github.com/go-multierror/multierror"
"tailscale.com/ipn/ipnserver" "tailscale.com/ipn/ipnserver"
"tailscale.com/logpolicy" "tailscale.com/logpolicy"
"tailscale.com/net/dns"
"tailscale.com/net/socks5" "tailscale.com/net/socks5"
"tailscale.com/net/tstun" "tailscale.com/net/tstun"
"tailscale.com/paths" "tailscale.com/paths"
@ -192,6 +193,7 @@ func run() error {
logf = logger.RateLimitedFn(logf, 5*time.Second, 5, 100) logf = logger.RateLimitedFn(logf, 5*time.Second, 5, 100)
if args.cleanup { if args.cleanup {
dns.Cleanup(logf, args.tunname)
router.Cleanup(logf, args.tunname) router.Cleanup(logf, args.tunname)
return nil return nil
} }

@ -98,3 +98,18 @@ func (m *Manager) Up() error {
func (m *Manager) Down() error { func (m *Manager) Down() error {
return m.impl.Down() return m.impl.Down()
} }
// Cleanup restores the system DNS configuration to its original state
// in case the Tailscale daemon terminated without closing the router.
// No other state needs to be instantiated before this runs.
func Cleanup(logf logger.Logf, interfaceName string) {
mconfig := ManagerConfig{
Logf: logf,
InterfaceName: interfaceName,
Cleanup: true,
}
dns := NewManager(mconfig)
if err := dns.Down(); err != nil {
logf("dns down: %v", err)
}
}

@ -41,15 +41,6 @@ func New(logf logger.Logf, tundev tun.Device) (Router, error) {
// in case the Tailscale daemon terminated without closing the router. // in case the Tailscale daemon terminated without closing the router.
// No other state needs to be instantiated before this runs. // No other state needs to be instantiated before this runs.
func Cleanup(logf logger.Logf, interfaceName string) { func Cleanup(logf logger.Logf, interfaceName string) {
mconfig := dns.ManagerConfig{
Logf: logf,
InterfaceName: interfaceName,
Cleanup: true,
}
dns := dns.NewManager(mconfig)
if err := dns.Down(); err != nil {
logf("dns down: %v", err)
}
cleanup(logf, interfaceName) cleanup(logf, interfaceName)
} }

Loading…
Cancel
Save