]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Ip4Dxe: fix a bug in IP4 driver for IpSec protocol notify.
authorFu Siyuan <siyuan.fu@intel.com>
Mon, 4 Sep 2017 08:04:13 +0000 (16:04 +0800)
committerFu Siyuan <siyuan.fu@intel.com>
Wed, 6 Sep 2017 06:57:29 +0000 (14:57 +0800)
The IP driver uses EfiCreateProtocolNotifyEvent() to register notify callback
function for IpSec protocol, but it didn't notice that the callback will always
be executed at least once, even the protocol wasn't in handle database.
As a result, the Ip4IpSecProcessPacket() will still always call LocateProtocol()
even the IpSec protocol is not installed, which will impact the network
performance.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c

index 792db5c173f2ad47a5578e31407ce8279074d73e..03ba458a96f5fb244bb61be27398309fdb8b1fbf 100644 (file)
@@ -41,12 +41,20 @@ IpSec2InstalledCallback (
   IN VOID       *Context\r
   )\r
 {\r
+  EFI_STATUS    Status;\r
   //\r
-  // Close the event so it does not get called again.\r
+  // Test if protocol was even found.\r
+  // Notification function will be called at least once.\r
   //\r
-  gBS->CloseEvent (Event);\r
+  Status = gBS->LocateProtocol (&gEfiIpSec2ProtocolGuid, NULL, &mIpSec);\r
+  if (Status == EFI_SUCCESS && mIpSec != NULL) {\r
+    //\r
+    // Close the event so it does not get called again.\r
+    //\r
+    gBS->CloseEvent (Event);\r
 \r
-  mIpSec2Installed = TRUE;\r
+    mIpSec2Installed = TRUE;\r
+  }\r
 }\r
 \r
 /**\r
index 09b8f2bac23554b5f759d78630c58025fd61e23f..e6943230195cb6e056c132e214e483206817a6ba 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   IP4 input process.\r
   \r
-Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
 \r
 This program and the accompanying materials\r
@@ -518,6 +518,7 @@ Ip4IpSecProcessPacket (
   if (!mIpSec2Installed) {\r
     goto ON_EXIT;\r
   }\r
+  ASSERT (mIpSec != NULL);\r
   \r
   Packet        = *Netbuf;\r
   RecycleEvent  = NULL;\r
@@ -527,13 +528,6 @@ Ip4IpSecProcessPacket (
   FragmentCount = Packet->BlockOpNum;\r
 \r
   ZeroMem (&ZeroHead, sizeof (IP4_HEAD));\r
-  \r
-  if (mIpSec == NULL) {\r
-    gBS->LocateProtocol (&gEfiIpSec2ProtocolGuid, NULL, (VOID **) &mIpSec);\r
-    if (mIpSec == NULL) {\r
-      goto ON_EXIT;\r
-    }\r
-  }\r
 \r
   //\r
   // Check whether the IPsec enable variable is set.\r