mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-08-10 13:20:33 +02:00
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:
@@ -0,0 +1,34 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
// Copied from https://gist.github.com/Ultraporing/fe52981f678be6831f747c206a4861cb
|
||||||
|
|
||||||
|
// Mac Address parts to look for, and identify non-physical devices. There may be more, update me!
|
||||||
|
var macAddrPartsToFilter = []string{
|
||||||
|
"00:03:FF", // Microsoft Hyper-V, Virtual Server, Virtual PC
|
||||||
|
"0A:00:27", // VirtualBox
|
||||||
|
"00:00:00:00:00", // Teredo Tunneling Pseudo-Interface
|
||||||
|
"00:50:56", // VMware ESX 3, Server, Workstation, Player
|
||||||
|
"00:1C:14", // VMware ESX 3, Server, Workstation, Player
|
||||||
|
"00:0C:29", // VMware ESX 3, Server, Workstation, Player
|
||||||
|
"00:05:69", // VMware ESX 3, Server, Workstation, Player
|
||||||
|
"00:1C:42", // Microsoft Hyper-V, Virtual Server, Virtual PC
|
||||||
|
"00:0F:4B", // Virtual Iron 4
|
||||||
|
"00:16:3E", // Red Hat Xen, Oracle VM, XenSource, Novell Xen
|
||||||
|
"08:00:27", // Sun xVM VirtualBox
|
||||||
|
"7A:79", // Hamachi
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filters the possible physical interface address by comparing it to known popular VM Software addresses
|
||||||
|
// and Teredo Tunneling Pseudo-Interface.
|
||||||
|
//
|
||||||
|
//lint:ignore U1000 use in net_windows.go
|
||||||
|
func isPhysicalInterface(addr string) bool {
|
||||||
|
for _, macPart := range macAddrPartsToFilter {
|
||||||
|
if strings.HasPrefix(strings.ToLower(addr), strings.ToLower(macPart)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
//go:build !darwin
|
//go:build !darwin && !windows
|
||||||
|
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
func patchNetIfaceName(iface *net.Interface) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// validInterface reports whether the *net.Interface is a valid one.
|
||||||
|
// On Windows, only physical interfaces are considered valid.
|
||||||
|
func validInterface(iface *net.Interface) bool {
|
||||||
|
if iface == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if isPhysicalInterface(iface.HardwareAddr.String()) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
+5
-5
@@ -707,13 +707,11 @@ func withEachPhysicalInterfaces(excludeIfaceName, context string, f func(i *net.
|
|||||||
if netIface.Name == excludeIfaceName {
|
if netIface.Name == excludeIfaceName {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Skip Windows Hyper-V Default Switch.
|
|
||||||
if strings.Contains(netIface.Name, "vEthernet") {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// TODO: investigate whether we should report this error?
|
// TODO: investigate whether we should report this error?
|
||||||
if err := f(netIface); err == nil {
|
if err := f(netIface); err == nil {
|
||||||
mainLog.Load().Debug().Msgf("%s for interface %q successfully", context, i.Name)
|
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.
|
// saveCurrentStaticDNS saves the current static DNS settings for restoring later.
|
||||||
// Only works on Windows and Mac.
|
// Only works on Windows and Mac.
|
||||||
func saveCurrentStaticDNS(iface *net.Interface) error {
|
func saveCurrentStaticDNS(iface *net.Interface) error {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "windows", "darwin":
|
case "windows", "darwin":
|
||||||
default:
|
default:
|
||||||
return nil
|
return errSaveCurrentStaticDNSNotSupported
|
||||||
}
|
}
|
||||||
file := savedStaticDnsSettingsFilePath(iface)
|
file := savedStaticDnsSettingsFilePath(iface)
|
||||||
ns, _ := currentStaticDNS(iface)
|
ns, _ := currentStaticDNS(iface)
|
||||||
|
|||||||
Reference in New Issue
Block a user