diff --git a/NetworkPkg/TcpDxe/SockImpl.c b/NetworkPkg/TcpDxe/SockImpl.c index 4eb42fb868..c5fb176255 100644 --- a/NetworkPkg/TcpDxe/SockImpl.c +++ b/NetworkPkg/TcpDxe/SockImpl.c @@ -1,7 +1,7 @@ /** @file Implementation of the Socket. - Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2017, 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 @@ -828,16 +828,8 @@ SockDestroy ( IN OUT SOCKET *Sock ) { - VOID *SockProtocol; - EFI_GUID *TcpProtocolGuid; - EFI_STATUS Status; - ASSERT (SockStream == Sock->Type); - if (Sock->DestroyCallback != NULL) { - Sock->DestroyCallback (Sock, Sock->Context); - } - // // Flush the completion token buffered // by sock and rcv, snd buffer @@ -872,52 +864,6 @@ SockDestroy ( Sock->Parent = NULL; } - // - // Set the protocol guid and driver binding handle - // in the light of Sock->SockType - // - if (Sock->IpVersion == IP_VERSION_4) { - TcpProtocolGuid = &gEfiTcp4ProtocolGuid; - } else { - TcpProtocolGuid = &gEfiTcp6ProtocolGuid; - } - - // - // Retrieve the protocol installed on this sock - // - Status = gBS->OpenProtocol ( - Sock->SockHandle, - TcpProtocolGuid, - &SockProtocol, - Sock->DriverBinding, - Sock->SockHandle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - - if (EFI_ERROR (Status)) { - - DEBUG ( - (EFI_D_ERROR, - "SockDestroy: Open protocol installed on socket failed with %r\n", - Status) - ); - - goto FreeSock; - } - - // - // Uninstall the protocol installed on this sock - // in the light of Sock->SockType - // - gBS->UninstallMultipleProtocolInterfaces ( - Sock->SockHandle, - TcpProtocolGuid, - SockProtocol, - NULL - ); - -FreeSock: - FreePool (Sock); } diff --git a/NetworkPkg/TcpDxe/SockImpl.h b/NetworkPkg/TcpDxe/SockImpl.h index 5a067deb41..80692b161e 100644 --- a/NetworkPkg/TcpDxe/SockImpl.h +++ b/NetworkPkg/TcpDxe/SockImpl.h @@ -1,7 +1,7 @@ /** @file The function declaration that provided for Socket Interface. - Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2017, 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 @@ -17,6 +17,7 @@ #define _SOCK_IMPL_H_ #include "Socket.h" +#include "TcpMain.h" /** Signal a event with the given status. diff --git a/NetworkPkg/TcpDxe/SockInterface.c b/NetworkPkg/TcpDxe/SockInterface.c index 21ce643a54..b4ba40afce 100644 --- a/NetworkPkg/TcpDxe/SockInterface.c +++ b/NetworkPkg/TcpDxe/SockInterface.c @@ -1,7 +1,7 @@ /** @file Interface function of the Socket. - Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2017, 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 @@ -142,7 +142,12 @@ SockDestroyChild ( IN OUT SOCKET *Sock ) { - EFI_STATUS Status; + EFI_STATUS Status; + TCP_PROTO_DATA *ProtoData; + TCP_CB *Tcb; + EFI_GUID *IpProtocolGuid; + EFI_GUID *TcpProtocolGuid; + VOID *SockProtocol; ASSERT ((Sock != NULL) && (Sock->ProtoHandler != NULL)); @@ -152,6 +157,18 @@ SockDestroyChild ( Sock->InDestroy = TRUE; + if (Sock->IpVersion == IP_VERSION_4) { + IpProtocolGuid = &gEfiIp4ProtocolGuid; + TcpProtocolGuid = &gEfiTcp4ProtocolGuid; + } else { + IpProtocolGuid = &gEfiIp6ProtocolGuid; + TcpProtocolGuid = &gEfiTcp6ProtocolGuid; + } + ProtoData = (TCP_PROTO_DATA *) Sock->ProtoReserved; + Tcb = ProtoData->TcpPcb; + + ASSERT (Tcb != NULL); + Status = EfiAcquireLockOrFail (&(Sock->Lock)); if (EFI_ERROR (Status)) { @@ -164,6 +181,51 @@ SockDestroyChild ( return EFI_ACCESS_DENIED; } + // + // Close the IP protocol. + // + gBS->CloseProtocol ( + Tcb->IpInfo->ChildHandle, + IpProtocolGuid, + ProtoData->TcpService->IpIo->Image, + Sock->SockHandle + ); + + if (Sock->DestroyCallback != NULL) { + Sock->DestroyCallback (Sock, Sock->Context); + } + + // + // Retrieve the protocol installed on this sock + // + Status = gBS->OpenProtocol ( + Sock->SockHandle, + TcpProtocolGuid, + &SockProtocol, + Sock->DriverBinding, + Sock->SockHandle, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + + if (EFI_ERROR (Status)) { + + DEBUG ( + (EFI_D_ERROR, + "SockDestroyChild: Open protocol installed on socket failed with %r\n", + Status) + ); + } + + // + // Uninstall the protocol installed on this sock + // + gBS->UninstallMultipleProtocolInterfaces ( + Sock->SockHandle, + TcpProtocolGuid, + SockProtocol, + NULL + ); + // // force protocol layer to detach the PCB // @@ -213,6 +275,8 @@ SockCreateChild ( { SOCKET *Sock; EFI_STATUS Status; + VOID *SockProtocol; + EFI_GUID *TcpProtocolGuid; // // create a new socket @@ -236,9 +300,7 @@ SockCreateChild ( "SockCreateChild: Get the lock to access socket failed with %r\n", Status) ); - - SockDestroy (Sock); - return NULL; + goto ERROR; } // // inform the protocol layer to attach the socket @@ -253,12 +315,42 @@ SockCreateChild ( "SockCreateChild: Protocol failed to attach a socket with %r\n", Status) ); - - SockDestroy (Sock); - Sock = NULL; + goto ERROR; } return Sock; + +ERROR: + + if (Sock->DestroyCallback != NULL) { + Sock->DestroyCallback (Sock, Sock->Context); + } + + if (Sock->IpVersion == IP_VERSION_4) { + TcpProtocolGuid = &gEfiTcp4ProtocolGuid; + } else { + TcpProtocolGuid = &gEfiTcp6ProtocolGuid; + } + + gBS->OpenProtocol ( + Sock->SockHandle, + TcpProtocolGuid, + &SockProtocol, + Sock->DriverBinding, + Sock->SockHandle, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + // + // Uninstall the protocol installed on this sock + // + gBS->UninstallMultipleProtocolInterfaces ( + Sock->SockHandle, + TcpProtocolGuid, + SockProtocol, + NULL + ); + SockDestroy (Sock); + return NULL; } /** diff --git a/NetworkPkg/TcpDxe/TcpDispatcher.c b/NetworkPkg/TcpDxe/TcpDispatcher.c index d4bc8ace55..9a352b1531 100644 --- a/NetworkPkg/TcpDxe/TcpDispatcher.c +++ b/NetworkPkg/TcpDxe/TcpDispatcher.c @@ -2,7 +2,7 @@ The implementation of a dispatch routine for processing TCP requests. (C) Copyright 2014 Hewlett-Packard Development Company, L.P.
- Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2017, 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 @@ -423,30 +423,13 @@ TcpDetachPcb ( { TCP_PROTO_DATA *ProtoData; TCP_CB *Tcb; - EFI_GUID *IpProtocolGuid; - if (Sk->IpVersion == IP_VERSION_4) { - IpProtocolGuid = &gEfiIp4ProtocolGuid; - } else { - IpProtocolGuid = &gEfiIp6ProtocolGuid; - } - ProtoData = (TCP_PROTO_DATA *) Sk->ProtoReserved; Tcb = ProtoData->TcpPcb; ASSERT (Tcb != NULL); TcpFlushPcb (Tcb); - - // - // Close the IP protocol. - // - gBS->CloseProtocol ( - Tcb->IpInfo->ChildHandle, - IpProtocolGuid, - ProtoData->TcpService->IpIo->Image, - Sk->SockHandle - ); IpIoRemoveIp (ProtoData->TcpService->IpIo, Tcb->IpInfo);