]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg/Mtftp6Dxe: Support windowsize in read request operation.
authorJiaxin Wu <Jiaxin.wu@intel.com>
Fri, 14 Sep 2018 07:47:52 +0000 (15:47 +0800)
committerJiaxin Wu <Jiaxin.wu@intel.com>
Thu, 27 Sep 2018 01:00:00 +0000 (09:00 +0800)
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=886

This patch is to support the TFTP windowsize option described in RFC 7440.
The feature allows the client and server to negotiate a window size of
consecutive blocks to send as an alternative for replacing the single-block
lockstep schema.

Currently, the windowsize for write request operation is not supported since
there is no real use cases.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Shao Ming <ming.shao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
NetworkPkg/Mtftp6Dxe/Mtftp6Impl.h
NetworkPkg/Mtftp6Dxe/Mtftp6Option.c
NetworkPkg/Mtftp6Dxe/Mtftp6Option.h
NetworkPkg/Mtftp6Dxe/Mtftp6Rrq.c
NetworkPkg/Mtftp6Dxe/Mtftp6Support.c
NetworkPkg/Mtftp6Dxe/Mtftp6Wrq.c

index 6b1ce7f853ff72a50bff4057de64043c8fa6db70..cf1b6abacce2c1ba6bb5e233a07422fea9ab998b 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Mtftp6 internal data structure and definition declaration.\r
 \r
-  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved. <BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -46,6 +46,7 @@ typedef struct _MTFTP6_INSTANCE MTFTP6_INSTANCE;
 #define MTFTP6_GET_MAPPING_TIMEOUT     3\r
 #define MTFTP6_DEFAULT_MAX_RETRY       5\r
 #define MTFTP6_DEFAULT_BLK_SIZE        512\r
+#define MTFTP6_DEFAULT_WINDOWSIZE      1\r
 #define MTFTP6_TICK_PER_SECOND         10000000U\r
 \r
 #define MTFTP6_SERVICE_FROM_THIS(a)    CR (a, MTFTP6_SERVICE, ServiceBinding, MTFTP6_SERVICE_SIGNATURE)\r
@@ -77,6 +78,16 @@ struct _MTFTP6_INSTANCE {
   UINT16                        LastBlk;\r
   LIST_ENTRY                    BlkList;\r
 \r
+  UINT16                        Operation;\r
+\r
+  UINT16                        WindowSize;\r
+\r
+  //\r
+  // Record the total received block number and the already acked block number.\r
+  //\r
+  UINT64                        TotalBlock;\r
+  UINT64                        AckedBlock;\r
+\r
   EFI_IPv6_ADDRESS              ServerIp;\r
   UINT16                        ServerCmdPort;\r
   UINT16                        ServerDataPort;\r
index 0dcf546fa82bef35188c4963aee4be2d94a00585..94790e3ad6e1e4a6700dd748b3380c9b9d51c56f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Mtftp6 option parse functions implementation.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -17,6 +17,7 @@
 \r
 CHAR8 *mMtftp6SupportedOptions[MTFTP6_SUPPORTED_OPTIONS_NUM] = {\r
   "blksize",\r
+  "windowsize",\r
   "timeout",\r
   "tsize",\r
   "multicast"\r
@@ -146,6 +147,7 @@ Mtftp6ParseMcastOption (
   @param[in]  Count         The num of the extension options.\r
   @param[in]  IsRequest     If FALSE, the extension options is included\r
                             by a request packet.\r
+  @param[in]  Operation     The current performed operation.\r
   @param[in]  ExtInfo       The pointer to the option information to be filled.\r
 \r
   @retval EFI_SUCCESS            Parse the multicast option successfully.\r
@@ -158,6 +160,7 @@ Mtftp6ParseExtensionOption (
   IN EFI_MTFTP6_OPTION        *Options,\r
   IN UINT32                   Count,\r
   IN BOOLEAN                  IsRequest,\r
+  IN UINT16                   Operation,\r
   IN MTFTP6_EXT_OPTION_INFO   *ExtInfo\r
   )\r
 {\r
@@ -228,6 +231,23 @@ Mtftp6ParseExtensionOption (
 \r
       ExtInfo->BitMap |= MTFTP6_OPT_MCAST_BIT;\r
 \r
+    } else if (AsciiStriCmp ((CHAR8 *) Opt->OptionStr, "windowsize") == 0) {\r
+      if (Operation == EFI_MTFTP6_OPCODE_WRQ) {\r
+        //\r
+        // Currently, windowsize is not supported in the write operation.\r
+        //\r
+        return EFI_UNSUPPORTED;\r
+      }\r
+\r
+      Value = (UINT32) AsciiStrDecimalToUintn ((CHAR8 *) Opt->ValueStr);\r
+\r
+      if ((Value < 1)) {\r
+        return EFI_INVALID_PARAMETER;\r
+      }\r
+\r
+      ExtInfo->WindowSize = (UINT16) Value;\r
+      ExtInfo->BitMap |= MTFTP6_OPT_WINDOWSIZE_BIT;\r
+\r
     } else if (IsRequest) {\r
       //\r
       // If it's a request, unsupported; else if it's a reply, ignore.\r
index 8e2671fa218ed2712498be045be27a9ef0a4c271..08aa45ff633a0615d07287282c4fb0c6e2ed5ff7 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Mtftp6 option parse functions declaration.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -26,7 +26,7 @@
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/UefiRuntimeServicesTableLib.h>\r
 \r
-#define MTFTP6_SUPPORTED_OPTIONS_NUM  4\r
+#define MTFTP6_SUPPORTED_OPTIONS_NUM  5\r
 #define MTFTP6_OPCODE_LEN             2\r
 #define MTFTP6_ERRCODE_LEN            2\r
 #define MTFTP6_BLKNO_LEN              2\r
 #define MTFTP6_OPT_TIMEOUT_BIT        0x02\r
 #define MTFTP6_OPT_TSIZE_BIT          0x04\r
 #define MTFTP6_OPT_MCAST_BIT          0x08\r
+#define MTFTP6_OPT_WINDOWSIZE_BIT     0X10\r
 \r
 extern CHAR8 *mMtftp6SupportedOptions[MTFTP6_SUPPORTED_OPTIONS_NUM];\r
 \r
 typedef struct {\r
   UINT16                    BlkSize;\r
+  UINT16                    WindowSize;\r
   UINT8                     Timeout;\r
   UINT32                    Tsize;\r
   EFI_IPv6_ADDRESS          McastIp;\r
@@ -76,11 +78,12 @@ Mtftp6ParseMcastOption (
   @param[in]  Count         The num of the extension options.\r
   @param[in]  IsRequest     If FALSE, the extension options is included\r
                             by a request packet.\r
+  @param[in]  Operation     The current performed operation.\r
   @param[in]  ExtInfo       The pointer to the option information to be filled.\r
 \r
-  @retval EFI_SUCCESS            Parse the multi-cast option successfully.\r
-  @retval EFI_INVALID_PARAMETER  An option is malformatted.\r
-  @retval EFI_UNSUPPORTED        An option is not supported.\r
+  @retval EFI_SUCCESS            Parse the multicast option successfully.\r
+  @retval EFI_INVALID_PARAMETER  There is one option is malformatted at least.\r
+  @retval EFI_UNSUPPORTED        There is one option is not supported at least.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -88,6 +91,7 @@ Mtftp6ParseExtensionOption (
   IN EFI_MTFTP6_OPTION        *Options,\r
   IN UINT32                   Count,\r
   IN BOOLEAN                  IsRequest,\r
+  IN UINT16                   Operation,\r
   IN MTFTP6_EXT_OPTION_INFO   *ExtInfo\r
   );\r
 \r
index 2aadef076cf0d55fe81a8ea71b7171d794e67be3..1f685b2bfe7360d1ed01da48070c42800764abb0 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Mtftp6 Rrq process functions implementation.\r
 \r
-  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -35,6 +35,9 @@ Mtftp6RrqSendAck (
 {\r
   EFI_MTFTP6_PACKET         *Ack;\r
   NET_BUF                   *Packet;\r
+  EFI_STATUS                Status;\r
+\r
+  Status = EFI_SUCCESS;\r
 \r
   //\r
   // Allocate net buffer to create ack packet.\r
@@ -61,7 +64,12 @@ Mtftp6RrqSendAck (
   Instance->CurRetry = 0;\r
   Instance->LastPacket = Packet;\r
 \r
-  return Mtftp6TransmitPacket (Instance, Packet);\r
+  Status = Mtftp6TransmitPacket (Instance, Packet);\r
+  if (!EFI_ERROR (Status)) {\r
+    Instance->AckedBlock = Instance->TotalBlock;\r
+  }\r
+\r
+  return Status;\r
 }\r
 \r
 \r
@@ -94,7 +102,6 @@ Mtftp6RrqSaveBlock (
   UINT16                    Block;\r
   UINT64                    Start;\r
   UINT32                    DataLen;\r
-  UINT64                    TotalBlock;\r
   BOOLEAN                   Completed;\r
 \r
   Completed = FALSE;\r
@@ -118,7 +125,7 @@ Mtftp6RrqSaveBlock (
   // to accept transfers of unlimited size. So TotalBlock is memorised as\r
   // continuous block counter.\r
   //\r
-  Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &TotalBlock);\r
+  Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &Instance->TotalBlock);\r
 \r
   if (Status == EFI_NOT_FOUND) {\r
     return EFI_SUCCESS;\r
@@ -154,7 +161,7 @@ Mtftp6RrqSaveBlock (
 \r
   if (Token->Buffer != NULL) {\r
 \r
-    Start = MultU64x32 (TotalBlock - 1, Instance->BlkSize);\r
+    Start = MultU64x32 (Instance->TotalBlock - 1, Instance->BlkSize);\r
     if (Start + DataLen <= Token->BufferSize) {\r
       CopyMem ((UINT8 *) Token->Buffer + Start, Packet->Data.Data, DataLen);\r
       //\r
@@ -224,15 +231,16 @@ Mtftp6RrqHandleData (
   INTN                      Expected;\r
 \r
   *IsCompleted = FALSE;\r
+  Status       = EFI_SUCCESS;\r
   BlockNum     = NTOHS (Packet->Data.Block);\r
   Expected     = Mtftp6GetNextBlockNum (&Instance->BlkList);\r
 \r
   ASSERT (Expected >= 0);\r
 \r
   //\r
-  // If we are active and received an unexpected packet, retransmit\r
-  // the last ACK then restart receiving. If we are passive, save\r
-  // the block.\r
+  // If we are active and received an unexpected packet, transmit\r
+  // the ACK for the block we received, then restart receiving the\r
+  // expected one. If we are passive, save the block.\r
   //\r
   if (Instance->IsMaster && (Expected != BlockNum)) {\r
     //\r
@@ -242,8 +250,10 @@ Mtftp6RrqHandleData (
     NetbufFree (*UdpPacket);\r
     *UdpPacket = NULL;\r
 \r
-    Mtftp6TransmitPacket (Instance, Instance->LastPacket);\r
-    return EFI_SUCCESS;\r
+    //\r
+    // If Expected is 0, (UINT16) (Expected - 1) is also the expected Ack number (65535).\r
+    //\r
+    return Mtftp6RrqSendAck (Instance,  (UINT16) (Expected - 1));\r
   }\r
 \r
   Status = Mtftp6RrqSaveBlock (Instance, Packet, Len, UdpPacket);\r
@@ -288,10 +298,12 @@ Mtftp6RrqHandleData (
     NetbufFree (*UdpPacket);\r
     *UdpPacket = NULL;\r
 \r
-    Mtftp6RrqSendAck (Instance, BlockNum);\r
+    if (Instance->WindowSize == (Instance->TotalBlock - Instance->AckedBlock) || Expected < 0) {\r
+      Status = Mtftp6RrqSendAck (Instance, BlockNum);\r
+    }\r
   }\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
 \r
@@ -326,12 +338,13 @@ Mtftp6RrqOackValid (
   }\r
 \r
   //\r
-  // Server can only specify a smaller block size to be used and\r
+  // Server can only specify a smaller block size and windowsize to be used and\r
   // return the timeout matches that requested.\r
   //\r
   if ((((ReplyInfo->BitMap & MTFTP6_OPT_BLKSIZE_BIT) != 0) && (ReplyInfo->BlkSize > RequestInfo->BlkSize)) ||\r
+      (((ReplyInfo->BitMap & MTFTP6_OPT_WINDOWSIZE_BIT) != 0) && (ReplyInfo->BlkSize > RequestInfo->BlkSize)) ||\r
       (((ReplyInfo->BitMap & MTFTP6_OPT_TIMEOUT_BIT) != 0) && (ReplyInfo->Timeout != RequestInfo->Timeout))\r
-      ) {\r
+     ) {\r
     return FALSE;\r
   }\r
 \r
@@ -485,7 +498,7 @@ Mtftp6RrqHandleOack (
   //\r
   // Parse the extensive options in the packet.\r
   //\r
-  Status = Mtftp6ParseExtensionOption (Options, Count, FALSE, &ExtInfo);\r
+  Status = Mtftp6ParseExtensionOption (Options, Count, FALSE, Instance->Operation, &ExtInfo);\r
 \r
   if (EFI_ERROR (Status) || !Mtftp6RrqOackValid (Instance, &ExtInfo, &Instance->ExtInfo)) {\r
     //\r
@@ -515,7 +528,7 @@ Mtftp6RrqHandleOack (
 \r
     //\r
     // Save the multicast info. Always update the Master, only update the\r
-    // multicast IP address, block size, timeoute at the first time. If IP\r
+    // multicast IP address, block size, window size, timeoute at the first time. If IP\r
     // address is updated, create a UDP child to receive the multicast.\r
     //\r
     Instance->IsMaster = ExtInfo.IsMaster;\r
@@ -612,6 +625,10 @@ Mtftp6RrqHandleOack (
         Instance->BlkSize = ExtInfo.BlkSize;\r
       }\r
 \r
+      if (ExtInfo.WindowSize != 0) {\r
+        Instance->WindowSize = ExtInfo.WindowSize;\r
+      }\r
+\r
       if (ExtInfo.Timeout != 0) {\r
         Instance->Timeout = ExtInfo.Timeout;\r
       }\r
@@ -625,6 +642,10 @@ Mtftp6RrqHandleOack (
       Instance->BlkSize = ExtInfo.BlkSize;\r
     }\r
 \r
+    if (ExtInfo.WindowSize != 0) {\r
+      Instance->WindowSize = ExtInfo.WindowSize;\r
+    }\r
+\r
     if (ExtInfo.Timeout != 0) {\r
       Instance->Timeout = ExtInfo.Timeout;\r
     }\r
index 282a9c8e4942e54dc385bc5e5038556c38b8ba62..275272b89e949e8aeb1f0788178c5e0dd63afdf6 100644 (file)
@@ -979,6 +979,10 @@ Mtftp6OperationClean (
   Instance->ServerDataPort = 0;\r
   Instance->McastPort      = 0;\r
   Instance->BlkSize        = 0;\r
+  Instance->Operation      = 0;\r
+  Instance->WindowSize     = 1;\r
+  Instance->TotalBlock     = 0;\r
+  Instance->AckedBlock     = 0;\r
   Instance->LastBlk        = 0;\r
   Instance->PacketToLive   = 0;\r
   Instance->MaxRetry       = 0;\r
@@ -1051,6 +1055,8 @@ Mtftp6OperationStart (
   Status           = EFI_SUCCESS;\r
   Instance->OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
+  Instance->Operation = OpCode;\r
+\r
   //\r
   // Parse the extension options in the request packet.\r
   //\r
@@ -1060,6 +1066,7 @@ Mtftp6OperationStart (
                Token->OptionList,\r
                Token->OptionCount,\r
                TRUE,\r
+               Instance->Operation,\r
                &Instance->ExtInfo\r
                );\r
 \r
@@ -1105,6 +1112,9 @@ Mtftp6OperationStart (
   if (Instance->BlkSize == 0) {\r
     Instance->BlkSize = MTFTP6_DEFAULT_BLK_SIZE;\r
   }\r
+  if (Instance->WindowSize == 0) {\r
+    Instance->WindowSize = MTFTP6_DEFAULT_WINDOWSIZE;\r
+  }\r
   if (Instance->MaxRetry == 0) {\r
     Instance->MaxRetry = MTFTP6_DEFAULT_MAX_RETRY;\r
   }\r
index 254b757f7e759e0caa7f5f41c4893d871e948db8..055fbe6d1b821fced0fc5bc36f94b4128431bbe7 100644 (file)
@@ -318,7 +318,7 @@ Mtftp6WrqHandleOack (
   }\r
   ASSERT (Options != NULL);\r
 \r
-  Status = Mtftp6ParseExtensionOption (Options, Count, FALSE, &ExtInfo);\r
+  Status = Mtftp6ParseExtensionOption (Options, Count, FALSE, Instance->Operation, &ExtInfo);\r
 \r
   if (EFI_ERROR(Status) || !Mtftp6WrqOackValid (&ExtInfo, &Instance->ExtInfo)) {\r
     //\r