Skip to content

Commit

Permalink
Better error messages when IP address autodetection fails
Browse files Browse the repository at this point in the history
This fix tries to improve error messages when IP address
autodetection fails, as is specified in 25141.

Previously, error messages only indicate that multiple IPs
exist when autodetection fails. In this fix, if one
interface consists of multiple addresses or multiple
interfaces consist of addresses, the error messages output
the address names and interface names so that end user could
take notice.

This fix is verified manually.
When multiple addresses exist on multiple interfaces:
```
$ sudo docker swarm init
Error response from daemon: could not choose an IP address
to advertise since this system has multiple addresses on different
interfaces (192.168.186.128 on ens33 and 192.168.100.199 on eth10)
 - specify one with --advertise-addr
```
When multiple addresses exist on single interface:
```
$ sudo docker swarm init
Error response from daemon: could not choose an IP address
to advertise since this system has multiple addresses
on interface ens33 (192.168.186.128 and 192.168.55.199)
- specify one with --advertise-addr
```

This fix fixes 25141.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
  • Loading branch information
yongtang committed Aug 1, 2016
1 parent b38c25a commit 59db010
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions daemon/cluster/listen_addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

var (
errNoSuchInterface = errors.New("no such interface")
errMultipleIPs = errors.New("could not choose an IP address to advertise since this system has multiple addresses")
errNoIP = errors.New("could not find the system's IP address")
errMustSpecifyListenAddr = errors.New("must specify a listening address because the address to advertise is not recognized as a system address")
errBadListenAddr = errors.New("listen address must be an IP address or network interface (with optional port number)")
Expand Down Expand Up @@ -159,6 +158,7 @@ func (c *Cluster) resolveSystemAddr() (net.IP, error) {
}

var systemAddr net.IP
var systemInterface net.Interface

// List Docker-managed subnets
v4Subnets := c.config.NetworkSubnetsProvider.V4Subnets()
Expand Down Expand Up @@ -197,7 +197,7 @@ ifaceLoop:
}

if interfaceAddr4 != nil {
return nil, errMultipleIPs
return nil, fmt.Errorf("could not choose an IP address to advertise since this system has multiple addresses on interface %s (%s and %s)", intf.Name, interfaceAddr4, ipAddr.IP)
}

interfaceAddr4 = ipAddr.IP
Expand All @@ -212,7 +212,7 @@ ifaceLoop:
}

if interfaceAddr6 != nil {
return nil, errMultipleIPs
return nil, fmt.Errorf("could not choose an IP address to advertise since this system has multiple addresses on interface %s (%s and %s)", intf.Name, interfaceAddr6, ipAddr.IP)
}

interfaceAddr6 = ipAddr.IP
Expand All @@ -223,14 +223,16 @@ ifaceLoop:
// and exactly one IPv6 address, favor IPv4 over IPv6.
if interfaceAddr4 != nil {
if systemAddr != nil {
return nil, errMultipleIPs
return nil, fmt.Errorf("could not choose an IP address to advertise since this system has multiple addresses on different interfaces (%s on %s and %s on %s)", systemAddr, systemInterface.Name, interfaceAddr4, intf.Name)
}
systemAddr = interfaceAddr4
systemInterface = intf
} else if interfaceAddr6 != nil {
if systemAddr != nil {
return nil, errMultipleIPs
return nil, fmt.Errorf("could not choose an IP address to advertise since this system has multiple addresses on different interfaces (%s on %s and %s on %s)", systemAddr, systemInterface.Name, interfaceAddr6, intf.Name)
}
systemAddr = interfaceAddr6
systemInterface = intf
}
}

Expand Down

0 comments on commit 59db010

Please sign in to comment.