]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/DnsDxe/DnsProtocol.c
NetworkPkg: Clean up source files
[mirror_edk2.git] / NetworkPkg / DnsDxe / DnsProtocol.c
index 70857c2b2f49290a9c58f62bd6f257aa258c33d0..b8d074998242c82f6e9fc1ce03aedb85a155aac7 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Implementation of EFI_DNS4_PROTOCOL and EFI_DNS6_PROTOCOL interfaces.\r
 \r
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2018, 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
@@ -37,17 +37,19 @@ EFI_DNS6_PROTOCOL  mDns6Protocol = {
 };\r
 \r
 /**\r
-  This function is used to retrieve DNS mode data for this DNS instance.\r
+  Retrieve mode data of this DNS instance.\r
 \r
-  @param[in]  This               Pointer to EFI_DNS4_PROTOCOL instance.\r
-  @param[out] DnsModeData        Pointer to the caller-allocated storage for the EFI_DNS4_MODE_DATA structure.\r
+  This function is used to retrieve DNS mode data for this DNS instance.\r
 \r
-  @retval  EFI_SUCCESS           The operation completed successfully.\r
-  @retval  EFI_NOT_STARTED       When DnsConfigData is queried, no configuration data is \r
-                                 available because this instance has not been configured.\r
-  @retval  EFI_OUT_OF_RESOURCES  Failed to allocate needed resources.\r
-  @retval  EFI_INVALID_PARAMETER This is NULL or DnsModeData is NULL.\r
+  @param[in]   This               Pointer to EFI_DNS4_PROTOCOL instance.\r
+  @param[out]  DnsModeData        Point to the mode data.\r
 \r
+  @retval EFI_SUCCESS             The operation completed successfully.\r
+  @retval EFI_NOT_STARTED         When DnsConfigData is queried, no configuration data\r
+                                  is available because this instance has not been\r
+                                  configured.\r
+  @retval EFI_INVALID_PARAMETER   This is NULL or DnsModeData is NULL.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -57,14 +59,14 @@ Dns4GetModeData (
   )\r
 {\r
   DNS_INSTANCE         *Instance;\r
-  \r
+\r
   EFI_TPL              OldTpl;\r
 \r
   UINTN                Index;\r
-  \r
+\r
   LIST_ENTRY           *Entry;\r
   LIST_ENTRY           *Next;\r
-  \r
+\r
   DNS4_SERVER_IP       *ServerItem;\r
   EFI_IPv4_ADDRESS     *ServerList;\r
   DNS4_CACHE           *CacheItem;\r
@@ -76,29 +78,28 @@ Dns4GetModeData (
   CacheItem  = NULL;\r
   CacheList  = NULL;\r
   Status     = EFI_SUCCESS;\r
-  \r
-    \r
+\r
+\r
   if ((This == NULL) || (DnsModeData == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
-    \r
+\r
   Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This);\r
   if (Instance->State == DNS_STATE_UNCONFIGED) {\r
-    gBS->RestoreTPL (OldTpl);\r
-    return  EFI_NOT_STARTED;\r
+    Status = EFI_NOT_STARTED;\r
+    goto ON_EXIT;\r
   }\r
-  \r
+\r
   ZeroMem (DnsModeData, sizeof (EFI_DNS4_MODE_DATA));\r
 \r
   //\r
-  // Get the current configuration data of this instance. \r
+  // Get the current configuration data of this instance.\r
   //\r
   Status = Dns4CopyConfigure (&DnsModeData->DnsConfigData, &Instance->Dns4CfgData);\r
   if (EFI_ERROR (Status)) {\r
-    gBS->RestoreTPL (OldTpl);\r
-    return Status;\r
+    goto ON_EXIT;\r
   }\r
 \r
   //\r
@@ -110,7 +111,12 @@ Dns4GetModeData (
   }\r
   DnsModeData->DnsServerCount = (UINT32) Index;\r
   ServerList = AllocatePool (sizeof (EFI_IPv4_ADDRESS) * DnsModeData->DnsServerCount);\r
-  ASSERT (ServerList != NULL);\r
+  if (ServerList == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    Dns4CleanConfigure (&DnsModeData->DnsConfigData);\r
+    goto ON_EXIT;\r
+  }\r
+\r
   Index = 0;\r
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns4ServerList) {\r
     ServerItem = NET_LIST_USER_STRUCT (Entry, DNS4_SERVER_IP, AllServerLink);\r
@@ -128,7 +134,13 @@ Dns4GetModeData (
   }\r
   DnsModeData->DnsCacheCount = (UINT32) Index;\r
   CacheList = AllocatePool (sizeof (EFI_DNS4_CACHE_ENTRY) * DnsModeData->DnsCacheCount);\r
-  ASSERT (CacheList != NULL);\r
+  if (CacheList == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    Dns4CleanConfigure (&DnsModeData->DnsConfigData);\r
+    FreePool (ServerList);\r
+    goto ON_EXIT;\r
+  }\r
+\r
   Index =0;\r
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns4CacheList) {\r
     CacheItem = NET_LIST_USER_STRUCT (Entry, DNS4_CACHE, AllCacheLink);\r
@@ -137,27 +149,35 @@ Dns4GetModeData (
   }\r
   DnsModeData->DnsCacheList = CacheList;\r
 \r
+ON_EXIT:\r
   gBS->RestoreTPL (OldTpl);\r
-  \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
 /**\r
-  This function is used to configure DNS configuration data for this DNS instance.\r
-\r
-  @param[in]  This               Pointer to EFI_DNS4_PROTOCOL instance.\r
-  @param[in]  DnsConfigData      Pointer to caller-allocated buffer containing EFI_DNS4_CONFIG_DATA structure. \r
-                                 If NULL, the driver will reinitialize the protocol instance to the unconfigured state.\r
-\r
-  @retval  EFI_SUCCESS           The operation completed successfully.\r
-  @retval  EFI_UNSUPPORTED       The designated protocol is not supported.\r
-  @retval  EFI_OUT_OF_RESOURCES  Failed to allocate needed resources.\r
-  @retval  EFI_INVALID_PARAMETER This is NULL.\r
-                                 The StationIp address provided in DnsConfigData is not a valid unicast.\r
-                                 DnsServerList is NULL while DnsServerListCount is not equal to Zero.\r
-                                 DnsServerListCount is Zero while DnsServerListCount is not equal to NULL.\r
-  @retval  EFI_DEVICE_ERROR      An unexpected system or network error occurred. The EFI DNSv4 Protocol instance is not configured.\r
-\r
+  Configure this DNS instance.\r
+\r
+  This function is used to configure DNS mode data for this DNS instance.\r
+\r
+  @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.\r
+  @param[in]  DnsConfigData       Point to the Configuration data.\r
+\r
+  @retval EFI_SUCCESS             The operation completed successfully.\r
+  @retval EFI_UNSUPPORTED         The designated protocol is not supported.\r
+  @retval EFI_INVALID_PARAMTER    Thisis NULL.\r
+                                  The StationIp address provided in DnsConfigData is not a\r
+                                  valid unicast.\r
+                                  DnsServerList is NULL while DnsServerListCount\r
+                                  is not ZERO.\r
+                                  DnsServerListCount is ZERO while DnsServerList\r
+                                  is not NULL\r
+  @retval EFI_OUT_OF_RESOURCES    The DNS instance data or required space could not be\r
+                                  allocated.\r
+  @retval EFI_DEVICE_ERROR        An unexpected system or network error occurred. The\r
+                                  EFI DNSv4 Protocol instance is not configured.\r
+  @retval EFI_ALREADY_STARTED     Second call to Configure() with DnsConfigData. To\r
+                                  reconfigure the instance the caller must call Configure()\r
+                                  with NULL first to return driver to unconfigured state.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -168,19 +188,19 @@ Dns4Configure (
 {\r
   EFI_STATUS                Status;\r
   DNS_INSTANCE              *Instance;\r
-  \r
+\r
   EFI_TPL                   OldTpl;\r
   IP4_ADDR                  Ip;\r
   IP4_ADDR                  Netmask;\r
 \r
   UINT32                    ServerListCount;\r
-  EFI_IPv4_ADDRESS          *ServerList;                  \r
+  EFI_IPv4_ADDRESS          *ServerList;\r
 \r
   Status     = EFI_SUCCESS;\r
   ServerList = NULL;\r
-    \r
-  if (This == NULL || \r
-     (DnsConfigData != NULL && ((DnsConfigData->DnsServerListCount != 0 && DnsConfigData->DnsServerList == NULL) || \r
+\r
+  if (This == NULL ||\r
+     (DnsConfigData != NULL && ((DnsConfigData->DnsServerListCount != 0 && DnsConfigData->DnsServerList == NULL) ||\r
                                 (DnsConfigData->DnsServerListCount == 0 && DnsConfigData->DnsServerList != NULL)))) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -195,7 +215,7 @@ Dns4Configure (
 \r
   if (DnsConfigData == NULL) {\r
     ZeroMem (&Instance->SessionDnsServer, sizeof (EFI_IP_ADDRESS));\r
-    \r
+\r
     //\r
     // Reset the Instance if ConfigData is NULL\r
     //\r
@@ -203,17 +223,15 @@ Dns4Configure (
       Dns4InstanceCancelToken(Instance, NULL);\r
     }\r
 \r
-    Instance->MaxRetry = 0;\r
-\r
     if (Instance->UdpIo != NULL){\r
       UdpIoCleanIo (Instance->UdpIo);\r
     }\r
-    \r
+\r
     if (Instance->Dns4CfgData.DnsServerList != NULL) {\r
       FreePool (Instance->Dns4CfgData.DnsServerList);\r
     }\r
     ZeroMem (&Instance->Dns4CfgData, sizeof (EFI_DNS4_CONFIG_DATA));\r
-    \r
+\r
     Instance->State = DNS_STATE_UNCONFIGED;\r
   } else {\r
     //\r
@@ -226,7 +244,7 @@ Dns4Configure (
     Netmask  = NTOHL (Netmask);\r
 \r
     if (!DnsConfigData->UseDefaultSetting &&\r
-       ((!IP4_IS_VALID_NETMASK (Netmask) || !NetIp4IsUnicast (Ip, Netmask)))) {\r
+        ((!IP4_IS_VALID_NETMASK (Netmask) || (Netmask != 0 && !NetIp4IsUnicast (Ip, Netmask))))) {\r
       Status = EFI_INVALID_PARAMETER;\r
       goto ON_EXIT;\r
     }\r
@@ -236,15 +254,15 @@ Dns4Configure (
       goto ON_EXIT;\r
     }\r
 \r
-    if (DnsConfigData->DnsServerListCount == 0 || DnsConfigData->DnsServerList == NULL) {\r
-      gBS->RestoreTPL (OldTpl); \r
-      \r
+    if (DnsConfigData->DnsServerListCount == 0) {\r
+      gBS->RestoreTPL (OldTpl);\r
+\r
       //\r
       // The DNS instance will retrieve DNS server from DHCP Server\r
       //\r
       Status = GetDns4ServerFromDhcp4 (\r
                  Instance,\r
-                 &ServerListCount, \r
+                 &ServerListCount,\r
                  &ServerList\r
                  );\r
       if (EFI_ERROR (Status)) {\r
@@ -252,7 +270,7 @@ Dns4Configure (
       }\r
 \r
       ASSERT(ServerList != NULL);\r
-      \r
+\r
       OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
       CopyMem (&Instance->SessionDnsServer.v4, &ServerList[0], sizeof (EFI_IPv4_ADDRESS));\r
@@ -267,6 +285,7 @@ Dns4Configure (
     if (EFI_ERROR (Status)) {\r
       if (Instance->Dns4CfgData.DnsServerList != NULL) {\r
         FreePool (Instance->Dns4CfgData.DnsServerList);\r
+        Instance->Dns4CfgData.DnsServerList = NULL;\r
       }\r
       goto ON_EXIT;\r
     }\r
@@ -278,10 +297,11 @@ Dns4Configure (
     if (EFI_ERROR (Status)) {\r
       if (Instance->Dns4CfgData.DnsServerList != NULL) {\r
         FreePool (Instance->Dns4CfgData.DnsServerList);\r
+        Instance->Dns4CfgData.DnsServerList = NULL;\r
       }\r
       goto ON_EXIT;\r
     }\r
-    \r
+\r
     Instance->State = DNS_STATE_CONFIGED;\r
   }\r
 \r
@@ -291,24 +311,24 @@ ON_EXIT:
 }\r
 \r
 /**\r
-  The function is used to translate the host name to host IP address. \r
-  A type A query is used to get the one or more IP addresses for this host. \r
-\r
-  @param[in]  This               Pointer to EFI_DNS4_PROTOCOL instance.\r
-  @param[in]  HostName           Pointer to caller-supplied buffer containing Host name to be translated. \r
-                                 This buffer contains 16 bit characters but these are translated to ASCII for use with \r
-                                 DNSv4 server and there is no requirement for driver to support non-ASCII Unicode characters.\r
-  @param[in]  Token              Pointer to the caller-allocated completion token to return at the completion of the process to translate host name to host address. \r
-\r
-  @retval  EFI_SUCCESS           The operation completed successfully.\r
-  @retval  EFI_OUT_OF_RESOURCES  Failed to allocate needed resources.\r
-  @retval  EFI_INVALID_PARAMETER This is NULL.\r
-                                 Token is NULL.\r
-                                 Token.Event is.NULL\r
-                                 HostName is NULL\r
-  @retval  EFI_NO_MAPPING        There's no source address is available for use.\r
-  @retval  EFI_NOT_STARTED       This instance has not been started.\r
-\r
+  Host name to host address translation.\r
+\r
+  The HostNameToIp () function is used to translate the host name to host IP address. A\r
+  type A query is used to get the one or more IP addresses for this host.\r
+\r
+  @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.\r
+  @param[in]  HostName            Host name.\r
+  @param[in]  Token               Point to the completion token to translate host name\r
+                                  to host address.\r
+\r
+  @retval EFI_SUCCESS             The operation completed successfully.\r
+  @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:\r
+                                  This is NULL.\r
+                                  Token is NULL.\r
+                                  Token.Event is NULL.\r
+                                  HostName is NULL. HostName string is unsupported format.\r
+  @retval EFI_NO_MAPPING          There's no source address is available for use.\r
+  @retval EFI_NOT_STARTED         This instance has not been started.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -319,57 +339,66 @@ Dns4HostNameToIp (
   )\r
 {\r
   EFI_STATUS            Status;\r
-  \r
+\r
   DNS_INSTANCE          *Instance;\r
-  \r
+\r
   EFI_DNS4_CONFIG_DATA  *ConfigData;\r
-  \r
+\r
   UINTN                 Index;\r
   DNS4_CACHE            *Item;\r
   LIST_ENTRY            *Entry;\r
   LIST_ENTRY            *Next;\r
-  \r
+\r
+  CHAR8                 *QueryName;\r
+\r
   DNS4_TOKEN_ENTRY      *TokenEntry;\r
   NET_BUF               *Packet;\r
-  \r
+\r
   EFI_TPL               OldTpl;\r
-  \r
+\r
   Status     = EFI_SUCCESS;\r
   Item       = NULL;\r
+  QueryName  = NULL;\r
   TokenEntry = NULL;\r
   Packet     = NULL;\r
-  \r
+\r
   //\r
   // Validate the parameters\r
   //\r
   if ((This == NULL) || (HostName == NULL) || Token == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   OldTpl   = gBS->RaiseTPL (TPL_CALLBACK);\r
-  \r
+\r
   Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This);\r
-  \r
+\r
   ConfigData = &(Instance->Dns4CfgData);\r
-  \r
-  Instance->MaxRetry = ConfigData->RetryCount;\r
-  \r
-  Token->Status = EFI_NOT_READY;\r
-  Token->RetryCount = 0;\r
-  Token->RetryInterval = ConfigData->RetryInterval;\r
 \r
   if (Instance->State != DNS_STATE_CONFIGED) {\r
     Status = EFI_NOT_STARTED;\r
     goto ON_EXIT;\r
   }\r
 \r
+  Token->Status = EFI_NOT_READY;\r
+\r
+  //\r
+  // If zero, use the parameter configured through Dns.Configure() interface.\r
+  //\r
+  if (Token->RetryCount == 0) {\r
+    Token->RetryCount = ConfigData->RetryCount;\r
+  }\r
+\r
   //\r
-  // Check the MaxRetry and RetryInterval values.\r
+  // If zero, use the parameter configured through Dns.Configure() interface.\r
   //\r
-  if (Instance->MaxRetry == 0) {\r
-    Instance->MaxRetry = DNS_DEFAULT_RETRY;\r
+  if (Token->RetryInterval == 0) {\r
+    Token->RetryInterval = ConfigData->RetryInterval;\r
   }\r
 \r
+  //\r
+  // Minimum interval of retry is 2 second. If the retry interval is less than 2 second, then use the 2 second.\r
+  //\r
   if (Token->RetryInterval < DNS_DEFAULT_TIMEOUT) {\r
     Token->RetryInterval = DNS_DEFAULT_TIMEOUT;\r
   }\r
@@ -399,7 +428,7 @@ Dns4HostNameToIp (
         if (Token->RspData.H2AData != NULL) {\r
           FreePool (Token->RspData.H2AData);\r
         }\r
-        \r
+\r
         Status = EFI_OUT_OF_RESOURCES;\r
         goto ON_EXIT;\r
       }\r
@@ -409,12 +438,12 @@ Dns4HostNameToIp (
         Item = NET_LIST_USER_STRUCT (Entry, DNS4_CACHE, AllCacheLink);\r
         if ((UINT32)Index < Token->RspData.H2AData->IpCount && StrCmp (HostName, Item->DnsCache.HostName) == 0) {\r
           CopyMem ((Token->RspData.H2AData->IpList) + Index, Item->DnsCache.IpAddress, sizeof (EFI_IPv4_ADDRESS));\r
-          Index++; \r
+          Index++;\r
         }\r
       }\r
-         \r
+\r
       Token->Status = EFI_SUCCESS;\r
-          \r
+\r
       if (Token->Event != NULL) {\r
         gBS->SignalEvent (Token->Event);\r
         DispatchDpc ();\r
@@ -422,7 +451,7 @@ Dns4HostNameToIp (
 \r
       Status = Token->Status;\r
       goto ON_EXIT;\r
-    } \r
+    }\r
   }\r
 \r
   //\r
@@ -433,72 +462,97 @@ Dns4HostNameToIp (
     Status = EFI_OUT_OF_RESOURCES;\r
     goto ON_EXIT;\r
   }\r
-  \r
+\r
   TokenEntry->PacketToLive = Token->RetryInterval;\r
-  TokenEntry->QueryHostName = HostName;\r
   TokenEntry->Token = Token;\r
+  TokenEntry->QueryHostName = AllocateZeroPool (StrSize (HostName));\r
+  if (TokenEntry->QueryHostName == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  CopyMem (TokenEntry->QueryHostName, HostName, StrSize (HostName));\r
+\r
+  //\r
+  // Construct QName.\r
+  //\r
+  QueryName = NetLibCreateDnsQName (TokenEntry->QueryHostName);\r
+  if (QueryName == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ON_EXIT;\r
+  }\r
 \r
   //\r
   // Construct DNS Query Packet.\r
   //\r
-  Status = ConstructDNSQueryIp (Instance, TokenEntry->QueryHostName, DNS_TYPE_A, &Packet);\r
+  Status = ConstructDNSQuery (Instance, QueryName, DNS_TYPE_A, DNS_CLASS_INET, &Packet);\r
   if (EFI_ERROR (Status)) {\r
-    if (TokenEntry != NULL) {\r
-      FreePool (TokenEntry);\r
-    }\r
-    \r
     goto ON_EXIT;\r
   }\r
 \r
+  ASSERT (Packet != NULL);\r
+\r
   //\r
   // Save the token into the Dns4TxTokens map.\r
   //\r
   Status = NetMapInsertTail (&Instance->Dns4TxTokens, TokenEntry, Packet);\r
   if (EFI_ERROR (Status)) {\r
-    if (TokenEntry != NULL) {\r
-      FreePool (TokenEntry);\r
-    }\r
-    \r
-    NetbufFree (Packet);\r
-    \r
     goto ON_EXIT;\r
   }\r
-  \r
+\r
   //\r
   // Dns Query Ip\r
   //\r
   Status = DoDnsQuery (Instance, Packet);\r
+  if (EFI_ERROR (Status)) {\r
+    Dns4RemoveTokenEntry (&Instance->Dns4TxTokens, TokenEntry);\r
+  }\r
+\r
+ON_EXIT:\r
+\r
   if (EFI_ERROR (Status)) {\r
     if (TokenEntry != NULL) {\r
+      if (TokenEntry->QueryHostName != NULL) {\r
+        FreePool (TokenEntry->QueryHostName);\r
+      }\r
+\r
       FreePool (TokenEntry);\r
     }\r
-    \r
-    NetbufFree (Packet);\r
+\r
+    if (Packet != NULL) {\r
+      NetbufFree (Packet);\r
+    }\r
   }\r
-  \r
-ON_EXIT:\r
+\r
+  if (QueryName != NULL) {\r
+    FreePool (QueryName);\r
+  }\r
+\r
   gBS->RestoreTPL (OldTpl);\r
   return Status;\r
 }\r
 \r
 /**\r
-  The function is used to translate the host address to host name. \r
-  A type PTR query is used to get the primary name of the host. \r
-\r
-  @param[in]  This               Pointer to EFI_DNS4_PROTOCOL instance.\r
-  @param[in]  IpAddress          IP address.\r
-  @param[in]  Token              Pointer to the caller-allocated completion used token to translate host address to host name.\r
-\r
-  @retval  EFI_SUCCESS           The operation completed successfully.\r
-  @retval  EFI_OUT_OF_RESOURCES  Failed to allocate needed resources.\r
-  @retval  EFI_INVALID_PARAMETER This is NULL.\r
-                                 Token is NULL.\r
-                                 Token.Event is NULL.\r
-                                 IpAddress is not valid IP address.\r
-  @retval  EFI_NO_MAPPING        There's no source address is available for use.\r
-  @retval  EFI_NOT_STARTED       This instance has not been started.\r
-  @retval  EFI_UNSUPPORTED       This function is not supported.\r
-\r
+  IPv4 address to host name translation also known as Reverse DNS lookup.\r
+\r
+  The IpToHostName() function is used to translate the host address to host name. A type PTR\r
+  query is used to get the primary name of the host. Support of this function is optional.\r
+\r
+  @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.\r
+  @param[in]  IpAddress           Ip Address.\r
+  @param[in]  Token               Point to the completion token to translate host\r
+                                  address to host name.\r
+\r
+  @retval EFI_SUCCESS             The operation completed successfully.\r
+  @retval EFI_UNSUPPORTED         This function is not supported.\r
+  @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:\r
+                                  This is NULL.\r
+                                  Token is NULL.\r
+                                  Token.Event is NULL.\r
+                                  IpAddress is not valid IP address .\r
+  @retval EFI_NO_MAPPING          There's no source address is available for use.\r
+  @retval EFI_ALREADY_STARTED     This Token is being used in another DNS session.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -512,60 +566,183 @@ Dns4IpToHostName (
 }\r
 \r
 /**\r
-  This function retrieves arbitrary information from the DNS. \r
-  The caller supplies a QNAME, QTYPE, and QCLASS, and all of the matching RRs are returned.  \r
-  All RR content (e.g., Ttl) was returned. \r
-  The caller need parse the returned RR to get required information. This function is optional.\r
-\r
-  @param[in]  This               Pointer to EFI_DNS4_PROTOCOL instance.\r
-  @param[in]  QName              Pointer to Query Name.\r
-  @param[in]  QType              Query Type.\r
-  @param[in]  QClass             Query Name.\r
-  @param[in]  Token              Point to the caller-allocated completion token to retrieve arbitrary information.\r
-\r
-  @retval  EFI_SUCCESS           The operation completed successfully.\r
-  @retval  EFI_OUT_OF_RESOURCES  Failed to allocate needed resources.\r
-  @retval  EFI_INVALID_PARAMETER This is NULL.\r
-                                 Token is NULL.\r
-                                 Token.Event is NULL.\r
-                                 QName is NULL.\r
-  @retval  EFI_NO_MAPPING        There's no source address is available for use.\r
-  @retval  EFI_ALREADY_STARTED   This Token is being used in another DNS session.\r
-  @retval  EFI_UNSUPPORTED       This function is not supported. Or the requested QType is not supported\r
-\r
+  Retrieve arbitrary information from the DNS server.\r
+\r
+  This GeneralLookup() function retrieves arbitrary information from the DNS. The caller\r
+  supplies a QNAME, QTYPE, and QCLASS, and all of the matching RRs are returned. All\r
+  RR content (e.g., TTL) was returned. The caller need parse the returned RR to get\r
+  required information. The function is optional.\r
+\r
+  @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.\r
+  @param[in]  QName               Pointer to Query Name.\r
+  @param[in]  QType               Query Type.\r
+  @param[in]  QClass              Query Name.\r
+  @param[in]  Token               Point to the completion token to retrieve arbitrary\r
+                                  information.\r
+\r
+  @retval EFI_SUCCESS             The operation completed successfully.\r
+  @retval EFI_UNSUPPORTED         This function is not supported. Or the requested\r
+                                  QType is not supported\r
+  @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:\r
+                                  This is NULL.\r
+                                  Token is NULL.\r
+                                  Token.Event is NULL.\r
+                                  QName is NULL.\r
+  @retval EFI_NO_MAPPING          There's no source address is available for use.\r
+  @retval EFI_ALREADY_STARTED     This Token is being used in another DNS session.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 Dns4GeneralLookUp (\r
   IN  EFI_DNS4_PROTOCOL                *This,\r
   IN  CHAR8                            *QName,\r
-  IN  UINT16                           QType, \r
+  IN  UINT16                           QType,\r
   IN  UINT16                           QClass,\r
   IN  EFI_DNS4_COMPLETION_TOKEN        *Token\r
   )\r
 {\r
-  return EFI_UNSUPPORTED;\r
+  EFI_STATUS            Status;\r
+\r
+  DNS_INSTANCE          *Instance;\r
+\r
+  EFI_DNS4_CONFIG_DATA  *ConfigData;\r
+\r
+  DNS4_TOKEN_ENTRY      *TokenEntry;\r
+  NET_BUF               *Packet;\r
+\r
+  EFI_TPL               OldTpl;\r
+\r
+  Status     = EFI_SUCCESS;\r
+  TokenEntry = NULL;\r
+  Packet     = NULL;\r
+\r
+  //\r
+  // Validate the parameters\r
+  //\r
+  if ((This == NULL) || (QName == NULL) || Token == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl   = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This);\r
+\r
+  ConfigData = &(Instance->Dns4CfgData);\r
+\r
+  if (Instance->State != DNS_STATE_CONFIGED) {\r
+    Status = EFI_NOT_STARTED;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  Token->Status = EFI_NOT_READY;\r
+\r
+  //\r
+  // If zero, use the parameter configured through Dns.Configure() interface.\r
+  //\r
+  if (Token->RetryCount == 0) {\r
+    Token->RetryCount = ConfigData->RetryCount;\r
+  }\r
+\r
+  //\r
+  // If zero, use the parameter configured through Dns.Configure() interface.\r
+  //\r
+  if (Token->RetryInterval == 0) {\r
+    Token->RetryInterval = ConfigData->RetryInterval;\r
+  }\r
+\r
+  //\r
+  // Minimum interval of retry is 2 second. If the retry interval is less than 2 second, then use the 2 second.\r
+  //\r
+  if (Token->RetryInterval < DNS_DEFAULT_TIMEOUT) {\r
+    Token->RetryInterval = DNS_DEFAULT_TIMEOUT;\r
+  }\r
+\r
+  //\r
+  // Construct DNS TokenEntry.\r
+  //\r
+  TokenEntry = AllocateZeroPool (sizeof(DNS4_TOKEN_ENTRY));\r
+  if (TokenEntry == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  TokenEntry->PacketToLive = Token->RetryInterval;\r
+  TokenEntry->GeneralLookUp = TRUE;\r
+  TokenEntry->Token = Token;\r
+\r
+  //\r
+  // Construct DNS Query Packet.\r
+  //\r
+  Status = ConstructDNSQuery (Instance, QName, QType, QClass, &Packet);\r
+  if (EFI_ERROR (Status)) {\r
+    if (TokenEntry != NULL) {\r
+      FreePool (TokenEntry);\r
+    }\r
+\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  ASSERT (Packet != NULL);\r
+\r
+  //\r
+  // Save the token into the Dns4TxTokens map.\r
+  //\r
+  Status = NetMapInsertTail (&Instance->Dns4TxTokens, TokenEntry, Packet);\r
+  if (EFI_ERROR (Status)) {\r
+    if (TokenEntry != NULL) {\r
+      FreePool (TokenEntry);\r
+    }\r
+\r
+    NetbufFree (Packet);\r
+\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  //\r
+  // Dns Query Ip\r
+  //\r
+  Status = DoDnsQuery (Instance, Packet);\r
+  if (EFI_ERROR (Status)) {\r
+    Dns4RemoveTokenEntry (&Instance->Dns4TxTokens, TokenEntry);\r
+\r
+    if (TokenEntry != NULL) {\r
+      FreePool (TokenEntry);\r
+    }\r
+\r
+    NetbufFree (Packet);\r
+  }\r
+\r
+ON_EXIT:\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
 }\r
 \r
 /**\r
-  This function is used to add/delete/modify DNS cache entry. \r
-  DNS cache can be normally dynamically updated after the DNS resolve succeeds. \r
-  This function provided capability to manually add/delete/modify the DNS cache.\r
-\r
-  @param[in]  This               Pointer to EFI_DNS4_PROTOCOL instance.\r
-  @param[in]  DeleteFlag         If FALSE, this function is to add one entry to the DNS Cache. \r
-                                 If TRUE, this function will delete matching DNS Cache entry. \r
-  @param[in]  Override           If TRUE, the matching DNS cache entry will be overwritten with the supplied parameter. \r
-                                 If FALSE, EFI_ACCESS_DENIED will be returned if the entry to be added is already exists.\r
-  @param[in]  DnsCacheEntry      Pointer to DNS Cache entry.\r
-\r
-  @retval  EFI_SUCCESS           The operation completed successfully.\r
-  @retval  EFI_INVALID_PARAMETER This is NULL. \r
-                                 DnsCacheEntry.HostName is NULL.\r
-                                 DnsCacheEntry.IpAddress is NULL.\r
-                                 DnsCacheEntry.Timeout is zero.\r
-  @retval  EFI_ACCESS_DENIED     The DNS cache entry already exists and Override is not TRUE. \r
-\r
+  This function is to update the DNS Cache.\r
+\r
+  The UpdateDnsCache() function is used to add/delete/modify DNS cache entry. DNS cache\r
+  can be normally dynamically updated after the DNS resolve succeeds. This function\r
+  provided capability to manually add/delete/modify the DNS cache.\r
+\r
+  @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.\r
+  @param[in]  DeleteFlag          If FALSE, this function is to add one entry to the\r
+                                  DNS Cahce. If TRUE, this function will delete\r
+                                  matching DNS Cache entry.\r
+  @param[in]  Override            If TRUE, the maching DNS cache entry will be\r
+                                  overwritten with the supplied parameter. If FALSE,\r
+                                  EFI_ACCESS_DENIED will be returned if the entry to\r
+                                  be added is already existed.\r
+  @param[in]  DnsCacheEntry       Pointer to DNS Cache entry.\r
+\r
+  @retval EFI_SUCCESS             The operation completed successfully.\r
+  @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:\r
+                                  This is NULL.\r
+                                  DnsCacheEntry.HostName is NULL.\r
+                                  DnsCacheEntry.IpAddress is NULL.\r
+                                  DnsCacheEntry.Timeout is zero.\r
+  @retval EFI_ACCESS_DENIED       The DNS cache entry already exists and Override is\r
+                                  not TRUE.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -576,15 +753,15 @@ Dns4UpdateDnsCache (
   IN EFI_DNS4_CACHE_ENTRY   DnsCacheEntry\r
   )\r
 {\r
-  EFI_STATUS    Status; \r
+  EFI_STATUS    Status;\r
   EFI_TPL       OldTpl;\r
 \r
   Status = EFI_SUCCESS;\r
-  \r
+\r
   if (DnsCacheEntry.HostName == NULL || DnsCacheEntry.IpAddress == NULL || DnsCacheEntry.Timeout == 0) {\r
-    return EFI_INVALID_PARAMETER; \r
+    return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
   //\r
@@ -593,25 +770,30 @@ Dns4UpdateDnsCache (
   Status = UpdateDns4Cache (&mDriverData->Dns4CacheList, DeleteFlag, Override, DnsCacheEntry);\r
 \r
   gBS->RestoreTPL (OldTpl);\r
-  \r
+\r
   return Status;\r
 }\r
 \r
 /**\r
-  This function can be used by network drivers and applications to increase the rate that data packets are moved between \r
-  the communications device and the transmit and receive queues. In some systems, the periodic timer event in the managed \r
-  network driver may not poll the underlying communications device fast enough to transmit and/or receive all data packets \r
-  without missing incoming packets or dropping outgoing packets.\r
-\r
-  @param[in]  This               Pointer to EFI_DNS4_PROTOCOL instance.\r
-\r
-  @retval  EFI_SUCCESS           Incoming or outgoing data was processed.\r
-  @retval  EFI_INVALID_PARAMETER This is NULL. \r
-  @retval  EFI_NOT_STARTED       This EFI DNS Protocol instance has not been started. \r
-  @retval  EFI_DEVICE_ERROR      An unexpected system or network error occurred. \r
-  @retval  EFI_TIMEOUT           Data was dropped out of the transmit and/or receive queue. \r
-                                 Consider increasing the polling rate.\r
-  \r
+  Polls for incoming data packets and processes outgoing data packets.\r
+\r
+  The Poll() function can be used by network drivers and applications to increase the\r
+  rate that data packets are moved between the communications device and the transmit\r
+  and receive queues.\r
+  In some systems, the periodic timer event in the managed network driver may not poll\r
+  the underlying communications device fast enough to transmit and/or receive all data\r
+  packets without missing incoming packets or dropping outgoing packets. Drivers and\r
+  applications that are experiencing packet loss should try calling the Poll()\r
+  function more often.\r
+\r
+  @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.\r
+\r
+  @retval EFI_SUCCESS             Incoming or outgoing data was processed.\r
+  @retval EFI_NOT_STARTED         This EFI DNS Protocol instance has not been started.\r
+  @retval EFI_INVALID_PARAMETER   This is NULL.\r
+  @retval EFI_DEVICE_ERROR        An unexpected system or network error occurred.\r
+  @retval EFI_TIMEOUT             Data was dropped out of the transmit and/or receive\r
+                                  queue. Consider increasing the polling rate.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -635,25 +817,34 @@ Dns4Poll (
   }\r
 \r
   Udp = Instance->UdpIo->Protocol.Udp4;\r
-  \r
+\r
   return Udp->Poll (Udp);\r
 }\r
 \r
 /**\r
-  This function is used to abort a pending resolution request. \r
-  After calling this function, Token.Status will be set to EFI_ABORTED and then Token.\r
-\r
-  @param[in]  This               Pointer to EFI_DNS4_PROTOCOL instance.\r
-  @param[in]  Token              Pointer to a token that has been issued by EFI_DNS4_PROTOCOL.HostNameToIp(), \r
-                                 EFI_DNS4_PROTOCOL.IpToHostName() or EFI_DNS4_PROTOCOL.GeneralLookup(). \r
-                                 If NULL, all pending tokens are aborted.\r
-\r
-  @retval  EFI_SUCCESS           Incoming or outgoing data was processed.\r
-  @retval  EFI_INVALID_PARAMETER This is NULL. \r
-  @retval  EFI_NOT_STARTED       This EFI DNS Protocol instance has not been started. \r
-  @retval  EFI_NOT_FOUND         When Token is not NULL, and the asynchronous DNS operation was not found in the transmit queue. \r
-                                 It was either completed or was not issued by HostNameToIp(), IpToHostName() or GeneralLookup().\r
-  \r
+  Abort an asynchronous DNS operation, including translation between IP and Host, and\r
+  general look up behavior.\r
+\r
+  The Cancel() function is used to abort a pending resolution request. After calling\r
+  this function, Token.Status will be set to EFI_ABORTED and then Token.Event will be\r
+  signaled. If the token is not in one of the queues, which usually means that the\r
+  asynchronous operation has completed, this function will not signal the token and\r
+  EFI_NOT_FOUND is returned.\r
+\r
+  @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.\r
+  @param[in]  Token               Pointer to a token that has been issued by\r
+                                  EFI_DNS4_PROTOCOL.HostNameToIp (),\r
+                                  EFI_DNS4_PROTOCOL.IpToHostName() or\r
+                                  EFI_DNS4_PROTOCOL.GeneralLookup().\r
+                                  If NULL, all pending tokens are aborted.\r
+\r
+  @retval EFI_SUCCESS             Incoming or outgoing data was processed.\r
+  @retval EFI_NOT_STARTED         This EFI DNS4 Protocol instance has not been started.\r
+  @retval EFI_INVALID_PARAMETER   This is NULL.\r
+  @retval EFI_NOT_FOUND           When Token is not NULL, and the asynchronous DNS\r
+                                  operation was not found in the transmit queue. It\r
+                                  was either completed or was not issued by\r
+                                  HostNameToIp(), IpToHostName() or GeneralLookup().\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -694,17 +885,20 @@ Dns4Cancel (
 }\r
 \r
 /**\r
-  This function is used to retrieve DNS mode data for this DNS instance.\r
+  Retrieve mode data of this DNS instance.\r
 \r
-  @param[in]  This               Pointer to EFI_DNS6_PROTOCOL instance.\r
-  @param[out] DnsModeData        Pointer to the caller-allocated storage for the EFI_DNS6_MODE_DATA structure.\r
+  This function is used to retrieve DNS mode data for this DNS instance.\r
 \r
-  @retval  EFI_SUCCESS           The operation completed successfully.\r
-  @retval  EFI_NOT_STARTED       When DnsConfigData is queried, no configuration data is \r
-                                 available because this instance has not been configured.\r
-  @retval  EFI_OUT_OF_RESOURCES  Failed to allocate needed resources.\r
-  @retval  EFI_INVALID_PARAMETER This is NULL or DnsModeData is NULL.\r
+  @param[in]   This                Pointer to EFI_DNS6_PROTOCOL instance.\r
+  @param[out]  DnsModeData         Pointer to the caller-allocated storage for the\r
+                                   EFI_DNS6_MODE_DATA data.\r
 \r
+  @retval EFI_SUCCESS             The operation completed successfully.\r
+  @retval EFI_NOT_STARTED         When DnsConfigData is queried, no configuration data\r
+                                  is available because this instance has not been\r
+                                  configured.\r
+  @retval EFI_INVALID_PARAMETER   This is NULL or DnsModeData is NULL.\r
+  @retval EFI_OUT_OF_RESOURCE     Failed to allocate needed resources.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -714,11 +908,11 @@ Dns6GetModeData (
   )\r
 {\r
   DNS_INSTANCE         *Instance;\r
-  \r
+\r
   EFI_TPL              OldTpl;\r
 \r
   UINTN                Index;\r
-  \r
+\r
   LIST_ENTRY           *Entry;\r
   LIST_ENTRY           *Next;\r
 \r
@@ -739,24 +933,23 @@ Dns6GetModeData (
   }\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
-    \r
+\r
   Instance  = DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This);\r
   if (Instance->State == DNS_STATE_UNCONFIGED) {\r
-    gBS->RestoreTPL (OldTpl);\r
-    return  EFI_NOT_STARTED;\r
+    Status =  EFI_NOT_STARTED;\r
+    goto ON_EXIT;\r
   }\r
 \r
   ZeroMem (DnsModeData, sizeof (EFI_DNS6_MODE_DATA));\r
 \r
   //\r
-  // Get the current configuration data of this instance. \r
+  // Get the current configuration data of this instance.\r
   //\r
-  Status = Dns6CopyConfigure(&DnsModeData->DnsConfigData, &Instance->Dns6CfgData);\r
+  Status = Dns6CopyConfigure (&DnsModeData->DnsConfigData, &Instance->Dns6CfgData);\r
   if (EFI_ERROR (Status)) {\r
-    gBS->RestoreTPL (OldTpl);\r
-    return Status;\r
+    goto ON_EXIT;\r
   }\r
-  \r
+\r
   //\r
   // Get the DnsServerCount and DnsServerList\r
   //\r
@@ -766,7 +959,12 @@ Dns6GetModeData (
   }\r
   DnsModeData->DnsServerCount = (UINT32) Index;\r
   ServerList = AllocatePool (sizeof(EFI_IPv6_ADDRESS) * DnsModeData->DnsServerCount);\r
-  ASSERT (ServerList != NULL);\r
+  if (ServerList == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    Dns6CleanConfigure (&DnsModeData->DnsConfigData);\r
+    goto ON_EXIT;\r
+  }\r
+\r
   Index = 0;\r
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns6ServerList) {\r
     ServerItem = NET_LIST_USER_STRUCT (Entry, DNS6_SERVER_IP, AllServerLink);\r
@@ -784,7 +982,13 @@ Dns6GetModeData (
   }\r
   DnsModeData->DnsCacheCount = (UINT32) Index;\r
   CacheList = AllocatePool (sizeof(EFI_DNS6_CACHE_ENTRY) * DnsModeData->DnsCacheCount);\r
-  ASSERT (CacheList != NULL);\r
+  if (CacheList == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    Dns6CleanConfigure (&DnsModeData->DnsConfigData);\r
+    FreePool (ServerList);\r
+    goto ON_EXIT;\r
+  }\r
+\r
   Index =0;\r
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns6CacheList) {\r
     CacheItem = NET_LIST_USER_STRUCT (Entry, DNS6_CACHE, AllCacheLink);\r
@@ -793,28 +997,33 @@ Dns6GetModeData (
   }\r
   DnsModeData->DnsCacheList = CacheList;\r
 \r
+ON_EXIT:\r
   gBS->RestoreTPL (OldTpl);\r
-  \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
 /**\r
-  The function is used to set and change the configuration data for this EFI DNSv6 Protocol driver instance. \r
-  Reset the DNS instance if DnsConfigData is NULL.\r
-\r
-  @param[in]  This               Pointer to EFI_DNS6_PROTOCOL instance.\r
-  @param[in]  DnsConfigData      Pointer to the configuration data structure. \r
-                                 All associated storage to be allocated and released by caller.\r
-\r
-  @retval  EFI_SUCCESS           The operation completed successfully.\r
-  @retval  EFI_UNSUPPORTED       The designated protocol is not supported.\r
-  @retval  EFI_OUT_OF_RESOURCES  Failed to allocate needed resources.\r
-  @retval  EFI_INVALID_PARAMETER This is NULL.\r
-                                 The StationIp address provided in DnsConfigData is not a valid unicast.\r
-                                 DnsServerList is NULL while DnsServerListCount is not equal to Zero.\r
-                                 DnsServerListCount is Zero while DnsServerList is not equal to NULL.\r
-  @retval  EFI_DEVICE_ERROR      An unexpected system or network error occurred. The EFI DNSv6 Protocol instance is not configured.\r
-\r
+  Configure this DNS instance.\r
+\r
+  The Configure() function is used to set and change the configuration data for this\r
+  EFI DNSv6 Protocol driver instance. Reset the DNS instance if DnsConfigData is NULL.\r
+\r
+  @param[in]  This                Pointer to EFI_DNS6_PROTOCOL instance.\r
+  @param[in]  DnsConfigData       Pointer to the configuration data structure. All associated\r
+                                  storage to be allocated and released by caller.\r
+\r
+  @retval EFI_SUCCESS             The operation completed successfully.\r
+  @retval EFI_INVALID_PARAMTER    This is NULL.\r
+                                  The StationIp address provided in DnsConfigData is not zero and not a valid unicast.\r
+                                  DnsServerList is NULL while DnsServerList Count is not ZERO.\r
+                                  DnsServerList Count is ZERO while DnsServerList is not NULL.\r
+  @retval EFI_OUT_OF_RESOURCES    The DNS instance data or required space could not be allocated.\r
+  @retval EFI_DEVICE_ERROR        An unexpected system or network error occurred. The\r
+                                  EFI DNSv6 Protocol instance is not configured.\r
+  @retval EFI_UNSUPPORTED         The designated protocol is not supported.\r
+  @retval EFI_ALREADY_STARTED     Second call to Configure() with DnsConfigData. To\r
+                                  reconfigure the instance the caller must call Configure() with\r
+                                  NULL first to return driver to unconfigured state.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -825,17 +1034,17 @@ Dns6Configure (
 {\r
   EFI_STATUS                Status;\r
   DNS_INSTANCE              *Instance;\r
-  \r
+\r
   EFI_TPL                   OldTpl;\r
 \r
   UINT32                    ServerListCount;\r
-  EFI_IPv6_ADDRESS          *ServerList; \r
+  EFI_IPv6_ADDRESS          *ServerList;\r
 \r
   Status     = EFI_SUCCESS;\r
   ServerList = NULL;\r
 \r
-  if (This == NULL || \r
-     (DnsConfigData != NULL && ((DnsConfigData->DnsServerCount != 0 && DnsConfigData->DnsServerList == NULL) || \r
+  if (This == NULL ||\r
+     (DnsConfigData != NULL && ((DnsConfigData->DnsServerCount != 0 && DnsConfigData->DnsServerList == NULL) ||\r
                                 (DnsConfigData->DnsServerCount == 0 && DnsConfigData->DnsServerList != NULL)))) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -858,8 +1067,6 @@ Dns6Configure (
       Dns6InstanceCancelToken(Instance, NULL);\r
     }\r
 \r
-    Instance->MaxRetry = 0;\r
-\r
     if (Instance->UdpIo != NULL){\r
       UdpIoCleanIo (Instance->UdpIo);\r
     }\r
@@ -868,7 +1075,7 @@ Dns6Configure (
       FreePool (Instance->Dns6CfgData.DnsServerList);\r
     }\r
     ZeroMem (&Instance->Dns6CfgData, sizeof (EFI_DNS6_CONFIG_DATA));\r
-    \r
+\r
     Instance->State = DNS_STATE_UNCONFIGED;\r
   } else {\r
     //\r
@@ -884,7 +1091,7 @@ Dns6Configure (
       goto ON_EXIT;\r
     }\r
 \r
-    if (DnsConfigData->DnsServerCount == 0 || DnsConfigData->DnsServerList == NULL) {\r
+    if (DnsConfigData->DnsServerCount == 0) {\r
       gBS->RestoreTPL (OldTpl);\r
 \r
       //\r
@@ -892,14 +1099,14 @@ Dns6Configure (
       //\r
       Status = GetDns6ServerFromDhcp6 (\r
                  Instance->Service->ImageHandle,\r
-                 Instance->Service->ControllerHandle, \r
-                 &ServerListCount, \r
+                 Instance->Service->ControllerHandle,\r
+                 &ServerListCount,\r
                  &ServerList\r
                  );\r
       if (EFI_ERROR (Status)) {\r
         goto ON_EXIT;\r
       }\r
-      \r
+\r
       ASSERT(ServerList != NULL);\r
 \r
       OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
@@ -912,10 +1119,13 @@ Dns6Configure (
     //\r
     // Config UDP\r
     //\r
+    gBS->RestoreTPL (OldTpl);\r
     Status = Dns6ConfigUdp (Instance, Instance->UdpIo);\r
+    OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
     if (EFI_ERROR (Status)) {\r
       if (Instance->Dns6CfgData.DnsServerList != NULL) {\r
         FreePool (Instance->Dns6CfgData.DnsServerList);\r
+        Instance->Dns6CfgData.DnsServerList = NULL;\r
       }\r
       goto ON_EXIT;\r
     }\r
@@ -927,10 +1137,11 @@ Dns6Configure (
     if (EFI_ERROR (Status)) {\r
       if (Instance->Dns6CfgData.DnsServerList != NULL) {\r
         FreePool (Instance->Dns6CfgData.DnsServerList);\r
+        Instance->Dns6CfgData.DnsServerList = NULL;\r
       }\r
       goto ON_EXIT;\r
     }\r
-    \r
+\r
     Instance->State = DNS_STATE_CONFIGED;\r
   }\r
 \r
@@ -940,24 +1151,26 @@ ON_EXIT:
 }\r
 \r
 /**\r
-  The function is used to translate the host name to host IP address. \r
-  A type AAAA query is used to get the one or more IPv6 addresses for this host. \r
-\r
-  @param[in]  This               Pointer to EFI_DNS6_PROTOCOL instance.\r
-  @param[in]  HostName           Pointer to caller-supplied buffer containing Host name to be translated. \r
-                                 This buffer contains 16 bit characters but these are translated to ASCII for use with \r
-                                 DNSv4 server and there is no requirement for driver to support non-ASCII Unicode characters.\r
-  @param[in]  Token              Pointer to the caller-allocated completion token to return at the completion of the process to translate host name to host address. \r
-\r
-  @retval  EFI_SUCCESS           The operation completed successfully.\r
-  @retval  EFI_OUT_OF_RESOURCES  Failed to allocate needed resources.\r
-  @retval  EFI_INVALID_PARAMETER This is NULL.\r
-                                 Token is NULL.\r
-                                 Token.Event is.NULL\r
-                                 HostName is NULL\r
-  @retval  EFI_NO_MAPPING        There's no source address is available for use.\r
-  @retval  EFI_NOT_STARTED       This instance has not been started.\r
-\r
+  Host name to host address translation.\r
+\r
+  The HostNameToIp () function is used to translate the host name to host IP address. A\r
+  type AAAA query is used to get the one or more IPv6 addresses for this host.\r
+\r
+  @param[in]  This                Pointer to EFI_DNS6_PROTOCOL instance.\r
+  @param[in]  HostName            Host name.\r
+  @param[in]  Token               Point to the completion token to translate host name\r
+                                  to host address.\r
+\r
+  @retval EFI_SUCCESS             The operation completed successfully.\r
+  @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:\r
+                                  This is NULL.\r
+                                  Token is NULL.\r
+                                  Token.Event is NULL.\r
+                                  HostName is NULL or buffer contained unsupported characters.\r
+  @retval EFI_NO_MAPPING          There's no source address is available for use.\r
+  @retval EFI_ALREADY_STARTED     This Token is being used in another DNS session.\r
+  @retval EFI_NOT_STARTED         This instance has not been started.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -968,23 +1181,26 @@ Dns6HostNameToIp (
   )\r
 {\r
   EFI_STATUS            Status;\r
-  \r
+\r
   DNS_INSTANCE          *Instance;\r
 \r
   EFI_DNS6_CONFIG_DATA  *ConfigData;\r
-  \r
-  UINTN                 Index; \r
+\r
+  UINTN                 Index;\r
   DNS6_CACHE            *Item;\r
   LIST_ENTRY            *Entry;\r
   LIST_ENTRY            *Next;\r
-  \r
+\r
+  CHAR8                 *QueryName;\r
+\r
   DNS6_TOKEN_ENTRY      *TokenEntry;\r
   NET_BUF               *Packet;\r
-  \r
+\r
   EFI_TPL               OldTpl;\r
-  \r
+\r
   Status     = EFI_SUCCESS;\r
   Item       = NULL;\r
+  QueryName  = NULL;\r
   TokenEntry = NULL;\r
   Packet     = NULL;\r
 \r
@@ -996,32 +1212,38 @@ Dns6HostNameToIp (
   }\r
 \r
   OldTpl   = gBS->RaiseTPL (TPL_CALLBACK);\r
-  \r
+\r
   Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This);\r
-  \r
-  ConfigData = &(Instance->Dns6CfgData);\r
-  \r
-  Instance->MaxRetry = ConfigData->RetryCount;\r
 \r
-  Token->Status = EFI_NOT_READY;\r
-  Token->RetryCount = 0;\r
-  Token->RetryInterval = ConfigData->RetryInterval;\r
+  ConfigData = &(Instance->Dns6CfgData);\r
 \r
   if (Instance->State != DNS_STATE_CONFIGED) {\r
     Status = EFI_NOT_STARTED;\r
     goto ON_EXIT;\r
   }\r
 \r
+  Token->Status = EFI_NOT_READY;\r
+\r
+  //\r
+  // If zero, use the parameter configured through Dns.Configure() interface.\r
+  //\r
+  if (Token->RetryCount == 0) {\r
+    Token->RetryCount = ConfigData->RetryCount;\r
+  }\r
+\r
   //\r
-  // Check the MaxRetry and RetryInterval values.\r
+  // If zero, use the parameter configured through Dns.Configure() interface.\r
   //\r
-  if (Instance->MaxRetry == 0) {\r
-    Instance->MaxRetry = DNS_DEFAULT_RETRY;\r
+  if (Token->RetryInterval == 0) {\r
+    Token->RetryInterval = ConfigData->RetryInterval;\r
   }\r
 \r
+  //\r
+  // Minimum interval of retry is 2 second. If the retry interval is less than 2 second, then use the 2 second.\r
+  //\r
   if (Token->RetryInterval < DNS_DEFAULT_TIMEOUT) {\r
     Token->RetryInterval = DNS_DEFAULT_TIMEOUT;\r
-  } \r
+  }\r
 \r
   //\r
   // Check cache\r
@@ -1048,7 +1270,7 @@ Dns6HostNameToIp (
         if (Token->RspData.H2AData != NULL) {\r
           FreePool (Token->RspData.H2AData);\r
         }\r
-        \r
+\r
         Status = EFI_OUT_OF_RESOURCES;\r
         goto ON_EXIT;\r
       }\r
@@ -1061,17 +1283,17 @@ Dns6HostNameToIp (
           Index++;\r
         }\r
       }\r
-         \r
+\r
       Token->Status = EFI_SUCCESS;\r
-          \r
+\r
       if (Token->Event != NULL) {\r
         gBS->SignalEvent (Token->Event);\r
         DispatchDpc ();\r
       }\r
-      \r
+\r
       Status = Token->Status;\r
       goto ON_EXIT;\r
-    } \r
+    }\r
   }\r
 \r
   //\r
@@ -1082,72 +1304,98 @@ Dns6HostNameToIp (
     Status = EFI_OUT_OF_RESOURCES;\r
     goto ON_EXIT;\r
   }\r
-  \r
+\r
   TokenEntry->PacketToLive = Token->RetryInterval;\r
-  TokenEntry->QueryHostName = HostName;\r
   TokenEntry->Token = Token;\r
+  TokenEntry->QueryHostName = AllocateZeroPool (StrSize (HostName));\r
+  if (TokenEntry->QueryHostName == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  CopyMem (TokenEntry->QueryHostName, HostName, StrSize (HostName));\r
+\r
+  //\r
+  // Construct QName.\r
+  //\r
+  QueryName = NetLibCreateDnsQName (TokenEntry->QueryHostName);\r
+  if (QueryName == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ON_EXIT;\r
+  }\r
 \r
   //\r
   // Construct DNS Query Packet.\r
   //\r
-  Status = ConstructDNSQueryIp (Instance, TokenEntry->QueryHostName, DNS_TYPE_AAAA, &Packet);\r
+  Status = ConstructDNSQuery (Instance, QueryName, DNS_TYPE_AAAA, DNS_CLASS_INET, &Packet);\r
   if (EFI_ERROR (Status)) {\r
-    if (TokenEntry != NULL) {\r
-      FreePool (TokenEntry);\r
-    }\r
-    \r
     goto ON_EXIT;\r
   }\r
 \r
+  ASSERT (Packet != NULL);\r
+\r
   //\r
   // Save the token into the Dns6TxTokens map.\r
   //\r
   Status = NetMapInsertTail (&Instance->Dns6TxTokens, TokenEntry, Packet);\r
   if (EFI_ERROR (Status)) {\r
-    if (TokenEntry != NULL) {\r
-      FreePool (TokenEntry);\r
-    }\r
-    \r
-    NetbufFree (Packet);\r
-    \r
     goto ON_EXIT;\r
   }\r
-  \r
+\r
   //\r
   // Dns Query Ip\r
   //\r
   Status = DoDnsQuery (Instance, Packet);\r
+  if (EFI_ERROR (Status)) {\r
+    Dns6RemoveTokenEntry (&Instance->Dns6TxTokens, TokenEntry);\r
+  }\r
+\r
+ON_EXIT:\r
+\r
   if (EFI_ERROR (Status)) {\r
     if (TokenEntry != NULL) {\r
+      if (TokenEntry->QueryHostName != NULL) {\r
+        FreePool (TokenEntry->QueryHostName);\r
+      }\r
+\r
       FreePool (TokenEntry);\r
     }\r
-    \r
-    NetbufFree (Packet);\r
+\r
+    if (Packet != NULL) {\r
+      NetbufFree (Packet);\r
+    }\r
   }\r
-  \r
-ON_EXIT:\r
+\r
+  if (QueryName != NULL) {\r
+    FreePool (QueryName);\r
+  }\r
+\r
   gBS->RestoreTPL (OldTpl);\r
   return Status;\r
 }\r
 \r
 /**\r
-  The function is used to translate the host address to host name. \r
-  A type PTR query is used to get the primary name of the host. \r
-\r
-  @param[in]  This               Pointer to EFI_DNS6_PROTOCOL instance.\r
-  @param[in]  IpAddress          IP address.\r
-  @param[in]  Token              Pointer to the caller-allocated completion used token to translate host address to host name.\r
-\r
-  @retval  EFI_SUCCESS           The operation completed successfully.\r
-  @retval  EFI_OUT_OF_RESOURCES  Failed to allocate needed resources.\r
-  @retval  EFI_INVALID_PARAMETER This is NULL.\r
-                                 Token is NULL.\r
-                                 Token.Event is NULL.\r
-                                 IpAddress is not valid IP address.\r
-  @retval  EFI_NO_MAPPING        There's no source address is available for use.\r
-  @retval  EFI_NOT_STARTED       This instance has not been started.\r
-  @retval  EFI_UNSUPPORTED       This function is not supported.\r
-\r
+  Host address to host name translation.\r
+\r
+  The IpToHostName () function is used to translate the host address to host name. A\r
+  type PTR query is used to get the primary name of the host. Implementation can choose\r
+  to support this function or not.\r
+\r
+  @param[in]  This                Pointer to EFI_DNS6_PROTOCOL instance.\r
+  @param[in]  IpAddress           Ip Address.\r
+  @param[in]  Token               Point to the completion token to translate host\r
+                                  address to host name.\r
+\r
+  @retval EFI_SUCCESS             The operation completed successfully.\r
+  @retval EFI_UNSUPPORTED         This function is not supported.\r
+  @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:\r
+                                  This is NULL.\r
+                                  Token is NULL.\r
+                                  Token.Event is NULL.\r
+                                  IpAddress is not valid IP address.\r
+  @retval EFI_NO_MAPPING          There's no source address is available for use.\r
+  @retval EFI_NOT_STARTED         This instance has not been started.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -1161,60 +1409,186 @@ Dns6IpToHostName (
 }\r
 \r
 /**\r
-  This function retrieves arbitrary information from the DNS. \r
-  The caller supplies a QNAME, QTYPE, and QCLASS, and all of the matching RRs are returned.  \r
-  All RR content (e.g., Ttl) was returned. \r
-  The caller need parse the returned RR to get required information. This function is optional.\r
-\r
-  @param[in]  This               Pointer to EFI_DNS6_PROTOCOL instance.\r
-  @param[in]  QName              Pointer to Query Name.\r
-  @param[in]  QType              Query Type.\r
-  @param[in]  QClass             Query Name.\r
-  @param[in]  Token              Point to the caller-allocated completion token to retrieve arbitrary information.\r
-\r
-  @retval  EFI_SUCCESS           The operation completed successfully.\r
-  @retval  EFI_OUT_OF_RESOURCES  Failed to allocate needed resources.\r
-  @retval  EFI_INVALID_PARAMETER This is NULL.\r
-                                 Token is NULL.\r
-                                 Token.Event is NULL.\r
-                                 QName is NULL.\r
-  @retval  EFI_NO_MAPPING        There's no source address is available for use.\r
-  @retval  EFI_NOT_STARTED       This instance has not been started.\r
-  @retval  EFI_UNSUPPORTED       This function is not supported. Or the requested QType is not supported\r
-\r
+  This function provides capability to retrieve arbitrary information from the DNS\r
+  server.\r
+\r
+  This GeneralLookup() function retrieves arbitrary information from the DNS. The caller\r
+  supplies a QNAME, QTYPE, and QCLASS, and all of the matching RRs are returned. All\r
+  RR content (e.g., TTL) was returned. The caller need parse the returned RR to get\r
+  required information. The function is optional. Implementation can choose to support\r
+  it or not.\r
+\r
+  @param[in]  This                Pointer to EFI_DNS6_PROTOCOL instance.\r
+  @param[in]  QName               Pointer to Query Name.\r
+  @param[in]  QType               Query Type.\r
+  @param[in]  QClass              Query Name.\r
+  @param[in]  Token               Point to the completion token to retrieve arbitrary\r
+                                  information.\r
+\r
+  @retval EFI_SUCCESS             The operation completed successfully.\r
+  @retval EFI_UNSUPPORTED         This function is not supported. Or the requested\r
+                                  QType is not supported\r
+  @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:\r
+                                  This is NULL.\r
+                                  Token is NULL.\r
+                                  Token.Event is NULL.\r
+                                  QName is NULL.\r
+  @retval EFI_NO_MAPPING          There's no source address is available for use.\r
+  @retval EFI_NOT_STARTED         This instance has not been started.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 Dns6GeneralLookUp (\r
   IN  EFI_DNS6_PROTOCOL                 *This,\r
   IN  CHAR8                             *QName,\r
-  IN  UINT16                            QType, \r
+  IN  UINT16                            QType,\r
   IN  UINT16                            QClass,\r
   IN  EFI_DNS6_COMPLETION_TOKEN         *Token\r
   )\r
 {\r
-  return EFI_UNSUPPORTED;\r
+  EFI_STATUS            Status;\r
+\r
+  DNS_INSTANCE          *Instance;\r
+\r
+  EFI_DNS6_CONFIG_DATA  *ConfigData;\r
+\r
+  DNS6_TOKEN_ENTRY      *TokenEntry;\r
+  NET_BUF               *Packet;\r
+\r
+  EFI_TPL               OldTpl;\r
+\r
+  Status     = EFI_SUCCESS;\r
+  TokenEntry = NULL;\r
+  Packet     = NULL;\r
+\r
+  //\r
+  // Validate the parameters\r
+  //\r
+  if ((This == NULL) || (QName == NULL) || Token == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl   = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This);\r
+\r
+  ConfigData = &(Instance->Dns6CfgData);\r
+\r
+  if (Instance->State != DNS_STATE_CONFIGED) {\r
+    Status = EFI_NOT_STARTED;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  Token->Status = EFI_NOT_READY;\r
+\r
+  //\r
+  // If zero, use the parameter configured through Dns.Configure() interface.\r
+  //\r
+  if (Token->RetryCount == 0) {\r
+    Token->RetryCount = ConfigData->RetryCount;\r
+  }\r
+\r
+  //\r
+  // If zero, use the parameter configured through Dns.Configure() interface.\r
+  //\r
+  if (Token->RetryInterval == 0) {\r
+    Token->RetryInterval = ConfigData->RetryInterval;\r
+  }\r
+\r
+  //\r
+  // Minimum interval of retry is 2 second. If the retry interval is less than 2 second, then use the 2 second.\r
+  //\r
+  if (Token->RetryInterval < DNS_DEFAULT_TIMEOUT) {\r
+    Token->RetryInterval = DNS_DEFAULT_TIMEOUT;\r
+  }\r
+\r
+  //\r
+  // Construct DNS TokenEntry.\r
+  //\r
+  TokenEntry = AllocateZeroPool (sizeof(DNS6_TOKEN_ENTRY));\r
+  if (TokenEntry == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  TokenEntry->PacketToLive = Token->RetryInterval;\r
+  TokenEntry->GeneralLookUp = TRUE;\r
+  TokenEntry->Token = Token;\r
+\r
+  //\r
+  // Construct DNS Query Packet.\r
+  //\r
+  Status = ConstructDNSQuery (Instance, QName, QType, QClass, &Packet);\r
+  if (EFI_ERROR (Status)) {\r
+    if (TokenEntry != NULL) {\r
+      FreePool (TokenEntry);\r
+    }\r
+\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  ASSERT (Packet != NULL);\r
+\r
+  //\r
+  // Save the token into the Dns6TxTokens map.\r
+  //\r
+  Status = NetMapInsertTail (&Instance->Dns6TxTokens, TokenEntry, Packet);\r
+  if (EFI_ERROR (Status)) {\r
+    if (TokenEntry != NULL) {\r
+      FreePool (TokenEntry);\r
+    }\r
+\r
+    NetbufFree (Packet);\r
+\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  //\r
+  // Dns Query Ip\r
+  //\r
+  Status = DoDnsQuery (Instance, Packet);\r
+  if (EFI_ERROR (Status)) {\r
+    Dns6RemoveTokenEntry (&Instance->Dns6TxTokens, TokenEntry);\r
+\r
+    if (TokenEntry != NULL) {\r
+      FreePool (TokenEntry);\r
+    }\r
+\r
+    NetbufFree (Packet);\r
+  }\r
+\r
+ON_EXIT:\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
 }\r
 \r
 /**\r
-  This function is used to add/delete/modify DNS cache entry. \r
-  DNS cache can be normally dynamically updated after the DNS resolve succeeds. \r
-  This function provided capability to manually add/delete/modify the DNS cache.\r
-\r
-  @param[in]  This               Pointer to EFI_DNS6_PROTOCOL instance.\r
-  @param[in]  DeleteFlag         If FALSE, this function is to add one entry to the DNS Cache. \r
-                                 If TRUE, this function will delete matching DNS Cache entry. \r
-  @param[in]  Override           If TRUE, the matching DNS cache entry will be overwritten with the supplied parameter. \r
-                                 If FALSE, EFI_ACCESS_DENIED will be returned if the entry to be added is already exists.\r
-  @param[in]  DnsCacheEntry      Pointer to DNS Cache entry.\r
-\r
-  @retval  EFI_SUCCESS           The operation completed successfully.\r
-  @retval  EFI_INVALID_PARAMETER This is NULL. \r
-                                 DnsCacheEntry.HostName is NULL.\r
-                                 DnsCacheEntry.IpAddress is NULL.\r
-                                 DnsCacheEntry.Timeout is zero.\r
-  @retval  EFI_ACCESS_DENIED     The DNS cache entry already exists and Override is not TRUE. \r
-\r
+  This function is to update the DNS Cache.\r
+\r
+  The UpdateDnsCache() function is used to add/delete/modify DNS cache entry. DNS cache\r
+  can be normally dynamically updated after the DNS resolve succeeds. This function\r
+  provided capability to manually add/delete/modify the DNS cache.\r
+\r
+  @param[in]  This                Pointer to EFI_DNS6_PROTOCOL instance.\r
+  @param[in]  DeleteFlag          If FALSE, this function is to add one entry to the\r
+                                  DNS Cahce. If TRUE, this function will delete\r
+                                  matching DNS Cache entry.\r
+  @param[in]  Override            If TRUE, the maching DNS cache entry will be\r
+                                  overwritten with the supplied parameter. If FALSE,\r
+                                  EFI_ACCESS_DENIED will be returned if the entry to\r
+                                  be added is already existed.\r
+  @param[in]  DnsCacheEntry       Pointer to DNS Cache entry.\r
+\r
+  @retval EFI_SUCCESS             The operation completed successfully.\r
+  @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:\r
+                                  This is NULL.\r
+                                  DnsCacheEntry.HostName is NULL.\r
+                                  DnsCacheEntry.IpAddress is NULL.\r
+                                  DnsCacheEntry.Timeout is zero.\r
+  @retval EFI_ACCESS_DENIED       The DNS cache entry already exists and Override is\r
+                                  not TRUE.\r
+  @retval EFI_OUT_OF_RESOURCE     Failed to allocate needed resources.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -1225,42 +1599,49 @@ Dns6UpdateDnsCache (
   IN EFI_DNS6_CACHE_ENTRY   DnsCacheEntry\r
   )\r
 {\r
-  EFI_STATUS    Status; \r
+  EFI_STATUS    Status;\r
   EFI_TPL       OldTpl;\r
 \r
   Status = EFI_SUCCESS;\r
-  \r
+\r
   if (DnsCacheEntry.HostName == NULL || DnsCacheEntry.IpAddress == NULL || DnsCacheEntry.Timeout == 0) {\r
-    return EFI_INVALID_PARAMETER; \r
+    return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
   //\r
   // Update Dns6Cache here.\r
   //\r
   Status = UpdateDns6Cache (&mDriverData->Dns6CacheList, DeleteFlag, Override, DnsCacheEntry);\r
-  \r
+\r
   gBS->RestoreTPL (OldTpl);\r
-  \r
+\r
   return Status;\r
 }\r
 \r
 /**\r
-  This function can be used by network drivers and applications to increase the rate that data packets are moved between \r
-  the communications device and the transmit and receive queues. In some systems, the periodic timer event in the managed \r
-  network driver may not poll the underlying communications device fast enough to transmit and/or receive all data packets \r
-  without missing incoming packets or dropping outgoing packets.\r
-\r
-  @param[in]  This               Pointer to EFI_DNS6_PROTOCOL instance.\r
-\r
-  @retval  EFI_SUCCESS           Incoming or outgoing data was processed.\r
-  @retval  EFI_INVALID_PARAMETER This is NULL. \r
-  @retval  EFI_NOT_STARTED       This EFI DNS Protocol instance has not been started. \r
-  @retval  EFI_DEVICE_ERROR      An unexpected system or network error occurred. \r
-  @retval  EFI_TIMEOUT           Data was dropped out of the transmit and/or receive queue. \r
-                                 Consider increasing the polling rate.\r
-  \r
+  Polls for incoming data packets and processes outgoing data packets.\r
+\r
+  The Poll() function can be used by network drivers and applications to increase the\r
+  rate that data packets are moved between the communications device and the transmit\r
+  and receive queues.\r
+\r
+  In some systems, the periodic timer event in the managed network driver may not poll\r
+  the underlying communications device fast enough to transmit and/or receive all data\r
+  packets without missing incoming packets or dropping outgoing packets. Drivers and\r
+  applications that are experiencing packet loss should try calling the Poll()\r
+  function more often.\r
+\r
+  @param[in]  This                Pointer to EFI_DNS6_PROTOCOL instance.\r
+\r
+  @retval EFI_SUCCESS             Incoming or outgoing data was processed.\r
+  @retval EFI_NOT_STARTED         This EFI DNS Protocol instance has not been started.\r
+  @retval EFI_INVALID_PARAMETER   This is NULL.\r
+  @retval EFI_NO_MAPPING          There is no source address is available for use.\r
+  @retval EFI_DEVICE_ERROR        An unexpected system or network error occurred.\r
+  @retval EFI_TIMEOUT             Data was dropped out of the transmit and/or receive\r
+                                  queue. Consider increasing the polling rate.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -1284,25 +1665,35 @@ Dns6Poll (
   }\r
 \r
   Udp = Instance->UdpIo->Protocol.Udp6;\r
-  \r
+\r
   return Udp->Poll (Udp);\r
 }\r
 \r
 /**\r
-  This function is used to abort a pending resolution request. \r
-  After calling this function, Token.Status will be set to EFI_ABORTED and then Token.\r
-\r
-  @param[in]  This               Pointer to EFI_DNS6_PROTOCOL instance.\r
-  @param[in]  Token              Pointer to a token that has been issued by EFI_DNS6_PROTOCOL.HostNameToIp(), \r
-                                 EFI_DNS6_PROTOCOL.IpToHostName() or EFI_DNS6_PROTOCOL.GeneralLookup(). \r
-                                 If NULL, all pending tokens are aborted.\r
-\r
-  @retval  EFI_SUCCESS           Incoming or outgoing data was processed.\r
-  @retval  EFI_INVALID_PARAMETER This is NULL. \r
-  @retval  EFI_NOT_STARTED       This EFI DNS Protocol instance has not been started. \r
-  @retval  EFI_NOT_FOUND         When Token is not NULL, and the asynchronous DNS operation was not found in the transmit queue. \r
-                                 It was either completed or was not issued by HostNameToIp(), IpToHostName() or GeneralLookup().\r
-  \r
+  Abort an asynchronous DNS operation, including translation between IP and Host, and\r
+  general look up behavior.\r
+\r
+  The Cancel() function is used to abort a pending resolution request. After calling\r
+  this function, Token.Status will be set to EFI_ABORTED and then Token.Event will be\r
+  signaled. If the token is not in one of the queues, which usually means that the\r
+  asynchronous operation has completed, this function will not signal the token and\r
+  EFI_NOT_FOUND is returned.\r
+\r
+  @param[in]  This                Pointer to EFI_DNS6_PROTOCOL instance.\r
+  @param[in]  Token               Pointer to a token that has been issued by\r
+                                  EFI_DNS6_PROTOCOL.HostNameToIp (),\r
+                                  EFI_DNS6_PROTOCOL.IpToHostName() or\r
+                                  EFI_DNS6_PROTOCOL.GeneralLookup().\r
+                                  If NULL, all pending tokens are aborted.\r
+\r
+  @retval EFI_SUCCESS             Incoming or outgoing data was processed.\r
+  @retval EFI_NOT_STARTED         This EFI DNS6 Protocol instance has not been started.\r
+  @retval EFI_INVALID_PARAMETER   This is NULL.\r
+  @retval EFI_NO_MAPPING          There's no source address is available for use.\r
+  @retval EFI_NOT_FOUND           When Token is not NULL, and the asynchronous DNS\r
+                                  operation was not found in the transmit queue. It\r
+                                  was either completed or was not issued by\r
+                                  HostNameToIp(), IpToHostName() or GeneralLookup().\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r