summaryrefslogtreecommitdiff
path: root/vendor/github.com/docker/go-connections/nat
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2022-02-03 18:33:22 -0500
committerDaniel J Walsh <dwalsh@redhat.com>2022-02-03 18:33:22 -0500
commit1d1b2b1509646e07ab4a984c7622fa002a0fcdb7 (patch)
treefd4078e58bc9ab0b6c2ef1938017ce5844f97744 /vendor/github.com/docker/go-connections/nat
parent608b6142edb7a4e179ce6d2ae69707be28f29359 (diff)
downloadpodman-1d1b2b1509646e07ab4a984c7622fa002a0fcdb7.tar.gz
podman-1d1b2b1509646e07ab4a984c7622fa002a0fcdb7.tar.bz2
podman-1d1b2b1509646e07ab4a984c7622fa002a0fcdb7.zip
Update containers/buildah v1.24.1
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'vendor/github.com/docker/go-connections/nat')
-rw-r--r--vendor/github.com/docker/go-connections/nat/nat.go28
-rw-r--r--vendor/github.com/docker/go-connections/nat/sort.go4
2 files changed, 15 insertions, 17 deletions
diff --git a/vendor/github.com/docker/go-connections/nat/nat.go b/vendor/github.com/docker/go-connections/nat/nat.go
index bb7e4e336..296c96a63 100644
--- a/vendor/github.com/docker/go-connections/nat/nat.go
+++ b/vendor/github.com/docker/go-connections/nat/nat.go
@@ -8,11 +8,6 @@ import (
"strings"
)
-const (
- // portSpecTemplate is the expected format for port specifications
- portSpecTemplate = "ip:hostPort:containerPort"
-)
-
// PortBinding represents a binding between a Host IP address and a Host Port
type PortBinding struct {
// HostIP is the host IP Address
@@ -158,30 +153,33 @@ type PortMapping struct {
func splitParts(rawport string) (string, string, string) {
parts := strings.Split(rawport, ":")
n := len(parts)
- containerport := parts[n-1]
+ containerPort := parts[n-1]
switch n {
case 1:
- return "", "", containerport
+ return "", "", containerPort
case 2:
- return "", parts[0], containerport
+ return "", parts[0], containerPort
case 3:
- return parts[0], parts[1], containerport
+ return parts[0], parts[1], containerPort
default:
- return strings.Join(parts[:n-2], ":"), parts[n-2], containerport
+ return strings.Join(parts[:n-2], ":"), parts[n-2], containerPort
}
}
// ParsePortSpec parses a port specification string into a slice of PortMappings
func ParsePortSpec(rawPort string) ([]PortMapping, error) {
var proto string
- rawIP, hostPort, containerPort := splitParts(rawPort)
+ ip, hostPort, containerPort := splitParts(rawPort)
proto, containerPort = SplitProtoPort(containerPort)
- // Strip [] from IPV6 addresses
- ip, _, err := net.SplitHostPort(rawIP + ":")
- if err != nil {
- return nil, fmt.Errorf("Invalid ip address %v: %s", rawIP, err)
+ if ip != "" && ip[0] == '[' {
+ // Strip [] from IPV6 addresses
+ rawIP, _, err := net.SplitHostPort(ip + ":")
+ if err != nil {
+ return nil, fmt.Errorf("Invalid ip address %v: %s", ip, err)
+ }
+ ip = rawIP
}
if ip != "" && net.ParseIP(ip) == nil {
return nil, fmt.Errorf("Invalid ip address: %s", ip)
diff --git a/vendor/github.com/docker/go-connections/nat/sort.go b/vendor/github.com/docker/go-connections/nat/sort.go
index ce950171e..b6eed145e 100644
--- a/vendor/github.com/docker/go-connections/nat/sort.go
+++ b/vendor/github.com/docker/go-connections/nat/sort.go
@@ -43,7 +43,7 @@ type portMapSorter []portMapEntry
func (s portMapSorter) Len() int { return len(s) }
func (s portMapSorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
-// sort the port so that the order is:
+// Less sorts the port so that the order is:
// 1. port with larger specified bindings
// 2. larger port
// 3. port with tcp protocol
@@ -58,7 +58,7 @@ func (s portMapSorter) Less(i, j int) bool {
func SortPortMap(ports []Port, bindings PortMap) {
s := portMapSorter{}
for _, p := range ports {
- if binding, ok := bindings[p]; ok {
+ if binding, ok := bindings[p]; ok && len(binding) > 0 {
for _, b := range binding {
s = append(s, portMapEntry{port: p, binding: b})
}