|
@@ -52,7 +52,7 @@ func (pm *PortMapper) Map(container net.Addr, hostIP net.IP, hostPort int, usePr
|
|
}
|
|
}
|
|
|
|
|
|
// MapRange maps the specified container transport address to the host's network address and transport port range
|
|
// MapRange maps the specified container transport address to the host's network address and transport port range
|
|
-func (pm *PortMapper) MapRange(container net.Addr, hostIP net.IP, hostPortStart, hostPortEnd int, useProxy bool) (host net.Addr, err error) {
|
|
|
|
|
|
+func (pm *PortMapper) MapRange(container net.Addr, hostIP net.IP, hostPortStart, hostPortEnd int, useProxy bool) (host net.Addr, retErr error) {
|
|
pm.lock.Lock()
|
|
pm.lock.Lock()
|
|
defer pm.lock.Unlock()
|
|
defer pm.lock.Unlock()
|
|
|
|
|
|
@@ -65,7 +65,10 @@ func (pm *PortMapper) MapRange(container net.Addr, hostIP net.IP, hostPortStart,
|
|
switch t := container.(type) {
|
|
switch t := container.(type) {
|
|
case *net.TCPAddr:
|
|
case *net.TCPAddr:
|
|
proto = "tcp"
|
|
proto = "tcp"
|
|
- if allocatedHostPort, err = pm.allocator.RequestPortInRange(hostIP, proto, hostPortStart, hostPortEnd); err != nil {
|
|
|
|
|
|
+
|
|
|
|
+ var err error
|
|
|
|
+ allocatedHostPort, err = pm.allocator.RequestPortInRange(hostIP, proto, hostPortStart, hostPortEnd)
|
|
|
|
+ if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
@@ -88,7 +91,10 @@ func (pm *PortMapper) MapRange(container net.Addr, hostIP net.IP, hostPortStart,
|
|
}
|
|
}
|
|
case *net.UDPAddr:
|
|
case *net.UDPAddr:
|
|
proto = "udp"
|
|
proto = "udp"
|
|
- if allocatedHostPort, err = pm.allocator.RequestPortInRange(hostIP, proto, hostPortStart, hostPortEnd); err != nil {
|
|
|
|
|
|
+
|
|
|
|
+ var err error
|
|
|
|
+ allocatedHostPort, err = pm.allocator.RequestPortInRange(hostIP, proto, hostPortStart, hostPortEnd)
|
|
|
|
+ if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
@@ -111,7 +117,10 @@ func (pm *PortMapper) MapRange(container net.Addr, hostIP net.IP, hostPortStart,
|
|
}
|
|
}
|
|
case *sctp.SCTPAddr:
|
|
case *sctp.SCTPAddr:
|
|
proto = "sctp"
|
|
proto = "sctp"
|
|
- if allocatedHostPort, err = pm.allocator.RequestPortInRange(hostIP, proto, hostPortStart, hostPortEnd); err != nil {
|
|
|
|
|
|
+
|
|
|
|
+ var err error
|
|
|
|
+ allocatedHostPort, err = pm.allocator.RequestPortInRange(hostIP, proto, hostPortStart, hostPortEnd)
|
|
|
|
+ if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
@@ -142,7 +151,7 @@ func (pm *PortMapper) MapRange(container net.Addr, hostIP net.IP, hostPortStart,
|
|
|
|
|
|
// release the allocated port on any further error during return.
|
|
// release the allocated port on any further error during return.
|
|
defer func() {
|
|
defer func() {
|
|
- if err != nil {
|
|
|
|
|
|
+ if retErr != nil {
|
|
pm.allocator.ReleasePort(hostIP, proto, allocatedHostPort)
|
|
pm.allocator.ReleasePort(hostIP, proto, allocatedHostPort)
|
|
}
|
|
}
|
|
}()
|
|
}()
|