Skip downed interfaces on Windows (#12910)

Disregard interfaces that are down when selecting bind addresses

Windows often has a number of disabled NICs used for VPN and other services.

This often causes minio to select an address for contacting the console that is on a disabled (virtual) NIC.

This checks if the interface is up before adding it to the pool on Windows.
This commit is contained in:
Klaus Post 2021-08-09 15:57:54 +02:00 committed by GitHub
parent 35cbe43b6d
commit 92c94011f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,6 +22,7 @@ import (
"fmt"
"net"
"net/url"
"runtime"
"sort"
"strings"
@ -46,9 +47,18 @@ func mustSplitHostPort(hostPort string) (host, port string) {
// mustGetLocalIP4 returns IPv4 addresses of localhost. It panics on error.
func mustGetLocalIP4() (ipList set.StringSet) {
ipList = set.NewStringSet()
addrs, err := net.InterfaceAddrs()
ifs, err := net.Interfaces()
logger.FatalIf(err, "Unable to get IP addresses of this host")
for _, interf := range ifs {
addrs, err := interf.Addrs()
if err != nil {
continue
}
if runtime.GOOS == "windows" && interf.Flags&net.FlagUp == 0 {
continue
}
for _, addr := range addrs {
var ip net.IP
switch v := addr.(type) {
@ -62,6 +72,7 @@ func mustGetLocalIP4() (ipList set.StringSet) {
ipList.Add(ip.String())
}
}
}
return ipList
}