Skip to content

Commit

Permalink
Check if system is our manager when resolvconf (#590)
Browse files Browse the repository at this point in the history
Sometimes resolvconf will manage the /etc/resolv.conf file
And systemd-resolved still the DNS manager
  • Loading branch information
mlsmaycon authored Nov 29, 2022
1 parent ae500b6 commit 4a30b66
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions client/internal/dns/host_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ func getOSDNSManagerType() (osManagerType, error) {
return systemdManager, nil
}
if strings.Contains(text, "resolvconf") {
if isDbusListenerRunning(systemdResolvedDest, systemdDbusObjectNode) {
var value string
err = getSystemdDbusProperty(systemdDbusResolvConfModeProperty, &value)
if err == nil {
if value == systemdDbusResolvConfModeForeign {
return systemdManager, nil
}
}
log.Errorf("got an error while checking systemd resolv conf mode, error: %s", err)
}
return resolvConfManager, nil
}
}
Expand Down
17 changes: 17 additions & 0 deletions client/internal/dns/systemd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ const (
systemdDbusObjectNode = "/org/freedesktop/resolve1"
systemdDbusGetLinkMethod = systemdDbusManagerInterface + ".GetLink"
systemdDbusFlushCachesMethod = systemdDbusManagerInterface + ".FlushCaches"
systemdDbusResolvConfModeProperty = systemdDbusManagerInterface + ".ResolvConfMode"
systemdDbusLinkInterface = "org.freedesktop.resolve1.Link"
systemdDbusRevertMethodSuffix = systemdDbusLinkInterface + ".Revert"
systemdDbusSetDNSMethodSuffix = systemdDbusLinkInterface + ".SetDNS"
systemdDbusSetDefaultRouteMethodSuffix = systemdDbusLinkInterface + ".SetDefaultRoute"
systemdDbusSetDomainsMethodSuffix = systemdDbusLinkInterface + ".SetDomains"
systemdDbusResolvConfModeForeign = "foreign"
)

type systemdDbusConfigurator struct {
Expand Down Expand Up @@ -183,3 +185,18 @@ func (s *systemdDbusConfigurator) callLinkMethod(method string, value any) error

return nil
}

func getSystemdDbusProperty(property string, store any) error {
obj, closeConn, err := getDbusObject(systemdResolvedDest, systemdDbusObjectNode)
if err != nil {
return fmt.Errorf("got error while attempting to retrieve the systemd dns manager object, error: %s", err)
}
defer closeConn()

v, e := obj.GetProperty(property)
if e != nil {
return fmt.Errorf("got an error getting property %s: %v", property, e)
}

return v.Store(store)
}

0 comments on commit 4a30b66

Please sign in to comment.