X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FTcp4Dxe%2FTcp4Misc.c;h=95f47f91bc40b41c2474480e858ae91ca2a3ee81;hb=185395a4a21dcb11bd59db256077a3b29d92ff55;hp=204c9d988177b2269f5cf42ce4ccdafe3e9c65bd;hpb=d0cca731c3d468a6ac84e8e49c1d8f9c5e0d0aec;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c index 204c9d9881..95f47f91bc 100644 --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c +++ b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c @@ -1,8 +1,8 @@ /** @file Misc support routines for tcp. -Copyright (c) 2005 - 2006, Intel Corporation
-All rights reserved. This program and the accompanying materials +Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php
@@ -52,7 +52,7 @@ CHAR16 *mTcpStateName[] = { **/ VOID TcpInitTcbLocal ( - IN TCP_CB *Tcb + IN OUT TCP_CB *Tcb ) { // @@ -77,7 +77,9 @@ TcpInitTcbLocal ( // // First window size is never scaled // - Tcb->RcvWndScale = 0; + Tcb->RcvWndScale = 0; + + Tcb->ProbeTimerOn = FALSE; } @@ -92,14 +94,14 @@ TcpInitTcbLocal ( **/ VOID TcpInitTcbPeer ( - IN TCP_CB *Tcb, - IN TCP_SEG *Seg, - IN TCP_OPTION *Opt + IN OUT TCP_CB *Tcb, + IN TCP_SEG *Seg, + IN TCP_OPTION *Opt ) { UINT16 RcvMss; - ASSERT (Tcb && Seg && Opt); + ASSERT ((Tcb != NULL) && (Seg != NULL) && (Opt != NULL)); ASSERT (TCP_FLG_ON (Seg->Flag, TCP_FLG_SYN)); Tcb->SndWnd = Seg->Wnd; @@ -155,6 +157,8 @@ TcpInitTcbPeer ( TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_SND_TS); TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_RCVD_TS); + Tcb->TsRecent = Opt->TSVal; + // // Compute the effective SndMss per RFC1122 // section 4.2.2.6. If timestamp option is @@ -171,7 +175,7 @@ TcpInitTcbPeer ( @param Local Pointer to the local (IP, Port). @param Remote Pointer to the remote (IP, Port). - @return Pointer to the TCP_CB with the least number of wildcard, + @return Pointer to the TCP_CB with the least number of wildcard, if NULL no match is found. **/ @@ -354,7 +358,6 @@ TcpInsertTcb ( LIST_ENTRY *Entry; LIST_ENTRY *Head; TCP_CB *Node; - TCP4_PROTO_DATA *TcpProto; ASSERT ( (Tcb != NULL) && @@ -389,9 +392,6 @@ TcpInsertTcb ( InsertHeadList (Head, &Tcb->List); - TcpProto = (TCP4_PROTO_DATA *) Tcb->Sk->ProtoReserved; - TcpSetVariableData (TcpProto->TcpService); - return 0; } @@ -432,7 +432,7 @@ TcpCloneTcb ( Clone->Sk = SockClone (Tcb->Sk); if (Clone->Sk == NULL) { DEBUG ((EFI_D_ERROR, "TcpCloneTcb: failed to clone a sock\n")); - gBS->FreePool (Clone); + FreePool (Clone); return NULL; } @@ -471,19 +471,19 @@ TcpGetRcvMss ( IN SOCKET *Sock ) { - EFI_SIMPLE_NETWORK_MODE SnpMode; + EFI_IP4_MODE_DATA Ip4Mode; TCP4_PROTO_DATA *TcpProto; EFI_IP4_PROTOCOL *Ip; ASSERT (Sock != NULL); TcpProto = (TCP4_PROTO_DATA *) Sock->ProtoReserved; - Ip = TcpProto->TcpService->IpIo->Ip; + Ip = TcpProto->TcpService->IpIo->Ip.Ip4; ASSERT (Ip != NULL); - Ip->GetModeData (Ip, NULL, NULL, &SnpMode); + Ip->GetModeData (Ip, &Ip4Mode, NULL, NULL); - return (UINT16) (SnpMode.MaxPacketSize - 40); + return (UINT16) (Ip4Mode.MaxPacketSize - sizeof (TCP_HEAD)); } @@ -496,10 +496,13 @@ TcpGetRcvMss ( **/ VOID TcpSetState ( - IN TCP_CB *Tcb, - IN TCP_STATES State + IN OUT TCP_CB *Tcb, + IN UINT8 State ) { + ASSERT (Tcb->State < (sizeof (mTcpStateName) / sizeof (CHAR16 *))); + ASSERT (State < (sizeof (mTcpStateName) / sizeof (CHAR16 *))); + DEBUG ( (EFI_D_INFO, "Tcb (%p) state %s --> %s\n", @@ -508,7 +511,7 @@ TcpSetState ( mTcpStateName[State]) ); - Tcb->State = (TCP_STATES)State; + Tcb->State = State; switch (State) { case TCP_ESTABLISHED: @@ -578,8 +581,8 @@ TcpChecksum ( **/ TCP_SEG * TcpFormatNetbuf ( - IN TCP_CB *Tcb, - IN NET_BUF *Nbuf + IN TCP_CB *Tcb, + IN OUT NET_BUF *Nbuf ) { TCP_SEG *Seg; @@ -587,6 +590,7 @@ TcpFormatNetbuf ( Seg = TCPSEG_NETBUF (Nbuf); Head = (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL); + ASSERT (Head != NULL); Nbuf->Tcp = Head; Seg->Seq = NTOHL (Head->Seq); @@ -652,7 +656,7 @@ TcpResetConnection ( Nhead->Ack = HTONL (Tcb->RcvNxt); Nhead->SrcPort = Tcb->LocalEnd.Port; Nhead->DstPort = Tcb->RemoteEnd.Port; - Nhead->HeadLen = (sizeof (TCP_HEAD) >> 2); + Nhead->HeadLen = (UINT8) (sizeof (TCP_HEAD) >> 2); Nhead->Res = 0; Nhead->Wnd = HTONS (0xFFFF); Nhead->Checksum = 0; @@ -674,7 +678,7 @@ TcpResetConnection ( **/ VOID TcpOnAppConnect ( - IN TCP_CB *Tcb + IN OUT TCP_CB *Tcb ) { TcpInitTcbLocal (Tcb); @@ -694,7 +698,7 @@ TcpOnAppConnect ( **/ VOID TcpOnAppClose ( - IN TCP_CB *Tcb + IN OUT TCP_CB *Tcb ) { ASSERT (Tcb != NULL); @@ -745,29 +749,25 @@ TcpOnAppClose ( **/ INTN TcpOnAppSend ( - IN TCP_CB *Tcb + IN OUT TCP_CB *Tcb ) { switch (Tcb->State) { case TCP_CLOSED: return -1; - break; case TCP_LISTEN: return -1; - break; case TCP_SYN_SENT: case TCP_SYN_RCVD: return 0; - break; case TCP_ESTABLISHED: case TCP_CLOSE_WAIT: TcpToSendData (Tcb, 0); return 0; - break; case TCP_FIN_WAIT_1: case TCP_FIN_WAIT_2: @@ -775,7 +775,7 @@ TcpOnAppSend ( case TCP_LAST_ACK: case TCP_TIME_WAIT: return -1; - break; + default: break; } @@ -791,7 +791,7 @@ TcpOnAppSend ( @param Tcb Pointer to the TCP_CB of this TCP instance. **/ -INTN +VOID TcpOnAppConsume ( IN TCP_CB *Tcb ) @@ -800,17 +800,14 @@ TcpOnAppConsume ( switch (Tcb->State) { case TCP_CLOSED: - return -1; - break; + return; case TCP_LISTEN: - return -1; - break; + return; case TCP_SYN_SENT: case TCP_SYN_RCVD: - return 0; - break; + return; case TCP_ESTABLISHED: TcpOld = TcpRcvWinOld (Tcb); @@ -834,19 +831,18 @@ TcpOnAppConsume ( break; case TCP_CLOSE_WAIT: - return 0; - break; + return; case TCP_FIN_WAIT_1: case TCP_FIN_WAIT_2: case TCP_CLOSING: case TCP_LAST_ACK: case TCP_TIME_WAIT: - return -1; + return; + + default: break; } - - return -1; } @@ -880,205 +876,6 @@ TcpOnAppAbort ( TcpSetState (Tcb, TCP_CLOSED); } - -/** - Set the Tdp4 variable data. - - @param Tcp4Service Pointer to Tcp4 service data. - - @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the variable. - @retval other Set variable failed. - -**/ -EFI_STATUS -TcpSetVariableData ( - IN TCP4_SERVICE_DATA *Tcp4Service - ) -{ - UINT32 NumConfiguredInstance; - LIST_ENTRY *Entry; - TCP_CB *TcpPcb; - TCP4_PROTO_DATA *TcpProto; - UINTN VariableDataSize; - EFI_TCP4_VARIABLE_DATA *Tcp4VariableData; - EFI_TCP4_SERVICE_POINT *Tcp4ServicePoint; - CHAR16 *NewMacString; - EFI_STATUS Status; - - NumConfiguredInstance = 0; - - // - // Go through the running queue to count the instances. - // - NET_LIST_FOR_EACH (Entry, &mTcpRunQue) { - TcpPcb = NET_LIST_USER_STRUCT (Entry, TCP_CB, List); - - TcpProto = (TCP4_PROTO_DATA *) TcpPcb->Sk->ProtoReserved; - - if (TcpProto->TcpService == Tcp4Service) { - // - // This tcp instance belongs to the Tcp4Service. - // - NumConfiguredInstance++; - } - } - - // - // Go through the listening queue to count the instances. - // - NET_LIST_FOR_EACH (Entry, &mTcpListenQue) { - TcpPcb = NET_LIST_USER_STRUCT (Entry, TCP_CB, List); - - TcpProto = (TCP4_PROTO_DATA *) TcpPcb->Sk->ProtoReserved; - - if (TcpProto->TcpService == Tcp4Service) { - // - // This tcp instance belongs to the Tcp4Service. - // - NumConfiguredInstance++; - } - } - - // - // Calculate the size of the Tcp4VariableData. As there may be no Tcp4 child, - // we should add extra buffer for the service points only if the number of configured - // children is more than 1. - // - VariableDataSize = sizeof (EFI_TCP4_VARIABLE_DATA); - - if (NumConfiguredInstance > 1) { - VariableDataSize += sizeof (EFI_TCP4_SERVICE_POINT) * (NumConfiguredInstance - 1); - } - - Tcp4VariableData = AllocatePool (VariableDataSize); - if (Tcp4VariableData == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Tcp4VariableData->DriverHandle = Tcp4Service->DriverBindingHandle; - Tcp4VariableData->ServiceCount = NumConfiguredInstance; - - Tcp4ServicePoint = &Tcp4VariableData->Services[0]; - - // - // Go through the running queue to fill the service points. - // - NET_LIST_FOR_EACH (Entry, &mTcpRunQue) { - TcpPcb = NET_LIST_USER_STRUCT (Entry, TCP_CB, List); - - TcpProto = (TCP4_PROTO_DATA *) TcpPcb->Sk->ProtoReserved; - - if (TcpProto->TcpService == Tcp4Service) { - // - // This tcp instance belongs to the Tcp4Service. - // - Tcp4ServicePoint->InstanceHandle = TcpPcb->Sk->SockHandle; - CopyMem (&Tcp4ServicePoint->LocalAddress, &TcpPcb->LocalEnd.Ip, sizeof (EFI_IPv4_ADDRESS)); - Tcp4ServicePoint->LocalPort = NTOHS (TcpPcb->LocalEnd.Port); - CopyMem (&Tcp4ServicePoint->RemoteAddress, &TcpPcb->RemoteEnd.Ip, sizeof (EFI_IPv4_ADDRESS)); - Tcp4ServicePoint->RemotePort = NTOHS (TcpPcb->RemoteEnd.Port); - - Tcp4ServicePoint++; - } - } - - // - // Go through the listening queue to fill the service points. - // - NET_LIST_FOR_EACH (Entry, &mTcpListenQue) { - TcpPcb = NET_LIST_USER_STRUCT (Entry, TCP_CB, List); - - TcpProto = (TCP4_PROTO_DATA *) TcpPcb->Sk->ProtoReserved; - - if (TcpProto->TcpService == Tcp4Service) { - // - // This tcp instance belongs to the Tcp4Service. - // - Tcp4ServicePoint->InstanceHandle = TcpPcb->Sk->SockHandle; - CopyMem (&Tcp4ServicePoint->LocalAddress, &TcpPcb->LocalEnd.Ip, sizeof (EFI_IPv4_ADDRESS)); - Tcp4ServicePoint->LocalPort = NTOHS (TcpPcb->LocalEnd.Port); - CopyMem (&Tcp4ServicePoint->RemoteAddress, &TcpPcb->RemoteEnd.Ip, sizeof (EFI_IPv4_ADDRESS)); - Tcp4ServicePoint->RemotePort = NTOHS (TcpPcb->RemoteEnd.Port); - - Tcp4ServicePoint++; - } - } - - // - // Get the mac string. - // - Status = NetLibGetMacString ( - Tcp4Service->ControllerHandle, - Tcp4Service->DriverBindingHandle, - &NewMacString - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - if (Tcp4Service->MacString != NULL) { - // - // The variable is set already, we're going to update it. - // - if (StrCmp (Tcp4Service->MacString, NewMacString) != 0) { - // - // The mac address is changed, delete the previous variable first. - // - gRT->SetVariable ( - Tcp4Service->MacString, - &gEfiTcp4ServiceBindingProtocolGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS, - 0, - NULL - ); - } - - gBS->FreePool (Tcp4Service->MacString); - } - - Tcp4Service->MacString = NewMacString; - - Status = gRT->SetVariable ( - Tcp4Service->MacString, - &gEfiTcp4ServiceBindingProtocolGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS, - VariableDataSize, - (VOID *) Tcp4VariableData - ); - -ON_ERROR: - - gBS->FreePool (Tcp4VariableData); - - return Status; -} - - -/** - Clear the variable and free the resource. - - @param Tcp4Service Pointer to Tcp4 service data. - -**/ -VOID -TcpClearVariableData ( - IN TCP4_SERVICE_DATA *Tcp4Service - ) -{ - ASSERT (Tcp4Service->MacString != NULL); - - gRT->SetVariable ( - Tcp4Service->MacString, - &gEfiTcp4ServiceBindingProtocolGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS, - 0, - NULL - ); - - gBS->FreePool (Tcp4Service->MacString); - Tcp4Service->MacString = NULL; -} - /** Install the device path protocol on the TCP instance. @@ -1098,22 +895,28 @@ TcpInstallDevicePath ( TCP_CB *Tcb; IPv4_DEVICE_PATH Ip4DPathNode; EFI_STATUS Status; + TCP_PORTNO LocalPort; + TCP_PORTNO RemotePort; TcpProto = (TCP4_PROTO_DATA *) Sock->ProtoReserved; TcpService = TcpProto->TcpService; Tcb = TcpProto->TcpPcb; + LocalPort = NTOHS (Tcb->LocalEnd.Port); + RemotePort = NTOHS (Tcb->RemoteEnd.Port); NetLibCreateIPv4DPathNode ( &Ip4DPathNode, TcpService->ControllerHandle, Tcb->LocalEnd.Ip, - NTOHS (Tcb->LocalEnd.Port), + LocalPort, Tcb->RemoteEnd.Ip, - NTOHS (Tcb->RemoteEnd.Port), + RemotePort, EFI_IP_PROTO_TCP, Tcb->UseDefaultAddr ); + IP4_COPY_ADDRESS (&Ip4DPathNode.SubnetMask, &Tcb->SubnetMask); + Sock->DevicePath = AppendDevicePathNode ( Sock->ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &Ip4DPathNode @@ -1129,7 +932,7 @@ TcpInstallDevicePath ( Sock->DevicePath ); if (EFI_ERROR (Status)) { - gBS->FreePool (Sock->DevicePath); + FreePool (Sock->DevicePath); } return Status;