summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Universal
diff options
context:
space:
mode:
authorZhang Lubo <lubo.zhang@intel.com>2017-03-16 18:03:36 +0800
committerJiaxin Wu <jiaxin.wu@intel.com>2017-03-17 10:14:30 +0800
commit4bb89650f5dd77a9807915ced2f454b8d39a323f (patch)
tree344eb5ebb51f23d7a2467650f4c99c49fa7cb862 /MdeModulePkg/Universal
parent962e62bcd84db8a684fb6f594b930726aa62b778 (diff)
downloadedk2-4bb89650f5dd77a9807915ced2f454b8d39a323f.tar.gz
edk2-4bb89650f5dd77a9807915ced2f454b8d39a323f.tar.bz2
edk2-4bb89650f5dd77a9807915ced2f454b8d39a323f.zip
MdeModulePkg: Fix service binding issue in TCP4 and Ip4 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 want to send the tcp reset packet in it's driver binding stop function, it will failed. The IpInstance destroy state is redundant and may cause ip transmit failed if up layer want to send ip packet. 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 'MdeModulePkg/Universal')
-rw-r--r--MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c10
-rw-r--r--MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c4
-rw-r--r--MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h8
-rw-r--r--MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.c48
-rw-r--r--MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.h3
-rw-r--r--MdeModulePkg/Universal/Network/Tcp4Dxe/SockInterface.c88
-rw-r--r--MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c12
7 files changed, 96 insertions, 77 deletions
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c
index 642e453e02..792db5c173 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c
@@ -1,7 +1,7 @@
/** @file
The driver binding and service binding protocol for IP4 driver.
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
This program and the accompanying materials
@@ -922,7 +922,6 @@ Ip4ServiceBindingDestroyChild (
IP4_PROTOCOL *IpInstance;
EFI_IP4_PROTOCOL *Ip4;
EFI_TPL OldTpl;
- INTN State;
if ((This == NULL) || (ChildHandle == NULL)) {
return EFI_INVALID_PARAMETER;
@@ -960,13 +959,12 @@ Ip4ServiceBindingDestroyChild (
// when UDP driver is being stopped, it will destroy all
// the IP child it opens.
//
- if (IpInstance->State == IP4_STATE_DESTROY) {
+ if (IpInstance->InDestroy) {
gBS->RestoreTPL (OldTpl);
return EFI_SUCCESS;
}
- State = IpInstance->State;
- IpInstance->State = IP4_STATE_DESTROY;
+ IpInstance->InDestroy = TRUE;
//
// Close the Managed Network protocol.
@@ -1009,6 +1007,7 @@ Ip4ServiceBindingDestroyChild (
);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
if (EFI_ERROR (Status)) {
+ IpInstance->InDestroy = FALSE;
goto ON_ERROR;
}
@@ -1033,7 +1032,6 @@ Ip4ServiceBindingDestroyChild (
return EFI_SUCCESS;
ON_ERROR:
- IpInstance->State = State;
gBS->RestoreTPL (OldTpl);
return Status;
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
index 5aa3ea1375..3cdf8ecaad 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
@@ -550,6 +550,7 @@ Ip4InitProtocol (
IpInstance->Signature = IP4_PROTOCOL_SIGNATURE;
CopyMem (&IpInstance->Ip4Proto, &mEfiIp4ProtocolTemplete, sizeof (IpInstance->Ip4Proto));
IpInstance->State = IP4_STATE_UNCONFIGED;
+ IpInstance->InDestroy = FALSE;
IpInstance->Service = IpSb;
InitializeListHead (&IpInstance->Link);
@@ -936,8 +937,7 @@ EfiIp4Configure (
Status = Ip4CleanProtocol (IpInstance);
//
- // Don't change the state if it is DESTROY, consider the following
- // valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,
+ // Consider the following valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,
// Configure (ThisIp, NULL). If the state is changed to UNCONFIGED,
// the unload fails miserably.
//
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h
index 7a7ad9d785..f6b4047941 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h
@@ -1,7 +1,7 @@
/** @file
Ip4 internal functions and type defintions.
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
This program and the accompanying materials
@@ -64,12 +64,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//
// The state of IP4 protocol. It starts from UNCONFIGED. if it is
// successfully configured, it goes to CONFIGED. if configure NULL
-// is called, it becomes UNCONFIGED again. If (partly) destroyed, it
-// becomes DESTROY.
+// is called, it becomes UNCONFIGED again.
//
#define IP4_STATE_UNCONFIGED 0
#define IP4_STATE_CONFIGED 1
-#define IP4_STATE_DESTROY 2
//
// The state of IP4 service. It starts from UNSTARTED. It transits
@@ -136,6 +134,8 @@ struct _IP4_PROTOCOL {
EFI_HANDLE Handle;
INTN State;
+ BOOLEAN InDestroy;
+
IP4_SERVICE *Service;
LIST_ENTRY Link; // Link to all the IP protocol from the service
diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.c b/MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.c
index fc7827325f..0476077c20 100644
--- a/MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.c
+++ b/MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.c
@@ -1,7 +1,7 @@
/** @file
Implementation of the Socket.
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 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
which accompanies this distribution. The full text of the license may be found at
@@ -717,16 +717,8 @@ SockDestroy (
IN OUT SOCKET *Sock
)
{
- VOID *SockProtocol;
- EFI_GUID *ProtocolGuid;
- 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
@@ -762,44 +754,6 @@ SockDestroy (
Sock->Parent = NULL;
}
- //
- // Set the protocol guid and driver binding handle
- // in the light of Sock->SockType
- //
- ProtocolGuid = &gEfiTcp4ProtocolGuid;
-
- //
- // Retrieve the protocol installed on this sock
- //
- Status = gBS->OpenProtocol (
- Sock->SockHandle,
- ProtocolGuid,
- &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,
- ProtocolGuid,
- SockProtocol,
- NULL
- );
-
-FreeSock:
FreePool (Sock);
return ;
}
diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.h b/MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.h
index 4a5a845b0e..bfd750a8ce 100644
--- a/MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.h
+++ b/MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.h
@@ -1,7 +1,7 @@
/** @file
Socket implementation header file.
-Copyright (c) 2005 - 2006, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 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
which accompanies this distribution. The full text of the license may be found at
@@ -16,6 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#define _SOCK_IMPL_H_
#include "Socket.h"
+#include "Tcp4Main.h"
/**
Signal a event with the given status.
diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/SockInterface.c b/MdeModulePkg/Universal/Network/Tcp4Dxe/SockInterface.c
index a8bdef6802..f8b535cf6e 100644
--- a/MdeModulePkg/Universal/Network/Tcp4Dxe/SockInterface.c
+++ b/MdeModulePkg/Universal/Network/Tcp4Dxe/SockInterface.c
@@ -1,7 +1,7 @@
/** @file
Interface function of the Socket.
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 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
which accompanies this distribution. The full text of the license may be found at
@@ -144,7 +144,10 @@ SockDestroyChild (
IN SOCKET *Sock
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
+ TCP4_PROTO_DATA *ProtoData;
+ TCP_CB *Tcb;
+ VOID *SockProtocol;
ASSERT ((Sock != NULL) && (Sock->ProtoHandler != NULL));
@@ -154,6 +157,11 @@ SockDestroyChild (
Sock->InDestroy = TRUE;
+ ProtoData = (TCP4_PROTO_DATA *) Sock->ProtoReserved;
+ Tcb = ProtoData->TcpPcb;
+
+ ASSERT (Tcb != NULL);
+
Status = EfiAcquireLockOrFail (&(Sock->Lock));
if (EFI_ERROR (Status)) {
@@ -164,6 +172,49 @@ SockDestroyChild (
}
//
+ // Close the IP protocol.
+ //
+ gBS->CloseProtocol (
+ Tcb->IpInfo->ChildHandle,
+ &gEfiIp4ProtocolGuid,
+ 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,
+ &gEfiTcp4ProtocolGuid,
+ &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
+ // in the light of Sock->SockType
+ //
+ gBS->UninstallMultipleProtocolInterfaces (
+ Sock->SockHandle,
+ &gEfiTcp4ProtocolGuid,
+ SockProtocol,
+ NULL
+ );
+
+ //
// force protocol layer to detach the PCB
//
Status = Sock->ProtoHandler (Sock, SOCK_DETACH, NULL);
@@ -209,6 +260,7 @@ SockCreateChild (
)
{
SOCKET *Sock;
+ VOID *SockProtocol;
EFI_STATUS Status;
//
@@ -229,8 +281,7 @@ SockCreateChild (
DEBUG ((EFI_D_ERROR, "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
@@ -243,11 +294,36 @@ SockCreateChild (
DEBUG ((EFI_D_ERROR, "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);
+ }
+
+ gBS->OpenProtocol (
+ Sock->SockHandle,
+ &gEfiTcp4ProtocolGuid,
+ &SockProtocol,
+ Sock->DriverBinding,
+ Sock->SockHandle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ //
+ // Uninstall the protocol installed on this sock
+ //
+ gBS->UninstallMultipleProtocolInterfaces (
+ Sock->SockHandle,
+ &gEfiTcp4ProtocolGuid,
+ SockProtocol,
+ NULL
+ );
+ SockDestroy (Sock);
+ return NULL;
}
diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c
index 5b327af721..702cae8d65 100644
--- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c
+++ b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c
@@ -2,7 +2,7 @@
Tcp request dispatcher implementation.
(C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
-Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 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
which accompanies this distribution. The full text of the license may be found at
@@ -332,16 +332,6 @@ Tcp4DetachPcb (
ASSERT (Tcb != NULL);
Tcp4FlushPcb (Tcb);
-
- //
- // Close the IP protocol.
- //
- gBS->CloseProtocol (
- Tcb->IpInfo->ChildHandle,
- &gEfiIp4ProtocolGuid,
- ProtoData->TcpService->IpIo->Image,
- Sk->SockHandle
- );
IpIoRemoveIp (ProtoData->TcpService->IpIo, Tcb->IpInfo);