From 5a0dbbd986ebc7c369abcb9fb24211df7ddf6e2c Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Mon, 26 Oct 2015 03:13:34 -0700 Subject: [PATCH] log an error if advertise is configured with a non-local ip-address Signed-off-by: Madhu Venugopal --- libnetwork/controller.go | 2 +- libnetwork/drivers/overlay/overlay.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/libnetwork/controller.go b/libnetwork/controller.go index d8a6d76f84..a81a9d67a0 100644 --- a/libnetwork/controller.go +++ b/libnetwork/controller.go @@ -178,7 +178,7 @@ func New(cfgOptions ...config.Option) (NetworkController, error) { if err := c.initDiscovery(cfg.Cluster.Watcher); err != nil { // Failing to initalize discovery is a bad situation to be in. // But it cannot fail creating the Controller - log.Debugf("Failed to Initialize Discovery : %v", err) + log.Errorf("Failed to Initialize Discovery : %v", err) } } diff --git a/libnetwork/drivers/overlay/overlay.go b/libnetwork/drivers/overlay/overlay.go index c190d3986a..982310d7a2 100644 --- a/libnetwork/drivers/overlay/overlay.go +++ b/libnetwork/drivers/overlay/overlay.go @@ -2,6 +2,7 @@ package overlay import ( "fmt" + "net" "sync" "github.com/Sirupsen/logrus" @@ -120,8 +121,30 @@ func (d *driver) Type() string { return networkType } +func validateSelf(node string) error { + advIP := net.ParseIP(node) + if advIP == nil { + return fmt.Errorf("invalid self address (%s)", node) + } + + addrs, err := net.InterfaceAddrs() + if err != nil { + return fmt.Errorf("Unable to get interface addresses %v", err) + } + for _, addr := range addrs { + ip, _, err := net.ParseCIDR(addr.String()) + if err == nil && ip.Equal(advIP) { + return nil + } + } + return fmt.Errorf("Multi-Host overlay networking requires cluster-advertise(%s) to be configured with a local ip-address that is reachable within the cluster", advIP.String()) +} + func (d *driver) nodeJoin(node string, self bool) { if self && !d.isSerfAlive() { + if err := validateSelf(node); err != nil { + logrus.Errorf("%s", err.Error()) + } d.Lock() d.bindAddress = node d.Unlock()