From 92c94011f107a2498596105b3f489e2eba2be36c Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Mon, 9 Aug 2021 15:57:54 +0200 Subject: [PATCH] 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. --- cmd/net.go | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/cmd/net.go b/cmd/net.go index 32e367232..1371e442f 100644 --- a/cmd/net.go +++ b/cmd/net.go @@ -22,6 +22,7 @@ import ( "fmt" "net" "net/url" + "runtime" "sort" "strings" @@ -46,20 +47,30 @@ 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 _, addr := range addrs { - var ip net.IP - switch v := addr.(type) { - case *net.IPNet: - ip = v.IP - case *net.IPAddr: - ip = v.IP + for _, interf := range ifs { + addrs, err := interf.Addrs() + if err != nil { + continue + } + if runtime.GOOS == "windows" && interf.Flags&net.FlagUp == 0 { + continue } - if ip.To4() != nil { - ipList.Add(ip.String()) + for _, addr := range addrs { + var ip net.IP + switch v := addr.(type) { + case *net.IPNet: + ip = v.IP + case *net.IPAddr: + ip = v.IP + } + + if ip.To4() != nil { + ipList.Add(ip.String()) + } } }