diff --git a/internal/port/port.go b/internal/port/port.go index bb6648f..1f05eab 100644 --- a/internal/port/port.go +++ b/internal/port/port.go @@ -74,9 +74,6 @@ func (pm *PortManager) SetPortStatus(port uint16, assigned bool) error { pm.mu.Lock() defer pm.mu.Unlock() - if _, exists := pm.ports[port]; !exists { - return fmt.Errorf("port %d already in use", port) - } pm.ports[port] = assigned return nil } diff --git a/session/handler.go b/session/handler.go index b1c4545..1efad69 100644 --- a/session/handler.go +++ b/session/handler.go @@ -271,7 +271,7 @@ func (s *SSHSession) handleTCPIPForward(req *ssh.Request) { } return } - } else if isUse, isExist := portUtil.Manager.GetPortStatus(portToBind); isExist || isUse { + } else if isUse, isExist := portUtil.Manager.GetPortStatus(portToBind); isExist && isUse { s.interaction.SendMessage(fmt.Sprintf("Port %d is already in use or restricted. Please choose a different port. (03)\r\n", portToBind)) err := req.Reply(false, nil) if err != nil {