Browse Source

Guard against a bad advertise address

pull/19/head
Armon Dadgar 11 years ago
parent
commit
caf3a847e6
  1. 7
      consul/config.go
  2. 21
      consul/server.go

7
consul/config.go

@ -5,6 +5,7 @@ import (
"github.com/hashicorp/raft"
"github.com/hashicorp/serf/serf"
"io"
"net"
"os"
)
@ -39,6 +40,12 @@ type Config struct {
// by the WAN and LAN
RPCAddr string
// RPCAdvertise is the address that is advertised to other nodes for
// the RPC endpoint. This can differ from the RPC address, if for example
// the RPCAddr is unspecified "0.0.0.0:8300", but this address must be
// reachable
RPCAdvertise net.Addr
// SerfLANConfig is the configuration for the intra-dc serf
SerfLANConfig *serf.Config

21
consul/server.go

@ -233,7 +233,26 @@ func (s *Server) setupRPC() error {
return err
}
s.rpcListener = list
s.raftLayer = NewRaftLayer(s.rpcListener.Addr())
var advertise net.Addr
if s.config.RPCAdvertise != nil {
advertise = s.config.RPCAdvertise
} else {
advertise = s.rpcListener.Addr()
}
// Verify that we have a usable advertise address
addr, ok := advertise.(*net.TCPAddr)
if !ok {
list.Close()
return fmt.Errorf("RPC advertise address is not a TCP Address: %v", addr)
}
if addr.IP.IsUnspecified() {
list.Close()
return fmt.Errorf("RPC advertise address is not advertisable: %v", addr)
}
s.raftLayer = NewRaftLayer(advertise)
go s.listen()
return nil
}

Loading…
Cancel
Save