|
@@ -7,10 +7,13 @@ import (
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
- errNoSuchInterface = errors.New("no such interface")
|
|
|
- errMultipleIPs = errors.New("could not choose an IP address to advertise since this system has multiple addresses")
|
|
|
- errNoIP = errors.New("could not find the system's IP address")
|
|
|
- errMustSpecifyListenAddr = errors.New("must specify a listening address because the address to advertise is not recognized as a system address")
|
|
|
+ errNoSuchInterface = errors.New("no such interface")
|
|
|
+ errMultipleIPs = errors.New("could not choose an IP address to advertise since this system has multiple addresses")
|
|
|
+ errNoIP = errors.New("could not find the system's IP address")
|
|
|
+ errMustSpecifyListenAddr = errors.New("must specify a listening address because the address to advertise is not recognized as a system address")
|
|
|
+ errBadListenAddr = errors.New("listen address must be an IP address or network interface (with optional port number)")
|
|
|
+ errBadAdvertiseAddr = errors.New("advertise address must be an IP address or network interface (with optional port number)")
|
|
|
+ errBadDefaultAdvertiseAddr = errors.New("default advertise address must be an IP address or network interface (without a port number)")
|
|
|
)
|
|
|
|
|
|
func resolveListenAddr(specifiedAddr string) (string, string, error) {
|
|
@@ -29,6 +32,11 @@ func resolveListenAddr(specifiedAddr string) (string, string, error) {
|
|
|
return "", "", err
|
|
|
}
|
|
|
|
|
|
+ // If it's not an interface, it must be an IP (for now)
|
|
|
+ if net.ParseIP(specifiedHost) == nil {
|
|
|
+ return "", "", errBadListenAddr
|
|
|
+ }
|
|
|
+
|
|
|
return specifiedHost, specifiedPort, nil
|
|
|
}
|
|
|
|
|
@@ -61,6 +69,11 @@ func (c *Cluster) resolveAdvertiseAddr(advertiseAddr, listenAddrPort string) (st
|
|
|
return "", "", err
|
|
|
}
|
|
|
|
|
|
+ // If it's not an interface, it must be an IP (for now)
|
|
|
+ if net.ParseIP(advertiseHost) == nil {
|
|
|
+ return "", "", errBadAdvertiseAddr
|
|
|
+ }
|
|
|
+
|
|
|
return advertiseHost, advertisePort, nil
|
|
|
}
|
|
|
|
|
@@ -76,6 +89,11 @@ func (c *Cluster) resolveAdvertiseAddr(advertiseAddr, listenAddrPort string) (st
|
|
|
return "", "", err
|
|
|
}
|
|
|
|
|
|
+ // If it's not an interface, it must be an IP (for now)
|
|
|
+ if net.ParseIP(c.config.DefaultAdvertiseAddr) == nil {
|
|
|
+ return "", "", errBadDefaultAdvertiseAddr
|
|
|
+ }
|
|
|
+
|
|
|
return c.config.DefaultAdvertiseAddr, listenAddrPort, nil
|
|
|
}
|
|
|
|