From f007a9dd6b9550a2d2eadbad3aa67df6d336be09 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 2 Apr 2021 19:31:58 -0700 Subject: [PATCH] health: add DNS subsystem and plumb errors in. Signed-off-by: David Anderson --- health/health.go | 11 ++++++++++- wgengine/userspace.go | 16 +++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/health/health.go b/health/health.go index 3da92b8a4..662114f2d 100644 --- a/health/health.go +++ b/health/health.go @@ -49,6 +49,9 @@ // SysRouter is the name the wgengine/router subsystem. SysRouter = Subsystem("router") + // SysDNS is the name of the net/dns subsystem. + SysDNS = Subsystem("dns") + // SysNetworkCategory is the name of the subsystem that sets // the Windows network adapter's "category" (public, private, domain). // If it's unhealthy, the Windows firewall rules won't match. @@ -80,12 +83,18 @@ func RegisterWatcher(cb func(key Subsystem, err error)) (unregister func()) { } } -// SetRouter sets the state of the wgengine/router.Router. +// SetRouterHealth sets the state of the wgengine/router.Router. func SetRouterHealth(err error) { set(SysRouter, err) } // RouterHealth returns the wgengine/router.Router error state. func RouterHealth() error { return get(SysRouter) } +// SetDNSHealth sets the state of the net/dns.Manager +func SetDNSHealth(err error) { set(SysDNS, err) } + +// DNSHealth returns the net/dns.Manager error state. +func DNSHealth() error { return get(SysDNS) } + // SetNetworkCategoryHealth sets the state of setting the network adaptor's category. // This only applies on Windows. func SetNetworkCategoryHealth(err error) { set(SysNetworkCategory, err) } diff --git a/wgengine/userspace.go b/wgengine/userspace.go index 987ab04c8..c7d044c92 100644 --- a/wgengine/userspace.go +++ b/wgengine/userspace.go @@ -1018,10 +1018,20 @@ func (e *userspaceEngine) Reconfig(cfg *wgcfg.Config, routerCfg *router.Config, } } osCfg.Domains = dnsCfg.SearchDomains - e.resolver.SetConfig(resolverCfg) // TODO: check error and propagate to health pkg - e.dns.Set(osCfg) // TODO: check error and propagate to health pkg + + e.logf("wgengine: Reconfig: configuring DNS") + err := e.resolver.SetConfig(resolverCfg) + health.SetDNSHealth(err) + if err != nil { + return err + } + err = e.dns.Set(osCfg) + health.SetDNSHealth(err) + if err != nil { + return err + } e.logf("wgengine: Reconfig: configuring router") - err := e.router.Set(routerCfg) + err = e.router.Set(routerCfg) health.SetRouterHealth(err) if err != nil { return err