mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-22 10:31:35 +00:00
tool: Make ports uint16
The type of the guest and host ports should be uint16 not int. Also make them public member of the PublishPort structure. Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
parent
d4517bc26f
commit
a272eba740
@ -640,13 +640,13 @@ func buildQemuForwardings(publishFlags multipleFlag, containerized bool) (string
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
hostPort := p.host
|
hostPort := p.Host
|
||||||
guestPort := p.guest
|
guestPort := p.Guest
|
||||||
|
|
||||||
if containerized {
|
if containerized {
|
||||||
hostPort = guestPort
|
hostPort = guestPort
|
||||||
}
|
}
|
||||||
forwardings = fmt.Sprintf("%s,hostfwd=%s::%d-:%d", forwardings, p.protocol, hostPort, guestPort)
|
forwardings = fmt.Sprintf("%s,hostfwd=%s::%d-:%d", forwardings, p.Protocol, hostPort, guestPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
return forwardings, nil
|
return forwardings, nil
|
||||||
@ -659,7 +659,7 @@ func buildDockerForwardings(publishedPorts []string) ([]string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
pmap = append(pmap, "-p", fmt.Sprintf("%d:%d/%s", s.host, s.guest, s.protocol))
|
pmap = append(pmap, "-p", fmt.Sprintf("%d:%d/%s", s.Host, s.Guest, s.Protocol))
|
||||||
}
|
}
|
||||||
return pmap, nil
|
return pmap, nil
|
||||||
}
|
}
|
||||||
|
@ -194,9 +194,9 @@ func (l *Disks) Set(value string) error {
|
|||||||
|
|
||||||
// PublishedPort is used by some backends to expose a VMs port on the host
|
// PublishedPort is used by some backends to expose a VMs port on the host
|
||||||
type PublishedPort struct {
|
type PublishedPort struct {
|
||||||
guest int
|
Guest uint16
|
||||||
host int
|
Host uint16
|
||||||
protocol string
|
Protocol string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPublishedPort parses a string of the form <host>:<guest>[/<tcp|udp>] and returns a PublishedPort structure
|
// NewPublishedPort parses a string of the form <host>:<guest>[/<tcp|udp>] and returns a PublishedPort structure
|
||||||
@ -208,10 +208,9 @@ func NewPublishedPort(publish string) (PublishedPort, error) {
|
|||||||
return p, fmt.Errorf("Unable to parse the ports to be published, should be in format <host>:<guest> or <host>:<guest>/<tcp|udp>")
|
return p, fmt.Errorf("Unable to parse the ports to be published, should be in format <host>:<guest> or <host>:<guest>/<tcp|udp>")
|
||||||
}
|
}
|
||||||
|
|
||||||
hostPort, err := strconv.Atoi(slice[0])
|
hostPort, err := strconv.ParseUint(slice[0], 10, 16)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return p, fmt.Errorf("The provided hostPort can't be converted to int")
|
return p, fmt.Errorf("The provided hostPort can't be converted to uint16")
|
||||||
}
|
}
|
||||||
|
|
||||||
right := strings.Split(slice[1], "/")
|
right := strings.Split(slice[1], "/")
|
||||||
@ -220,26 +219,24 @@ func NewPublishedPort(publish string) (PublishedPort, error) {
|
|||||||
if len(right) == 2 {
|
if len(right) == 2 {
|
||||||
protocol = strings.TrimSpace(strings.ToLower(right[1]))
|
protocol = strings.TrimSpace(strings.ToLower(right[1]))
|
||||||
}
|
}
|
||||||
|
|
||||||
if protocol != "tcp" && protocol != "udp" {
|
if protocol != "tcp" && protocol != "udp" {
|
||||||
return p, fmt.Errorf("Provided protocol is not valid, valid options are: udp and tcp")
|
return p, fmt.Errorf("Provided protocol is not valid, valid options are: udp and tcp")
|
||||||
}
|
}
|
||||||
guestPort, err := strconv.Atoi(right[0])
|
|
||||||
|
|
||||||
|
guestPort, err := strconv.ParseUint(right[0], 10, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return p, fmt.Errorf("The provided guestPort can't be converted to int")
|
return p, fmt.Errorf("The provided guestPort can't be converted to uint16")
|
||||||
}
|
}
|
||||||
|
|
||||||
if hostPort < 1 || hostPort > 65535 {
|
if hostPort < 1 || hostPort > 65535 {
|
||||||
return p, fmt.Errorf("Invalid hostPort: %d", hostPort)
|
return p, fmt.Errorf("Invalid hostPort: %d", hostPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
if guestPort < 1 || guestPort > 65535 {
|
if guestPort < 1 || guestPort > 65535 {
|
||||||
return p, fmt.Errorf("Invalid guestPort: %d", guestPort)
|
return p, fmt.Errorf("Invalid guestPort: %d", guestPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.guest = guestPort
|
p.Guest = uint16(guestPort)
|
||||||
p.host = hostPort
|
p.Host = uint16(hostPort)
|
||||||
p.protocol = protocol
|
p.Protocol = protocol
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user