Skip to content

Commit

Permalink
agent: use bind address as src unless INADDR_ANY
Browse files Browse the repository at this point in the history
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
  • Loading branch information
magiconair committed May 10, 2017
1 parent 9cb01da commit 6777373
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6777373

Please sign in to comment.