From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5419EC53210 for ; Thu, 5 Jan 2023 13:02:14 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0B1C6855A3; Thu, 5 Jan 2023 14:02:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="cT0WKZy4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C8A5685587; Thu, 5 Jan 2023 01:45:47 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by phobos.denx.de (Postfix) with ESMTP id 31C1C8552C for ; Thu, 5 Jan 2023 01:45:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanedmond@linux.microsoft.com Received: from ovlvm106.redmond.corp.microsoft.com (unknown [131.107.174.57]) by linux.microsoft.com (Postfix) with ESMTPSA id A135620B8762; Wed, 4 Jan 2023 16:45:43 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A135620B8762 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1672879543; bh=SpzMngjJYTete8WxPxDpckHfWNZO8+B+EOYMgNBUnNk=; h=From:To:Cc:Subject:Date:From; b=cT0WKZy4NJLYC3aOciDLdVTy5FdXRCU5az2CqxXvpnLWCf/FavuT/lHCrnsYnNdu/ MegEMQ+PURfZHKt9j8rHemZOKcyr1GRHPvTIvF0a4i4U+Rfb167Ms39lJ7hD3C9cog k8qo/oBN7aku6oGKJthPfOCehNAY4Nn129ulW9xE= From: seanedmond@linux.microsoft.com To: u-boot@lists.denx.de Cc: joe.hershberger@ni.com, rfried.dev@gmail.com Subject: [PATCH] net: tftp: Fix for DATA ACK for block count out of order Date: Wed, 4 Jan 2023 16:45:42 -0800 Message-Id: <20230105004542.13638-1-seanedmond@linux.microsoft.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Thu, 05 Jan 2023 14:02:10 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean From: Sean Edmond 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 --- net/tftp.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/tftp.c b/net/tftp.c index c780c33f37..51e062bddf 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -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 -- 2.17.1