all: move nameserver resolution to public API

Make nameserver resolution functions more consistent and accessible:
- Rename currentNameserversFromResolvconf to CurrentNameserversFromResolvconf
- Move function to public API for better reusability
- Update all internal references to use the new public API
- Add comprehensive godoc comments for nameserver functions
- Improve code organization by centralizing DNS resolution logic

This change makes the nameserver resolution functionality more maintainable
and easier to use across different parts of the codebase.
This commit is contained in:
Cuong Manh Le
2025-06-18 15:50:30 +07:00
committed by Cuong Manh Le
parent 64632fa640
commit f0cb810dd6
8 changed files with 25 additions and 17 deletions

View File

@@ -9,7 +9,6 @@ import (
"strings"
"github.com/Control-D-Inc/ctrld"
"github.com/Control-D-Inc/ctrld/internal/resolvconffile"
)
// allocate loopback ip
@@ -92,7 +91,7 @@ func restoreDNS(iface *net.Interface) (err error) {
}
func currentDNS(_ *net.Interface) []string {
return resolvconffile.NameServers()
return ctrld.CurrentNameserversFromResolvconf()
}
// currentStaticDNS returns the current static DNS settings of given interface.

View File

@@ -9,8 +9,8 @@ import (
"tailscale.com/health"
"tailscale.com/util/dnsname"
"github.com/Control-D-Inc/ctrld"
"github.com/Control-D-Inc/ctrld/internal/dns"
"github.com/Control-D-Inc/ctrld/internal/resolvconffile"
)
// allocate loopback ip
@@ -94,7 +94,7 @@ func restoreDNS(iface *net.Interface) (err error) {
}
func currentDNS(_ *net.Interface) []string {
return resolvconffile.NameServers()
return ctrld.CurrentNameserversFromResolvconf()
}
// currentStaticDNS returns the current static DNS settings of given interface.

View File

@@ -21,9 +21,9 @@ import (
"tailscale.com/health"
"tailscale.com/util/dnsname"
"github.com/Control-D-Inc/ctrld"
"github.com/Control-D-Inc/ctrld/internal/dns"
ctrldnet "github.com/Control-D-Inc/ctrld/internal/net"
"github.com/Control-D-Inc/ctrld/internal/resolvconffile"
)
const resolvConfBackupFailedMsg = "open /etc/resolv.pre-ctrld-backup.conf: read-only file system"
@@ -201,7 +201,7 @@ func restoreDNS(iface *net.Interface) (err error) {
}
func currentDNS(iface *net.Interface) []string {
resolvconfFunc := func(_ string) []string { return resolvconffile.NameServers() }
resolvconfFunc := func(_ string) []string { return ctrld.CurrentNameserversFromResolvconf() }
for _, fn := range []getDNS{getDNSByResolvectl, getDNSBySystemdResolved, getDNSByNmcli, resolvconfFunc} {
if ns := fn(iface.Name); len(ns) > 0 {
return ns