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 <siyuan.fu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
This commit is contained in:
Fu Siyuan 2017-09-04 16:04:13 +08:00
parent 12cfc9009e
commit 5aae2d35de
2 changed files with 13 additions and 11 deletions

View File

@ -41,6 +41,13 @@ IpSec2InstalledCallback (
IN VOID *Context IN VOID *Context
) )
{ {
EFI_STATUS Status;
//
// Test if protocol was even found.
// Notification function will be called at least once.
//
Status = gBS->LocateProtocol (&gEfiIpSec2ProtocolGuid, NULL, &mIpSec);
if (Status == EFI_SUCCESS && mIpSec != NULL) {
// //
// Close the event so it does not get called again. // Close the event so it does not get called again.
// //
@ -48,6 +55,7 @@ IpSec2InstalledCallback (
mIpSec2Installed = TRUE; mIpSec2Installed = TRUE;
} }
}
/** /**
This is the declaration of an EFI image entry point. This entry point is This is the declaration of an EFI image entry point. This entry point is

View File

@ -1,7 +1,7 @@
/** @file /** @file
IP4 input process. IP4 input process.
Copyright (c) 2005 - 2014, 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> (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
This program and the accompanying materials This program and the accompanying materials
@ -518,6 +518,7 @@ Ip4IpSecProcessPacket (
if (!mIpSec2Installed) { if (!mIpSec2Installed) {
goto ON_EXIT; goto ON_EXIT;
} }
ASSERT (mIpSec != NULL);
Packet = *Netbuf; Packet = *Netbuf;
RecycleEvent = NULL; RecycleEvent = NULL;
@ -528,13 +529,6 @@ Ip4IpSecProcessPacket (
ZeroMem (&ZeroHead, sizeof (IP4_HEAD)); 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. // Check whether the IPsec enable variable is set.
// //