From: Fu Siyuan Date: Mon, 4 Sep 2017 08:04:13 +0000 (+0800) Subject: MdeModulePkg/Ip4Dxe: fix a bug in IP4 driver for IpSec protocol notify. X-Git-Tag: edk2-stable201903~3476 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=5aae2d35de031a38e7812c615ff6bce36b31466a;p=mirror_edk2.git MdeModulePkg/Ip4Dxe: fix a bug in IP4 driver for IpSec protocol notify. 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 Reviewed-by: Ye Ting --- diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c index 792db5c173..03ba458a96 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c @@ -41,12 +41,20 @@ IpSec2InstalledCallback ( IN VOID *Context ) { + EFI_STATUS Status; // - // Close the event so it does not get called again. + // Test if protocol was even found. + // Notification function will be called at least once. // - gBS->CloseEvent (Event); + Status = gBS->LocateProtocol (&gEfiIpSec2ProtocolGuid, NULL, &mIpSec); + if (Status == EFI_SUCCESS && mIpSec != NULL) { + // + // Close the event so it does not get called again. + // + gBS->CloseEvent (Event); - mIpSec2Installed = TRUE; + mIpSec2Installed = TRUE; + } } /** diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c index 09b8f2bac2..e694323019 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c @@ -1,7 +1,7 @@ /** @file IP4 input process. -Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.
This program and the accompanying materials @@ -518,6 +518,7 @@ Ip4IpSecProcessPacket ( if (!mIpSec2Installed) { goto ON_EXIT; } + ASSERT (mIpSec != NULL); Packet = *Netbuf; RecycleEvent = NULL; @@ -527,13 +528,6 @@ Ip4IpSecProcessPacket ( FragmentCount = Packet->BlockOpNum; ZeroMem (&ZeroHead, sizeof (IP4_HEAD)); - - if (mIpSec == NULL) { - gBS->LocateProtocol (&gEfiIpSec2ProtocolGuid, NULL, (VOID **) &mIpSec); - if (mIpSec == NULL) { - goto ON_EXIT; - } - } // // Check whether the IPsec enable variable is set.