fear: Implement 'mc support top net' (#17598)

This commit is contained in:
jiuker
2023-07-14 02:41:19 +08:00
committed by GitHub
parent fc6d873758
commit 183428db03
6 changed files with 85 additions and 3 deletions

View File

@@ -248,6 +248,9 @@ func serverHandleCmdArgs(ctx *cli.Context) {
logger.FatalIf(err, "Invalid command line arguments")
globalNodes = globalEndpoints.GetNodes()
// Initialize, see which NIC the service is running on, and save it as global
_ = getGlobalInternodeInterface(ctx.String("interface"))
globalLocalNodeName = GetLocalPeer(globalEndpoints, globalMinioHost, globalMinioPort)
nodeNameSum := sha256.Sum256([]byte(globalLocalNodeName))
globalLocalNodeNameHex = hex.EncodeToString(nodeNameSum[:])
@@ -461,6 +464,33 @@ func initConfigSubsystem(ctx context.Context, newObject ObjectLayer) error {
return nil
}
func getGlobalInternodeInterface(interfs ...string) string {
globalInternodeInterfaceOnce.Do(func() {
if len(interfs) != 0 && strings.TrimSpace(interfs[0]) != "" {
globalInternodeInterface = interfs[0]
return
}
ip := "127.0.0.1"
host, _ := mustSplitHostPort(globalMinioAddr)
if host != "" {
ip = host
}
globalInternodeInterface = ip
ifs, _ := net.Interfaces()
for _, interf := range ifs {
addrs, err := interf.Addrs()
if err == nil {
for _, addr := range addrs {
if strings.SplitN(addr.String(), "/", 2)[0] == ip {
globalInternodeInterface = interf.Name
}
}
}
}
})
return globalInternodeInterface
}
// Return the list of address that MinIO server needs to listen on:
// - Returning 127.0.0.1 is necessary so Console will be able to send
// requests to the local S3 API.