]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Change the default IPv4 config policy
authorJiaxin Wu <jiaxin.wu@intel.com>
Thu, 25 Feb 2016 02:48:58 +0000 (10:48 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Wed, 2 Mar 2016 07:43:50 +0000 (15:43 +0800)
Git version '3d0a49ad' commit provided a scenario to resolve the
performance issue for IPv4, but it's not workable for IPv6. To
avoid IPv4 and IPv6 inconsistency, we decided to revert that version
fix.

If so, the default policy for Ip4Config2 is Ip4Config2PolicyDhcp,
which results in all NIC ports attempting DHCP. So, this patch is
used to changes the the default IPv4 config policy to
Ip4Config2PolicyStatic and also defer the SetData operation after
Ip4Config2Protocol installed. This update let the other platform
drivers have chance to change the default config data by consume
Ip4Config2Protocol.

Cc: Subramanian Sriram <sriram-s@hpe.com>
Cc: El-Haj-Mahmoud Samer <samer.el-haj-mahmoud@hpe.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Subramanian Sriram <sriram-s@hpe.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.h
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c

index edbddba02118d70f8a226371232226095df61b27..1f763b6bfe0df8a62f91ffd7bcac2c376a552a76 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The implementation of EFI IPv4 Configuration II Protocol.\r
 \r
-  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
   (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
 \r
   This program and the accompanying materials\r
@@ -1144,7 +1144,9 @@ Ip4Config2SetPolicy (
   }\r
 \r
   if (NewPolicy == Instance->Policy) {\r
-     return EFI_ABORTED;\r
+    if (NewPolicy != Ip4Config2PolicyDhcp || Instance->DhcpSuccess) {\r
+      return EFI_ABORTED;\r
+    }\r
   } else {\r
     if (NewPolicy == Ip4Config2PolicyDhcp) {\r
       //\r
@@ -1908,7 +1910,7 @@ Ip4Config2InitInstance (
   DataItem->SetData  = Ip4Config2SetPolicy;\r
   DataItem->Data.Ptr = &Instance->Policy;\r
   DataItem->DataSize = sizeof (Instance->Policy);\r
-  Instance->Policy   = Ip4Config2PolicyDhcp;\r
+  Instance->Policy   = Ip4Config2PolicyStatic;\r
   SET_DATA_ATTRIB (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED);\r
 \r
   DataItem           = &Instance->DataItem[Ip4Config2DataTypeManualAddress];\r
@@ -1939,6 +1941,8 @@ Ip4Config2InitInstance (
 \r
   //\r
   // Try to read the config data from NV variable.\r
+  // If not found, write initialized config data into NV variable \r
+  // as a default config data.\r
   //\r
   Status = Ip4Config2ReadConfigData (IpSb->MacString, Instance);\r
   if (Status == EFI_NOT_FOUND) {\r
@@ -1948,21 +1952,7 @@ Ip4Config2InitInstance (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
-\r
-  //\r
-  // Try to set the configured parameter.\r
-  //\r
-  for (Index = Ip4Config2DataTypePolicy; Index < Ip4Config2DataTypeMaximum; Index++) {\r
-    DataItem = &IpSb->Ip4Config2Instance.DataItem[Index];\r
-    if (DataItem->Data.Ptr != NULL) {\r
-      DataItem->SetData (\r
-                  &IpSb->Ip4Config2Instance,\r
-                  DataItem->DataSize,\r
-                  DataItem->Data.Ptr\r
-                  );\r
-    }\r
-  }\r
-\r
+  \r
   Instance->Ip4Config2.SetData              = EfiIp4Config2SetData;\r
   Instance->Ip4Config2.GetData              = EfiIp4Config2GetData;\r
   Instance->Ip4Config2.RegisterDataNotify   = EfiIp4Config2RegisterDataNotify;\r
@@ -2029,3 +2019,53 @@ Ip4Config2CleanInstance (
   RemoveEntryList (&Instance->Link);\r
 }\r
 \r
+/**\r
+  The event handle for IP4 auto reconfiguration. The original default\r
+  interface and route table will be removed as the default.\r
+\r
+  @param[in]  Context                The IP4 service binding instance.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+Ip4AutoReconfigCallBackDpc (\r
+  IN VOID                   *Context\r
+  )\r
+{\r
+  IP4_SERVICE               *IpSb;\r
+\r
+  IpSb      = (IP4_SERVICE *) Context;\r
+  NET_CHECK_SIGNATURE (IpSb, IP4_SERVICE_SIGNATURE);\r
+\r
+  if (IpSb->State > IP4_SERVICE_UNSTARTED) {\r
+    IpSb->State = IP4_SERVICE_UNSTARTED;\r
+  }\r
+  \r
+  IpSb->Reconfig = TRUE;\r
+\r
+  Ip4StartAutoConfig (&IpSb->Ip4Config2Instance);\r
+\r
+  return ;\r
+}\r
+\r
+\r
+/**\r
+  Request Ip4AutoReconfigCallBackDpc as a DPC at TPL_CALLBACK.\r
+\r
+  @param Event     The event that is signalled.\r
+  @param Context   The IP4 service binding instance.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+Ip4AutoReconfigCallBack (\r
+  IN EFI_EVENT              Event,\r
+  IN VOID                   *Context\r
+  )\r
+{\r
+  //\r
+  // Request Ip4AutoReconfigCallBackDpc as a DPC at TPL_CALLBACK\r
+  //\r
+  QueueDpc (TPL_CALLBACK, Ip4AutoReconfigCallBackDpc, Context);\r
+}\r
+\r
index ab72525646772388e92ee05d2fce8a861b1b02e0..77bdc8dcb645ccd067726fc4edff8f2d95df3934 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Definitions for EFI IPv4 Configuration II Protocol implementation.\r
 \r
-  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
   (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
 \r
   This program and the accompanying materials\r
@@ -212,6 +212,26 @@ typedef struct {
 } IP4_CONFIG2_DHCP4_OPTION;\r
 #pragma pack()\r
 \r
+/**\r
+  Read the configuration data from variable storage according to the VarName and\r
+  gEfiIp4Config2ProtocolGuid. It checks the integrity of variable data. If the\r
+  data is corrupted, it clears the variable data to ZERO. Othewise, it outputs the\r
+  configuration data to IP4_CONFIG2_INSTANCE.\r
+\r
+  @param[in]      VarName       The pointer to the variable name\r
+  @param[in, out] Instance      The pointer to the IP4 config2 instance data.\r
+\r
+  @retval EFI_NOT_FOUND         The variable can not be found or already corrupted.\r
+  @retval EFI_OUT_OF_RESOURCES  Fail to allocate resource to complete the operation.\r
+  @retval EFI_SUCCESS           The configuration data was retrieved successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+Ip4Config2ReadConfigData (\r
+  IN     CHAR16               *VarName,\r
+  IN OUT IP4_CONFIG2_INSTANCE *Instance\r
+  );\r
+\r
 /**\r
   Start the DHCP configuration for this IP service instance.\r
   It will locates the EFI_IP4_CONFIG2_PROTOCOL, then start the\r
@@ -253,6 +273,20 @@ Ip4Config2CleanInstance (
   IN OUT IP4_CONFIG2_INSTANCE  *Instance\r
   );\r
 \r
+/**\r
+  Request Ip4AutoReconfigCallBackDpc as a DPC at TPL_CALLBACK.\r
+\r
+  @param Event     The event that is signalled.\r
+  @param Context   The IP4 service binding instance.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+Ip4AutoReconfigCallBack (\r
+  IN EFI_EVENT              Event,\r
+  IN VOID                   *Context\r
+  );\r
+\r
 /**\r
   Destroy the Dhcp4 child in IP4_CONFIG2_INSTANCE and release the resources.\r
 \r
index 3dc4d88f13b7d2bed0933b4a9be21f12f50a63ef..fb83784da96a6403487bb8637bbe384ec41d5ee8 100644 (file)
@@ -1,7 +1,7 @@
 /** @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
@@ -254,7 +254,7 @@ Ip4CreateService (
 \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
@@ -276,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
@@ -511,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
@@ -536,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
@@ -544,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
index f561af0c75a46901913343c504e3c370380cab43..313528783d7bb59d3d3fde214027188fbab349dd 100644 (file)
@@ -6,7 +6,7 @@
 #  subset of the Internet Control Message Protocol (ICMP) and may include support for\r
 #  the Internet Group Management Protocol (IGMP).\r
 #\r
-#  Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\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
index b9a294b19916dbf806469851400183bcce4e0e53..58adba7c8c158518dcaa5ff55d8378a46fc4dc28 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\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
@@ -563,57 +563,6 @@ Ip4InitProtocol (
 }\r
 \r
 \r
-/**\r
-  The event handle for IP4 auto reconfiguration. The original default\r
-  interface and route table will be removed as the default.\r
-\r
-  @param[in]  Context                The IP4 service binding instance.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-Ip4AutoReconfigCallBackDpc (\r
-  IN VOID                   *Context\r
-  )\r
-{\r
-  IP4_SERVICE               *IpSb;\r
-\r
-  IpSb      = (IP4_SERVICE *) Context;\r
-  NET_CHECK_SIGNATURE (IpSb, IP4_SERVICE_SIGNATURE);\r
-\r
-  if (IpSb->State > IP4_SERVICE_UNSTARTED) {\r
-    IpSb->State = IP4_SERVICE_UNSTARTED;\r
-  }\r
-  \r
-  IpSb->Reconfig = TRUE;\r
-\r
-  Ip4StartAutoConfig (&IpSb->Ip4Config2Instance);\r
-\r
-  return ;\r
-}\r
-\r
-\r
-/**\r
-  Request Ip4AutoReconfigCallBackDpc as a DPC at TPL_CALLBACK.\r
-\r
-  @param Event     The event that is signalled.\r
-  @param Context   The IP4 service binding instance.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-Ip4AutoReconfigCallBack (\r
-  IN EFI_EVENT              Event,\r
-  IN VOID                   *Context\r
-  )\r
-{\r
-  //\r
-  // Request Ip4AutoReconfigCallBackDpc as a DPC at TPL_CALLBACK\r
-  //\r
-  QueueDpc (TPL_CALLBACK, Ip4AutoReconfigCallBackDpc, Context);\r
-}\r
-\r
-\r
 /**\r
   Configure the IP4 child. If the child is already configured,\r
   change the configuration parameter. Otherwise configure it\r
@@ -724,32 +673,11 @@ Ip4ConfigProtocol (
 \r
   } else {\r
     //\r
-    // Use the default address. If the default configuration hasn't\r
-    // been started, start it.\r
+    // Use the default address. Check the state.\r
     //\r
     if (IpSb->State == IP4_SERVICE_UNSTARTED) {\r
-      //\r
-      // Create the ReconfigEvent to start the new configuration.\r
-      //\r
-      if (IpSb->ReconfigEvent == NULL) {\r
-        Status = gBS->CreateEvent (\r
-                        EVT_NOTIFY_SIGNAL,\r
-                        TPL_NOTIFY,\r
-                        Ip4AutoReconfigCallBack,\r
-                        IpSb,\r
-                        &IpSb->ReconfigEvent\r
-                        );\r
-\r
-        if (EFI_ERROR (Status)) {\r
-          goto ON_ERROR;\r
-        }\r
-      }\r
-      \r
-      Status = Ip4StartAutoConfig (&IpSb->Ip4Config2Instance);\r
-\r
-      if (EFI_ERROR (Status)) {\r
-        goto CLOSE_RECONFIG_EVENT;\r
-      }\r
+      Status = EFI_NO_MAPPING;\r
+      goto ON_ERROR;\r
     }\r
 \r
     IpIf = IpSb->DefaultInterface;\r
@@ -778,7 +706,7 @@ Ip4ConfigProtocol (
                     EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
                     );\r
     if (EFI_ERROR (Status)) {\r
-      goto CLOSE_RECONFIG_EVENT;\r
+      goto ON_ERROR;\r
     }\r
   }\r
   InsertTailList (&IpIf->IpInstances, &IpInstance->AddrLink);\r
@@ -797,12 +725,6 @@ Ip4ConfigProtocol (
 \r
   return EFI_SUCCESS;\r
 \r
-CLOSE_RECONFIG_EVENT:\r
-  if (IpSb->ReconfigEvent != NULL) {\r
-    gBS->CloseEvent (IpSb->ReconfigEvent);\r
-    IpSb->ReconfigEvent = NULL;\r
-  }\r
-\r
 ON_ERROR:\r
   Ip4FreeRouteTable (IpInstance->RouteTable);\r
   IpInstance->RouteTable = NULL;\r
@@ -2417,7 +2339,7 @@ Ip4TimerTicking (
   //\r
   // Media transimit Unpresent to Present means new link movement is detected.\r
   //\r
-  if (!OldMediaPresent && IpSb->MediaPresent) {\r
+  if (!OldMediaPresent && IpSb->MediaPresent && (IpSb->Ip4Config2Instance.Policy == Ip4Config2PolicyDhcp)) {\r
     //\r
     // Signal the IP4 to run the dhcp configuration again. IP4 driver will free\r
     // old IP address related resource, such as route table and Interface, then \r