Turn off printing IPv6 endpoints when listening on all interfaces (#6986)

By default when we listen on all interfaces, we print all the
endpoints that at local to all interfaces including IPv6
addresses. Remove IPv6 addresses in endpoint list to be
printed in endpoints unless explicitly specified with '--address'
This commit is contained in:
Harshavardhana 2018-12-18 08:26:30 -08:00 committed by Nitish Tiwari
parent 7c9f934875
commit c5bf22fd90
3 changed files with 23 additions and 4 deletions

View File

@ -55,8 +55,9 @@ func printGatewayCommonMsg(apiEndpoints []string) {
cred := globalServerConfig.GetCredential()
apiEndpointStr := strings.Join(apiEndpoints, " ")
// Colorize the message and print.
logger.StartupMessage(colorBlue("\nEndpoint: ") + colorBold(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 1), apiEndpointStr)))
logger.StartupMessage(colorBlue("Endpoint: ") + colorBold(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 1), apiEndpointStr)))
if isTerminal() {
logger.StartupMessage(colorBlue("AccessKey: ") + colorBold(fmt.Sprintf("%s ", cred.AccessKey)))
logger.StartupMessage(colorBlue("SecretKey: ") + colorBold(fmt.Sprintf("%s ", cred.SecretKey)))

View File

@ -89,7 +89,7 @@ func mustGetLocalIP6() (ipList set.StringSet) {
ip = v.IP
}
if ip.To16() != nil {
if ip.To4() == nil {
ipList.Add(ip.String())
}
}

View File

@ -20,6 +20,7 @@ import (
"context"
"crypto/x509"
"fmt"
"net"
"runtime"
"strings"
@ -76,6 +77,19 @@ func printStartupMessage(apiEndPoints []string) {
}
}
// Returns true if input is not IPv4, false if it is.
func isNotIPv4(host string) bool {
h, _, err := net.SplitHostPort(host)
if err != nil {
h = host
}
ip := net.ParseIP(h)
ok := ip.To4() != nil // This is always true of IP is IPv4
// Returns true if input is not IPv4.
return !ok
}
// strip api endpoints list with standard ports such as
// port "80" and "443" before displaying on the startup
// banner. Returns a new list of API endpoints.
@ -83,12 +97,16 @@ func stripStandardPorts(apiEndpoints []string) (newAPIEndpoints []string) {
newAPIEndpoints = make([]string, len(apiEndpoints))
// Check all API endpoints for standard ports and strip them.
for i, apiEndpoint := range apiEndpoints {
url, err := xnet.ParseURL(apiEndpoint)
u, err := xnet.ParseURL(apiEndpoint)
if err != nil {
newAPIEndpoints[i] = apiEndpoint
continue
}
newAPIEndpoints[i] = url.String()
if globalMinioHost == "" && isNotIPv4(u.Host) {
// Skip all non-IPv4 endpoints when we bind to all interfaces.
continue
}
newAPIEndpoints[i] = u.String()
}
return newAPIEndpoints
}