Samer El-Haj-Mahmoud
2015-06-28 05:52:11 UTC
Modified the logic in Ip4Dxe and Ip6Dxe to not locate EFI_IPSEC2_PROTOCOL on each message transmit/receive. Instead, register a callback in the drivers entry points on the IpSec protocol installation, and process only if the protocol is installed. This speeds up the network stacks when IpSec is not installed since there is a penalty associated with searching the entire handle database on each packet processing.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Samer El-Haj-Mahmoud <samer.el-haj-***@hp.com>
---
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c | 70 ++++++++++++++++++++++
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h | 4 ++
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c | 6 ++
NetworkPkg/Ip6Dxe/Ip6Driver.c | 73 +++++++++++++++++++++++
NetworkPkg/Ip6Dxe/Ip6Impl.h | 3 +
NetworkPkg/Ip6Dxe/Ip6Input.c | 6 ++
6 files changed, 162 insertions(+)
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c
index 4944113..ee39820 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c
@@ -1,6 +1,7 @@
/** @file
The driver binding and service binding protocol for IP4 driver.
+(C) Copyright 2014 - 2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2005 - 2014, 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
@@ -23,6 +24,72 @@ EFI_DRIVER_BINDING_PROTOCOL gIp4DriverBinding = {
NULL
};
+BOOLEAN mIpSec2Installed = FALSE;
+
+/**
+ Callback function for IpSec2 Protocol install.
+
+ @param[in] Event Event whose notification function is being invoked
+ @param[in] Context Pointer to the notification function's context
+
+**/
+VOID
+EFIAPI
+IpSec2InstalledCallback (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ //
+ // Close the event so it does not get called again.
+ //
+ gBS->CloseEvent (Event);
+
+ mIpSec2Installed = TRUE;
+}
+
+/**
+ Register the Notification callback function for IpSec2 Protocol install.
+
+ @retval EFI_SUCCESS Successfully registered the callback function.
+ @retval other Registration was not successful.
+**/
+EFI_STATUS
+EFIAPI
+RegisterIpSec2ProtocolNotify (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ EFI_EVENT Event;
+ VOID *Registration;
+
+ //
+ // New event, to register for IpSec2 Protocol installation.
+ //
+ Status = gBS->CreateEvent (
+ EVT_NOTIFY_SIGNAL,
+ TPL_CALLBACK,
+ IpSec2InstalledCallback,
+ NULL,
+ &Event
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "RegisterIpSec2ProtocolNotify: CreateEvent returned error %r\n", Status));
+ } else {
+ Status = gBS->RegisterProtocolNotify (
+ &gEfiIpSec2ProtocolGuid,
+ Event,
+ &Registration
+ );
+ if (EFI_ERROR (Status)) {
+ gBS->CloseEvent (Event);
+ }
+ }
+
+ return Status;
+}
+
/**
This is the declaration of an EFI image entry point. This entry point is
the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
@@ -45,6 +112,9 @@ Ip4DriverEntryPoint (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
+
+ RegisterIpSec2ProtocolNotify ();
+
return EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h
index c49e013..6f958db 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h
@@ -1,5 +1,7 @@
/** @file
Ip4 internal functions and type defintions.
+
+(C) Copyright 2014 - 2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
@@ -376,4 +378,6 @@ Ip4FreeTxToken (
extern EFI_IPSEC2_PROTOCOL *mIpSec;
+extern BOOLEAN mIpSec2Installed;
+
#endif
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c
index 38ad1c3..cf0a65d 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c
@@ -1,6 +1,7 @@
/** @file
IP4 input process.
+(C) Copyright 2014 - 2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2005 - 2014, 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
@@ -512,6 +513,11 @@ Ip4IpSecProcessPacket (
IP4_HEAD ZeroHead;
Status = EFI_SUCCESS;
+
+ if (!mIpSec2Installed) {
+ goto ON_EXIT;
+ }
+
Packet = *Netbuf;
RecycleEvent = NULL;
IpSecWrap = NULL;
diff --git a/NetworkPkg/Ip6Dxe/Ip6Driver.c b/NetworkPkg/Ip6Dxe/Ip6Driver.c
index 6958784..ba877dd 100644
--- a/NetworkPkg/Ip6Dxe/Ip6Driver.c
+++ b/NetworkPkg/Ip6Dxe/Ip6Driver.c
@@ -1,6 +1,7 @@
/** @file
The driver binding and service binding protocol for IP6 driver.
+ (C) Copyright 2014 - 2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
@@ -24,6 +25,75 @@ EFI_DRIVER_BINDING_PROTOCOL gIp6DriverBinding = {
NULL
};
+BOOLEAN mIpSec2Installed = FALSE;
+
+/**
+ Callback function for IpSec2 Protocol install.
+
+ @param[in] Event Event whose notification function is being invoked
+ @param[in] Context Pointer to the notification function's context
+
+ @retval EFI_SUCCESS Callback successful.
+**/
+VOID
+EFIAPI
+IpSec2InstalledCallback (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ //
+ // Close the event so it does not get called again.
+ //
+ gBS->CloseEvent (Event);
+
+ mIpSec2Installed = TRUE;
+
+ return;
+}
+
+/**
+ Register the Notification callback function for IpSec2 Protocol install.
+
+ @retval EFI_SUCCESS Successfully registered the callback function.
+ @retval other Registration was not successful.
+**/
+EFI_STATUS
+EFIAPI
+RegisterIpSec2ProtocolNotify (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ EFI_EVENT Event;
+ VOID *Registration;
+
+ //
+ // New event, to register for IpSec2 Protocol installation.
+ //
+ Status = gBS->CreateEvent (
+ EVT_NOTIFY_SIGNAL,
+ TPL_CALLBACK,
+ IpSec2InstalledCallback,
+ NULL,
+ &Event
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Ip6Dxe RegisterIpSec2ProtocolNotify: CreateEvent returned error %r\n", Status));
+ } else {
+ Status = gBS->RegisterProtocolNotify (
+ &gEfiIpSec2ProtocolGuid,
+ Event,
+ &Registration
+ );
+ if (EFI_ERROR (Status)) {
+ gBS->CloseEvent (Event);
+ }
+ }
+
+ return Status;
+}
+
/**
This is the declaration of an EFI image entry point. This entry point is
the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
@@ -46,6 +116,9 @@ Ip6DriverEntryPoint (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
+
+ RegisterIpSec2ProtocolNotify ();
+
return EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
diff --git a/NetworkPkg/Ip6Dxe/Ip6Impl.h b/NetworkPkg/Ip6Dxe/Ip6Impl.h
index 8f114bb..629d03f 100644
--- a/NetworkPkg/Ip6Dxe/Ip6Impl.h
+++ b/NetworkPkg/Ip6Dxe/Ip6Impl.h
@@ -1,6 +1,7 @@
/** @file
Implementation of EFI_IP6_PROTOCOL protocol interfaces and type definitions.
+ (C) Copyright 2014 - 2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
@@ -90,6 +91,8 @@
extern EFI_IPSEC2_PROTOCOL *mIpSec;
+extern BOOLEAN mIpSec2Installed;
+
//
// IP6_TXTOKEN_WRAP wraps the upper layer's transmit token.
// The user's data is kept in the Packet. When fragment is
diff --git a/NetworkPkg/Ip6Dxe/Ip6Input.c b/NetworkPkg/Ip6Dxe/Ip6Input.c
index cf88884..ed51859 100644
--- a/NetworkPkg/Ip6Dxe/Ip6Input.c
+++ b/NetworkPkg/Ip6Dxe/Ip6Input.c
@@ -1,6 +1,7 @@
/** @file
IP6 internal functions to process the incoming packets.
+ (C) Copyright 2014 - 2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
@@ -525,6 +526,11 @@ Ip6IpSecProcessPacket (
EFI_IP6_HEADER ZeroHead;
Status = EFI_SUCCESS;
+
+ if (!mIpSec2Installed) {
+ goto ON_EXIT;
+ }
+
Packet = *Netbuf;
RecycleEvent = NULL;
IpSecWrap = NULL;
--
1.9.5.msysgit.0
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Samer El-Haj-Mahmoud <samer.el-haj-***@hp.com>
---
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c | 70 ++++++++++++++++++++++
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h | 4 ++
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c | 6 ++
NetworkPkg/Ip6Dxe/Ip6Driver.c | 73 +++++++++++++++++++++++
NetworkPkg/Ip6Dxe/Ip6Impl.h | 3 +
NetworkPkg/Ip6Dxe/Ip6Input.c | 6 ++
6 files changed, 162 insertions(+)
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c
index 4944113..ee39820 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c
@@ -1,6 +1,7 @@
/** @file
The driver binding and service binding protocol for IP4 driver.
+(C) Copyright 2014 - 2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2005 - 2014, 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
@@ -23,6 +24,72 @@ EFI_DRIVER_BINDING_PROTOCOL gIp4DriverBinding = {
NULL
};
+BOOLEAN mIpSec2Installed = FALSE;
+
+/**
+ Callback function for IpSec2 Protocol install.
+
+ @param[in] Event Event whose notification function is being invoked
+ @param[in] Context Pointer to the notification function's context
+
+**/
+VOID
+EFIAPI
+IpSec2InstalledCallback (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ //
+ // Close the event so it does not get called again.
+ //
+ gBS->CloseEvent (Event);
+
+ mIpSec2Installed = TRUE;
+}
+
+/**
+ Register the Notification callback function for IpSec2 Protocol install.
+
+ @retval EFI_SUCCESS Successfully registered the callback function.
+ @retval other Registration was not successful.
+**/
+EFI_STATUS
+EFIAPI
+RegisterIpSec2ProtocolNotify (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ EFI_EVENT Event;
+ VOID *Registration;
+
+ //
+ // New event, to register for IpSec2 Protocol installation.
+ //
+ Status = gBS->CreateEvent (
+ EVT_NOTIFY_SIGNAL,
+ TPL_CALLBACK,
+ IpSec2InstalledCallback,
+ NULL,
+ &Event
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "RegisterIpSec2ProtocolNotify: CreateEvent returned error %r\n", Status));
+ } else {
+ Status = gBS->RegisterProtocolNotify (
+ &gEfiIpSec2ProtocolGuid,
+ Event,
+ &Registration
+ );
+ if (EFI_ERROR (Status)) {
+ gBS->CloseEvent (Event);
+ }
+ }
+
+ return Status;
+}
+
/**
This is the declaration of an EFI image entry point. This entry point is
the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
@@ -45,6 +112,9 @@ Ip4DriverEntryPoint (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
+
+ RegisterIpSec2ProtocolNotify ();
+
return EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h
index c49e013..6f958db 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h
@@ -1,5 +1,7 @@
/** @file
Ip4 internal functions and type defintions.
+
+(C) Copyright 2014 - 2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
@@ -376,4 +378,6 @@ Ip4FreeTxToken (
extern EFI_IPSEC2_PROTOCOL *mIpSec;
+extern BOOLEAN mIpSec2Installed;
+
#endif
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c
index 38ad1c3..cf0a65d 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c
@@ -1,6 +1,7 @@
/** @file
IP4 input process.
+(C) Copyright 2014 - 2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2005 - 2014, 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
@@ -512,6 +513,11 @@ Ip4IpSecProcessPacket (
IP4_HEAD ZeroHead;
Status = EFI_SUCCESS;
+
+ if (!mIpSec2Installed) {
+ goto ON_EXIT;
+ }
+
Packet = *Netbuf;
RecycleEvent = NULL;
IpSecWrap = NULL;
diff --git a/NetworkPkg/Ip6Dxe/Ip6Driver.c b/NetworkPkg/Ip6Dxe/Ip6Driver.c
index 6958784..ba877dd 100644
--- a/NetworkPkg/Ip6Dxe/Ip6Driver.c
+++ b/NetworkPkg/Ip6Dxe/Ip6Driver.c
@@ -1,6 +1,7 @@
/** @file
The driver binding and service binding protocol for IP6 driver.
+ (C) Copyright 2014 - 2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
@@ -24,6 +25,75 @@ EFI_DRIVER_BINDING_PROTOCOL gIp6DriverBinding = {
NULL
};
+BOOLEAN mIpSec2Installed = FALSE;
+
+/**
+ Callback function for IpSec2 Protocol install.
+
+ @param[in] Event Event whose notification function is being invoked
+ @param[in] Context Pointer to the notification function's context
+
+ @retval EFI_SUCCESS Callback successful.
+**/
+VOID
+EFIAPI
+IpSec2InstalledCallback (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ //
+ // Close the event so it does not get called again.
+ //
+ gBS->CloseEvent (Event);
+
+ mIpSec2Installed = TRUE;
+
+ return;
+}
+
+/**
+ Register the Notification callback function for IpSec2 Protocol install.
+
+ @retval EFI_SUCCESS Successfully registered the callback function.
+ @retval other Registration was not successful.
+**/
+EFI_STATUS
+EFIAPI
+RegisterIpSec2ProtocolNotify (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ EFI_EVENT Event;
+ VOID *Registration;
+
+ //
+ // New event, to register for IpSec2 Protocol installation.
+ //
+ Status = gBS->CreateEvent (
+ EVT_NOTIFY_SIGNAL,
+ TPL_CALLBACK,
+ IpSec2InstalledCallback,
+ NULL,
+ &Event
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Ip6Dxe RegisterIpSec2ProtocolNotify: CreateEvent returned error %r\n", Status));
+ } else {
+ Status = gBS->RegisterProtocolNotify (
+ &gEfiIpSec2ProtocolGuid,
+ Event,
+ &Registration
+ );
+ if (EFI_ERROR (Status)) {
+ gBS->CloseEvent (Event);
+ }
+ }
+
+ return Status;
+}
+
/**
This is the declaration of an EFI image entry point. This entry point is
the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
@@ -46,6 +116,9 @@ Ip6DriverEntryPoint (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
+
+ RegisterIpSec2ProtocolNotify ();
+
return EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
diff --git a/NetworkPkg/Ip6Dxe/Ip6Impl.h b/NetworkPkg/Ip6Dxe/Ip6Impl.h
index 8f114bb..629d03f 100644
--- a/NetworkPkg/Ip6Dxe/Ip6Impl.h
+++ b/NetworkPkg/Ip6Dxe/Ip6Impl.h
@@ -1,6 +1,7 @@
/** @file
Implementation of EFI_IP6_PROTOCOL protocol interfaces and type definitions.
+ (C) Copyright 2014 - 2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
@@ -90,6 +91,8 @@
extern EFI_IPSEC2_PROTOCOL *mIpSec;
+extern BOOLEAN mIpSec2Installed;
+
//
// IP6_TXTOKEN_WRAP wraps the upper layer's transmit token.
// The user's data is kept in the Packet. When fragment is
diff --git a/NetworkPkg/Ip6Dxe/Ip6Input.c b/NetworkPkg/Ip6Dxe/Ip6Input.c
index cf88884..ed51859 100644
--- a/NetworkPkg/Ip6Dxe/Ip6Input.c
+++ b/NetworkPkg/Ip6Dxe/Ip6Input.c
@@ -1,6 +1,7 @@
/** @file
IP6 internal functions to process the incoming packets.
+ (C) Copyright 2014 - 2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
@@ -525,6 +526,11 @@ Ip6IpSecProcessPacket (
EFI_IP6_HEADER ZeroHead;
Status = EFI_SUCCESS;
+
+ if (!mIpSec2Installed) {
+ goto ON_EXIT;
+ }
+
Packet = *Netbuf;
RecycleEvent = NULL;
IpSecWrap = NULL;
--
1.9.5.msysgit.0