]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Input.c
Code clean up in NetLib:
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / Tcp4Input.c
index 2e436249f23b14b71a01977feb624f8da43892ae..9bea6b298b5ab5f1f7dbf3817efa06d6df033082 100644 (file)
@@ -1,36 +1,29 @@
 /** @file\r
+  TCP input process routines.\r
 \r
-Copyright (c) 2005 - 2007, Intel Corporation\r
+Copyright (c) 2005 - 2009, Intel Corporation<BR>\r
 All rights reserved. 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\r
+http://opensource.org/licenses/bsd-license.php<BR>\r
 \r
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-Module Name:\r
-\r
-  Tcp4Input.c\r
-\r
-Abstract:\r
-\r
-  TCP input process routines.\r
-\r
-\r
 **/\r
 \r
+\r
 #include "Tcp4Main.h"\r
 \r
 \r
 /**\r
-  Check whether the sequence number of the incoming segment\r
-  is acceptable.\r
+  Check whether the sequence number of the incoming segment is acceptable.\r
 \r
   @param  Tcb      Pointer to the TCP_CB of this TCP instance.\r
   @param  Seg      Pointer to the incoming segment.\r
 \r
-  @return 1 if the sequence number is acceptable, otherwise 0.\r
+  @retval 1       The sequence number is acceptable.\r
+  @retval 0       The sequence number is not acceptable.\r
 \r
 **/\r
 INTN\r
@@ -50,13 +43,11 @@ TcpSeqAcceptable (
   @param  Tcb      Pointer to the TCP_CB of this TCP instance.\r
   @param  Seg      Segment that triggers the fast recovery.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 TcpFastRecover (\r
-  IN TCP_CB  *Tcb,\r
-  IN TCP_SEG *Seg\r
+  IN OUT TCP_CB  *Tcb,\r
+  IN     TCP_SEG *Seg\r
   )\r
 {\r
   UINT32  FlightSize;\r
@@ -162,13 +153,11 @@ TcpFastRecover (
   @param  Tcb      Pointer to the TCP_CB of this TCP instance.\r
   @param  Seg      Segment that triggers the fast loss recovery.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 TcpFastLossRecover (\r
-  IN TCP_CB  *Tcb,\r
-  IN TCP_SEG *Seg\r
+  IN OUT TCP_CB  *Tcb,\r
+  IN     TCP_SEG *Seg\r
   )\r
 {\r
   if (TCP_SEQ_GT (Seg->Ack, Tcb->SndUna)) {\r
@@ -203,18 +192,16 @@ TcpFastLossRecover (
 \r
 \r
 /**\r
-  Compute the RTT as specified in RFC2988\r
+  Compute the RTT as specified in RFC2988.\r
 \r
   @param  Tcb      Pointer to the TCP_CB of this TCP instance.\r
   @param  Measure  Currently measured RTT in heart beats.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 TcpComputeRtt (\r
-  IN TCP_CB *Tcb,\r
-  IN UINT32 Measure\r
+  IN OUT TCP_CB *Tcb,\r
+  IN     UINT32 Measure\r
   )\r
 {\r
   INT32 Var;\r
@@ -264,17 +251,14 @@ TcpComputeRtt (
 \r
 \r
 /**\r
-  Trim the data, SYN and FIN to fit into the window defined by\r
-  Left and Right.\r
+  Trim the data, SYN and FIN to fit into the window defined by Left and Right.\r
 \r
   @param  Nbuf     Buffer that contains received TCP segment without IP header.\r
   @param  Left     The sequence number of the window's left edge.\r
   @param  Right    The sequence number of the window's right edge.\r
 \r
-  @return 0, the data is successfully trimmed.\r
-\r
 **/\r
-INTN\r
+VOID\r
 TcpTrimSegment (\r
   IN NET_BUF   *Nbuf,\r
   IN TCP_SEQNO Left,\r
@@ -298,7 +282,7 @@ TcpTrimSegment (
 \r
     Seg->Seq = Seg->End;\r
     NetbufTrim (Nbuf, Nbuf->TotalSize, NET_BUF_HEAD);\r
-    return 0;\r
+    return;\r
   }\r
 \r
   //\r
@@ -351,8 +335,7 @@ TcpTrimSegment (
     }\r
   }\r
 \r
-  ASSERT (TcpVerifySegment (Nbuf));\r
-  return 0;\r
+  ASSERT (TcpVerifySegment (Nbuf) != 0);\r
 }\r
 \r
 \r
@@ -362,16 +345,14 @@ TcpTrimSegment (
   @param  Tcb      Pointer to the TCP_CB of this TCP instance.\r
   @param  Nbuf     Pointer to the NET_BUF containing the received tcp segment.\r
 \r
-  @return 0, the data is trimmed.\r
-\r
 **/\r
-INTN\r
+VOID\r
 TcpTrimInWnd (\r
   IN TCP_CB  *Tcb,\r
   IN NET_BUF *Nbuf\r
   )\r
 {\r
-  return TcpTrimSegment (Nbuf, Tcb->RcvNxt, Tcb->RcvWl2 + Tcb->RcvWnd);\r
+  TcpTrimSegment (Nbuf, Tcb->RcvNxt, Tcb->RcvWl2 + Tcb->RcvWnd);\r
 }\r
 \r
 \r
@@ -388,7 +369,7 @@ TcpTrimInWnd (
 **/\r
 INTN\r
 TcpDeliverData (\r
-  IN TCP_CB *Tcb\r
+  IN OUT TCP_CB *Tcb\r
   )\r
 {\r
   LIST_ENTRY      *Entry;\r
@@ -397,7 +378,7 @@ TcpDeliverData (
   TCP_SEG         *Seg;\r
   UINT32          Urgent;\r
 \r
-  ASSERT (Tcb && Tcb->Sk);\r
+  ASSERT ((Tcb != NULL) && (Tcb->Sk != NULL));\r
 \r
   //\r
   // make sure there is some data queued,\r
@@ -418,7 +399,7 @@ TcpDeliverData (
     Nbuf  = NET_LIST_USER_STRUCT (Entry, NET_BUF, List);\r
     Seg   = TCPSEG_NETBUF (Nbuf);\r
 \r
-    ASSERT (TcpVerifySegment (Nbuf));\r
+    ASSERT (TcpVerifySegment (Nbuf) != 0);\r
     ASSERT (Nbuf->Tcp == NULL);\r
 \r
     if (TCP_SEQ_GT (Seg->Seq, Seq)) {\r
@@ -498,6 +479,8 @@ TcpDeliverData (
         NetbufFree (Nbuf);\r
         return -1;\r
         break;\r
+      default:\r
+        break;\r
       }\r
 \r
       TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_ACK_NOW);\r
@@ -513,7 +496,7 @@ TcpDeliverData (
       TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_ACK_NOW);\r
     }\r
 \r
-    if (Nbuf->TotalSize) {\r
+    if (Nbuf->TotalSize != 0) {\r
       Urgent = 0;\r
 \r
       if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_RCVD_URG) &&\r
@@ -547,13 +530,11 @@ TcpDeliverData (
   @param  Tcb      Pointer to the TCP_CB of this TCP instance.\r
   @param  Nbuf     Pointer to the buffer containing the data to be queued.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 TcpQueueData (\r
-  IN TCP_CB  *Tcb,\r
-  IN NET_BUF *Nbuf\r
+  IN OUT TCP_CB  *Tcb,\r
+  IN     NET_BUF *Nbuf\r
   )\r
 {\r
   TCP_SEG         *Seg;\r
@@ -562,7 +543,7 @@ TcpQueueData (
   LIST_ENTRY      *Cur;\r
   NET_BUF         *Node;\r
 \r
-  ASSERT (Tcb && Nbuf && (Nbuf->Tcp == NULL));\r
+  ASSERT ((Tcb != NULL) && (Nbuf != NULL) && (Nbuf->Tcp == NULL));\r
 \r
   NET_GET_REF (Nbuf);\r
 \r
@@ -655,8 +636,6 @@ TcpQueueData (
   @param  Tcb      Pointer to the TCP_CB of this TCP instance.\r
   @param  Ack      The acknowledge seuqence number of the received segment.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 TcpAdjustSndQue (\r
@@ -783,10 +762,6 @@ TcpInput (
   NetbufTrim (Nbuf, (Head->HeadLen << 2), NET_BUF_HEAD);\r
   Nbuf->Tcp = NULL;\r
 \r
-  //\r
-  // TODO: add fast path process here\r
-  //\r
-\r
   //\r
   // Process the segment in LISTEN state.\r
   //\r
@@ -824,7 +799,7 @@ TcpInput (
       Tcb     = TcpCloneTcb (Parent);\r
       if (Tcb == NULL) {\r
         DEBUG ((EFI_D_ERROR, "TcpInput: discard a segment because"\r
-          "failed to clone a child for TCB%x\n", Tcb));\r
+          " failed to clone a child for TCB%x\n", Tcb));\r
 \r
         goto DISCARD;\r
       }\r
@@ -872,14 +847,14 @@ TcpInput (
       if (TCP_FLG_ON (Seg->Flag, TCP_FLG_ACK)) {\r
 \r
         DEBUG ((EFI_D_WARN, "TcpInput: connection reset by"\r
-          " peer for TCB%x in SYN_SENT\n", Tcb));\r
+          " peer for TCB %p in SYN_SENT\n", Tcb));\r
 \r
         SOCK_ERROR (Tcb->Sk, EFI_CONNECTION_RESET);\r
         goto DROP_CONNECTION;\r
       } else {\r
 \r
         DEBUG ((EFI_D_WARN, "TcpInput: discard a reset segment "\r
-          "because of no ACK for TCB%x in SYN_SENT\n", Tcb));\r
+          "because of no ACK for TCB %p in SYN_SENT\n", Tcb));\r
 \r
         goto DISCARD;\r
       }\r
@@ -989,17 +964,14 @@ TcpInput (
       // if it comes from a LISTEN TCB.\r
       //\r
     } else if ((Tcb->State == TCP_ESTABLISHED) ||\r
-             (Tcb->State == TCP_FIN_WAIT_1) ||\r
-             (Tcb->State == TCP_FIN_WAIT_2) ||\r
-             (Tcb->State == TCP_CLOSE_WAIT)\r
-            ) {\r
+               (Tcb->State == TCP_FIN_WAIT_1) ||\r
+               (Tcb->State == TCP_FIN_WAIT_2) ||\r
+               (Tcb->State == TCP_CLOSE_WAIT)) {\r
 \r
       SOCK_ERROR (Tcb->Sk, EFI_CONNECTION_RESET);\r
 \r
     } else {\r
-      //\r
-      // TODO: set socket error to CLOSED\r
-      //\r
+\r
     }\r
 \r
     goto DROP_CONNECTION;\r
@@ -1162,7 +1134,7 @@ TcpInput (
     Tcb->SndUna = Seg->Ack;\r
 \r
     if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_SND_URG) &&\r
-        (TCP_SEQ_LT (Tcb->SndUp, Seg->Ack))) {\r
+        TCP_SEQ_LT (Tcb->SndUp, Seg->Ack)) {\r
 \r
       TCP_CLEAR_FLG (Tcb->CtrlFlag, TCP_CTRL_SND_URG);\r
     }\r
@@ -1186,7 +1158,7 @@ TcpInput (
       }\r
 \r
       DEBUG ((EFI_D_WARN, "TcpInput: peer shrinks the"\r
-        " window  for connected TCB %p\n", Tcb));\r
+        " window for connected TCB %p\n", Tcb));\r
 \r
       if ((Tcb->CongestState == TCP_CONGEST_RECOVER) &&\r
           (TCP_SEQ_LT (Right, Tcb->Recover))) {\r
@@ -1295,6 +1267,9 @@ NO_UPDATE:
       TcpClose (Tcb);\r
     }\r
     break;\r
+\r
+  default:\r
+    break;\r
   }\r
 \r
   //\r
@@ -1378,7 +1353,7 @@ StepSix:
 \r
   if ((Tcb->State != TCP_CLOSED) &&\r
       (TcpToSendData (Tcb, 0) == 0) &&\r
-      (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_ACK_NOW) || Nbuf->TotalSize)) {\r
+      (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_ACK_NOW) || (Nbuf->TotalSize != 0))) {\r
 \r
     TcpToSendAck (Tcb);\r
   }\r
@@ -1390,7 +1365,7 @@ RESET_THEN_DROP:
   TcpSendReset (Tcb, Head, Len, Dst, Src);\r
 \r
 DROP_CONNECTION:\r
-  ASSERT (Tcb && Tcb->Sk);\r
+  ASSERT ((Tcb != NULL) && (Tcb->Sk != NULL));\r
 \r
   NetbufFree (Nbuf);\r
   TcpClose (Tcb);\r
@@ -1411,7 +1386,7 @@ DISCARD:
 \r
   if ((Parent != NULL) && (Tcb != NULL)) {\r
 \r
-    ASSERT (Tcb->Sk);\r
+    ASSERT (Tcb->Sk != NULL);\r
     TcpClose (Tcb);\r
   }\r
 \r
@@ -1428,13 +1403,11 @@ DISCARD:
   @param  Src      Source address of the ICMP error message.\r
   @param  Dst      Destination address of the ICMP error message.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 TcpIcmpInput (\r
   IN NET_BUF     *Nbuf,\r
-  IN ICMP_ERROR  IcmpErr,\r
+  IN UINT8       IcmpErr,\r
   IN UINT32      Src,\r
   IN UINT32      Dst\r
   )\r
@@ -1468,7 +1441,12 @@ TcpIcmpInput (
     goto CLEAN_EXIT;\r
   }\r
 \r
-  IcmpErrStatus = IpIoGetIcmpErrStatus (IcmpErr, &IcmpErrIsHard, &IcmpErrNotify);\r
+  IcmpErrStatus = IpIoGetIcmpErrStatus (\r
+                    IcmpErr,\r
+                    IP_VERSION_4,\r
+                    &IcmpErrIsHard,\r
+                    &IcmpErrNotify\r
+                    );\r
 \r
   if (IcmpErrNotify) {\r
 \r