diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-06-11 08:50:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-11 08:50:13 -0400 |
commit | 09e4faa7dfa99719d67039a9e39bebb5376d9ecb (patch) | |
tree | 6ae45b568940a022073babf90df7ad677217d420 /cmd | |
parent | 7b85d5c6d272da17bcdb9fb266859c3e5ec8fd09 (diff) | |
parent | 4e2a0b5b9c534a3bdf64ff22ecbca4a43f65e65c (diff) | |
download | podman-09e4faa7dfa99719d67039a9e39bebb5376d9ecb.tar.gz podman-09e4faa7dfa99719d67039a9e39bebb5376d9ecb.tar.bz2 podman-09e4faa7dfa99719d67039a9e39bebb5376d9ecb.zip |
Merge pull request #6529 from mheon/v6_ports
Enable IPv6 port binding
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/common/util.go | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/cmd/podman/common/util.go b/cmd/podman/common/util.go index a3626b4e4..0d9f3ba26 100644 --- a/cmd/podman/common/util.go +++ b/cmd/podman/common/util.go @@ -71,14 +71,44 @@ func createPortBindings(ports []string) ([]specgen.PortMapping, error) { return nil, errors.Errorf("invalid port format - protocol can only be specified once") } - splitPort := strings.Split(splitProto[0], ":") + remainder := splitProto[0] + haveV6 := false + + // Check for an IPv6 address in brackets + splitV6 := strings.Split(remainder, "]") + switch len(splitV6) { + case 1: + // Do nothing, proceed as before + case 2: + // We potentially have an IPv6 address + haveV6 = true + if !strings.HasPrefix(splitV6[0], "[") { + return nil, errors.Errorf("invalid port format - IPv6 addresses must be enclosed by []") + } + if !strings.HasPrefix(splitV6[1], ":") { + return nil, errors.Errorf("invalid port format - IPv6 address must be followed by a colon (':')") + } + ipNoPrefix := strings.TrimPrefix(splitV6[0], "[") + hostIP = &ipNoPrefix + remainder = strings.TrimPrefix(splitV6[1], ":") + default: + return nil, errors.Errorf("invalid port format - at most one IPv6 address can be specified in a --publish") + } + + splitPort := strings.Split(remainder, ":") switch len(splitPort) { case 1: + if haveV6 { + return nil, errors.Errorf("invalid port format - must provide host and destination port if specifying an IP") + } ctrPort = splitPort[0] case 2: hostPort = &(splitPort[0]) ctrPort = splitPort[1] case 3: + if haveV6 { + return nil, errors.Errorf("invalid port format - when v6 address specified, must be [ipv6]:hostPort:ctrPort") + } hostIP = &(splitPort[0]) hostPort = &(splitPort[1]) ctrPort = splitPort[2] |