فهرست منبع

libnetwork/portmapper: un-export PortMapper.Allocator

It was only accessed through methods on PortMapper, and in tests.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 1 سال پیش
والد
کامیت
f5d6af13d0

+ 9 - 9
libnetwork/portmapper/mapper.go

@@ -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
 }
 }

+ 1 - 1
libnetwork/portmapper/mapper_linux.go

@@ -18,7 +18,7 @@ type PortMapper struct {
 
 
 	proxyPath string
 	proxyPath string
 
 
-	Allocator *portallocator.PortAllocator
+	allocator *portallocator.PortAllocator
 	chain     *iptables.ChainInfo
 	chain     *iptables.ChainInfo
 }
 }
 
 

+ 1 - 1
libnetwork/portmapper/mapper_linux_test.go

@@ -171,7 +171,7 @@ func TestMapAllPortsSingleInterface(t *testing.T) {
 	}()
 	}()
 
 
 	for i := 0; i < 10; i++ {
 	for i := 0; i < 10; i++ {
-		start, end := pm.Allocator.Begin, pm.Allocator.End
+		start, end := pm.allocator.Begin, pm.allocator.End
 		for i := start; i < end; i++ {
 		for i := start; i < end; i++ {
 			if host, err = pm.Map(srcAddr1, dstIP1, 0, true); err != nil {
 			if host, err = pm.Map(srcAddr1, dstIP1, 0, true); err != nil {
 				t.Fatal(err)
 				t.Fatal(err)

+ 1 - 1
libnetwork/portmapper/mapper_windows.go

@@ -17,7 +17,7 @@ type PortMapper struct {
 
 
 	proxyPath string
 	proxyPath string
 
 
-	Allocator *portallocator.PortAllocator
+	allocator *portallocator.PortAllocator
 }
 }
 
 
 // AppendForwardingTableEntry adds a port mapping to the forwarding table
 // AppendForwardingTableEntry adds a port mapping to the forwarding table