]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/TcpDxe/TcpInput.c
NetworkPkg: Add wnd scale check before shrinking window.
[mirror_edk2.git] / NetworkPkg / TcpDxe / TcpInput.c
index 04c8a8269ea704b1a2b8593455ff394097217349..f8845dca470e97732482077ef6770b78533347df 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   TCP input process routines.\r
 \r
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2017, 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
@@ -738,6 +738,7 @@ TcpInput (
   TCP_SEQNO   Right;\r
   TCP_SEQNO   Urg;\r
   UINT16      Checksum;\r
+  INT32       Usable;\r
 \r
   ASSERT ((Version == IP_VERSION_4) || (Version == IP_VERSION_6));\r
 \r
@@ -1306,9 +1307,27 @@ TcpInput (
       }\r
 \r
       if (TCP_SEQ_LT (Right, Tcb->SndNxt)) {\r
-\r
-        Tcb->SndNxt = Right;\r
-\r
+        //\r
+        // Check for Window Retraction in RFC7923 section 2.4.\r
+        // The lower n bits of the peer's actual receive window is wiped out if TCP\r
+        // window scale is enabled, it will look like the peer is shrinking the window.\r
+        // Check whether the SndNxt is out of the advertised receive window by more than\r
+        // 2^Rcv.Wind.Shift before moving the SndNxt to the left.\r
+        //\r
+        DEBUG (\r
+          (EFI_D_WARN,\r
+          "TcpInput: peer advise negative useable window for connected TCB %p\n",\r
+          Tcb)\r
+          );\r
+        Usable = TCP_SUB_SEQ (Tcb->SndNxt, Right);\r
+        if ((Usable >> Tcb->SndWndScale) > 0) {\r
+          DEBUG (\r
+            (EFI_D_WARN,\r
+            "TcpInput: SndNxt is out of window by more than window scale for TCB %p\n",\r
+            Tcb)\r
+            );\r
+          Tcb->SndNxt = Right;\r
+        }\r
         if (Right == Tcb->SndUna) {\r
 \r
           TcpClearTimer (Tcb, TCP_TIMER_REXMIT);\r