From c5bf22fd9048fcc9ecb5397007d37cec0b46a727 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 18 Dec 2018 08:26:30 -0800 Subject: [PATCH] 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' --- cmd/gateway-startup-msg.go | 3 ++- cmd/net.go | 2 +- cmd/server-startup-msg.go | 22 ++++++++++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cmd/gateway-startup-msg.go b/cmd/gateway-startup-msg.go index eb7ee97b5..f5c850b43 100644 --- a/cmd/gateway-startup-msg.go +++ b/cmd/gateway-startup-msg.go @@ -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))) diff --git a/cmd/net.go b/cmd/net.go index d357449d1..4f88d44d2 100644 --- a/cmd/net.go +++ b/cmd/net.go @@ -89,7 +89,7 @@ func mustGetLocalIP6() (ipList set.StringSet) { ip = v.IP } - if ip.To16() != nil { + if ip.To4() == nil { ipList.Add(ip.String()) } } diff --git a/cmd/server-startup-msg.go b/cmd/server-startup-msg.go index 2b5744e7f..b1c5bb123 100644 --- a/cmd/server-startup-msg.go +++ b/cmd/server-startup-msg.go @@ -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 }