]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Tcp4Dxe/SockInterface.c
MdeModulePkg: Fix service binding issue in TCP4 and Ip4 dxe.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / SockInterface.c
index a8bdef6802b425bef556e5a1c82895796cb5c5f4..f8b535cf6e7f0ad125a1647bf22e063daca7ff1e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Interface function of the Socket.\r
 \r
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2017, 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
@@ -144,7 +144,10 @@ SockDestroyChild (
   IN SOCKET *Sock\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
+  EFI_STATUS       Status;\r
+  TCP4_PROTO_DATA  *ProtoData;\r
+  TCP_CB           *Tcb;\r
+  VOID             *SockProtocol;\r
 \r
   ASSERT ((Sock != NULL) && (Sock->ProtoHandler != NULL));\r
 \r
@@ -154,6 +157,11 @@ SockDestroyChild (
 \r
   Sock->InDestroy = TRUE;\r
 \r
+  ProtoData = (TCP4_PROTO_DATA *) Sock->ProtoReserved;\r
+  Tcb       = ProtoData->TcpPcb;\r
+\r
+  ASSERT (Tcb != NULL);\r
+\r
   Status = EfiAcquireLockOrFail (&(Sock->Lock));\r
   if (EFI_ERROR (Status)) {\r
 \r
@@ -163,6 +171,49 @@ SockDestroyChild (
     return EFI_ACCESS_DENIED;\r
   }\r
 \r
+  //\r
+  // Close the IP protocol.\r
+  //\r
+  gBS->CloseProtocol (\r
+         Tcb->IpInfo->ChildHandle,\r
+         &gEfiIp4ProtocolGuid,\r
+         ProtoData->TcpService->IpIo->Image,\r
+         Sock->SockHandle\r
+         );\r
+\r
+  if (Sock->DestroyCallback != NULL) {\r
+    Sock->DestroyCallback (Sock, Sock->Context);\r
+  }\r
+\r
+  //\r
+  // Retrieve the protocol installed on this sock\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Sock->SockHandle,\r
+                  &gEfiTcp4ProtocolGuid,\r
+                  &SockProtocol,\r
+                  Sock->DriverBinding,\r
+                  Sock->SockHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+\r
+    DEBUG ((EFI_D_ERROR, "SockDestroyChild: Open protocol installed "\r
+      "on socket failed with %r\n", Status));\r
+  }\r
+\r
+  //\r
+  // Uninstall the protocol installed on this sock\r
+  // in the light of Sock->SockType\r
+  //\r
+  gBS->UninstallMultipleProtocolInterfaces (\r
+        Sock->SockHandle,\r
+        &gEfiTcp4ProtocolGuid,\r
+        SockProtocol,\r
+        NULL\r
+        );\r
+\r
   //\r
   // force protocol layer to detach the PCB\r
   //\r
@@ -209,6 +260,7 @@ SockCreateChild (
   )\r
 {\r
   SOCKET      *Sock;\r
+  VOID        *SockProtocol;\r
   EFI_STATUS  Status;\r
 \r
   //\r
@@ -229,8 +281,7 @@ SockCreateChild (
     DEBUG ((EFI_D_ERROR, "SockCreateChild: Get the lock to "\r
       "access socket failed with %r\n", Status));\r
 \r
-    SockDestroy (Sock);\r
-    return NULL;\r
+    goto ERROR;\r
   }\r
   //\r
   // inform the protocol layer to attach the socket\r
@@ -243,11 +294,36 @@ SockCreateChild (
     DEBUG ((EFI_D_ERROR, "SockCreateChild: Protocol failed to"\r
       " attach a socket with %r\n", Status));\r
 \r
-    SockDestroy (Sock);\r
-    Sock = NULL;\r
+    goto ERROR;\r
   }\r
 \r
   return Sock;\r
+\r
+ERROR:\r
+\r
+  if (Sock->DestroyCallback != NULL) {\r
+    Sock->DestroyCallback (Sock, Sock->Context);\r
+  }\r
+\r
+  gBS->OpenProtocol (\r
+         Sock->SockHandle,\r
+         &gEfiTcp4ProtocolGuid,\r
+         &SockProtocol,\r
+         Sock->DriverBinding,\r
+         Sock->SockHandle,\r
+         EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+         );\r
+  //\r
+  // Uninstall the protocol installed on this sock\r
+  //\r
+  gBS->UninstallMultipleProtocolInterfaces (\r
+        Sock->SockHandle,\r
+        &gEfiTcp4ProtocolGuid,\r
+        SockProtocol,\r
+        NULL\r
+        );\r
+   SockDestroy (Sock);\r
+   return NULL;\r
 }\r
 \r
 \r