Browse code

Require listen address and advertise address to be an IP address or an interface name

Hostnames are not supported for now because libnetwork can't use them
for overlay networking yet.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>

Aaron Lehmann authored on 2016/07/22 02:40:19
Showing 8 changed files
... ...
@@ -44,8 +44,8 @@ func newInitCommand(dockerCli *client.DockerCli) *cobra.Command {
44 44
 	}
45 45
 
46 46
 	flags := cmd.Flags()
47
-	flags.Var(&opts.listenAddr, flagListenAddr, "Listen address (format: <ip|hostname|interface>[:port])")
48
-	flags.StringVar(&opts.advertiseAddr, flagAdvertiseAddr, "", "Advertised address (format: <ip|hostname|interface>[:port])")
47
+	flags.Var(&opts.listenAddr, flagListenAddr, "Listen address (format: <ip|interface>[:port])")
48
+	flags.StringVar(&opts.advertiseAddr, flagAdvertiseAddr, "", "Advertised address (format: <ip|interface>[:port])")
49 49
 	flags.BoolVar(&opts.forceNewCluster, "force-new-cluster", false, "Force create a new cluster from current state.")
50 50
 	addSwarmFlags(flags, &opts.swarmOptions)
51 51
 	return cmd
... ...
@@ -35,8 +35,8 @@ func newJoinCommand(dockerCli *client.DockerCli) *cobra.Command {
35 35
 	}
36 36
 
37 37
 	flags := cmd.Flags()
38
-	flags.Var(&opts.listenAddr, flagListenAddr, "Listen address (format: <ip|hostname|interface>[:port])")
39
-	flags.StringVar(&opts.advertiseAddr, flagAdvertiseAddr, "", "Advertised address (format: <ip|hostname|interface>[:port])")
38
+	flags.Var(&opts.listenAddr, flagListenAddr, "Listen address (format: <ip|interface>[:port])")
39
+	flags.StringVar(&opts.advertiseAddr, flagAdvertiseAddr, "", "Advertised address (format: <ip|interface>[:port])")
40 40
 	flags.StringVar(&opts.token, flagToken, "", "Token for entry into the swarm")
41 41
 	return cmd
42 42
 }
... ...
@@ -7,10 +7,13 @@ import (
7 7
 )
8 8
 
9 9
 var (
10
-	errNoSuchInterface       = errors.New("no such interface")
11
-	errMultipleIPs           = errors.New("could not choose an IP address to advertise since this system has multiple addresses")
12
-	errNoIP                  = errors.New("could not find the system's IP address")
13
-	errMustSpecifyListenAddr = errors.New("must specify a listening address because the address to advertise is not recognized as a system address")
10
+	errNoSuchInterface         = errors.New("no such interface")
11
+	errMultipleIPs             = errors.New("could not choose an IP address to advertise since this system has multiple addresses")
12
+	errNoIP                    = errors.New("could not find the system's IP address")
13
+	errMustSpecifyListenAddr   = errors.New("must specify a listening address because the address to advertise is not recognized as a system address")
14
+	errBadListenAddr           = errors.New("listen address must be an IP address or network interface (with optional port number)")
15
+	errBadAdvertiseAddr        = errors.New("advertise address must be an IP address or network interface (with optional port number)")
16
+	errBadDefaultAdvertiseAddr = errors.New("default advertise address must be an IP address or network interface (without a port number)")
14 17
 )
15 18
 
16 19
 func resolveListenAddr(specifiedAddr string) (string, string, error) {
... ...
@@ -29,6 +32,11 @@ func resolveListenAddr(specifiedAddr string) (string, string, error) {
29 29
 		return "", "", err
30 30
 	}
31 31
 
32
+	// If it's not an interface, it must be an IP (for now)
33
+	if net.ParseIP(specifiedHost) == nil {
34
+		return "", "", errBadListenAddr
35
+	}
36
+
32 37
 	return specifiedHost, specifiedPort, nil
33 38
 }
34 39
 
... ...
@@ -61,6 +69,11 @@ func (c *Cluster) resolveAdvertiseAddr(advertiseAddr, listenAddrPort string) (st
61 61
 			return "", "", err
62 62
 		}
63 63
 
64
+		// If it's not an interface, it must be an IP (for now)
65
+		if net.ParseIP(advertiseHost) == nil {
66
+			return "", "", errBadAdvertiseAddr
67
+		}
68
+
64 69
 		return advertiseHost, advertisePort, nil
65 70
 	}
66 71
 
... ...
@@ -76,6 +89,11 @@ func (c *Cluster) resolveAdvertiseAddr(advertiseAddr, listenAddrPort string) (st
76 76
 			return "", "", err
77 77
 		}
78 78
 
79
+		// If it's not an interface, it must be an IP (for now)
80
+		if net.ParseIP(c.config.DefaultAdvertiseAddr) == nil {
81
+			return "", "", errBadDefaultAdvertiseAddr
82
+		}
83
+
79 84
 		return c.config.DefaultAdvertiseAddr, listenAddrPort, nil
80 85
 	}
81 86
 
... ...
@@ -3591,6 +3591,7 @@ Initialize a new Swarm
3591 3591
 
3592 3592
     {
3593 3593
       "ListenAddr": "0.0.0.0:4500",
3594
+      "AdvertiseAddr": "192.168.1.1:4500",
3594 3595
       "ForceNewCluster": false,
3595 3596
       "Spec": {
3596 3597
         "Orchestration": {},
... ...
@@ -3619,6 +3620,11 @@ JSON Parameters:
3619 3619
   address/port combination in the form `192.168.1.1:4567`, or an interface followed by a port
3620 3620
   number, like `eth0:4567`. If the port number is omitted, the default swarm listening port is
3621 3621
   used.
3622
+- **AdvertiseAddr** – Externally reachable address advertised to other nodes. This can either be
3623
+  an address/port combination in the form `192.168.1.1:4567`, or an interface followed by a port
3624
+  number, like `eth0:4567`. If the port number is omitted, the port number from the listen
3625
+  address is used. If `AdvertiseAddr` is not specified, it will be automatically detected when
3626
+  possible.
3622 3627
 - **ForceNewCluster** – Force creating a new Swarm even if already part of one.
3623 3628
 - **Spec** – Configuration settings of the new Swarm.
3624 3629
     - **Orchestration** – Configuration settings for the orchestration aspects of the Swarm.
... ...
@@ -3659,6 +3665,7 @@ Join an existing new Swarm
3659 3659
 
3660 3660
     {
3661 3661
       "ListenAddr": "0.0.0.0:4500",
3662
+      "AdvertiseAddr: "192.168.1.1:4500",
3662 3663
       "RemoteAddrs": ["node1:4500"],
3663 3664
       "JoinToken": "SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-7p73s1dx5in4tatdymyhg9hu2"
3664 3665
     }
... ...
@@ -3679,6 +3686,11 @@ JSON Parameters:
3679 3679
 
3680 3680
 - **ListenAddr** – Listen address used for inter-manager communication if the node gets promoted to
3681 3681
   manager, as well as determining the networking interface used for the VXLAN Tunnel Endpoint (VTEP).
3682
+- **AdvertiseAddr** – Externally reachable address advertised to other nodes. This can either be
3683
+  an address/port combination in the form `192.168.1.1:4567`, or an interface followed by a port
3684
+  number, like `eth0:4567`. If the port number is omitted, the port number from the listen
3685
+  address is used. If `AdvertiseAddr` is not specified, it will be automatically detected when
3686
+  possible.
3682 3687
 - **RemoteAddr** – Address of any manager node already participating in the Swarm to join.
3683 3688
 - **JoinToken** – Secret token for joining this Swarm.
3684 3689
 
... ...
@@ -3592,6 +3592,7 @@ Initialize a new Swarm
3592 3592
 
3593 3593
     {
3594 3594
       "ListenAddr": "0.0.0.0:4500",
3595
+      "AdvertiseAddr": "192.168.1.1:4500",
3595 3596
       "ForceNewCluster": false,
3596 3597
       "Spec": {
3597 3598
         "Orchestration": {},
... ...
@@ -3620,6 +3621,11 @@ JSON Parameters:
3620 3620
   address/port combination in the form `192.168.1.1:4567`, or an interface followed by a port
3621 3621
   number, like `eth0:4567`. If the port number is omitted, the default swarm listening port is
3622 3622
   used.
3623
+- **AdvertiseAddr** – Externally reachable address advertised to other nodes. This can either be
3624
+  an address/port combination in the form `192.168.1.1:4567`, or an interface followed by a port
3625
+  number, like `eth0:4567`. If the port number is omitted, the port number from the listen
3626
+  address is used. If `AdvertiseAddr` is not specified, it will be automatically detected when
3627
+  possible.
3623 3628
 - **ForceNewCluster** – Force creating a new Swarm even if already part of one.
3624 3629
 - **Spec** – Configuration settings of the new Swarm.
3625 3630
     - **Orchestration** – Configuration settings for the orchestration aspects of the Swarm.
... ...
@@ -3660,6 +3666,7 @@ Join an existing new Swarm
3660 3660
 
3661 3661
     {
3662 3662
       "ListenAddr": "0.0.0.0:4500",
3663
+      "AdvertiseAddr": "192.168.1.1:4500",
3663 3664
       "RemoteAddrs": ["node1:4500"],
3664 3665
       "JoinToken": "SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-7p73s1dx5in4tatdymyhg9hu2"
3665 3666
     }
... ...
@@ -3680,6 +3687,11 @@ JSON Parameters:
3680 3680
 
3681 3681
 - **ListenAddr** – Listen address used for inter-manager communication if the node gets promoted to
3682 3682
   manager, as well as determining the networking interface used for the VXLAN Tunnel Endpoint (VTEP).
3683
+- **AdvertiseAddr** – Externally reachable address advertised to other nodes. This can either be
3684
+  an address/port combination in the form `192.168.1.1:4567`, or an interface followed by a port
3685
+  number, like `eth0:4567`. If the port number is omitted, the port number from the listen
3686
+  address is used. If `AdvertiseAddr` is not specified, it will be automatically detected when
3687
+  possible.
3683 3688
 - **RemoteAddr** – Address of any manager node already participating in the Swarm to join.
3684 3689
 - **JoinToken** – Secret token for joining this Swarm.
3685 3690
 
... ...
@@ -17,13 +17,13 @@ Usage:  docker swarm init [OPTIONS]
17 17
 Initialize a swarm
18 18
 
19 19
 Options:
20
-      --advertise-addr value            Advertised address (format: <ip|hostname|interface>[:port])
20
+      --advertise-addr value            Advertised address (format: <ip|interface>[:port])
21 21
       --cert-expiry duration            Validity period for node certificates (default 2160h0m0s)
22 22
       --dispatcher-heartbeat duration   Dispatcher heartbeat period (default 5s)
23 23
       --external-ca value               Specifications of one or more certificate signing endpoints
24 24
       --force-new-cluster               Force create a new cluster from current state.
25 25
       --help                            Print usage
26
-      --listen-addr value               Listen address (format: <ip|hostname|interface>[:port])
26
+      --listen-addr value               Listen address (format: <ip|interface>[:port])
27 27
       --task-history-limit int          Task history retention limit (default 5)
28 28
 ```
29 29
 
... ...
@@ -79,7 +79,7 @@ The node listens for inbound Swarm manager traffic on this address. The default
79 79
 0.0.0.0:2377. It is also possible to specify a network interface to listen on that interface's
80 80
 address; for example `--listen-addr eth0:2377`.
81 81
 
82
-Specifying a port is optional. If the value is a bare IP address, hostname, or interface
82
+Specifying a port is optional. If the value is a bare IP address or interface
83 83
 name, the default port 2377 will be used.
84 84
 
85 85
 ### `--advertise-addr value`
... ...
@@ -94,7 +94,7 @@ inter-manager communication and overlay networking.
94 94
 It is also possible to specify a network interface to advertise that interface's address;
95 95
 for example `--advertise-addr eth0:2377`.
96 96
 
97
-Specifying a port is optional. If the value is a bare IP address, hostname, or interface
97
+Specifying a port is optional. If the value is a bare IP address or interface
98 98
 name, the default port 2377 will be used.
99 99
 
100 100
 ### `--task-history-limit`
... ...
@@ -17,9 +17,9 @@ Usage:  docker swarm join [OPTIONS] HOST:PORT
17 17
 Join a swarm as a node and/or manager
18 18
 
19 19
 Options:
20
-      --advertise-addr value   Advertised address (format: <ip|hostname|interface>[:port])
20
+      --advertise-addr value   Advertised address (format: <ip|interface>[:port])
21 21
       --help                   Print usage
22
-      --listen-addr value      Listen address
22
+      --listen-addr value      Listen address (format: <ip|interface>[:port)
23 23
       --token string           Token for entry into the swarm
24 24
 ```
25 25
 
... ...
@@ -64,7 +64,7 @@ If the node is a manager, it will listen for inbound Swarm manager traffic on th
64 64
 address. The default is to listen on 0.0.0.0:2377. It is also possible to specify a
65 65
 network interface to listen on that interface's address; for example `--listen-addr eth0:2377`.
66 66
 
67
-Specifying a port is optional. If the value is a bare IP address, hostname, or interface
67
+Specifying a port is optional. If the value is a bare IP address, or interface
68 68
 name, the default port 2377 will be used.
69 69
 
70 70
 This flag is generally not necessary when joining an existing swarm.
... ...
@@ -81,7 +81,7 @@ communication and overlay networking.
81 81
 It is also possible to specify a network interface to advertise that interface's address;
82 82
 for example `--advertise-addr eth0:2377`.
83 83
 
84
-Specifying a port is optional. If the value is a bare IP address, hostname, or interface
84
+Specifying a port is optional. If the value is a bare IP address, or interface
85 85
 name, the default port 2377 will be used.
86 86
 
87 87
 This flag is generally not necessary when joining an existing swarm.
... ...
@@ -55,7 +55,7 @@ dockerd - Enable daemon mode
55 55
 [**-s**|**--storage-driver**[=*STORAGE-DRIVER*]]
56 56
 [**--selinux-enabled**]
57 57
 [**--storage-opt**[=*[]*]]
58
-[**--swarm-default-advertise-addr**[=*IP|HOSTNAME|INTERFACE*]]
58
+[**--swarm-default-advertise-addr**[=*IP|INTERFACE*]]
59 59
 [**--tls**]
60 60
 [**--tlscacert**[=*~/.docker/ca.pem*]]
61 61
 [**--tlscert**[=*~/.docker/cert.pem*]]
... ...
@@ -240,7 +240,7 @@ output otherwise.
240 240
 **--storage-opt**=[]
241 241
   Set storage driver options. See STORAGE DRIVER OPTIONS.
242 242
 
243
-**--swarm-default-advertise-addr**=*IP|HOSTNAME|INTERFACE*
243
+**--swarm-default-advertise-addr**=*IP|INTERFACE*
244 244
   Set default address or interface for swarm to advertise as its externally-reachable address to other cluster
245 245
   members. This can be a hostname, an IP address, or an interface such as `eth0`. A port cannot be specified with
246 246
   this option.