From e375341c33abba66acb719332c682d2f15d6526a Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 7 Apr 2020 09:40:20 -0700 Subject: [PATCH] fix: allow any 127.0.0.x as bind IPs (#9281) It is some times common and convenient to use just local IPs for testing purposes, 127.0.0.x are special IPs regardless of being available on an interface they can be bound to on all operating systems. Allow this behavior to work for minio server fixes #9274 --- cmd/net.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cmd/net.go b/cmd/net.go index a20ccad1f..4ef4fe010 100644 --- a/cmd/net.go +++ b/cmd/net.go @@ -277,9 +277,23 @@ func isLocalHost(host string, port string, localPort string) (bool, error) { return false, err } + nonInterIPV4s := mustGetLocalIP4().Intersection(hostIPs) + if nonInterIPV4s.IsEmpty() { + hostIPs = hostIPs.ApplyFunc(func(ip string) string { + if net.ParseIP(ip).IsLoopback() { + // Any loopback IP which is not 127.0.0.1 + // convert it to check for intersections. + return "127.0.0.1" + } + return ip + }) + nonInterIPV4s = mustGetLocalIP4().Intersection(hostIPs) + } + nonInterIPV6s := mustGetLocalIP6().Intersection(hostIPs) + // If intersection of two IP sets is not empty, then the host is localhost. - isLocalv4 := !mustGetLocalIP4().Intersection(hostIPs).IsEmpty() - isLocalv6 := !mustGetLocalIP6().Intersection(hostIPs).IsEmpty() + isLocalv4 := !nonInterIPV4s.IsEmpty() + isLocalv6 := !nonInterIPV6s.IsEmpty() if port != "" { return (isLocalv4 || isLocalv6) && (port == localPort), nil }