agent: use bind address as src unless INADDR_ANY

Use the bind address as source address for outgoing
RPC connections unless it is INADDR_ANY.

The current code uses the advertise address which will
not work in certain environments where the advertise
address is not routable in the network of the agent,
e.g. NAT environment, container... After all, that is
the purpose of the advertise address.

See #2822
This commit is contained in:
Frank Schroeder 2017-05-10 09:30:19 +02:00 committed by Frank Schröder
parent e6c6f8cedd
commit 914a83cae0
1 changed files with 4 additions and 3 deletions

View File

@ -440,9 +440,10 @@ func (a *Agent) consulConfig() (*consul.Config, error) {
}
// set the src address for outgoing rpc connections
// to RPCAdvertise with port 0 so that outgoing
// connections use a random port.
base.RPCSrcAddr = &net.TCPAddr{IP: base.RPCAdvertise.IP}
// Use port 0 so that outgoing connections use a random port.
if !isAddrANY(base.RPCAddr.IP) {
base.RPCSrcAddr = &net.TCPAddr{IP: base.RPCAddr.IP}
}
// Format the build string
revision := a.config.Revision