Guard against a bad advertise address

pull/19/head
Armon Dadgar 11 years ago
parent 638ba36953
commit caf3a847e6

@ -5,6 +5,7 @@ import (
"github.com/hashicorp/raft" "github.com/hashicorp/raft"
"github.com/hashicorp/serf/serf" "github.com/hashicorp/serf/serf"
"io" "io"
"net"
"os" "os"
) )
@ -39,6 +40,12 @@ type Config struct {
// by the WAN and LAN // by the WAN and LAN
RPCAddr string 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 is the configuration for the intra-dc serf
SerfLANConfig *serf.Config SerfLANConfig *serf.Config

@ -233,7 +233,26 @@ func (s *Server) setupRPC() error {
return err return err
} }
s.rpcListener = list 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() go s.listen()
return nil return nil
} }

Loading…
Cancel
Save