Skip to contentSkip to conversation

net: tftp: Fix for DATA ACK for block count out of order

PATCH In review [email protected] 3 participants 3 messages Jan 5, 2023 – Feb 3, 2023 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: tftp: Fix for DATA ACK for block count out of order

From: Sean Edmond <[email protected]>

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.

---
 net/tftp.c | 8 ++++++++
 1 file changed, 8 insertions(+)
net/tftp.c +8 -0
index c780c33f37..51e062bddf 100644
@@ -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
Signature · 1 line
2.39.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 35 lines · On Thu, Jan 5, 2023 at 4:16 AM <[email protected]> wrote:

From: Sean Edmond <[email protected]>

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.

---
 net/tftp.c | 8 ++++++++
 1 file changed, 8 insertions(+)
net/tftp.c +8 -1
index c780c33f37..51e062bddf 100644
@@ -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
--
Quoted 2 lines

2.39.0

#2 lore raw
In reply to [email protected]
Quoted 11 lines · On Wed, Jan 04, 2023 at 06:16:26PM -0800, [email protected] wrote:

From: Sean Edmond <[email protected]>

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.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom