]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / NetworkPkg / Ip6Dxe / Ip6ConfigImpl.c
index e309b69d775d4cdb9cdd05b94f3589d9d7cc6d72..70e232ce6c4d232a26ab4aa818286f2a8c521ee8 100644 (file)
@@ -1,21 +1,16 @@
 /** @file\r
   The implementation of EFI IPv6 Configuration Protocol.\r
 \r
-  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) Microsoft Corporation.<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
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include "Ip6Impl.h"\r
 \r
-LIST_ENTRY  mIp6ConfigInstanceList = {&mIp6ConfigInstanceList, &mIp6ConfigInstanceList};\r
+LIST_ENTRY  mIp6ConfigInstanceList = { &mIp6ConfigInstanceList, &mIp6ConfigInstanceList };\r
 \r
 /**\r
   The event process routine when the DHCPv6 service binding protocol is installed\r
@@ -47,13 +42,18 @@ Ip6ConfigOnPolicyChanged (
   IN EFI_IP6_CONFIG_POLICY  NewPolicy\r
   )\r
 {\r
-  LIST_ENTRY      *Entry;\r
-  LIST_ENTRY      *Entry2;\r
-  LIST_ENTRY      *Next;\r
-  IP6_INTERFACE   *IpIf;\r
-  IP6_DAD_ENTRY   *DadEntry;\r
-  IP6_DELAY_JOIN_LIST       *DelayNode;\r
-  \r
+  LIST_ENTRY           *Entry;\r
+  LIST_ENTRY           *Entry2;\r
+  LIST_ENTRY           *Next;\r
+  IP6_INTERFACE        *IpIf;\r
+  IP6_DAD_ENTRY        *DadEntry;\r
+  IP6_DELAY_JOIN_LIST  *DelayNode;\r
+  IP6_ADDRESS_INFO     *AddrInfo;\r
+  IP6_PROTOCOL         *Instance;\r
+  BOOLEAN              Recovery;\r
+\r
+  Recovery = FALSE;\r
+\r
   //\r
   // Currently there are only two policies: Manual and Automatic. Regardless of\r
   // what transition is going on, i.e., Manual -> Automatic and Automatic ->\r
@@ -73,25 +73,54 @@ Ip6ConfigOnPolicyChanged (
     Ip6CreatePrefixListEntry (\r
       IpSb,\r
       TRUE,\r
-      (UINT32) IP6_INFINIT_LIFETIME,\r
-      (UINT32) IP6_INFINIT_LIFETIME,\r
+      (UINT32)IP6_INFINIT_LIFETIME,\r
+      (UINT32)IP6_INFINIT_LIFETIME,\r
       IP6_LINK_LOCAL_PREFIX_LENGTH,\r
       &IpSb->LinkLocalAddr\r
       );\r
   }\r
 \r
-  //\r
-  // All IPv6 children that use global unicast address as it's source address\r
-  // should be destryoed now. The survivers are those use the link-local address\r
-  // or the unspecified address as the source address.\r
-  // TODO: Conduct a check here.\r
-  Ip6RemoveAddr (\r
-    IpSb,\r
-    &IpSb->DefaultInterface->AddressList,\r
-    &IpSb->DefaultInterface->AddressCount,\r
-    NULL,\r
-    0\r
-    );\r
+  if (!IsListEmpty (&IpSb->DefaultInterface->AddressList) && (IpSb->DefaultInterface->AddressCount > 0)) {\r
+    //\r
+    // If any IPv6 children (Instance) in configured state and use global unicast address, it will be\r
+    // destroyed in Ip6RemoveAddr() function later. Then, the upper layer driver's Stop() function will be\r
+    // called, which may break the upper layer network stacks. So, the driver should take the responsibility\r
+    // for the recovery by using ConnectController() after Ip6RemoveAddr().\r
+    // Here, just check whether need to recover the upper layer network stacks later.\r
+    //\r
+    NET_LIST_FOR_EACH (Entry, &IpSb->DefaultInterface->AddressList) {\r
+      AddrInfo = NET_LIST_USER_STRUCT_S (Entry, IP6_ADDRESS_INFO, Link, IP6_ADDR_INFO_SIGNATURE);\r
+      if (!IsListEmpty (&IpSb->Children)) {\r
+        NET_LIST_FOR_EACH (Entry2, &IpSb->Children) {\r
+          Instance = NET_LIST_USER_STRUCT_S (Entry2, IP6_PROTOCOL, Link, IP6_PROTOCOL_SIGNATURE);\r
+          if ((Instance->State == IP6_STATE_CONFIGED) && EFI_IP6_EQUAL (&Instance->ConfigData.StationAddress, &AddrInfo->Address)) {\r
+            Recovery = TRUE;\r
+            break;\r
+          }\r
+        }\r
+      }\r
+    }\r
+\r
+    //\r
+    // All IPv6 children that use global unicast address as its source address\r
+    // should be destroyed now. The survivers are those use the link-local address\r
+    // or the unspecified address as the source address.\r
+    // TODO: Conduct a check here.\r
+    Ip6RemoveAddr (\r
+      IpSb,\r
+      &IpSb->DefaultInterface->AddressList,\r
+      &IpSb->DefaultInterface->AddressCount,\r
+      NULL,\r
+      0\r
+      );\r
+\r
+    if ((IpSb->Controller != NULL) && Recovery) {\r
+      //\r
+      // ConnectController() to recover the upper layer network stacks.\r
+      //\r
+      gBS->ConnectController (IpSb->Controller, NULL, NULL, TRUE);\r
+    }\r
+  }\r
 \r
   NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {\r
     //\r
@@ -128,9 +157,8 @@ Ip6ConfigOnPolicyChanged (
     //\r
     // delay 1 second\r
     //\r
-    IpSb->Ticks                   = (UINT32) IP6_GET_TICKS (IP6_ONE_SECOND_IN_MS);\r
+    IpSb->Ticks = (UINT32)IP6_GET_TICKS (IP6_ONE_SECOND_IN_MS);\r
   }\r
-\r
 }\r
 \r
 /**\r
@@ -187,7 +215,7 @@ Ip6ConfigStartStatefulAutoConfig (
                                        &gEfiDhcp6ServiceBindingProtocolGuid,\r
                                        TPL_CALLBACK,\r
                                        Ip6ConfigOnDhcp6SbInstalled,\r
-                                       (VOID *) Instance,\r
+                                       (VOID *)Instance,\r
                                        &Instance->Registration\r
                                        );\r
     }\r
@@ -204,7 +232,7 @@ Ip6ConfigStartStatefulAutoConfig (
   Status = gBS->OpenProtocol (\r
                   Instance->Dhcp6Handle,\r
                   &gEfiDhcp6ProtocolGuid,\r
-                  (VOID **) &Instance->Dhcp6,\r
+                  (VOID **)&Instance->Dhcp6,\r
                   IpSb->Image,\r
                   IpSb->Controller,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
@@ -218,13 +246,13 @@ Ip6ConfigStartStatefulAutoConfig (
   // Set the exta options to send. Here we only want the option request option\r
   // with DNS SERVERS.\r
   //\r
-  Oro                         = (EFI_DHCP6_PACKET_OPTION *) OptBuf;\r
-  Oro->OpCode                 = HTONS (DHCP6_OPT_ORO);\r
-  Oro->OpLen                  = HTONS (2);\r
-  *((UINT16 *) &Oro->Data[0]) = HTONS (DHCP6_OPT_DNS_SERVERS);\r
-  OptList[0]                  = Oro;\r
+  Oro                        = (EFI_DHCP6_PACKET_OPTION *)OptBuf;\r
+  Oro->OpCode                = HTONS (DHCP6_OPT_ORO);\r
+  Oro->OpLen                 = HTONS (2);\r
+  *((UINT16 *)&Oro->Data[0]) = HTONS (DHCP6_OPT_DNS_SERVERS);\r
+  OptList[0]                 = Oro;\r
 \r
-  Status                      = EFI_SUCCESS;\r
+  Status = EFI_SUCCESS;\r
 \r
   if (!OtherInfoOnly) {\r
     //\r
@@ -244,13 +272,11 @@ Ip6ConfigStartStatefulAutoConfig (
     Status = Dhcp6->Configure (Dhcp6, &Dhcp6CfgData);\r
 \r
     if (!EFI_ERROR (Status)) {\r
-\r
       if (IpSb->LinkLocalOk) {\r
         Status = Dhcp6->Start (Dhcp6);\r
       } else {\r
         IpSb->Dhcp6NeedStart = TRUE;\r
       }\r
-\r
     }\r
   } else {\r
     //\r
@@ -277,7 +303,6 @@ Ip6ConfigStartStatefulAutoConfig (
     } else {\r
       IpSb->Dhcp6NeedInfoRequest = TRUE;\r
     }\r
-\r
   }\r
 \r
   return Status;\r
@@ -294,12 +319,12 @@ Ip6ConfigStartStatefulAutoConfig (
 EFI_STATUS\r
 EFIAPI\r
 Ip6ConfigSignalEvent (\r
-  IN NET_MAP                *Map,\r
-  IN NET_MAP_ITEM           *Item,\r
-  IN VOID                   *Arg\r
+  IN NET_MAP       *Map,\r
+  IN NET_MAP_ITEM  *Item,\r
+  IN VOID          *Arg\r
   )\r
 {\r
-  gBS->SignalEvent ((EFI_EVENT) Item->Key);\r
+  gBS->SignalEvent ((EFI_EVENT)Item->Key);\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -307,7 +332,7 @@ Ip6ConfigSignalEvent (
 /**\r
   Read the configuration data from variable storage according to the VarName and\r
   gEfiIp6ConfigProtocolGuid. 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
+  data is corrupted, it clears the variable data to ZERO. Otherwise, it outputs the\r
   configuration data to IP6_CONFIG_INSTANCE.\r
 \r
   @param[in]      VarName  The pointer to the variable name\r
@@ -360,26 +385,11 @@ Ip6ConfigReadConfigData (
                     &VarSize,\r
                     Variable\r
                     );\r
-    if (EFI_ERROR (Status) || (UINT16) (~NetblockChecksum ((UINT8 *) Variable, (UINT32) VarSize)) != 0) {\r
-      //\r
-      // GetVariable still error or the variable is corrupted.\r
-      // Fall back to the default value.\r
-      //\r
-      FreePool (Variable);\r
-\r
+    if (EFI_ERROR (Status) || ((UINT16)(~NetblockChecksum ((UINT8 *)Variable, (UINT32)VarSize)) != 0)) {\r
       //\r
-      // Remove the problematic variable and return EFI_NOT_FOUND, a new\r
-      // variable will be set again.\r
+      // GetVariable error or the variable is corrupted.\r
       //\r
-      gRT->SetVariable (\r
-             VarName,\r
-             &gEfiIp6ConfigProtocolGuid,\r
-             IP6_CONFIG_VARIABLE_ATTRIBUTE,\r
-             0,\r
-             NULL\r
-             );\r
-\r
-      return EFI_NOT_FOUND;\r
+      goto Error;\r
     }\r
 \r
     //\r
@@ -388,13 +398,13 @@ Ip6ConfigReadConfigData (
     Instance->IaId = Variable->IaId;\r
 \r
     for (Index = 0; Index < Variable->DataRecordCount; Index++) {\r
-\r
       CopyMem (&DataRecord, &Variable->DataRecord[Index], sizeof (DataRecord));\r
 \r
       DataItem = &Instance->DataItem[DataRecord.DataType];\r
       if (DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED) &&\r
           (DataItem->DataSize != DataRecord.DataSize)\r
-          ) {\r
+          )\r
+      {\r
         //\r
         // Perhaps a corrupted data record...\r
         //\r
@@ -404,7 +414,12 @@ Ip6ConfigReadConfigData (
       if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED)) {\r
         //\r
         // This data item has variable length data.\r
+        // Check that the length is contained within the variable before allocating.\r
         //\r
+        if (DataRecord.DataSize > VarSize - DataRecord.Offset) {\r
+          goto Error;\r
+        }\r
+\r
         DataItem->Data.Ptr = AllocatePool (DataRecord.DataSize);\r
         if (DataItem->Data.Ptr == NULL) {\r
           //\r
@@ -414,7 +429,7 @@ Ip6ConfigReadConfigData (
         }\r
       }\r
 \r
-      Data = (CHAR8 *) Variable + DataRecord.Offset;\r
+      Data = (CHAR8 *)Variable + DataRecord.Offset;\r
       CopyMem (DataItem->Data.Ptr, Data, DataRecord.DataSize);\r
 \r
       DataItem->DataSize = DataRecord.DataSize;\r
@@ -426,6 +441,28 @@ Ip6ConfigReadConfigData (
   }\r
 \r
   return Status;\r
+\r
+Error:\r
+  //\r
+  // Fall back to the default value.\r
+  //\r
+  if (Variable != NULL) {\r
+    FreePool (Variable);\r
+  }\r
+\r
+  //\r
+  // Remove the problematic variable and return EFI_NOT_FOUND, a new\r
+  // variable will be set again.\r
+  //\r
+  gRT->SetVariable (\r
+         VarName,\r
+         &gEfiIp6ConfigProtocolGuid,\r
+         IP6_CONFIG_VARIABLE_ATTRIBUTE,\r
+         0,\r
+         NULL\r
+         );\r
+\r
+  return EFI_NOT_FOUND;\r
 }\r
 \r
 /**\r
@@ -455,10 +492,8 @@ Ip6ConfigWriteConfigData (
   VarSize = sizeof (IP6_CONFIG_VARIABLE) - sizeof (IP6_CONFIG_DATA_RECORD);\r
 \r
   for (Index = 0; Index < Ip6ConfigDataTypeMaximum; Index++) {\r
-\r
     DataItem = &Instance->DataItem[Index];\r
     if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_VOLATILE) && !EFI_ERROR (DataItem->Status)) {\r
-\r
       VarSize += sizeof (IP6_CONFIG_DATA_RECORD) + DataItem->DataSize;\r
     }\r
   }\r
@@ -469,28 +504,26 @@ Ip6ConfigWriteConfigData (
   }\r
 \r
   Variable->IaId            = Instance->IaId;\r
-  Heap                      = (CHAR8 *) Variable + VarSize;\r
+  Heap                      = (CHAR8 *)Variable + VarSize;\r
   Variable->DataRecordCount = 0;\r
 \r
   for (Index = 0; Index < Ip6ConfigDataTypeMaximum; Index++) {\r
-\r
     DataItem = &Instance->DataItem[Index];\r
     if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_VOLATILE) && !EFI_ERROR (DataItem->Status)) {\r
-\r
       Heap -= DataItem->DataSize;\r
       CopyMem (Heap, DataItem->Data.Ptr, DataItem->DataSize);\r
 \r
       DataRecord           = &Variable->DataRecord[Variable->DataRecordCount];\r
-      DataRecord->DataType = (EFI_IP6_CONFIG_DATA_TYPE) Index;\r
-      DataRecord->DataSize = (UINT32) DataItem->DataSize;\r
-      DataRecord->Offset   = (UINT16) (Heap - (CHAR8 *) Variable);\r
+      DataRecord->DataType = (EFI_IP6_CONFIG_DATA_TYPE)Index;\r
+      DataRecord->DataSize = (UINT32)DataItem->DataSize;\r
+      DataRecord->Offset   = (UINT16)(Heap - (CHAR8 *)Variable);\r
 \r
       Variable->DataRecordCount++;\r
     }\r
   }\r
 \r
   Variable->Checksum = 0;\r
-  Variable->Checksum = (UINT16) ~NetblockChecksum ((UINT8 *) Variable, (UINT32) VarSize);\r
+  Variable->Checksum = (UINT16) ~NetblockChecksum ((UINT8 *)Variable, (UINT32)VarSize);\r
 \r
   Status = gRT->SetVariable (\r
                   VarName,\r
@@ -556,20 +589,20 @@ Ip6ConfigGetIfInfo (
   //\r
   // Copy the fixed size part of the interface info.\r
   //\r
-  Item = &Instance->DataItem[Ip6ConfigDataTypeInterfaceInfo];\r
-  IfInfo = (EFI_IP6_CONFIG_INTERFACE_INFO *) Data;\r
+  Item   = &Instance->DataItem[Ip6ConfigDataTypeInterfaceInfo];\r
+  IfInfo = (EFI_IP6_CONFIG_INTERFACE_INFO *)Data;\r
   CopyMem (IfInfo, Item->Data.Ptr, sizeof (EFI_IP6_CONFIG_INTERFACE_INFO));\r
 \r
   //\r
   // AddressInfo\r
   //\r
-  IfInfo->AddressInfo = (EFI_IP6_ADDRESS_INFO *) (IfInfo + 1);\r
+  IfInfo->AddressInfo = (EFI_IP6_ADDRESS_INFO *)(IfInfo + 1);\r
   Ip6BuildEfiAddressList (IpSb, &IfInfo->AddressInfoCount, &IfInfo->AddressInfo);\r
 \r
   //\r
   // RouteTable\r
   //\r
-  IfInfo->RouteTable = (EFI_IP6_ROUTE_TABLE *) (IfInfo->AddressInfo + IfInfo->AddressInfoCount);\r
+  IfInfo->RouteTable = (EFI_IP6_ROUTE_TABLE *)(IfInfo->AddressInfo + IfInfo->AddressInfoCount);\r
   Ip6BuildEfiRouteTable (IpSb->RouteTable, &IfInfo->RouteCount, &IfInfo->RouteTable);\r
 \r
   if (IfInfo->AddressInfoCount == 0) {\r
@@ -584,7 +617,7 @@ Ip6ConfigGetIfInfo (
 }\r
 \r
 /**\r
-  The work function for EfiIp6ConfigSetData() to set the alternative inteface ID\r
+  The work function for EfiIp6ConfigSetData() to set the alternative interface ID\r
   for the communication device managed by this IP6Config instance, if the link local\r
   IPv6 addresses generated from the interface ID based on the default source the\r
   EFI IPv6 Protocol uses is a duplicate address.\r
@@ -616,7 +649,7 @@ Ip6ConfigSetAltIfId (
 \r
   DataItem = &Instance->DataItem[Ip6ConfigDataTypeAltInterfaceId];\r
   OldIfId  = DataItem->Data.AltIfId;\r
-  NewIfId  = (EFI_IP6_CONFIG_INTERFACE_ID *) Data;\r
+  NewIfId  = (EFI_IP6_CONFIG_INTERFACE_ID *)Data;\r
 \r
   CopyMem (OldIfId, NewIfId, DataSize);\r
   DataItem->Status = EFI_SUCCESS;\r
@@ -655,33 +688,34 @@ Ip6ConfigSetPolicy (
     return EFI_BAD_BUFFER_SIZE;\r
   }\r
 \r
-  NewPolicy = *((EFI_IP6_CONFIG_POLICY *) Data);\r
+  NewPolicy = *((EFI_IP6_CONFIG_POLICY *)Data);\r
 \r
   if (NewPolicy > Ip6ConfigPolicyAutomatic) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   if (NewPolicy == Instance->Policy) {\r
-\r
     return EFI_ABORTED;\r
   } else {\r
     //\r
     // Clean the ManualAddress, Gateway and DnsServers, shrink the variable\r
     // data size, and fire up all the related events.\r
     //\r
-    DataItem           = &Instance->DataItem[Ip6ConfigDataTypeManualAddress];\r
+    DataItem = &Instance->DataItem[Ip6ConfigDataTypeManualAddress];\r
     if (DataItem->Data.Ptr != NULL) {\r
       FreePool (DataItem->Data.Ptr);\r
     }\r
+\r
     DataItem->Data.Ptr = NULL;\r
     DataItem->DataSize = 0;\r
     DataItem->Status   = EFI_NOT_FOUND;\r
     NetMapIterate (&DataItem->EventMap, Ip6ConfigSignalEvent, NULL);\r
 \r
-    DataItem           = &Instance->DataItem[Ip6ConfigDataTypeGateway];\r
+    DataItem = &Instance->DataItem[Ip6ConfigDataTypeGateway];\r
     if (DataItem->Data.Ptr != NULL) {\r
       FreePool (DataItem->Data.Ptr);\r
     }\r
+\r
     DataItem->Data.Ptr = NULL;\r
     DataItem->DataSize = 0;\r
     DataItem->Status   = EFI_NOT_FOUND;\r
@@ -692,7 +726,7 @@ Ip6ConfigSetPolicy (
     DataItem->DataSize = 0;\r
     DataItem->Status   = EFI_NOT_FOUND;\r
     NetMapIterate (&DataItem->EventMap, Ip6ConfigSignalEvent, NULL);\r
-    \r
+\r
     if (NewPolicy == Ip6ConfigPolicyManual) {\r
       //\r
       // The policy is changed from automatic to manual. Stop the DHCPv6 process\r
@@ -743,12 +777,10 @@ Ip6ConfigSetDadXmits (
 \r
   OldDadXmits = Instance->DataItem[Ip6ConfigDataTypeDupAddrDetectTransmits].Data.DadXmits;\r
 \r
-  if ((*(UINT32 *) Data) == OldDadXmits->DupAddrDetectTransmits) {\r
-\r
+  if ((*(UINT32 *)Data) == OldDadXmits->DupAddrDetectTransmits) {\r
     return EFI_ABORTED;\r
   } else {\r
-\r
-    OldDadXmits->DupAddrDetectTransmits = *((UINT32 *) Data);\r
+    OldDadXmits->DupAddrDetectTransmits = *((UINT32 *)Data);\r
     return EFI_SUCCESS;\r
   }\r
 }\r
@@ -756,7 +788,7 @@ Ip6ConfigSetDadXmits (
 /**\r
   The callback function for Ip6SetAddr. The prototype is defined\r
   as IP6_DAD_CALLBACK. It is called after Duplicate Address Detection is performed\r
-  for the manual address set by Ip6ConfigSetMaunualAddress.\r
+  for the manual address set by Ip6ConfigSetManualAddress.\r
 \r
   @param[in]     IsDadPassed   If TRUE, Duplicate Address Detection passed.\r
   @param[in]     TargetAddress The tentative IPv6 address to be checked.\r
@@ -779,11 +811,15 @@ Ip6ManualAddrDadCallback (
   UINTN                          DadFailCount;\r
   IP6_SERVICE                    *IpSb;\r
 \r
-  Instance   = (IP6_CONFIG_INSTANCE *) Context;\r
+  Instance = (IP6_CONFIG_INSTANCE *)Context;\r
   NET_CHECK_SIGNATURE (Instance, IP6_CONFIG_INSTANCE_SIGNATURE);\r
   Item       = &Instance->DataItem[Ip6ConfigDataTypeManualAddress];\r
   ManualAddr = NULL;\r
 \r
+  if (Item->DataSize == 0) {\r
+    return;\r
+  }\r
+\r
   for (Index = 0; Index < Item->DataSize / sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS); Index++) {\r
     //\r
     // Find the original tag used to place into the NET_MAP.\r
@@ -827,20 +863,20 @@ Ip6ManualAddrDadCallback (
         // Part of addresses are detected to be duplicates, so update the\r
         // data with those passed.\r
         //\r
-        PassedAddr = (EFI_IP6_CONFIG_MANUAL_ADDRESS *) AllocatePool (Item->DataSize);\r
+        PassedAddr = (EFI_IP6_CONFIG_MANUAL_ADDRESS *)AllocatePool (Item->DataSize);\r
         ASSERT (PassedAddr != NULL);\r
 \r
         Item->Data.Ptr = PassedAddr;\r
         Item->Status   = EFI_SUCCESS;\r
 \r
         while (!NetMapIsEmpty (&Instance->DadPassedMap)) {\r
-          ManualAddr = (EFI_IP6_CONFIG_MANUAL_ADDRESS *) NetMapRemoveHead (&Instance->DadPassedMap, NULL);\r
+          ManualAddr = (EFI_IP6_CONFIG_MANUAL_ADDRESS *)NetMapRemoveHead (&Instance->DadPassedMap, NULL);\r
           CopyMem (PassedAddr, ManualAddr, sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS));\r
 \r
           PassedAddr++;\r
         }\r
 \r
-        ASSERT ((UINTN) PassedAddr - (UINTN) Item->Data.Ptr == Item->DataSize);\r
+        ASSERT ((UINTN)PassedAddr - (UINTN)Item->Data.Ptr == Item->DataSize);\r
       }\r
     } else {\r
       //\r
@@ -883,7 +919,7 @@ Ip6ManualAddrDadCallback (
                                 under the current policy.\r
   @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.\r
   @retval EFI_OUT_OF_RESOURCES  Fail to allocate resource to complete the operation.\r
-  @retval EFI_NOT_READY         An asynchrous process is invoked to set the specified\r
+  @retval EFI_NOT_READY         An asynchronous process is invoked to set the specified\r
                                 configuration data, and the process is not finished.\r
   @retval EFI_ABORTED           The manual addresses to be set equal current\r
                                 configuration.\r
@@ -892,7 +928,7 @@ Ip6ManualAddrDadCallback (
 \r
 **/\r
 EFI_STATUS\r
-Ip6ConfigSetMaunualAddress (\r
+Ip6ConfigSetManualAddress (\r
   IN IP6_CONFIG_INSTANCE  *Instance,\r
   IN UINTN                DataSize,\r
   IN VOID                 *Data\r
@@ -915,10 +951,26 @@ Ip6ConfigSetMaunualAddress (
   IP6_PREFIX_LIST_ENTRY          *PrefixEntry;\r
   EFI_STATUS                     Status;\r
   BOOLEAN                        IsUpdated;\r
+  LIST_ENTRY                     *Next;\r
+  IP6_DAD_ENTRY                  *DadEntry;\r
+  IP6_DELAY_JOIN_LIST            *DelayNode;\r
+\r
+  NewAddress      = NULL;\r
+  TmpAddress      = NULL;\r
+  CurrentAddrInfo = NULL;\r
+  Copy            = NULL;\r
+  Entry           = NULL;\r
+  Entry2          = NULL;\r
+  IpIf            = NULL;\r
+  PrefixEntry     = NULL;\r
+  Next            = NULL;\r
+  DadEntry        = NULL;\r
+  DelayNode       = NULL;\r
+  Status          = EFI_SUCCESS;\r
 \r
   ASSERT (Instance->DataItem[Ip6ConfigDataTypeManualAddress].Status != EFI_NOT_READY);\r
 \r
-  if (((DataSize % sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS)) != 0) || (DataSize == 0)) {\r
+  if ((DataSize != 0) && ((DataSize % sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS)) != 0)) {\r
     return EFI_BAD_BUFFER_SIZE;\r
   }\r
 \r
@@ -926,239 +978,303 @@ Ip6ConfigSetMaunualAddress (
     return EFI_WRITE_PROTECTED;\r
   }\r
 \r
-  NewAddressCount = DataSize / sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS);\r
-  NewAddress      = (EFI_IP6_CONFIG_MANUAL_ADDRESS *) Data;\r
-\r
-  for (Index1 = 0; Index1 < NewAddressCount; Index1++, NewAddress++) {\r
+  IpSb = IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance);\r
 \r
-    if (NetIp6IsLinkLocalAddr (&NewAddress->Address)    ||\r
-        !NetIp6IsValidUnicast (&NewAddress->Address)    ||\r
-        (NewAddress->PrefixLength > 128)\r
-        ) {\r
-      //\r
-      // make sure the IPv6 address is unicast and not link-local address &&\r
-      // the prefix length is valid.\r
-      //\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
+  DataItem = &Instance->DataItem[Ip6ConfigDataTypeManualAddress];\r
 \r
-    TmpAddress = NewAddress + 1;\r
-    for (Index2 = Index1 + 1; Index2 < NewAddressCount; Index2++, TmpAddress++) {\r
-      //\r
-      // Any two addresses in the array can't be equal.\r
-      //\r
-      if (EFI_IP6_EQUAL (&TmpAddress->Address, &NewAddress->Address)) {\r
+  if ((Data != NULL) && (DataSize != 0)) {\r
+    NewAddressCount = DataSize / sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS);\r
+    NewAddress      = (EFI_IP6_CONFIG_MANUAL_ADDRESS *)Data;\r
 \r
+    for (Index1 = 0; Index1 < NewAddressCount; Index1++, NewAddress++) {\r
+      if (NetIp6IsLinkLocalAddr (&NewAddress->Address)    ||\r
+          !NetIp6IsValidUnicast (&NewAddress->Address)    ||\r
+          (NewAddress->PrefixLength > 128)\r
+          )\r
+      {\r
+        //\r
+        // make sure the IPv6 address is unicast and not link-local address &&\r
+        // the prefix length is valid.\r
+        //\r
         return EFI_INVALID_PARAMETER;\r
       }\r
+\r
+      TmpAddress = NewAddress + 1;\r
+      for (Index2 = Index1 + 1; Index2 < NewAddressCount; Index2++, TmpAddress++) {\r
+        //\r
+        // Any two addresses in the array can't be equal.\r
+        //\r
+        if (EFI_IP6_EQUAL (&TmpAddress->Address, &NewAddress->Address)) {\r
+          return EFI_INVALID_PARAMETER;\r
+        }\r
+      }\r
     }\r
-  }\r
 \r
-  IpSb = IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance);\r
+    //\r
+    // Build the current source address list.\r
+    //\r
+    InitializeListHead (&CurrentSourceList);\r
+    CurrentSourceCount = 0;\r
 \r
-  //\r
-  // Build the current source address list.\r
-  //\r
-  InitializeListHead (&CurrentSourceList);\r
-  CurrentSourceCount = 0;\r
+    NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {\r
+      IpIf = NET_LIST_USER_STRUCT_S (Entry, IP6_INTERFACE, Link, IP6_INTERFACE_SIGNATURE);\r
 \r
-  NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {\r
-    IpIf = NET_LIST_USER_STRUCT_S (Entry, IP6_INTERFACE, Link, IP6_INTERFACE_SIGNATURE);\r
+      NET_LIST_FOR_EACH (Entry2, &IpIf->AddressList) {\r
+        CurrentAddrInfo = NET_LIST_USER_STRUCT_S (Entry2, IP6_ADDRESS_INFO, Link, IP6_ADDR_INFO_SIGNATURE);\r
 \r
-    NET_LIST_FOR_EACH (Entry2, &IpIf->AddressList) {\r
-      CurrentAddrInfo = NET_LIST_USER_STRUCT_S (Entry2, IP6_ADDRESS_INFO, Link, IP6_ADDR_INFO_SIGNATURE);\r
+        Copy = AllocateCopyPool (sizeof (IP6_ADDRESS_INFO), CurrentAddrInfo);\r
+        if (Copy == NULL) {\r
+          break;\r
+        }\r
 \r
-      Copy            = AllocateCopyPool (sizeof (IP6_ADDRESS_INFO), CurrentAddrInfo);\r
-      if (Copy == NULL) {\r
-        break;\r
+        InsertTailList (&CurrentSourceList, &Copy->Link);\r
+        CurrentSourceCount++;\r
       }\r
+    }\r
 \r
-      InsertTailList (&CurrentSourceList, &Copy->Link);\r
-      CurrentSourceCount++;\r
+    //\r
+    // Update the value... a long journey starts\r
+    //\r
+    NewAddress = AllocateCopyPool (DataSize, Data);\r
+    if (NewAddress == NULL) {\r
+      Ip6RemoveAddr (NULL, &CurrentSourceList, &CurrentSourceCount, NULL, 0);\r
+\r
+      return EFI_OUT_OF_RESOURCES;\r
     }\r
-  }\r
 \r
-  //\r
-  // Update the value... a long journey starts\r
-  //\r
-  NewAddress = AllocateCopyPool (DataSize, Data);\r
-  if (NewAddress == NULL) {\r
-    Ip6RemoveAddr (NULL, &CurrentSourceList, &CurrentSourceCount, NULL, 0);\r
+    //\r
+    // Store the new data, and init the DataItem status to EFI_NOT_READY because\r
+    // we may have an asynchronous configuration process.\r
+    //\r
+    if (DataItem->Data.Ptr != NULL) {\r
+      FreePool (DataItem->Data.Ptr);\r
+    }\r
 \r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
+    DataItem->Data.Ptr = NewAddress;\r
+    DataItem->DataSize = DataSize;\r
+    DataItem->Status   = EFI_NOT_READY;\r
 \r
-  //\r
-  // Store the new data, and init the DataItem status to EFI_NOT_READY because\r
-  // we may have an asynchronous configuration process.\r
-  //\r
-  DataItem = &Instance->DataItem[Ip6ConfigDataTypeManualAddress];\r
-  if (DataItem->Data.Ptr != NULL) {\r
-    FreePool (DataItem->Data.Ptr);\r
-  }\r
-  DataItem->Data.Ptr = NewAddress;\r
-  DataItem->DataSize = DataSize;\r
-  DataItem->Status   = EFI_NOT_READY;\r
+    //\r
+    // Trigger DAD, it's an asynchronous process.\r
+    //\r
+    IsUpdated = FALSE;\r
 \r
-  //\r
-  // Trigger DAD, it's an asynchronous process.\r
-  //\r
-  IsUpdated  = FALSE;\r
+    for (Index1 = 0; Index1 < NewAddressCount; Index1++, NewAddress++) {\r
+      if (Ip6IsOneOfSetAddress (IpSb, &NewAddress->Address, NULL, &CurrentAddrInfo)) {\r
+        ASSERT (CurrentAddrInfo != NULL);\r
+        //\r
+        // Remove this already existing source address from the CurrentSourceList\r
+        // built before.\r
+        //\r
+        Ip6RemoveAddr (\r
+          NULL,\r
+          &CurrentSourceList,\r
+          &CurrentSourceCount,\r
+          &CurrentAddrInfo->Address,\r
+          128\r
+          );\r
 \r
-  for (Index1 = 0; Index1 < NewAddressCount; Index1++, NewAddress++) {\r
-    if (Ip6IsOneOfSetAddress (IpSb, &NewAddress->Address, NULL, &CurrentAddrInfo)) {\r
-      ASSERT (CurrentAddrInfo != NULL);\r
-      //\r
-      // Remove this already existing source address from the CurrentSourceList\r
-      // built before.\r
-      //\r
-      Ip6RemoveAddr (\r
-        NULL,\r
-        &CurrentSourceList,\r
-        &CurrentSourceCount,\r
-        &CurrentAddrInfo->Address,\r
-        128\r
-        );\r
+        //\r
+        // If the new address's prefix length is not specified, just use the previous configured\r
+        // prefix length for this address.\r
+        //\r
+        if (NewAddress->PrefixLength == 0) {\r
+          NewAddress->PrefixLength = CurrentAddrInfo->PrefixLength;\r
+        }\r
 \r
-      //\r
-      // If the new address's prefix length is not specified, just use the previous configured\r
-      // prefix length for this address.\r
-      //\r
-      if (NewAddress->PrefixLength == 0) {\r
-        NewAddress->PrefixLength = CurrentAddrInfo->PrefixLength;\r
-      }\r
+        //\r
+        // This manual address is already in use, see whether prefix length is changed.\r
+        //\r
+        if (NewAddress->PrefixLength != CurrentAddrInfo->PrefixLength) {\r
+          //\r
+          // Remove the on-link prefix table, the route entry will be removed\r
+          // implicitly.\r
+          //\r
+          PrefixEntry = Ip6FindPrefixListEntry (\r
+                          IpSb,\r
+                          TRUE,\r
+                          CurrentAddrInfo->PrefixLength,\r
+                          &CurrentAddrInfo->Address\r
+                          );\r
+          if (PrefixEntry != NULL) {\r
+            Ip6DestroyPrefixListEntry (IpSb, PrefixEntry, TRUE, FALSE);\r
+          }\r
+\r
+          //\r
+          // Save the prefix length.\r
+          //\r
+          CurrentAddrInfo->PrefixLength = NewAddress->PrefixLength;\r
+          IsUpdated                     = TRUE;\r
+        }\r
 \r
-      //\r
-      // This manual address is already in use, see whether prefix length is changed.\r
-      //\r
-      if (NewAddress->PrefixLength != CurrentAddrInfo->PrefixLength) {\r
         //\r
-        // Remove the on-link prefix table, the route entry will be removed\r
-        // implicitly.\r
+        // create a new on-link prefix entry.\r
         //\r
         PrefixEntry = Ip6FindPrefixListEntry (\r
                         IpSb,\r
                         TRUE,\r
-                        CurrentAddrInfo->PrefixLength,\r
-                        &CurrentAddrInfo->Address\r
+                        NewAddress->PrefixLength,\r
+                        &NewAddress->Address\r
                         );\r
-        if (PrefixEntry != NULL) {\r
-          Ip6DestroyPrefixListEntry (IpSb, PrefixEntry, TRUE, FALSE);\r
+        if (PrefixEntry == NULL) {\r
+          Ip6CreatePrefixListEntry (\r
+            IpSb,\r
+            TRUE,\r
+            (UINT32)IP6_INFINIT_LIFETIME,\r
+            (UINT32)IP6_INFINIT_LIFETIME,\r
+            NewAddress->PrefixLength,\r
+            &NewAddress->Address\r
+            );\r
         }\r
 \r
+        CurrentAddrInfo->IsAnycast = NewAddress->IsAnycast;\r
+        //\r
+        // Artificially mark this address passed DAD be'coz it is already in use.\r
         //\r
-        // Save the prefix length.\r
+        Ip6ManualAddrDadCallback (TRUE, &NewAddress->Address, Instance);\r
+      } else {\r
+        //\r
+        // A new address.\r
         //\r
-        CurrentAddrInfo->PrefixLength = NewAddress->PrefixLength;\r
         IsUpdated = TRUE;\r
+\r
+        //\r
+        // Set the new address, this will trigger DAD and activate the address if\r
+        // DAD succeeds.\r
+        //\r
+        Ip6SetAddress (\r
+          IpSb->DefaultInterface,\r
+          &NewAddress->Address,\r
+          NewAddress->IsAnycast,\r
+          NewAddress->PrefixLength,\r
+          (UINT32)IP6_INFINIT_LIFETIME,\r
+          (UINT32)IP6_INFINIT_LIFETIME,\r
+          Ip6ManualAddrDadCallback,\r
+          Instance\r
+          );\r
       }\r
+    }\r
+\r
+    //\r
+    // Check the CurrentSourceList, it now contains those addresses currently in\r
+    // use and will be removed.\r
+    //\r
+    IpIf = IpSb->DefaultInterface;\r
+\r
+    while (!IsListEmpty (&CurrentSourceList)) {\r
+      IsUpdated = TRUE;\r
+\r
+      CurrentAddrInfo = NET_LIST_HEAD (&CurrentSourceList, IP6_ADDRESS_INFO, Link);\r
 \r
       //\r
-      // create a new on-link prefix entry.\r
+      // This local address is going to be removed, the IP instances that are\r
+      // currently using it will be destroyed.\r
+      //\r
+      Ip6RemoveAddr (\r
+        IpSb,\r
+        &IpIf->AddressList,\r
+        &IpIf->AddressCount,\r
+        &CurrentAddrInfo->Address,\r
+        128\r
+        );\r
+\r
+      //\r
+      // Remove the on-link prefix table, the route entry will be removed\r
+      // implicitly.\r
       //\r
       PrefixEntry = Ip6FindPrefixListEntry (\r
                       IpSb,\r
                       TRUE,\r
-                      NewAddress->PrefixLength,\r
-                      &NewAddress->Address\r
+                      CurrentAddrInfo->PrefixLength,\r
+                      &CurrentAddrInfo->Address\r
                       );\r
-      if (PrefixEntry == NULL) {\r
-        Ip6CreatePrefixListEntry (\r
-          IpSb,\r
-          TRUE,\r
-          (UINT32) IP6_INFINIT_LIFETIME,\r
-          (UINT32) IP6_INFINIT_LIFETIME,\r
-          NewAddress->PrefixLength,\r
-          &NewAddress->Address\r
-          );\r
+      if (PrefixEntry != NULL) {\r
+        Ip6DestroyPrefixListEntry (IpSb, PrefixEntry, TRUE, FALSE);\r
       }\r
 \r
-      CurrentAddrInfo->IsAnycast = NewAddress->IsAnycast;\r
-      //\r
-      // Artificially mark this address passed DAD be'coz it is already in use.\r
-      //\r
-      Ip6ManualAddrDadCallback (TRUE, &NewAddress->Address, Instance);\r
-    } else {\r
-      //\r
-      // A new address.\r
-      //\r
-      IsUpdated = TRUE;\r
+      RemoveEntryList (&CurrentAddrInfo->Link);\r
+      FreePool (CurrentAddrInfo);\r
+    }\r
 \r
+    if (IsUpdated) {\r
+      if (DataItem->Status == EFI_NOT_READY) {\r
+        //\r
+        // If DAD is disabled on this interface, the configuration process is\r
+        // actually synchronous, and the data item's status will be changed to\r
+        // the final status before we reach here, just check it.\r
+        //\r
+        Status = EFI_NOT_READY;\r
+      } else {\r
+        Status = EFI_SUCCESS;\r
+      }\r
+    } else {\r
       //\r
-      // Set the new address, this will trigger DAD and activate the address if\r
-      // DAD succeeds.\r
+      // No update is taken, reset the status to success and return EFI_ABORTED.\r
       //\r
-      Ip6SetAddress (\r
-        IpSb->DefaultInterface,\r
-        &NewAddress->Address,\r
-        NewAddress->IsAnycast,\r
-        NewAddress->PrefixLength,\r
-        (UINT32) IP6_INFINIT_LIFETIME,\r
-        (UINT32) IP6_INFINIT_LIFETIME,\r
-        Ip6ManualAddrDadCallback,\r
-        Instance\r
-        );\r
+      DataItem->Status = EFI_SUCCESS;\r
+      Status           = EFI_ABORTED;\r
+    }\r
+  } else {\r
+    //\r
+    // DataSize is 0 and Data is NULL, clean up the manual address.\r
+    //\r
+    if (DataItem->Data.Ptr != NULL) {\r
+      FreePool (DataItem->Data.Ptr);\r
     }\r
-  }\r
 \r
-  //\r
-  // Check the CurrentSourceList, it now contains those addresses currently in\r
-  // use and will be removed.\r
-  //\r
-  IpIf = IpSb->DefaultInterface;\r
+    DataItem->Data.Ptr = NULL;\r
+    DataItem->DataSize = 0;\r
+    DataItem->Status   = EFI_NOT_FOUND;\r
 \r
-  while (!IsListEmpty (&CurrentSourceList)) {\r
-    IsUpdated = TRUE;\r
+    Ip6CleanDefaultRouterList (IpSb);\r
+    Ip6CleanPrefixListTable (IpSb, &IpSb->OnlinkPrefix);\r
+    Ip6CleanPrefixListTable (IpSb, &IpSb->AutonomousPrefix);\r
+    Ip6CleanAssembleTable (&IpSb->Assemble);\r
 \r
-    CurrentAddrInfo = NET_LIST_HEAD (&CurrentSourceList, IP6_ADDRESS_INFO, Link);\r
+    if (IpSb->LinkLocalOk) {\r
+      Ip6CreatePrefixListEntry (\r
+        IpSb,\r
+        TRUE,\r
+        (UINT32)IP6_INFINIT_LIFETIME,\r
+        (UINT32)IP6_INFINIT_LIFETIME,\r
+        IP6_LINK_LOCAL_PREFIX_LENGTH,\r
+        &IpSb->LinkLocalAddr\r
+        );\r
+    }\r
 \r
-    //\r
-    // This local address is going to be removed, the IP instances that are\r
-    // currently using it will be destroyed.\r
-    //\r
     Ip6RemoveAddr (\r
       IpSb,\r
-      &IpIf->AddressList,\r
-      &IpIf->AddressCount,\r
-      &CurrentAddrInfo->Address,\r
-      128\r
+      &IpSb->DefaultInterface->AddressList,\r
+      &IpSb->DefaultInterface->AddressCount,\r
+      NULL,\r
+      0\r
       );\r
 \r
-    //\r
-    // Remove the on-link prefix table, the route entry will be removed\r
-    // implicitly.\r
-    //\r
-    PrefixEntry = Ip6FindPrefixListEntry (\r
-                    IpSb,\r
-                    TRUE,\r
-                    CurrentAddrInfo->PrefixLength,\r
-                    &CurrentAddrInfo->Address\r
-                    );\r
-    if (PrefixEntry != NULL) {\r
-      Ip6DestroyPrefixListEntry (IpSb, PrefixEntry, TRUE, FALSE);\r
-    }\r
-\r
-    RemoveEntryList (&CurrentAddrInfo->Link);\r
-    FreePool (CurrentAddrInfo);\r
-  }\r
-\r
-  if (IsUpdated) {\r
-    if (DataItem->Status == EFI_NOT_READY) {\r
+    NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {\r
       //\r
-      // If DAD is disabled on this interface, the configuration process is\r
-      // actually synchronous, and the data item's status will be changed to\r
-      // the final status before we reach here, just check it.\r
+      // Remove all pending delay node and DAD entries for the global addresses.\r
       //\r
-      Status = EFI_NOT_READY;\r
-    } else {\r
-      Status = EFI_SUCCESS;\r
+      IpIf = NET_LIST_USER_STRUCT_S (Entry, IP6_INTERFACE, Link, IP6_INTERFACE_SIGNATURE);\r
+\r
+      NET_LIST_FOR_EACH_SAFE (Entry2, Next, &IpIf->DelayJoinList) {\r
+        DelayNode = NET_LIST_USER_STRUCT (Entry2, IP6_DELAY_JOIN_LIST, Link);\r
+        if (!NetIp6IsLinkLocalAddr (&DelayNode->AddressInfo->Address)) {\r
+          RemoveEntryList (&DelayNode->Link);\r
+          FreePool (DelayNode);\r
+        }\r
+      }\r
+\r
+      NET_LIST_FOR_EACH_SAFE (Entry2, Next, &IpIf->DupAddrDetectList) {\r
+        DadEntry = NET_LIST_USER_STRUCT_S (Entry2, IP6_DAD_ENTRY, Link, IP6_DAD_ENTRY_SIGNATURE);\r
+\r
+        if (!NetIp6IsLinkLocalAddr (&DadEntry->AddressInfo->Address)) {\r
+          //\r
+          // Fail this DAD entry if the address is not link-local.\r
+          //\r
+          Ip6OnDADFinished (FALSE, IpIf, DadEntry);\r
+        }\r
+      }\r
     }\r
-  } else {\r
-    //\r
-    // No update is taken, reset the status to success and return EFI_ABORTED.\r
-    //\r
-    DataItem->Status = EFI_SUCCESS;\r
-    Status           = EFI_ABORTED;\r
   }\r
 \r
   return Status;\r
@@ -1206,7 +1322,15 @@ Ip6ConfigSetGateway (
   IP6_DEFAULT_ROUTER    *DefaultRouter;\r
   VOID                  *Tmp;\r
 \r
-  if ((DataSize % sizeof (EFI_IPv6_ADDRESS) != 0) || (DataSize == 0)) {\r
+  OldGateway    = NULL;\r
+  NewGateway    = NULL;\r
+  Item          = NULL;\r
+  DefaultRouter = NULL;\r
+  Tmp           = NULL;\r
+  OneRemoved    = FALSE;\r
+  OneAdded      = FALSE;\r
+\r
+  if ((DataSize != 0) && (DataSize % sizeof (EFI_IPv6_ADDRESS) != 0)) {\r
     return EFI_BAD_BUFFER_SIZE;\r
   }\r
 \r
@@ -1214,86 +1338,85 @@ Ip6ConfigSetGateway (
     return EFI_WRITE_PROTECTED;\r
   }\r
 \r
-  NewGateway      = (EFI_IPv6_ADDRESS *) Data;\r
-  NewGatewayCount = DataSize / sizeof (EFI_IPv6_ADDRESS);\r
-  for (Index1 = 0; Index1 < NewGatewayCount; Index1++) {\r
-\r
-    if (!NetIp6IsValidUnicast (NewGateway + Index1)) {\r
-\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
-\r
-    for (Index2 = Index1 + 1; Index2 < NewGatewayCount; Index2++) {\r
-      if (EFI_IP6_EQUAL (NewGateway + Index1, NewGateway + Index2)) {\r
-        return EFI_INVALID_PARAMETER;\r
-      }\r
-    }\r
-  }\r
-\r
   IpSb            = IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance);\r
   Item            = &Instance->DataItem[Ip6ConfigDataTypeGateway];\r
   OldGateway      = Item->Data.Gateway;\r
   OldGatewayCount = Item->DataSize / sizeof (EFI_IPv6_ADDRESS);\r
-  OneRemoved      = FALSE;\r
-  OneAdded        = FALSE;\r
-\r
-  if (NewGatewayCount != OldGatewayCount) {\r
-    Tmp = AllocatePool (DataSize);\r
-    if (Tmp == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-  } else {\r
-    Tmp = NULL;\r
-  }\r
 \r
   for (Index1 = 0; Index1 < OldGatewayCount; Index1++) {\r
     //\r
-    // Find the gateways that are no long in the new setting and remove them.\r
+    // Remove this default router.\r
     //\r
-    for (Index2 = 0; Index2 < NewGatewayCount; Index2++) {\r
-      if (EFI_IP6_EQUAL (OldGateway + Index1, NewGateway + Index2)) {\r
-        OneRemoved = TRUE;\r
-        break;\r
-      }\r
+    DefaultRouter = Ip6FindDefaultRouter (IpSb, OldGateway + Index1);\r
+    if (DefaultRouter != NULL) {\r
+      Ip6DestroyDefaultRouter (IpSb, DefaultRouter);\r
+      OneRemoved = TRUE;\r
     }\r
+  }\r
 \r
-    if (Index2 == NewGatewayCount) {\r
-      //\r
-      // Remove this default router.\r
-      //\r
-      DefaultRouter = Ip6FindDefaultRouter (IpSb, OldGateway + Index1);\r
-      if (DefaultRouter != NULL) {\r
-        Ip6DestroyDefaultRouter (IpSb, DefaultRouter);\r
+  if ((Data != NULL) && (DataSize != 0)) {\r
+    NewGateway      = (EFI_IPv6_ADDRESS *)Data;\r
+    NewGatewayCount = DataSize / sizeof (EFI_IPv6_ADDRESS);\r
+    for (Index1 = 0; Index1 < NewGatewayCount; Index1++) {\r
+      if (!NetIp6IsValidUnicast (NewGateway + Index1)) {\r
+        return EFI_INVALID_PARAMETER;\r
+      }\r
+\r
+      for (Index2 = Index1 + 1; Index2 < NewGatewayCount; Index2++) {\r
+        if (EFI_IP6_EQUAL (NewGateway + Index1, NewGateway + Index2)) {\r
+          return EFI_INVALID_PARAMETER;\r
+        }\r
       }\r
     }\r
-  }\r
 \r
-  for (Index1 = 0; Index1 < NewGatewayCount; Index1++) {\r
+    if (NewGatewayCount != OldGatewayCount) {\r
+      Tmp = AllocatePool (DataSize);\r
+      if (Tmp == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+    } else {\r
+      Tmp = NULL;\r
+    }\r
 \r
-    DefaultRouter = Ip6FindDefaultRouter (IpSb, NewGateway + Index1);\r
-    if (DefaultRouter == NULL) {\r
-      Ip6CreateDefaultRouter (IpSb, NewGateway + Index1, IP6_INF_ROUTER_LIFETIME);\r
-      OneAdded = TRUE;\r
+    for (Index1 = 0; Index1 < NewGatewayCount; Index1++) {\r
+      DefaultRouter = Ip6FindDefaultRouter (IpSb, NewGateway + Index1);\r
+      if (DefaultRouter == NULL) {\r
+        Ip6CreateDefaultRouter (IpSb, NewGateway + Index1, IP6_INF_ROUTER_LIFETIME);\r
+        OneAdded = TRUE;\r
+      }\r
     }\r
-  }\r
 \r
-  if (!OneRemoved && !OneAdded) {\r
-    Item->Status = EFI_SUCCESS;\r
-    return EFI_ABORTED;\r
-  } else {\r
+    if (!OneRemoved && !OneAdded) {\r
+      Item->Status = EFI_SUCCESS;\r
+      return EFI_ABORTED;\r
+    } else {\r
+      if (Tmp != NULL) {\r
+        if (Item->Data.Ptr != NULL) {\r
+          FreePool (Item->Data.Ptr);\r
+        }\r
 \r
-    if (Tmp != NULL) {\r
-      if (Item->Data.Ptr != NULL) {\r
-        FreePool (Item->Data.Ptr);\r
+        Item->Data.Ptr = Tmp;\r
       }\r
-      Item->Data.Ptr = Tmp;\r
+\r
+      CopyMem (Item->Data.Ptr, Data, DataSize);\r
+      Item->DataSize = DataSize;\r
+      Item->Status   = EFI_SUCCESS;\r
+      return EFI_SUCCESS;\r
+    }\r
+  } else {\r
+    //\r
+    // DataSize is 0 and Data is NULL, clean up the Gateway address.\r
+    //\r
+    if (Item->Data.Ptr != NULL) {\r
+      FreePool (Item->Data.Ptr);\r
     }\r
 \r
-    CopyMem (Item->Data.Ptr, Data, DataSize);\r
-    Item->DataSize = DataSize;\r
-    Item->Status   = EFI_SUCCESS;\r
-    return EFI_SUCCESS;\r
+    Item->Data.Ptr = NULL;\r
+    Item->DataSize = 0;\r
+    Item->Status   = EFI_NOT_FOUND;\r
   }\r
+\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -1327,7 +1450,6 @@ Ip6ConfigSetDnsServer (
 {\r
   UINTN                 OldIndex;\r
   UINTN                 NewIndex;\r
-  UINTN                 Index1;\r
   EFI_IPv6_ADDRESS      *OldDns;\r
   EFI_IPv6_ADDRESS      *NewDns;\r
   UINTN                 OldDnsCount;\r
@@ -1336,7 +1458,12 @@ Ip6ConfigSetDnsServer (
   BOOLEAN               OneAdded;\r
   VOID                  *Tmp;\r
 \r
-  if ((DataSize % sizeof (EFI_IPv6_ADDRESS) != 0) || (DataSize == 0)) {\r
+  OldDns = NULL;\r
+  NewDns = NULL;\r
+  Item   = NULL;\r
+  Tmp    = NULL;\r
+\r
+  if ((DataSize != 0) && (DataSize % sizeof (EFI_IPv6_ADDRESS) != 0)) {\r
     return EFI_BAD_BUFFER_SIZE;\r
   }\r
 \r
@@ -1344,84 +1471,91 @@ Ip6ConfigSetDnsServer (
     return EFI_WRITE_PROTECTED;\r
   }\r
 \r
-  Item        = &Instance->DataItem[Ip6ConfigDataTypeDnsServer];\r
-  NewDns      = (EFI_IPv6_ADDRESS *) Data;\r
-  OldDns      = Item->Data.DnsServers;\r
-  NewDnsCount = DataSize / sizeof (EFI_IPv6_ADDRESS);\r
-  OldDnsCount = Item->DataSize / sizeof (EFI_IPv6_ADDRESS);\r
-  OneAdded    = FALSE;\r
+  Item = &Instance->DataItem[Ip6ConfigDataTypeDnsServer];\r
 \r
-  if (NewDnsCount != OldDnsCount) {\r
-    Tmp = AllocatePool (DataSize);\r
-    if (Tmp == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-  } else {\r
-    Tmp = NULL;\r
-  }\r
+  if ((Data != NULL) && (DataSize != 0)) {\r
+    NewDns      = (EFI_IPv6_ADDRESS *)Data;\r
+    OldDns      = Item->Data.DnsServers;\r
+    NewDnsCount = DataSize / sizeof (EFI_IPv6_ADDRESS);\r
+    OldDnsCount = Item->DataSize / sizeof (EFI_IPv6_ADDRESS);\r
+    OneAdded    = FALSE;\r
 \r
-  for (NewIndex = 0; NewIndex < NewDnsCount; NewIndex++) {\r
-\r
-    if (!NetIp6IsValidUnicast (NewDns + NewIndex)) {\r
-      //\r
-      // The dns server address must be unicast.\r
-      //\r
-      if (Tmp != NULL) {\r
-        FreePool (Tmp);\r
+    if (NewDnsCount != OldDnsCount) {\r
+      Tmp = AllocatePool (DataSize);\r
+      if (Tmp == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
       }\r
-      return EFI_INVALID_PARAMETER;\r
+    } else {\r
+      Tmp = NULL;\r
     }\r
 \r
-    for (Index1 = NewIndex + 1; Index1 < NewDnsCount; Index1++) {\r
-      if (EFI_IP6_EQUAL (NewDns + NewIndex, NewDns + Index1)) {\r
+    for (NewIndex = 0; NewIndex < NewDnsCount; NewIndex++) {\r
+      if (!NetIp6IsValidUnicast (NewDns + NewIndex)) {\r
+        //\r
+        // The dns server address must be unicast.\r
+        //\r
         if (Tmp != NULL) {\r
           FreePool (Tmp);\r
         }\r
+\r
         return EFI_INVALID_PARAMETER;\r
       }\r
+\r
+      if (OneAdded) {\r
+        //\r
+        // If any address in the new setting is not in the old settings, skip the\r
+        // comparision below.\r
+        //\r
+        continue;\r
+      }\r
+\r
+      for (OldIndex = 0; OldIndex < OldDnsCount; OldIndex++) {\r
+        if (EFI_IP6_EQUAL (NewDns + NewIndex, OldDns + OldIndex)) {\r
+          //\r
+          // If found break out.\r
+          //\r
+          break;\r
+        }\r
+      }\r
+\r
+      if (OldIndex == OldDnsCount) {\r
+        OneAdded = TRUE;\r
+      }\r
     }\r
 \r
-    if (OneAdded) {\r
+    if (!OneAdded && (DataSize == Item->DataSize)) {\r
       //\r
-      // If any address in the new setting is not in the old settings, skip the\r
-      // comparision below.\r
+      // No new item is added and the size is the same.\r
       //\r
-      continue;\r
-    }\r
+      Item->Status = EFI_SUCCESS;\r
+      return EFI_ABORTED;\r
+    } else {\r
+      if (Tmp != NULL) {\r
+        if (Item->Data.Ptr != NULL) {\r
+          FreePool (Item->Data.Ptr);\r
+        }\r
 \r
-    for (OldIndex = 0; OldIndex < OldDnsCount; OldIndex++) {\r
-      if (EFI_IP6_EQUAL (NewDns + NewIndex, OldDns + OldIndex)) {\r
-        //\r
-        // If found break out.\r
-        //\r
-        break;\r
+        Item->Data.Ptr = Tmp;\r
       }\r
-    }\r
 \r
-    if (OldIndex == OldDnsCount) {\r
-      OneAdded = TRUE;\r
+      CopyMem (Item->Data.Ptr, Data, DataSize);\r
+      Item->DataSize = DataSize;\r
+      Item->Status   = EFI_SUCCESS;\r
     }\r
-  }\r
-\r
-  if (!OneAdded && (DataSize == Item->DataSize)) {\r
+  } else {\r
     //\r
-    // No new item is added and the size is the same.\r
+    // DataSize is 0 and Data is NULL, clean up the DnsServer address.\r
     //\r
-    Item->Status = EFI_SUCCESS;\r
-    return EFI_ABORTED;\r
-  } else {\r
-    if (Tmp != NULL) {\r
-      if (Item->Data.Ptr != NULL) {\r
-        FreePool (Item->Data.Ptr);\r
-      }\r
-      Item->Data.Ptr = Tmp;\r
+    if (Item->Data.Ptr != NULL) {\r
+      FreePool (Item->Data.Ptr);\r
     }\r
 \r
-    CopyMem (Item->Data.Ptr, Data, DataSize);\r
-    Item->DataSize = DataSize;\r
-    Item->Status   = EFI_SUCCESS;\r
-    return EFI_SUCCESS;\r
+    Item->Data.Ptr = NULL;\r
+    Item->DataSize = 0;\r
+    Item->Status   = EFI_NOT_FOUND;\r
   }\r
+\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -1441,9 +1575,9 @@ Ip6ConfigInitIfInfo (
   UnicodeSPrint (\r
     IfInfo->Name,\r
     sizeof (IfInfo->Name),\r
-    L"eth%x",\r
+    L"eth%d",\r
     IpSb->Ip6ConfigInstance.IfIndex\r
-  );\r
+    );\r
 \r
   IfInfo->IfType        = IpSb->SnpMode.IfType;\r
   IfInfo->HwAddressSize = IpSb->SnpMode.HwAddressSize;\r
@@ -1465,9 +1599,9 @@ Ip6ConfigInitIfInfo (
 **/\r
 EFI_STATUS\r
 Ip6ConfigParseDhcpReply (\r
-  IN     EFI_DHCP6_PROTOCOL  *Dhcp6,\r
-  IN OUT IP6_CONFIG_INSTANCE *Instance,\r
-  IN     EFI_DHCP6_PACKET    *Reply\r
+  IN     EFI_DHCP6_PROTOCOL   *Dhcp6,\r
+  IN OUT IP6_CONFIG_INSTANCE  *Instance,\r
+  IN     EFI_DHCP6_PACKET     *Reply\r
   )\r
 {\r
   EFI_STATUS               Status;\r
@@ -1527,7 +1661,7 @@ Ip6ConfigParseDhcpReply (
       //\r
       // Validate the DnsServers: whether they are unicast addresses.\r
       //\r
-      DnsServer = (EFI_IPv6_ADDRESS *) OptList[Index]->Data;\r
+      DnsServer = (EFI_IPv6_ADDRESS *)OptList[Index]->Data;\r
       for (Index2 = 0; Index2 < Length / sizeof (EFI_IPv6_ADDRESS); Index2++) {\r
         if (!NetIp6IsValidUnicast (DnsServer)) {\r
           Status = EFI_NOT_READY;\r
@@ -1586,7 +1720,7 @@ Ip6ConfigSetStatefulAddrCallback (
 {\r
   IP6_CONFIG_INSTANCE  *Instance;\r
 \r
-  Instance = (IP6_CONFIG_INSTANCE *) Context;\r
+  Instance = (IP6_CONFIG_INSTANCE *)Context;\r
   NET_CHECK_SIGNATURE (Instance, IP6_CONFIG_INSTANCE_SIGNATURE);\r
 \r
   //\r
@@ -1627,6 +1761,7 @@ Ip6ConfigSetStatefulAddrCallback (
     if (Instance->DeclineAddress != NULL) {\r
       FreePool (Instance->DeclineAddress);\r
     }\r
+\r
     Instance->DeclineAddress      = NULL;\r
     Instance->DeclineAddressCount = 0;\r
   }\r
@@ -1646,25 +1781,25 @@ Ip6ConfigOnDhcp6Event (
   IN VOID       *Context\r
   )\r
 {\r
-  IP6_CONFIG_INSTANCE      *Instance;\r
-  EFI_DHCP6_PROTOCOL       *Dhcp6;\r
-  EFI_STATUS               Status;\r
-  EFI_DHCP6_MODE_DATA      Dhcp6ModeData;\r
-  EFI_DHCP6_IA             *Ia;\r
-  EFI_DHCP6_IA_ADDRESS     *IaAddr;\r
-  UINT32                   Index;\r
-  IP6_SERVICE              *IpSb;\r
-  IP6_ADDRESS_INFO         *AddrInfo;\r
-  IP6_INTERFACE            *IpIf;\r
+  IP6_CONFIG_INSTANCE   *Instance;\r
+  EFI_DHCP6_PROTOCOL    *Dhcp6;\r
+  EFI_STATUS            Status;\r
+  EFI_DHCP6_MODE_DATA   Dhcp6ModeData;\r
+  EFI_DHCP6_IA          *Ia;\r
+  EFI_DHCP6_IA_ADDRESS  *IaAddr;\r
+  UINT32                Index;\r
+  IP6_SERVICE           *IpSb;\r
+  IP6_ADDRESS_INFO      *AddrInfo;\r
+  IP6_INTERFACE         *IpIf;\r
 \r
-  Instance = (IP6_CONFIG_INSTANCE *) Context;\r
+  Instance = (IP6_CONFIG_INSTANCE *)Context;\r
 \r
   if ((Instance->Policy != Ip6ConfigPolicyAutomatic) || Instance->OtherInfoOnly) {\r
     //\r
     // IPv6 is not operating in the automatic policy now or\r
     // the DHCPv6 information request message exchange is aborted.\r
     //\r
-    return ;\r
+    return;\r
   }\r
 \r
   //\r
@@ -1674,7 +1809,7 @@ Ip6ConfigOnDhcp6Event (
 \r
   Status = Dhcp6->GetModeData (Dhcp6, &Dhcp6ModeData, NULL);\r
   if (EFI_ERROR (Status)) {\r
-    return ;\r
+    return;\r
   }\r
 \r
   IpSb   = IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance);\r
@@ -1686,16 +1821,16 @@ Ip6ConfigOnDhcp6Event (
     FreePool (Instance->DeclineAddress);\r
   }\r
 \r
-  Instance->DeclineAddress = (EFI_IPv6_ADDRESS *) AllocatePool (Ia->IaAddressCount * sizeof (EFI_IPv6_ADDRESS));\r
+  Instance->DeclineAddress = (EFI_IPv6_ADDRESS *)AllocatePool (Ia->IaAddressCount * sizeof (EFI_IPv6_ADDRESS));\r
   if (Instance->DeclineAddress == NULL) {\r
     goto ON_EXIT;\r
   }\r
 \r
   Instance->FailedIaAddressCount = Ia->IaAddressCount;\r
-  Instance->DeclineAddressCount   = 0;\r
+  Instance->DeclineAddressCount  = 0;\r
 \r
   for (Index = 0; Index < Ia->IaAddressCount; Index++, IaAddr++) {\r
-    if (Ia->IaAddress[Index].ValidLifetime != 0 && Ia->State == Dhcp6Bound) {\r
+    if ((Ia->IaAddress[Index].ValidLifetime != 0) && (Ia->State == Dhcp6Bound)) {\r
       //\r
       // Set this address, either it's a new address or with updated lifetimes.\r
       // An appropriate prefix length will be set.\r
@@ -1766,7 +1901,7 @@ Ip6ConfigOnDhcp6Reply (
   IN EFI_DHCP6_PACKET    *Packet\r
   )\r
 {\r
-  return Ip6ConfigParseDhcpReply (This, (IP6_CONFIG_INSTANCE *) Context, Packet);\r
+  return Ip6ConfigParseDhcpReply (This, (IP6_CONFIG_INSTANCE *)Context, Packet);\r
 }\r
 \r
 /**\r
@@ -1786,13 +1921,13 @@ Ip6ConfigOnDhcp6SbInstalled (
 {\r
   IP6_CONFIG_INSTANCE  *Instance;\r
 \r
-  Instance = (IP6_CONFIG_INSTANCE *) Context;\r
+  Instance = (IP6_CONFIG_INSTANCE *)Context;\r
 \r
   if ((Instance->Dhcp6Handle != NULL) || (Instance->Policy != Ip6ConfigPolicyAutomatic)) {\r
     //\r
     // The DHCP6 child is already created or the policy is no longer AUTOMATIC.\r
     //\r
-    return ;\r
+    return;\r
   }\r
 \r
   Ip6ConfigStartStatefulAutoConfig (Instance, Instance->OtherInfoOnly);\r
@@ -1830,9 +1965,8 @@ Ip6ConfigOnDhcp6SbInstalled (
                                 network stack was set successfully.\r
   @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:\r
                                 - This is NULL.\r
-                                - Data is NULL.\r
-                                - One or more fields in Data do not match the requirement of the\r
-                                  data type indicated by DataType.\r
+                                - One or more fields in Data and DataSizedo not match the\r
+                                  requirement of the data type indicated by DataType.\r
   @retval EFI_WRITE_PROTECTED   The specified configuration data is read-only or the specified\r
                                 configuration data cannot be set under the current policy.\r
   @retval EFI_ACCESS_DENIED     Another set operation on the specified configuration\r
@@ -1849,10 +1983,10 @@ Ip6ConfigOnDhcp6SbInstalled (
 EFI_STATUS\r
 EFIAPI\r
 EfiIp6ConfigSetData (\r
-  IN EFI_IP6_CONFIG_PROTOCOL    *This,\r
-  IN EFI_IP6_CONFIG_DATA_TYPE   DataType,\r
-  IN UINTN                      DataSize,\r
-  IN VOID                       *Data\r
+  IN EFI_IP6_CONFIG_PROTOCOL   *This,\r
+  IN EFI_IP6_CONFIG_DATA_TYPE  DataType,\r
+  IN UINTN                     DataSize,\r
+  IN VOID                      *Data\r
   )\r
 {\r
   EFI_TPL              OldTpl;\r
@@ -1860,7 +1994,7 @@ EfiIp6ConfigSetData (
   IP6_CONFIG_INSTANCE  *Instance;\r
   IP6_SERVICE          *IpSb;\r
 \r
-  if ((This == NULL) || (Data == NULL)) {\r
+  if ((This == NULL) || ((Data == NULL) && (DataSize != 0)) || ((Data != NULL) && (DataSize == 0))) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -1880,14 +2014,12 @@ EfiIp6ConfigSetData (
 \r
   Status = Instance->DataItem[DataType].Status;\r
   if (Status != EFI_NOT_READY) {\r
-\r
     if (Instance->DataItem[DataType].SetData == NULL) {\r
       //\r
       // This type of data is readonly.\r
       //\r
       Status = EFI_WRITE_PROTECTED;\r
     } else {\r
-\r
       Status = Instance->DataItem[DataType].SetData (Instance, DataSize, Data);\r
       if (!EFI_ERROR (Status)) {\r
         //\r
@@ -1906,7 +2038,7 @@ EfiIp6ConfigSetData (
     }\r
   } else {\r
     //\r
-    // Another asynchornous process is on the way.\r
+    // Another asynchronous process is on the way.\r
     //\r
     Status = EFI_ACCESS_DENIED;\r
   }\r
@@ -1957,10 +2089,10 @@ EfiIp6ConfigSetData (
 EFI_STATUS\r
 EFIAPI\r
 EfiIp6ConfigGetData (\r
-  IN EFI_IP6_CONFIG_PROTOCOL    *This,\r
-  IN EFI_IP6_CONFIG_DATA_TYPE   DataType,\r
-  IN OUT UINTN                  *DataSize,\r
-  IN VOID                       *Data   OPTIONAL\r
+  IN EFI_IP6_CONFIG_PROTOCOL   *This,\r
+  IN EFI_IP6_CONFIG_DATA_TYPE  DataType,\r
+  IN OUT UINTN                 *DataSize,\r
+  IN VOID                      *Data   OPTIONAL\r
   )\r
 {\r
   EFI_TPL               OldTpl;\r
@@ -1981,11 +2113,9 @@ EfiIp6ConfigGetData (
   Instance = IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This);\r
   DataItem = &Instance->DataItem[DataType];\r
 \r
-  Status   = Instance->DataItem[DataType].Status;\r
+  Status = Instance->DataItem[DataType].Status;\r
   if (!EFI_ERROR (Status)) {\r
-\r
     if (DataItem->GetData != NULL) {\r
-\r
       Status = DataItem->GetData (Instance, DataSize, Data);\r
     } else if (*DataSize < Instance->DataItem[DataType].DataSize) {\r
       //\r
@@ -1994,7 +2124,6 @@ EfiIp6ConfigGetData (
       *DataSize = Instance->DataItem[DataType].DataSize;\r
       Status    = EFI_BUFFER_TOO_SMALL;\r
     } else {\r
-\r
       *DataSize = Instance->DataItem[DataType].DataSize;\r
       CopyMem (Data, Instance->DataItem[DataType].Data.Ptr, *DataSize);\r
     }\r
@@ -2030,9 +2159,9 @@ EfiIp6ConfigGetData (
 EFI_STATUS\r
 EFIAPI\r
 EfiIp6ConfigRegisterDataNotify (\r
-  IN EFI_IP6_CONFIG_PROTOCOL    *This,\r
-  IN EFI_IP6_CONFIG_DATA_TYPE   DataType,\r
-  IN EFI_EVENT                  Event\r
+  IN EFI_IP6_CONFIG_PROTOCOL   *This,\r
+  IN EFI_IP6_CONFIG_DATA_TYPE  DataType,\r
+  IN EFI_EVENT                 Event\r
   )\r
 {\r
   EFI_TPL              OldTpl;\r
@@ -2049,26 +2178,22 @@ EfiIp6ConfigRegisterDataNotify (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  OldTpl    = gBS->RaiseTPL (TPL_CALLBACK);\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
-  Instance  = IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This);\r
-  EventMap  = &Instance->DataItem[DataType].EventMap;\r
+  Instance = IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This);\r
+  EventMap = &Instance->DataItem[DataType].EventMap;\r
 \r
   //\r
   // Check whether this event is already registered for this DataType.\r
   //\r
   Item = NetMapFindKey (EventMap, Event);\r
   if (Item == NULL) {\r
-\r
     Status = NetMapInsertTail (EventMap, Event, NULL);\r
 \r
     if (EFI_ERROR (Status)) {\r
-\r
       Status = EFI_OUT_OF_RESOURCES;\r
     }\r
-\r
   } else {\r
-\r
     Status = EFI_ACCESS_DENIED;\r
   }\r
 \r
@@ -2095,9 +2220,9 @@ EfiIp6ConfigRegisterDataNotify (
 EFI_STATUS\r
 EFIAPI\r
 EfiIp6ConfigUnregisterDataNotify (\r
-  IN EFI_IP6_CONFIG_PROTOCOL    *This,\r
-  IN EFI_IP6_CONFIG_DATA_TYPE   DataType,\r
-  IN EFI_EVENT                  Event\r
+  IN EFI_IP6_CONFIG_PROTOCOL   *This,\r
+  IN EFI_IP6_CONFIG_DATA_TYPE  DataType,\r
+  IN EFI_EVENT                 Event\r
   )\r
 {\r
   EFI_TPL              OldTpl;\r
@@ -2119,11 +2244,9 @@ EfiIp6ConfigUnregisterDataNotify (
 \r
   Item = NetMapFindKey (&Instance->DataItem[DataType].EventMap, Event);\r
   if (Item != NULL) {\r
-\r
     NetMapRemoveItem (&Instance->DataItem[DataType].EventMap, Item, NULL);\r
     Status = EFI_SUCCESS;\r
   } else {\r
-\r
     Status = EFI_NOT_FOUND;\r
   }\r
 \r
@@ -2216,24 +2339,24 @@ Ip6ConfigInitInstance (
   Instance->Policy   = Ip6ConfigPolicyManual;\r
   SET_DATA_ATTRIB (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED);\r
 \r
-  DataItem           = &Instance->DataItem[Ip6ConfigDataTypeDupAddrDetectTransmits];\r
-  DataItem->SetData  = Ip6ConfigSetDadXmits;\r
-  DataItem->Data.Ptr = &Instance->DadXmits;\r
-  DataItem->DataSize = sizeof (Instance->DadXmits);\r
+  DataItem                                  = &Instance->DataItem[Ip6ConfigDataTypeDupAddrDetectTransmits];\r
+  DataItem->SetData                         = Ip6ConfigSetDadXmits;\r
+  DataItem->Data.Ptr                        = &Instance->DadXmits;\r
+  DataItem->DataSize                        = sizeof (Instance->DadXmits);\r
   Instance->DadXmits.DupAddrDetectTransmits = IP6_CONFIG_DEFAULT_DAD_XMITS;\r
   SET_DATA_ATTRIB (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED);\r
 \r
-  DataItem           = &Instance->DataItem[Ip6ConfigDataTypeManualAddress];\r
-  DataItem->SetData  = Ip6ConfigSetMaunualAddress;\r
-  DataItem->Status   = EFI_NOT_FOUND;\r
+  DataItem          = &Instance->DataItem[Ip6ConfigDataTypeManualAddress];\r
+  DataItem->SetData = Ip6ConfigSetManualAddress;\r
+  DataItem->Status  = EFI_NOT_FOUND;\r
 \r
-  DataItem           = &Instance->DataItem[Ip6ConfigDataTypeGateway];\r
-  DataItem->SetData  = Ip6ConfigSetGateway;\r
-  DataItem->Status   = EFI_NOT_FOUND;\r
+  DataItem          = &Instance->DataItem[Ip6ConfigDataTypeGateway];\r
+  DataItem->SetData = Ip6ConfigSetGateway;\r
+  DataItem->Status  = EFI_NOT_FOUND;\r
 \r
-  DataItem           = &Instance->DataItem[Ip6ConfigDataTypeDnsServer];\r
-  DataItem->SetData  = Ip6ConfigSetDnsServer;\r
-  DataItem->Status   = EFI_NOT_FOUND;\r
+  DataItem          = &Instance->DataItem[Ip6ConfigDataTypeDnsServer];\r
+  DataItem->SetData = Ip6ConfigSetDnsServer;\r
+  DataItem->Status  = EFI_NOT_FOUND;\r
 \r
   //\r
   // Create the event used for DHCP.\r
@@ -2247,7 +2370,7 @@ Ip6ConfigInitInstance (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  Instance->Configured  = TRUE;\r
+  Instance->Configured = TRUE;\r
 \r
   //\r
   // Try to read the config data from NV variable.\r
@@ -2274,7 +2397,6 @@ Ip6ConfigInitInstance (
   Instance->Ip6Config.RegisterDataNotify   = EfiIp6ConfigRegisterDataNotify;\r
   Instance->Ip6Config.UnregisterDataNotify = EfiIp6ConfigUnregisterDataNotify;\r
 \r
-\r
   //\r
   // Publish the IP6 configuration form\r
   //\r
@@ -2300,11 +2422,10 @@ Ip6ConfigCleanInstance (
   }\r
 \r
   if (!Instance->Configured) {\r
-    return ;\r
+    return;\r
   }\r
 \r
   if (Instance->Dhcp6Handle != NULL) {\r
-\r
     Ip6ConfigDestroyDhcp6 (Instance);\r
   }\r
 \r
@@ -2319,13 +2440,13 @@ Ip6ConfigCleanInstance (
   NetMapClean (&Instance->DadFailedMap);\r
 \r
   for (Index = 0; Index < Ip6ConfigDataTypeMaximum; Index++) {\r
-\r
     DataItem = &Instance->DataItem[Index];\r
 \r
     if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED)) {\r
       if (DataItem->Data.Ptr != NULL) {\r
         FreePool (DataItem->Data.Ptr);\r
       }\r
+\r
       DataItem->Data.Ptr = NULL;\r
       DataItem->DataSize = 0;\r
     }\r
@@ -2352,9 +2473,9 @@ Ip6ConfigDestroyDhcp6 (
   IN OUT IP6_CONFIG_INSTANCE  *Instance\r
   )\r
 {\r
-  IP6_SERVICE                 *IpSb;\r
-  EFI_STATUS                  Status;\r
-  EFI_DHCP6_PROTOCOL          *Dhcp6;\r
+  IP6_SERVICE         *IpSb;\r
+  EFI_STATUS          Status;\r
+  EFI_DHCP6_PROTOCOL  *Dhcp6;\r
 \r
   Dhcp6 = Instance->Dhcp6;\r
   ASSERT (Dhcp6 != NULL);\r
@@ -2389,4 +2510,3 @@ Ip6ConfigDestroyDhcp6 (
 \r
   return Status;\r
 }\r
-\r