]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c
MdeModulePkg: Fix IPv4 double free
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Driver.c
index 101390cdf85270d5d733f34ca819ac8e83458e81..fb83784da96a6403487bb8637bbe384ec41d5ee8 100644 (file)
@@ -1,7 +1,9 @@
 /** @file\r
   The driver binding and service binding protocol for IP4 driver.\r
 \r
-Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2016, 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
 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
@@ -23,6 +25,30 @@ EFI_DRIVER_BINDING_PROTOCOL gIp4DriverBinding = {
   NULL\r
 };\r
 \r
+BOOLEAN  mIpSec2Installed = FALSE;\r
+\r
+/**\r
+   Callback function for IpSec2 Protocol install.\r
+\r
+   @param[in] Event           Event whose notification function is being invoked\r
+   @param[in] Context         Pointer to the notification function's context\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+IpSec2InstalledCallback (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+  //\r
+  // Close the event so it does not get called again.\r
+  //\r
+  gBS->CloseEvent (Event);\r
+\r
+  mIpSec2Installed = TRUE;\r
+}\r
+\r
 /**\r
   This is the declaration of an EFI image entry point. This entry point is\r
   the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r
@@ -45,6 +71,16 @@ Ip4DriverEntryPoint (
   IN EFI_SYSTEM_TABLE       *SystemTable\r
   )\r
 {\r
+  VOID            *Registration;\r
+\r
+  EfiCreateProtocolNotifyEvent (\r
+    &gEfiIpSec2ProtocolGuid,\r
+    TPL_CALLBACK,\r
+    IpSec2InstalledCallback,\r
+    NULL,\r
+    &Registration\r
+    );\r
+\r
   return EfiLibInstallDriverBindingComponentName2 (\r
            ImageHandle,\r
            SystemTable,\r
@@ -210,9 +246,15 @@ Ip4CreateService (
 \r
   IpSb->Timer = NULL;\r
 \r
+  IpSb->ReconfigEvent = NULL;\r
+\r
+  IpSb->Reconfig = FALSE;\r
+  \r
+  IpSb->MediaPresent = TRUE;\r
+\r
   //\r
   // Create various resources. First create the route table, timer\r
-  // event and MNP child. IGMP, interface's initialization depend\r
+  // event, ReconfigEvent and MNP child. IGMP, interface's initialization depend\r
   // on the MNP child.\r
   //\r
   IpSb->DefaultRouteTable = Ip4CreateRouteTable ();\r
@@ -234,6 +276,17 @@ Ip4CreateService (
     goto ON_ERROR;\r
   }\r
 \r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  Ip4AutoReconfigCallBack,\r
+                  IpSb,\r
+                  &IpSb->ReconfigEvent\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_ERROR;\r
+  }\r
+\r
   Status = NetLibCreateServiceChild (\r
              Controller,\r
              ImageHandle,\r
@@ -386,6 +439,14 @@ Ip4CleanService (
     IpSb->Timer = NULL;\r
   }\r
 \r
+  if (IpSb->ReconfigEvent != NULL) {\r
+    gBS->CloseEvent (IpSb->ReconfigEvent);\r
+\r
+    IpSb->ReconfigEvent = NULL;\r
+  }\r
+\r
+  IpSb->Reconfig = FALSE;\r
+\r
   if (IpSb->MacString != NULL) {\r
     FreePool (IpSb->MacString);\r
   }\r
@@ -461,6 +522,13 @@ Ip4DriverBindingStart (
 { \r
   EFI_STATUS                    Status;\r
   IP4_SERVICE                   *IpSb;\r
+  EFI_IP4_CONFIG2_PROTOCOL      *Ip4Cfg2;\r
+  UINTN                         Index;\r
+  IP4_CONFIG2_DATA_ITEM         *DataItem;\r
+\r
+  IpSb     = NULL;\r
+  Ip4Cfg2  = NULL;\r
+  DataItem = NULL;\r
 \r
   //\r
   // Test for the Ip4 service binding protocol\r
@@ -486,6 +554,8 @@ Ip4DriverBindingStart (
   \r
   ASSERT (IpSb != NULL);\r
 \r
+  Ip4Cfg2  = &IpSb->Ip4Config2Instance.Ip4Config2;\r
+\r
   //\r
   // Install the Ip4ServiceBinding Protocol onto ControlerHandle\r
   //\r
@@ -494,13 +564,40 @@ Ip4DriverBindingStart (
                   &gEfiIp4ServiceBindingProtocolGuid,\r
                   &IpSb->ServiceBinding,\r
                   &gEfiIp4Config2ProtocolGuid,\r
-                  &IpSb->Ip4Config2Instance.Ip4Config2,\r
+                  Ip4Cfg2,\r
                   NULL\r
                   );\r
 \r
   if (EFI_ERROR (Status)) {\r
     goto FREE_SERVICE;\r
   }\r
+\r
+  //\r
+  // Read the config data from NV variable again. \r
+  // The default data can be changed by other drivers.\r
+  //\r
+  Status = Ip4Config2ReadConfigData (IpSb->MacString, &IpSb->Ip4Config2Instance);\r
+  if (EFI_ERROR (Status)) {\r
+    goto UNINSTALL_PROTOCOL;\r
+  }\r
+  \r
+  //\r
+  // Consume the installed EFI_IP4_CONFIG2_PROTOCOL to set the default data items. \r
+  //\r
+  for (Index = Ip4Config2DataTypePolicy; Index < Ip4Config2DataTypeMaximum; Index++) {\r
+    DataItem = &IpSb->Ip4Config2Instance.DataItem[Index];\r
+    if (DataItem->Data.Ptr != NULL) {\r
+      Status = Ip4Cfg2->SetData (\r
+                          Ip4Cfg2,\r
+                          Index,\r
+                          DataItem->DataSize,\r
+                          DataItem->Data.Ptr\r
+                          );\r
+      if (EFI_ERROR(Status)) {\r
+        goto UNINSTALL_PROTOCOL;\r
+      }\r
+    }\r
+  }\r
  \r
   //\r
   // Ready to go: start the receiving and timer.\r