Fix: FTP server non-compliance with RFC 959 regarding data connection…#404
Open
pnfd wants to merge 1 commit into
Open
Fix: FTP server non-compliance with RFC 959 regarding data connection…#404pnfd wants to merge 1 commit into
pnfd wants to merge 1 commit into
Conversation
… closing codes Signed-off-by: David Penfold <david.penfold@pnfd.de>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a critical state-machine issue where the NetX Duo FTP server sends the incorrect FTP reply code (250) after closing a data connection, instead of the RFC 959 compliant code (226).
Impact
Standard-compliant FTP clients (e.g., standard Yocto FTP clients, Rust FTP clients) hang indefinitely after downloading a file, uploading a file, or requesting a directory listing. The clients detect that the data connection was closed but wait endlessly for the 226 Transfer complete code on the control channel to properly finalize the transaction.
Root Cause
According to RFC 959:
250 Requested file action okay, completed should only be used when the command does not involve closing a data connection (e.g., RNTO, DELE).
226 Closing data connection must be sent to indicate that a data transfer (like RETR, STOR, LIST, NLST) has concluded successfully and the data port was closed.
In nxd_ftp_server.c, the macro NX_FTP_CODE_COMPLETED ("250") is currently hardcoded for all successful operations, including those that close the data socket (lines processing RETR, STOR, LIST, and NLST).
Wireshark traces clearly show the following sequence:
Evidence of Protocol Violation
1. Application Layer (Control Channel)
The server incorrectly replies with
250instead of226after the transfer is done:The Wireshark capture of the corresponding data port shows that the server (10.0.0.27) explicitly closes the socket by sending a [FIN, ACK] (Packet 201), proving that a 226 response was required:
Solution implemented
link macro NX_FTP_CODE_LOGOFF correcly if a connection cleanup occurs previously
Replaced the incorrect NX_FTP_CODE_COMPLETED macro in nxd_ftp_server.c for the RETR, STOR, LIST, and NLST command processing blocks.
Operations without data channels (like DELE, RNTO, CWD) correctly retain the 250 response code.
This fully restores interoperability with strict FTP clients.