Browse code

Merge pull request #27860 from vdemeester/update-go-connections-vendor

Update go-connections vendoring

Brian Goff authored on 2016/10/29 04:01:59
Showing 4 changed files
... ...
@@ -64,7 +64,7 @@ clone git github.com/vdemeester/shakers 24d7f1d6a71aa5d9cbe7390e4afb66b7eef9e1b3
64 64
 clone git golang.org/x/net 2beffdc2e92c8a3027590f898fe88f69af48a3f8 https://github.com/tonistiigi/net.git
65 65
 clone git golang.org/x/sys eb2c74142fd19a79b3f237334c7384d5167b1b46 https://github.com/golang/sys.git
66 66
 clone git github.com/docker/go-units 8a7beacffa3009a9ac66bad506b18ffdd110cf97
67
-clone git github.com/docker/go-connections 988efe982fdecb46f01d53465878ff1f2ff411ce
67
+clone git github.com/docker/go-connections 1494b6df4050e60923d68cd8cc6a19e7af9f1c01
68 68
 
69 69
 clone git github.com/RackSec/srslog 365bf33cd9acc21ae1c355209865f17228ca534e
70 70
 clone git github.com/imdario/mergo 0.2.1
... ...
@@ -155,33 +155,36 @@ type PortMapping struct {
155 155
 	Binding PortBinding
156 156
 }
157 157
 
158
+func splitParts(rawport string) (string, string, string) {
159
+	parts := strings.Split(rawport, ":")
160
+	n := len(parts)
161
+	containerport := parts[n-1]
162
+
163
+	switch n {
164
+	case 1:
165
+		return "", "", containerport
166
+	case 2:
167
+		return "", parts[0], containerport
168
+	case 3:
169
+		return parts[0], parts[1], containerport
170
+	default:
171
+		return strings.Join(parts[:n-2], ":"), parts[n-2], containerport
172
+	}
173
+}
174
+
158 175
 // ParsePortSpec parses a port specification string into a slice of PortMappings
159 176
 func ParsePortSpec(rawPort string) ([]PortMapping, error) {
160
-	proto := "tcp"
161
-
162
-	if i := strings.LastIndex(rawPort, "/"); i != -1 {
163
-		proto = rawPort[i+1:]
164
-		rawPort = rawPort[:i]
165
-	}
166
-	if !strings.Contains(rawPort, ":") {
167
-		rawPort = fmt.Sprintf("::%s", rawPort)
168
-	} else if len(strings.Split(rawPort, ":")) == 2 {
169
-		rawPort = fmt.Sprintf(":%s", rawPort)
170
-	}
177
+	var proto string
178
+	rawIP, hostPort, containerPort := splitParts(rawPort)
179
+	proto, containerPort = SplitProtoPort(containerPort)
171 180
 
172
-	parts, err := PartParser(portSpecTemplate, rawPort)
181
+	// Strip [] from IPV6 addresses
182
+	ip, _, err := net.SplitHostPort(rawIP + ":")
173 183
 	if err != nil {
174
-		return nil, err
184
+		return nil, fmt.Errorf("Invalid ip address %v: %s", rawIP, err)
175 185
 	}
176
-
177
-	var (
178
-		containerPort = parts["containerPort"]
179
-		rawIP         = parts["ip"]
180
-		hostPort      = parts["hostPort"]
181
-	)
182
-
183
-	if rawIP != "" && net.ParseIP(rawIP) == nil {
184
-		return nil, fmt.Errorf("Invalid ip address: %s", rawIP)
186
+	if ip != "" && net.ParseIP(ip) == nil {
187
+		return nil, fmt.Errorf("Invalid ip address: %s", ip)
185 188
 	}
186 189
 	if containerPort == "" {
187 190
 		return nil, fmt.Errorf("No port specified: %s<empty>", rawPort)
... ...
@@ -230,7 +233,7 @@ func ParsePortSpec(rawPort string) ([]PortMapping, error) {
230 230
 		}
231 231
 
232 232
 		binding := PortBinding{
233
-			HostIP:   rawIP,
233
+			HostIP:   ip,
234 234
 			HostPort: hostPort,
235 235
 		}
236 236
 		ports = append(ports, PortMapping{Port: port, Binding: binding})
... ...
@@ -8,6 +8,7 @@ import (
8 8
 
9 9
 // PartParser parses and validates the specified string (data) using the specified template
10 10
 // e.g. ip:public:private -> 192.168.0.1:80:8000
11
+// DEPRECATED: do not use, this function may be removed in a future version
11 12
 func PartParser(template, data string) (map[string]string, error) {
12 13
 	// ip:public:private
13 14
 	var (
... ...
@@ -7,7 +7,7 @@ import (
7 7
 )
8 8
 
9 9
 // NewTCPSocket creates a TCP socket listener with the specified address and
10
-// and the specified tls configuration. If TLSConfig is set, will encapsulate the
10
+// the specified tls configuration. If TLSConfig is set, will encapsulate the
11 11
 // TCP listener inside a TLS one.
12 12
 func NewTCPSocket(addr string, tlsConfig *tls.Config) (net.Listener, error) {
13 13
 	l, err := net.Listen("tcp", addr)