cmd/ctrld: do not try random local ip if IP is v4/v6 zero

This commit is contained in:
Cuong Manh Le
2023-07-14 00:06:25 +00:00
committed by Cuong Manh Le
parent dc61fd2554
commit e65a71b2ae

View File

@@ -1253,6 +1253,7 @@ func updateListenerConfig() {
check := lcc[strconv.Itoa(n)]
oldIP := listener.IP
oldPort := listener.Port
isZeroIP := listener.IP == "0.0.0.0" || listener.IP == "::"
// Check if we could listen on the current IP + Port, if not, try following thing, pick first one success:
// - Try 127.0.0.1:53
@@ -1331,7 +1332,7 @@ func updateListenerConfig() {
mainLog.Warn().Msgf("could not listen on address: %s, trying 0.0.0.0:5354", addr)
continue
}
if check.IP {
if check.IP && !isZeroIP { // for "0.0.0.0" or "::", we only need to try new port.
listener.IP = randomLocalIP()
} else {
listener.IP = oldIP