mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
cmd/cli: save DNS settings only once
While at it, also fixing a bug in getting saved nameservers.
This commit is contained in:
committed by
Cuong Manh Le
parent
d55563cac5
commit
18e8616834
@@ -268,6 +268,14 @@ func initCLI() {
|
||||
{s.Stop, false},
|
||||
{func() error { return doGenerateNextDNSConfig(nextdns) }, true},
|
||||
{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
|
||||
})
|
||||
return nil
|
||||
}, false},
|
||||
{s.Install, false},
|
||||
{s.Start, true},
|
||||
// Note that startCmd do not actually write ControlD config, but the config file was
|
||||
|
||||
@@ -462,7 +462,6 @@ func (p *prog) setDNS() {
|
||||
if needRFC1918Listeners(lc) {
|
||||
nameservers = append(nameservers, ctrld.Rfc1918Addresses()...)
|
||||
}
|
||||
saveCurrentDNS(netIface)
|
||||
if err := setDNS(netIface, nameservers); err != nil {
|
||||
logger.Error().Err(err).Msgf("could not set DNS for interface")
|
||||
return
|
||||
@@ -470,7 +469,6 @@ func (p *prog) setDNS() {
|
||||
logger.Debug().Msg("setting DNS successfully")
|
||||
if allIfaces {
|
||||
withEachPhysicalInterfaces(netIface.Name, "set DNS", func(i *net.Interface) error {
|
||||
saveCurrentDNS(i)
|
||||
return setDNS(i, nameservers)
|
||||
})
|
||||
}
|
||||
@@ -753,7 +751,7 @@ func savedDnsSettingsFilePath(iface *net.Interface) string {
|
||||
// savedNameservers returns the static DNS nameservers of the given interface.
|
||||
func savedNameservers(iface *net.Interface) []string {
|
||||
file := savedDnsSettingsFilePath(iface)
|
||||
if data, err := os.ReadFile(file); err != nil && len(data) > 0 {
|
||||
if data, _ := os.ReadFile(file); len(data) > 0 {
|
||||
return strings.Split(string(data), ",")
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user