diff options
author | Zhang Lubo <lubo.zhang@intel.com> | 2017-03-16 17:52:51 +0800 |
---|---|---|
committer | Jiaxin Wu <jiaxin.wu@intel.com> | 2017-03-17 10:14:37 +0800 |
commit | d555699b3ccda17b79abc436d191228921d2631c (patch) | |
tree | ab2a8b475969f38948d4ebed9f16bd011c3522ec /NetworkPkg/TcpDxe/SockInterface.c | |
parent | 4bb89650f5dd77a9807915ced2f454b8d39a323f (diff) | |
download | edk2-d555699b3ccda17b79abc436d191228921d2631c.zip edk2-d555699b3ccda17b79abc436d191228921d2631c.tar.gz edk2-d555699b3ccda17b79abc436d191228921d2631c.tar.bz2 |
NetworkPkg: Fix service binding issue in TCP dxe.
v2: Handle error case in SockCreateChild and fix typo issue
when we destroy the socket Sock and its associated
protocol control block, we need to first close the
parent protocol, then remove the protocol from childHandle
and last to free any data structures that allocated in
CreateChild. But currently, we free the socket data (Socket ConfigureState)
before removing the protocol form the childhandle. So if the up layer
perform the driverbing stop to abort tcp session and send the tcp reset
packet, it will failed.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Zhang Lubo <lubo.zhang@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
Diffstat (limited to 'NetworkPkg/TcpDxe/SockInterface.c')
-rw-r--r-- | NetworkPkg/TcpDxe/SockInterface.c | 108 |
1 files changed, 100 insertions, 8 deletions
diff --git a/NetworkPkg/TcpDxe/SockInterface.c b/NetworkPkg/TcpDxe/SockInterface.c index 21ce643..b4ba40a 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.<BR>
+ Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
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)) {
@@ -165,6 +182,51 @@ SockDestroyChild ( }
//
+ // 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
//
Status = Sock->ProtoHandler (Sock, SOCK_DETACH, NULL);
@@ -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;
}
/**
|