cmd/cli: only set DNS for physical interfaces on Windows

By filtering the interfaces by MAC address instead of name.
This commit is contained in:
Cuong Manh Le
2024-03-01 15:16:40 +07:00
committed by Cuong Manh Le
parent 73a697b2fa
commit e89021ec3a
4 changed files with 61 additions and 6 deletions
+5 -5
View File
@@ -707,13 +707,11 @@ func withEachPhysicalInterfaces(excludeIfaceName, context string, f func(i *net.
if netIface.Name == excludeIfaceName {
return
}
// Skip Windows Hyper-V Default Switch.
if strings.Contains(netIface.Name, "vEthernet") {
return
}
// TODO: investigate whether we should report this error?
if err := f(netIface); err == nil {
mainLog.Load().Debug().Msgf("%s for interface %q successfully", context, i.Name)
} else if !errors.Is(err, errSaveCurrentStaticDNSNotSupported) {
mainLog.Load().Err(err).Msgf("%s for interface %q failed", context, i.Name)
}
})
}
@@ -728,13 +726,15 @@ func requiredMultiNICsConfig() bool {
}
}
var errSaveCurrentStaticDNSNotSupported = errors.New("saving current DNS is not supported on this platform")
// saveCurrentStaticDNS saves the current static DNS settings for restoring later.
// Only works on Windows and Mac.
func saveCurrentStaticDNS(iface *net.Interface) error {
switch runtime.GOOS {
case "windows", "darwin":
default:
return nil
return errSaveCurrentStaticDNSNotSupported
}
file := savedStaticDnsSettingsFilePath(iface)
ns, _ := currentStaticDNS(iface)