|
@@ -41,7 +41,7 @@ func New() *PortMapper {
|
|
func NewWithPortAllocator(allocator *portallocator.PortAllocator, proxyPath string) *PortMapper {
|
|
func NewWithPortAllocator(allocator *portallocator.PortAllocator, proxyPath string) *PortMapper {
|
|
return &PortMapper{
|
|
return &PortMapper{
|
|
currentMappings: make(map[string]*mapping),
|
|
currentMappings: make(map[string]*mapping),
|
|
- Allocator: allocator,
|
|
|
|
|
|
+ allocator: allocator,
|
|
proxyPath: proxyPath,
|
|
proxyPath: proxyPath,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -65,7 +65,7 @@ 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 {
|
|
|
|
|
|
+ if allocatedHostPort, err = pm.allocator.RequestPortInRange(hostIP, proto, hostPortStart, hostPortEnd); err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
@@ -88,7 +88,7 @@ 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 {
|
|
|
|
|
|
+ if allocatedHostPort, err = pm.allocator.RequestPortInRange(hostIP, proto, hostPortStart, hostPortEnd); err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
@@ -111,7 +111,7 @@ 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 {
|
|
|
|
|
|
+ if allocatedHostPort, err = pm.allocator.RequestPortInRange(hostIP, proto, hostPortStart, hostPortEnd); err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
@@ -143,7 +143,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 err != nil {
|
|
- pm.Allocator.ReleasePort(hostIP, proto, allocatedHostPort)
|
|
|
|
|
|
+ pm.allocator.ReleasePort(hostIP, proto, allocatedHostPort)
|
|
}
|
|
}
|
|
}()
|
|
}()
|
|
|
|
|
|
@@ -161,7 +161,7 @@ func (pm *PortMapper) MapRange(container net.Addr, hostIP net.IP, hostPortStart,
|
|
// need to undo the iptables rules before we return
|
|
// need to undo the iptables rules before we return
|
|
m.userlandProxy.Stop()
|
|
m.userlandProxy.Stop()
|
|
pm.DeleteForwardingTableEntry(m.proto, hostIP, allocatedHostPort, containerIP.String(), containerPort)
|
|
pm.DeleteForwardingTableEntry(m.proto, hostIP, allocatedHostPort, containerIP.String(), containerPort)
|
|
- if err := pm.Allocator.ReleasePort(hostIP, m.proto, allocatedHostPort); err != nil {
|
|
|
|
|
|
+ if err := pm.allocator.ReleasePort(hostIP, m.proto, allocatedHostPort); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
@@ -204,14 +204,14 @@ func (pm *PortMapper) Unmap(host net.Addr) error {
|
|
|
|
|
|
switch a := host.(type) {
|
|
switch a := host.(type) {
|
|
case *net.TCPAddr:
|
|
case *net.TCPAddr:
|
|
- return pm.Allocator.ReleasePort(a.IP, "tcp", a.Port)
|
|
|
|
|
|
+ return pm.allocator.ReleasePort(a.IP, "tcp", a.Port)
|
|
case *net.UDPAddr:
|
|
case *net.UDPAddr:
|
|
- return pm.Allocator.ReleasePort(a.IP, "udp", a.Port)
|
|
|
|
|
|
+ return pm.allocator.ReleasePort(a.IP, "udp", a.Port)
|
|
case *sctp.SCTPAddr:
|
|
case *sctp.SCTPAddr:
|
|
if len(a.IPAddrs) == 0 {
|
|
if len(a.IPAddrs) == 0 {
|
|
return ErrSCTPAddrNoIP
|
|
return ErrSCTPAddrNoIP
|
|
}
|
|
}
|
|
- return pm.Allocator.ReleasePort(a.IPAddrs[0].IP, "sctp", a.Port)
|
|
|
|
|
|
+ return pm.allocator.ReleasePort(a.IPAddrs[0].IP, "sctp", a.Port)
|
|
}
|
|
}
|
|
return ErrUnknownBackendAddressType
|
|
return ErrUnknownBackendAddressType
|
|
}
|
|
}
|