cmd/cli: only save/restore static DNS

The save/restore DNS functionality always perform its job, even though
the DNS is not static, aka set by DHCP. That may lead to confusion to
users. Since DHCP settings was changed to static settings, even though
the namesers set are the same.

To fix this, ctrld should save/restore only there's actual static DNS
set. For DHCP, thing should work as-is like we are doing.
This commit is contained in:
Cuong Manh Le authored and Cuong Manh Le committed 2024-02-19 18:29:22 +07:00
1 parent 18e8616834
commit 4d810261a4
6 files changed
+122 -26

No files matched your search

+3 -5
View File
@@ -270,10 +270,7 @@ func initCLI() {
{func() error { return ensureUninstall(s) }, false},
{func() error {
// Save current DNS so we can restore later.
withEachPhysicalInterfaces("", "save DNS settings", func(i *net.Interface) error {
saveCurrentDNS(i)
return nil
})
withEachPhysicalInterfaces("", "save DNS settings", saveCurrentStaticDNS)
return nil
}, false},
{s.Install, false},
@@ -2197,7 +2194,8 @@ func exchangeContextWithTimeout(c *dns.Client, timeout time.Duration, msg *dns.M
// powershell runs the given powershell command.
func powershell(cmd string) ([]byte, error) {
return exec.Command("powershell", "-Command", cmd).CombinedOutput()
out, err := exec.Command("powershell", "-Command", cmd).CombinedOutput()
return bytes.TrimSpace(out), err
}
// windowsHasLocalDnsServerRunning reports whether we are on Windows and having Dns server running.