]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
net: tftp: Fix for DATA ACK for block count out of order
authorSean Edmond <seanedmond@linux.microsoft.com>
Thu, 5 Jan 2023 02:16:26 +0000 (18:16 -0800)
committerTom Rini <trini@konsulko.com>
Thu, 2 Feb 2023 19:44:53 +0000 (14:44 -0500)
In rfc7440, if an ACK is not received by the server or if the
last data block in a window is dropped, the server will timeout and
retransmit the window.  In this case, the block count received will be
less than the internal block count.  In this case, the client
should not ACK.  ACK should only be sent if the received block
count is greater than the expected block count.

Signed-off-by: Sean Edmond <seanedmond@linux.microsoft.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
net/tftp.c

index c780c33f3792c62f330e803160af8b4368f6dfb0..51e062bddf722a9117700a8e2ac7d7a46a60a4ce 100644 (file)
@@ -592,6 +592,14 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
                        debug("Received unexpected block: %d, expected: %d\n",
                              ntohs(*(__be16 *)pkt),
                              (ushort)(tftp_cur_block + 1));
+                       /*
+                        * Only ACK if the block count received is greater than
+                        * the expected block count, otherwise skip ACK.
+                        * (required to properly handle the server retransmitting
+                        *  the window)
+                        */
+                       if ((ushort)(tftp_cur_block + 1) - (short)(ntohs(*(__be16 *)pkt)) > 0)
+                               break;
                        /*
                         * If one packet is dropped most likely
                         * all other buffers in the window