Skip to content

Commit

Permalink
Merge pull request #1237 from aaronlehmann/dont-leak-listen-addr-to-raft
Browse files Browse the repository at this point in the history
Allow remote address autodetection when bound to a particular address
  • Loading branch information
aaronlehmann committed Jul 26, 2016
2 parents 740449b + 72756f8 commit 9d4c2f7
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package manager
import (
"crypto/x509"
"encoding/pem"
"errors"
"fmt"
"net"
"os"
Expand Down Expand Up @@ -121,16 +120,26 @@ func New(config *Config) (*Manager, error) {
config.ProtoAddr["tcp"] = config.ProtoListener["tcp"].Addr().String()
}

tcpAddr := config.ProtoAddr["tcp"]

if config.AdvertiseAddr != "" {
tcpAddr = config.AdvertiseAddr
}
// If an AdvertiseAddr was specified, we use that as our
// externally-reachable address.
tcpAddr := config.AdvertiseAddr

if tcpAddr == "" {
return nil, errors.New("no tcp listen address or listener provided")
// Otherwise, we know we are joining an existing swarm. Use a
// wildcard address to trigger remote autodetection of our
// address.
_, tcpAddrPort, err := net.SplitHostPort(config.ProtoAddr["tcp"])
if err != nil {
return nil, fmt.Errorf("missing or invalid listen address %s", config.ProtoAddr["tcp"])
}

// Even with an IPv6 listening address, it's okay to use
// 0.0.0.0 here. Any "unspecified" (wildcard) IP will
// be substituted with the actual source address.
tcpAddr = net.JoinHostPort("0.0.0.0", tcpAddrPort)
}

// FIXME(aaronl): Remove this. It appears to be unused.
dispatcherConfig.Addr = tcpAddr

err := os.MkdirAll(filepath.Dir(config.ProtoAddr["unix"]), 0700)
Expand Down

0 comments on commit 9d4c2f7

Please sign in to comment.