wgengine/router: tighten isMissingIPv6Err

So it doesn't false positive if misused.

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2020-09-11 20:02:00 -07:00 committed by Brad Fitzpatrick
parent 8f5b52e571
commit 7e9d1f7808

View File

@ -11,6 +11,7 @@ import (
"fmt" "fmt"
"log" "log"
"net" "net"
"os"
"sort" "sort"
"time" "time"
@ -366,13 +367,18 @@ func configureInterface(cfg *Config, tun *tun.NativeTun) error {
// isMissingIPv6Err reports whether err is due to IPv6 not being enabled on the machine. // isMissingIPv6Err reports whether err is due to IPv6 not being enabled on the machine.
// //
// It's intended for use on errors returned by the winipcfg.Interface.GetIpInterface // It only currently supports the errors returned by winipcfg.Interface.GetIpInterface.
// method, which ultimately calls:
// https://docs.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-getipinterfaceentry
func isMissingIPv6Err(err error) bool { func isMissingIPv6Err(err error) bool {
// ERROR_NOT_FOUND from means the address family (IPv6) is not found. if se, ok := err.(*os.SyscallError); ok {
// (ERROR_FILE_NOT_FOUND means that the interface doesn't exist.) switch se.Syscall {
return errors.Is(err, windows.ERROR_NOT_FOUND) case "iphlpapi.GetIpInterfaceEntry":
// ERROR_NOT_FOUND from means the address family (IPv6) is not found.
// (ERROR_FILE_NOT_FOUND means that the interface doesn't exist.)
// https://docs.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-getipinterfaceentry
return se.Err == windows.ERROR_NOT_FOUND
}
}
return false
} }
// routeLess reports whether ri should sort before rj. // routeLess reports whether ri should sort before rj.