]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c
MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for Ip4Config2
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / Tcp4Misc.c
index 0014fc993f61218e01eb97d1060032207b97baa5..1a7c41aa0b564a2e2e770e6ff2f8cca2844f2dc9 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Misc support routines for tcp.\r
 \r
-Copyright (c) 2005 - 2009, Intel Corporation<BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2005 - 2016, 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
@@ -77,7 +77,9 @@ TcpInitTcbLocal (
   //\r
   // First window size is never scaled\r
   //\r
-  Tcb->RcvWndScale = 0;\r
+  Tcb->RcvWndScale  = 0;\r
+\r
+  Tcb->ProbeTimerOn = FALSE;\r
 }\r
 \r
 \r
@@ -155,6 +157,8 @@ TcpInitTcbPeer (
     TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_SND_TS);\r
     TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_RCVD_TS);\r
 \r
+    Tcb->TsRecent = Opt->TSVal;\r
+\r
     //\r
     // Compute the effective SndMss per RFC1122\r
     // section 4.2.2.6. If timestamp option is\r
@@ -171,7 +175,7 @@ TcpInitTcbPeer (
   @param  Local                 Pointer to the local (IP, Port).\r
   @param  Remote                Pointer to the remote (IP, Port).\r
 \r
-  @return  Pointer to the TCP_CB with the least number of wildcard, \r
+  @return  Pointer to the TCP_CB with the least number of wildcard,\r
            if NULL no match is found.\r
 \r
 **/\r
@@ -354,7 +358,6 @@ TcpInsertTcb (
   LIST_ENTRY       *Entry;\r
   LIST_ENTRY       *Head;\r
   TCP_CB           *Node;\r
-  TCP4_PROTO_DATA  *TcpProto;\r
 \r
   ASSERT (\r
     (Tcb != NULL) &&\r
@@ -389,9 +392,6 @@ TcpInsertTcb (
 \r
   InsertHeadList (Head, &Tcb->List);\r
 \r
-  TcpProto = (TCP4_PROTO_DATA *) Tcb->Sk->ProtoReserved;\r
-  TcpSetVariableData (TcpProto->TcpService);\r
-\r
   return 0;\r
 }\r
 \r
@@ -478,7 +478,7 @@ TcpGetRcvMss (
   ASSERT (Sock != NULL);\r
 \r
   TcpProto = (TCP4_PROTO_DATA *) Sock->ProtoReserved;\r
-  Ip       = (EFI_IP4_PROTOCOL *) (TcpProto->TcpService->IpIo->Ip);\r
+  Ip       = TcpProto->TcpService->IpIo->Ip.Ip4;\r
   ASSERT (Ip != NULL);\r
 \r
   Ip->GetModeData (Ip, &Ip4Mode, NULL, NULL);\r
@@ -500,8 +500,11 @@ TcpSetState (
   IN     UINT8   State\r
   )\r
 {\r
+  ASSERT (Tcb->State < (sizeof (mTcpStateName) / sizeof (CHAR16 *)));\r
+  ASSERT (State < (sizeof (mTcpStateName) / sizeof (CHAR16 *)));\r
+\r
   DEBUG (\r
-    (EFI_D_INFO,\r
+    (EFI_D_NET,\r
     "Tcb (%p) state %s --> %s\n",\r
     Tcb,\r
     mTcpStateName[Tcb->State],\r
@@ -587,6 +590,7 @@ TcpFormatNetbuf (
 \r
   Seg       = TCPSEG_NETBUF (Nbuf);\r
   Head      = (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL);\r
+  ASSERT (Head != NULL);\r
   Nbuf->Tcp = Head;\r
 \r
   Seg->Seq  = NTOHL (Head->Seq);\r
@@ -652,7 +656,7 @@ TcpResetConnection (
   Nhead->Ack      = HTONL (Tcb->RcvNxt);\r
   Nhead->SrcPort  = Tcb->LocalEnd.Port;\r
   Nhead->DstPort  = Tcb->RemoteEnd.Port;\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
@@ -811,13 +815,13 @@ TcpOnAppConsume (
 \r
       if (TcpOld < Tcb->RcvMss) {\r
 \r
-        DEBUG ((EFI_D_INFO, "TcpOnAppConsume: send a window"\r
+        DEBUG ((EFI_D_NET, "TcpOnAppConsume: send a window"\r
           " update for a window closed Tcb %p\n", Tcb));\r
 \r
         TcpSendAck (Tcb);\r
       } else if (Tcb->DelayedAck == 0) {\r
 \r
-        DEBUG ((EFI_D_INFO, "TcpOnAppConsume: scheduled a delayed"\r
+        DEBUG ((EFI_D_NET, "TcpOnAppConsume: scheduled a delayed"\r
           " ACK to update window for Tcb %p\n", Tcb));\r
 \r
         Tcb->DelayedAck = 1;\r
@@ -872,205 +876,6 @@ TcpOnAppAbort (
   TcpSetState (Tcb, TCP_CLOSED);\r
 }\r
 \r
-\r
-/**\r
-  Set the Tdp4 variable data.\r
-\r
-  @param  Tcp4Service           Pointer to Tcp4 service data.\r
-\r
-  @retval EFI_OUT_OF_RESOURCES  There are not enough resources to set the variable.\r
-  @retval other                 Set variable failed.\r
-\r
-**/\r
-EFI_STATUS\r
-TcpSetVariableData (\r
-  IN TCP4_SERVICE_DATA  *Tcp4Service\r
-  )\r
-{\r
-  UINT32                  NumConfiguredInstance;\r
-  LIST_ENTRY              *Entry;\r
-  TCP_CB                  *TcpPcb;\r
-  TCP4_PROTO_DATA         *TcpProto;\r
-  UINTN                   VariableDataSize;\r
-  EFI_TCP4_VARIABLE_DATA  *Tcp4VariableData;\r
-  EFI_TCP4_SERVICE_POINT  *Tcp4ServicePoint;\r
-  CHAR16                  *NewMacString;\r
-  EFI_STATUS              Status;\r
-\r
-  NumConfiguredInstance = 0;\r
-\r
-  //\r
-  // Go through the running queue to count the instances.\r
-  //\r
-  NET_LIST_FOR_EACH (Entry, &mTcpRunQue) {\r
-    TcpPcb = NET_LIST_USER_STRUCT (Entry, TCP_CB, List);\r
-\r
-    TcpProto = (TCP4_PROTO_DATA *) TcpPcb->Sk->ProtoReserved;\r
-\r
-    if (TcpProto->TcpService == Tcp4Service) {\r
-      //\r
-      // This tcp instance belongs to the Tcp4Service.\r
-      //\r
-      NumConfiguredInstance++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Go through the listening queue to count the instances.\r
-  //\r
-  NET_LIST_FOR_EACH (Entry, &mTcpListenQue) {\r
-    TcpPcb = NET_LIST_USER_STRUCT (Entry, TCP_CB, List);\r
-\r
-    TcpProto = (TCP4_PROTO_DATA *) TcpPcb->Sk->ProtoReserved;\r
-\r
-    if (TcpProto->TcpService == Tcp4Service) {\r
-      //\r
-      // This tcp instance belongs to the Tcp4Service.\r
-      //\r
-      NumConfiguredInstance++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Calculate the size of the Tcp4VariableData. As there may be no Tcp4 child,\r
-  // we should add extra buffer for the service points only if the number of configured\r
-  // children is more than 1.\r
-  //\r
-  VariableDataSize = sizeof (EFI_TCP4_VARIABLE_DATA);\r
-\r
-  if (NumConfiguredInstance > 1) {\r
-    VariableDataSize += sizeof (EFI_TCP4_SERVICE_POINT) * (NumConfiguredInstance - 1);\r
-  }\r
-\r
-  Tcp4VariableData = AllocatePool (VariableDataSize);\r
-  if (Tcp4VariableData == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  Tcp4VariableData->DriverHandle = Tcp4Service->DriverBindingHandle;\r
-  Tcp4VariableData->ServiceCount = NumConfiguredInstance;\r
-\r
-  Tcp4ServicePoint = &Tcp4VariableData->Services[0];\r
-\r
-  //\r
-  // Go through the running queue to fill the service points.\r
-  //\r
-  NET_LIST_FOR_EACH (Entry, &mTcpRunQue) {\r
-    TcpPcb = NET_LIST_USER_STRUCT (Entry, TCP_CB, List);\r
-\r
-    TcpProto = (TCP4_PROTO_DATA *) TcpPcb->Sk->ProtoReserved;\r
-\r
-    if (TcpProto->TcpService == Tcp4Service) {\r
-      //\r
-      // This tcp instance belongs to the Tcp4Service.\r
-      //\r
-      Tcp4ServicePoint->InstanceHandle          = TcpPcb->Sk->SockHandle;\r
-      CopyMem (&Tcp4ServicePoint->LocalAddress, &TcpPcb->LocalEnd.Ip, sizeof (EFI_IPv4_ADDRESS));\r
-      Tcp4ServicePoint->LocalPort               = NTOHS (TcpPcb->LocalEnd.Port);\r
-      CopyMem (&Tcp4ServicePoint->RemoteAddress, &TcpPcb->RemoteEnd.Ip, sizeof (EFI_IPv4_ADDRESS));\r
-      Tcp4ServicePoint->RemotePort              = NTOHS (TcpPcb->RemoteEnd.Port);\r
-\r
-      Tcp4ServicePoint++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Go through the listening queue to fill the service points.\r
-  //\r
-  NET_LIST_FOR_EACH (Entry, &mTcpListenQue) {\r
-    TcpPcb = NET_LIST_USER_STRUCT (Entry, TCP_CB, List);\r
-\r
-    TcpProto = (TCP4_PROTO_DATA *) TcpPcb->Sk->ProtoReserved;\r
-\r
-    if (TcpProto->TcpService == Tcp4Service) {\r
-      //\r
-      // This tcp instance belongs to the Tcp4Service.\r
-      //\r
-      Tcp4ServicePoint->InstanceHandle          = TcpPcb->Sk->SockHandle;\r
-      CopyMem (&Tcp4ServicePoint->LocalAddress, &TcpPcb->LocalEnd.Ip, sizeof (EFI_IPv4_ADDRESS));\r
-      Tcp4ServicePoint->LocalPort               = NTOHS (TcpPcb->LocalEnd.Port);\r
-      CopyMem (&Tcp4ServicePoint->RemoteAddress, &TcpPcb->RemoteEnd.Ip, sizeof (EFI_IPv4_ADDRESS));\r
-      Tcp4ServicePoint->RemotePort              = NTOHS (TcpPcb->RemoteEnd.Port);\r
-\r
-      Tcp4ServicePoint++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Get the mac string.\r
-  //\r
-  Status = NetLibGetMacString (\r
-             Tcp4Service->ControllerHandle,\r
-             Tcp4Service->DriverBindingHandle,\r
-             &NewMacString\r
-             );\r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
-  }\r
-\r
-  if (Tcp4Service->MacString != NULL) {\r
-    //\r
-    // The variable is set already, we're going to update it.\r
-    //\r
-    if (StrCmp (Tcp4Service->MacString, NewMacString) != 0) {\r
-      //\r
-      // The mac address is changed, delete the previous variable first.\r
-      //\r
-      gRT->SetVariable (\r
-             Tcp4Service->MacString,\r
-             &gEfiTcp4ServiceBindingProtocolGuid,\r
-             EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-             0,\r
-             NULL\r
-             );\r
-    }\r
-\r
-    FreePool (Tcp4Service->MacString);\r
-  }\r
-\r
-  Tcp4Service->MacString = NewMacString;\r
-\r
-  Status = gRT->SetVariable (\r
-                  Tcp4Service->MacString,\r
-                  &gEfiTcp4ServiceBindingProtocolGuid,\r
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-                  VariableDataSize,\r
-                  (VOID *) Tcp4VariableData\r
-                  );\r
-\r
-ON_ERROR:\r
-\r
-  FreePool (Tcp4VariableData);\r
-\r
-  return Status;\r
-}\r
-\r
-\r
-/**\r
-  Clear the variable and free the resource.\r
-\r
-  @param  Tcp4Service           Pointer to Tcp4 service data.\r
-\r
-**/\r
-VOID\r
-TcpClearVariableData (\r
-  IN TCP4_SERVICE_DATA  *Tcp4Service\r
-  )\r
-{\r
-  ASSERT (Tcp4Service->MacString != NULL);\r
-\r
-  gRT->SetVariable (\r
-         Tcp4Service->MacString,\r
-         &gEfiTcp4ServiceBindingProtocolGuid,\r
-         EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-         0,\r
-         NULL\r
-         );\r
-\r
-  FreePool (Tcp4Service->MacString);\r
-  Tcp4Service->MacString = NULL;\r
-}\r
-\r
 /**\r
   Install the device path protocol on the TCP instance.\r
 \r
@@ -1110,6 +915,8 @@ TcpInstallDevicePath (
     Tcb->UseDefaultAddr\r
     );\r
 \r
+  IP4_COPY_ADDRESS (&Ip4DPathNode.SubnetMask, &Tcb->SubnetMask);\r
+\r
   Sock->DevicePath = AppendDevicePathNode (\r
                        Sock->ParentDevicePath,\r
                        (EFI_DEVICE_PATH_PROTOCOL *) &Ip4DPathNode\r