libnetwork/portallocator: PortAllocator.ReleasePort: remove unused err-return

This function never returned an error, and was not matching an interface, so
remove the error-return.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-12-29 10:31:23 +01:00
parent a5b4670c79
commit f714730c40
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
3 changed files with 14 additions and 22 deletions

View file

@ -154,7 +154,7 @@ func (p *PortAllocator) RequestPortInRange(ip net.IP, proto string, portStart, p
}
// ReleasePort releases port from global ports pool for specified ip and proto.
func (p *PortAllocator) ReleasePort(ip net.IP, proto string, port int) error {
func (p *PortAllocator) ReleasePort(ip net.IP, proto string, port int) {
p.mutex.Lock()
defer p.mutex.Unlock()
@ -163,10 +163,9 @@ func (p *PortAllocator) ReleasePort(ip net.IP, proto string, port int) error {
}
protomap, ok := p.ipMap[ip.String()]
if !ok {
return nil
return
}
delete(protomap[proto].p, port)
return nil
}
func (p *PortAllocator) newPortMap() *portMap {

View file

@ -48,9 +48,7 @@ func TestReleasePort(t *testing.T) {
t.Fatalf("Expected port 5000 got %d", port)
}
if err := p.ReleasePort(defaultIP, "tcp", 5000); err != nil {
t.Fatal(err)
}
p.ReleasePort(defaultIP, "tcp", 5000)
}
func TestReuseReleasedPort(t *testing.T) {
@ -65,9 +63,7 @@ func TestReuseReleasedPort(t *testing.T) {
t.Fatalf("Expected port 5000 got %d", port)
}
if err := p.ReleasePort(defaultIP, "tcp", 5000); err != nil {
t.Fatal(err)
}
p.ReleasePort(defaultIP, "tcp", 5000)
port, err = p.RequestPort(defaultIP, "tcp", 5000)
if err != nil {
@ -131,9 +127,7 @@ func TestAllocateAllPorts(t *testing.T) {
// release a port in the middle and ensure we get another tcp port
port := p.Begin + 5
if err := p.ReleasePort(defaultIP, "tcp", port); err != nil {
t.Fatal(err)
}
p.ReleasePort(defaultIP, "tcp", port)
newPort, err := p.RequestPort(defaultIP, "tcp", 0)
if err != nil {
t.Fatal(err)
@ -144,9 +138,7 @@ func TestAllocateAllPorts(t *testing.T) {
// now pm.last == newPort, release it so that it's the only free port of
// the range, and ensure we get it back
if err := p.ReleasePort(defaultIP, "tcp", newPort); err != nil {
t.Fatal(err)
}
p.ReleasePort(defaultIP, "tcp", newPort)
port, err = p.RequestPort(defaultIP, "tcp", 0)
if err != nil {
t.Fatal(err)
@ -215,9 +207,7 @@ func TestPortAllocation(t *testing.T) {
if _, err := p.RequestPort(ip2, "tcp", 80); err == nil {
t.Fatalf("Acquiring a port already in use should return an error")
}
if err := p.ReleasePort(ip, "tcp", 80); err != nil {
t.Fatal(err)
}
p.ReleasePort(ip, "tcp", 80)
if _, err := p.RequestPort(ip, "tcp", 80); err != nil {
t.Fatal(err)
}

View file

@ -211,16 +211,19 @@ func (pm *PortMapper) Unmap(host net.Addr) error {
switch a := host.(type) {
case *net.TCPAddr:
return pm.allocator.ReleasePort(a.IP, "tcp", a.Port)
pm.allocator.ReleasePort(a.IP, "tcp", a.Port)
case *net.UDPAddr:
return pm.allocator.ReleasePort(a.IP, "udp", a.Port)
pm.allocator.ReleasePort(a.IP, "udp", a.Port)
case *sctp.SCTPAddr:
if len(a.IPAddrs) == 0 {
return ErrSCTPAddrNoIP
}
return pm.allocator.ReleasePort(a.IPAddrs[0].IP, "sctp", a.Port)
pm.allocator.ReleasePort(a.IPAddrs[0].IP, "sctp", a.Port)
default:
return ErrUnknownBackendAddressType
}
return ErrUnknownBackendAddressType
return nil
}
// ReMapAll re-applies all port mappings