]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Output.c
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / Tcp4Output.c
index c9a1f6b106aa9cd495490a08e73192a420f8b168..760b09a1eda1fe58fe4aebb0d29c58a04066790e 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   TCP output process routines.\r
-    \r
-Copyright (c) 2005 - 2006, Intel Corporation<BR>\r
-All rights reserved. This program and the accompanying materials\r
+\r
+Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php<BR>\r
@@ -267,7 +267,9 @@ SetPersistTimer:
       Tcb)\r
       );\r
 \r
-    TcpSetProbeTimer (Tcb);\r
+    if (!Tcb->ProbeTimerOn) {\r
+      TcpSetProbeTimer (Tcb);\r
+    }\r
   }\r
 \r
   return 0;\r
@@ -445,7 +447,9 @@ TcpGetSegmentSndQue (
     }\r
   }\r
 \r
-  ASSERT (Cur != Head);\r
+  ASSERT (Cur  != Head);\r
+  ASSERT (Node != NULL);\r
+  ASSERT (Seg  != NULL);\r
 \r
   //\r
   // Return the buffer if it can be returned without\r
@@ -482,7 +486,7 @@ TcpGetSegmentSndQue (
 \r
   //\r
   // If SYN is set and out of the range, clear the flag.\r
-  // Becuase the sequence of the first byte is SEG.SEQ+1,\r
+  // Because the sequence of the first byte is SEG.SEQ+1,\r
   // adjust Offset by -1. If SYN is in the range, copy\r
   // one byte less.\r
   //\r
@@ -667,17 +671,39 @@ TcpRetransmit (
   // 2. must in the current send window\r
   // 3. will not change the boundaries of queued segments.\r
   //\r
-  if (TCP_SEQ_LT (Tcb->SndWl2 + Tcb->SndWnd, Seq)) {\r
-    DEBUG ((EFI_D_WARN, "TcpRetransmit: retransmission cancelled "\r
-      "because send window too small for TCB %p\n", Tcb));\r
+\r
+  //\r
+  // Handle the Window Retraction if TCP window scale is enabled according to RFC7323:\r
+  //   On first retransmission, or if the sequence number is out of\r
+  //   window by less than 2^Rcv.Wind.Shift, then do normal\r
+  //   retransmission(s) without regard to the receiver window as long\r
+  //   as the original segment was in window when it was sent.\r
+  //\r
+  if ((Tcb->SndWndScale != 0) &&\r
+      (TCP_SEQ_GT (Seq, Tcb->RetxmitSeqMax) || TCP_SEQ_BETWEEN (Tcb->SndWl2 + Tcb->SndWnd, Seq, Tcb->SndWl2 + Tcb->SndWnd + (1 << Tcb->SndWndScale)))) {\r
+    Len = TCP_SUB_SEQ (Tcb->SndNxt, Seq);\r
+    DEBUG (\r
+      (EFI_D_WARN,\r
+      "TcpRetransmit: retransmission without regard to the receiver window for TCB %p\n",\r
+      Tcb)\r
+      );\r
+\r
+  } else if (TCP_SEQ_GEQ (Tcb->SndWl2 + Tcb->SndWnd, Seq)) {\r
+    Len = TCP_SUB_SEQ (Tcb->SndWl2 + Tcb->SndWnd, Seq);\r
+\r
+  } else {\r
+    DEBUG (\r
+      (EFI_D_WARN,\r
+      "TcpRetransmit: retransmission cancelled because send window too small for TCB %p\n",\r
+      Tcb)\r
+      );\r
 \r
     return 0;\r
   }\r
 \r
-  Len   = TCP_SUB_SEQ (Tcb->SndWl2 + Tcb->SndWnd, Seq);\r
-  Len   = MIN (Len, Tcb->SndMss);\r
+  Len = MIN (Len, Tcb->SndMss);\r
 \r
-  Nbuf  = TcpGetSegmentSndQue (Tcb, Seq, Len);\r
+  Nbuf = TcpGetSegmentSndQue (Tcb, Seq, Len);\r
   if (Nbuf == NULL) {\r
     return -1;\r
   }\r
@@ -688,6 +714,10 @@ TcpRetransmit (
     goto OnError;\r
   }\r
 \r
+  if (TCP_SEQ_GT (Seq, Tcb->RetxmitSeqMax)) {\r
+    Tcb->RetxmitSeqMax = Seq;\r
+  }\r
+\r
   //\r
   // The retransmitted buffer may be on the SndQue,\r
   // trim TCP head because all the buffer on SndQue\r
@@ -750,6 +780,7 @@ SEND_AGAIN:
   Len   = TcpDataToSend (Tcb, Force);\r
   Seq   = Tcb->SndNxt;\r
 \r
+  ASSERT ((Tcb->State) < (ARRAY_SIZE (mTcpOutFlag)));\r
   Flag  = mTcpOutFlag[Tcb->State];\r
 \r
   if ((Flag & TCP_FLG_SYN) != 0) {\r
@@ -762,7 +793,7 @@ SEND_AGAIN:
   // only send a segment without data if SYN or\r
   // FIN is set.\r
   //\r
-  if ((Len == 0) && \r
+  if ((Len == 0) &&\r
       ((Flag & (TCP_FLG_SYN | TCP_FLG_FIN)) == 0)) {\r
     return Sent;\r
   }\r
@@ -800,10 +831,10 @@ SEND_AGAIN:
         TCP_SEQ_LT (End + 1, Tcb->SndWnd + Tcb->SndWl2)) {\r
 \r
       DEBUG (\r
-               (EFI_D_INFO, \r
-               "TcpToSendData: send FIN "\r
-        "to peer for TCB %p in state %s\n", \r
-        Tcb, \r
+      (EFI_D_NET,\r
+      "TcpToSendData: send FIN "\r
+        "to peer for TCB %p in state %s\n",\r
+        Tcb,\r
         mTcpStateName[Tcb->State])\r
       );\r
 \r
@@ -878,7 +909,7 @@ SEND_AGAIN:
   if ((Tcb->CongestState == TCP_CONGEST_OPEN) &&\r
       !TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_RTT_ON)) {\r
 \r
-    DEBUG ((EFI_D_INFO, "TcpToSendData: set RTT measure "\r
+    DEBUG ((EFI_D_NET, "TcpToSendData: set RTT measure "\r
       "sequence %d for TCB %p\n", Seq, Tcb));\r
 \r
     TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_RTT_ON);\r
@@ -1006,7 +1037,7 @@ TcpToSendAck (
     return;\r
   }\r
 \r
-  DEBUG ((EFI_D_INFO, "TcpToSendAck: scheduled a delayed"\r
+  DEBUG ((EFI_D_NET, "TcpToSendAck: scheduled a delayed"\r
     " ACK for TCB %p\n", Tcb));\r
 \r
   //\r
@@ -1089,7 +1120,7 @@ TcpSendReset (
 \r
   Nhead->SrcPort  = Head->DstPort;\r
   Nhead->DstPort  = Head->SrcPort;\r
-  Nhead->HeadLen  = (sizeof (TCP_HEAD) >> 2);\r
+  Nhead->HeadLen  = (UINT8) (sizeof (TCP_HEAD) >> 2);\r
   Nhead->Res      = 0;\r
   Nhead->Wnd      = HTONS (0xFFFF);\r
   Nhead->Checksum = 0;\r