X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=NetworkPkg%2FDnsDxe%2FDnsImpl.c;h=89ea755cb2b95b094f81e76e352cb771e18a0e44;hp=617e623286d86f448b77e224735c62cae6afc4d9;hb=f75a7f568e6d0944327970b3f3f2dafd9bba76b1;hpb=ce22514e4800dca7854a4778a66e8f08d2b18345 diff --git a/NetworkPkg/DnsDxe/DnsImpl.c b/NetworkPkg/DnsDxe/DnsImpl.c index 617e623286..89ea755cb2 100644 --- a/NetworkPkg/DnsDxe/DnsImpl.c +++ b/NetworkPkg/DnsDxe/DnsImpl.c @@ -1,7 +1,7 @@ /** @file DnsDxe support functions implementation. - -Copyright (c) 2016, Intel Corporation. All rights reserved.
+ +Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -45,7 +45,7 @@ Dns4RemoveTokenEntry ( return EFI_SUCCESS; } - + return EFI_NOT_FOUND; } @@ -57,7 +57,7 @@ Dns4RemoveTokenEntry ( @retval EFI_SUCCESS Remove TokenEntry from TokenMap sucessfully. @retval EFI_NOT_FOUND TokenEntry is not found in TokenMap. - + **/ EFI_STATUS Dns6RemoveTokenEntry ( @@ -80,7 +80,7 @@ Dns6RemoveTokenEntry ( return EFI_SUCCESS; } - + return EFI_NOT_FOUND; } @@ -219,24 +219,24 @@ EFI_STATUS EFIAPI GetDns4TokenEntry ( IN NET_MAP *TokensMap, - IN EFI_DNS4_COMPLETION_TOKEN *Token, + IN EFI_DNS4_COMPLETION_TOKEN *Token, OUT DNS4_TOKEN_ENTRY **TokenEntry ) { LIST_ENTRY *Entry; - + NET_MAP_ITEM *Item; - + NET_LIST_FOR_EACH (Entry, &TokensMap->Used) { Item = NET_LIST_USER_STRUCT (Entry, NET_MAP_ITEM, Link); - *TokenEntry = (DNS4_TOKEN_ENTRY *) (Item->Key); + *TokenEntry = (DNS4_TOKEN_ENTRY *) (Item->Key); if ((*TokenEntry)->Token == Token) { return EFI_SUCCESS; } } - + *TokenEntry = NULL; - + return EFI_NOT_FOUND; } @@ -255,24 +255,24 @@ EFI_STATUS EFIAPI GetDns6TokenEntry ( IN NET_MAP *TokensMap, - IN EFI_DNS6_COMPLETION_TOKEN *Token, + IN EFI_DNS6_COMPLETION_TOKEN *Token, OUT DNS6_TOKEN_ENTRY **TokenEntry ) { LIST_ENTRY *Entry; - + NET_MAP_ITEM *Item; - + NET_LIST_FOR_EACH (Entry, &TokensMap->Used) { Item = NET_LIST_USER_STRUCT (Entry, NET_MAP_ITEM, Link); - *TokenEntry = (DNS6_TOKEN_ENTRY *) (Item->Key); + *TokenEntry = (DNS6_TOKEN_ENTRY *) (Item->Key); if ((*TokenEntry)->Token == Token) { return EFI_SUCCESS; } } - + *TokenEntry =NULL; - + return EFI_NOT_FOUND; } @@ -325,7 +325,7 @@ Dns4InstanceCancelToken ( } ASSERT ((TokenEntry != NULL) || (0 == NetMapGetCount (&Instance->Dns4TxTokens))); - + if (NetMapIsEmpty (&Instance->Dns4TxTokens)) { Instance->UdpIo->Protocol.Udp4->Cancel (Instance->UdpIo->Protocol.Udp4, &Instance->UdpIo->RecvRequest->Token.Udp4); } @@ -382,7 +382,7 @@ Dns6InstanceCancelToken ( } ASSERT ((TokenEntry != NULL) || (0 == NetMapGetCount (&Instance->Dns6TxTokens))); - + if (NetMapIsEmpty (&Instance->Dns6TxTokens)) { Instance->UdpIo->Protocol.Udp6->Cancel (Instance->UdpIo->Protocol.Udp6, &Instance->UdpIo->RecvRequest->Token.Udp6); } @@ -526,9 +526,9 @@ DnsDummyExtFree ( /** Poll the UDP to get the IP4 default address, which may be retrieved - by DHCP. - - The default time out value is 5 seconds. If IP has retrieved the default address, + by DHCP. + + The default time out value is 5 seconds. If IP has retrieved the default address, the UDP is reconfigured. @param Instance The DNS instance @@ -565,7 +565,7 @@ Dns4GetMapping ( return FALSE; } - while (!EFI_ERROR (gBS->CheckEvent (Service->TimerToGetMap))) { + while (EFI_ERROR (gBS->CheckEvent (Service->TimerToGetMap))) { Udp->Poll (Udp); if (!EFI_ERROR (Udp->GetModeData (Udp, NULL, &Ip4Mode, NULL, NULL)) && @@ -615,7 +615,7 @@ Dns6GetMapping ( return FALSE; } - while (!EFI_ERROR (gBS->CheckEvent (Service->TimerToGetMap))) { + while (EFI_ERROR (gBS->CheckEvent (Service->TimerToGetMap))) { Udp->Poll (Udp); if (!EFI_ERROR (Udp->GetModeData (Udp, NULL, &Ip6Mode, NULL, NULL))) { @@ -643,9 +643,11 @@ Dns6GetMapping ( FreePool (Ip6Mode.IcmpTypeList); } - if (Ip6Mode.IsConfigured) { + if (!Ip6Mode.IsStarted || Ip6Mode.IsConfigured) { Udp->Configure (Udp, NULL); - return (BOOLEAN) (Udp->Configure (Udp, UdpCfgData) == EFI_SUCCESS); + if (Udp->Configure (Udp, UdpCfgData) == EFI_SUCCESS) { + return TRUE; + } } } } @@ -655,10 +657,10 @@ Dns6GetMapping ( /** Configure the UDP. - + @param Instance The DNS session @param UdpIo The UDP_IO instance - + @retval EFI_SUCCESS The UDP is successfully configured for the session. @@ -697,13 +699,13 @@ Dns4ConfigUdp ( if ((Status == EFI_NO_MAPPING) && Dns4GetMapping (Instance, UdpIo, &UdpConfig)) { return EFI_SUCCESS; } - + return Status; } /** Configure the UDP. - + @param Instance The DNS session @param UdpIo The UDP_IO instance @@ -740,24 +742,24 @@ Dns6ConfigUdp ( if ((Status == EFI_NO_MAPPING) && Dns6GetMapping (Instance, UdpIo, &UdpConfig)) { return EFI_SUCCESS; } - + return Status; } /** Update Dns4 cache to shared list of caches of all DNSv4 instances. - + @param Dns4CacheList All Dns4 cache list. - @param DeleteFlag If FALSE, this function is to add one entry to the DNS Cache. - If TRUE, this function will delete matching DNS Cache entry. - @param Override If TRUE, the matching DNS cache entry will be overwritten with the supplied parameter. + @param DeleteFlag If FALSE, this function is to add one entry to the DNS Cache. + If TRUE, this function will delete matching DNS Cache entry. + @param Override If TRUE, the matching DNS cache entry will be overwritten with the supplied parameter. If FALSE, EFI_ACCESS_DENIED will be returned if the entry to be added is already exists. @param DnsCacheEntry Entry Pointer to DNS Cache entry. @retval EFI_SUCCESS Update Dns4 cache successfully. - @retval Others Failed to update Dns4 cache. - -**/ + @retval Others Failed to update Dns4 cache. + +**/ EFI_STATUS EFIAPI UpdateDns4Cache ( @@ -767,14 +769,14 @@ UpdateDns4Cache ( IN EFI_DNS4_CACHE_ENTRY DnsCacheEntry ) { - DNS4_CACHE *NewDnsCache; + DNS4_CACHE *NewDnsCache; DNS4_CACHE *Item; LIST_ENTRY *Entry; LIST_ENTRY *Next; NewDnsCache = NULL; Item = NULL; - + // // Search the database for the matching EFI_DNS_CACHE_ENTRY // @@ -790,14 +792,18 @@ UpdateDns4Cache ( // Delete matching DNS Cache entry // RemoveEntryList (&Item->AllCacheLink); - + + FreePool (Item->DnsCache.HostName); + FreePool (Item->DnsCache.IpAddress); + FreePool (Item); + return EFI_SUCCESS; } else if (Override) { // // Update this one // Item->DnsCache.Timeout = DnsCacheEntry.Timeout; - + return EFI_SUCCESS; }else { return EFI_ACCESS_DENIED; @@ -809,46 +815,49 @@ UpdateDns4Cache ( // Add new one // NewDnsCache = AllocatePool (sizeof (DNS4_CACHE)); - if (NewDnsCache == NULL) { + if (NewDnsCache == NULL) { return EFI_OUT_OF_RESOURCES; } - + InitializeListHead (&NewDnsCache->AllCacheLink); - + NewDnsCache->DnsCache.HostName = AllocatePool (StrSize (DnsCacheEntry.HostName)); - if (NewDnsCache->DnsCache.HostName == NULL) { + if (NewDnsCache->DnsCache.HostName == NULL) { + FreePool (NewDnsCache); return EFI_OUT_OF_RESOURCES; } - + CopyMem (NewDnsCache->DnsCache.HostName, DnsCacheEntry.HostName, StrSize (DnsCacheEntry.HostName)); NewDnsCache->DnsCache.IpAddress = AllocatePool (sizeof (EFI_IPv4_ADDRESS)); - if (NewDnsCache->DnsCache.IpAddress == NULL) { + if (NewDnsCache->DnsCache.IpAddress == NULL) { + FreePool (NewDnsCache->DnsCache.HostName); + FreePool (NewDnsCache); return EFI_OUT_OF_RESOURCES; } CopyMem (NewDnsCache->DnsCache.IpAddress, DnsCacheEntry.IpAddress, sizeof (EFI_IPv4_ADDRESS)); NewDnsCache->DnsCache.Timeout = DnsCacheEntry.Timeout; - + InsertTailList (Dns4CacheList, &NewDnsCache->AllCacheLink); - + return EFI_SUCCESS; } /** - Update Dns6 cache to shared list of caches of all DNSv6 instances. + Update Dns6 cache to shared list of caches of all DNSv6 instances. @param Dns6CacheList All Dns6 cache list. - @param DeleteFlag If FALSE, this function is to add one entry to the DNS Cache. - If TRUE, this function will delete matching DNS Cache entry. - @param Override If TRUE, the matching DNS cache entry will be overwritten with the supplied parameter. + @param DeleteFlag If FALSE, this function is to add one entry to the DNS Cache. + If TRUE, this function will delete matching DNS Cache entry. + @param Override If TRUE, the matching DNS cache entry will be overwritten with the supplied parameter. If FALSE, EFI_ACCESS_DENIED will be returned if the entry to be added is already exists. @param DnsCacheEntry Entry Pointer to DNS Cache entry. - + @retval EFI_SUCCESS Update Dns6 cache successfully. @retval Others Failed to update Dns6 cache. -**/ +**/ EFI_STATUS EFIAPI UpdateDns6Cache ( @@ -858,14 +867,14 @@ UpdateDns6Cache ( IN EFI_DNS6_CACHE_ENTRY DnsCacheEntry ) { - DNS6_CACHE *NewDnsCache; + DNS6_CACHE *NewDnsCache; DNS6_CACHE *Item; LIST_ENTRY *Entry; LIST_ENTRY *Next; NewDnsCache = NULL; Item = NULL; - + // // Search the database for the matching EFI_DNS_CACHE_ENTRY // @@ -881,14 +890,18 @@ UpdateDns6Cache ( // Delete matching DNS Cache entry // RemoveEntryList (&Item->AllCacheLink); - + + FreePool (Item->DnsCache.HostName); + FreePool (Item->DnsCache.IpAddress); + FreePool (Item); + return EFI_SUCCESS; } else if (Override) { // // Update this one // Item->DnsCache.Timeout = DnsCacheEntry.Timeout; - + return EFI_SUCCESS; }else { return EFI_ACCESS_DENIED; @@ -900,43 +913,46 @@ UpdateDns6Cache ( // Add new one // NewDnsCache = AllocatePool (sizeof (DNS6_CACHE)); - if (NewDnsCache == NULL) { + if (NewDnsCache == NULL) { return EFI_OUT_OF_RESOURCES; } - + InitializeListHead (&NewDnsCache->AllCacheLink); - + NewDnsCache->DnsCache.HostName = AllocatePool (StrSize (DnsCacheEntry.HostName)); - if (NewDnsCache->DnsCache.HostName == NULL) { + if (NewDnsCache->DnsCache.HostName == NULL) { + FreePool (NewDnsCache); return EFI_OUT_OF_RESOURCES; } - + CopyMem (NewDnsCache->DnsCache.HostName, DnsCacheEntry.HostName, StrSize (DnsCacheEntry.HostName)); NewDnsCache->DnsCache.IpAddress = AllocatePool (sizeof (EFI_IPv6_ADDRESS)); - if (NewDnsCache->DnsCache.IpAddress == NULL) { + if (NewDnsCache->DnsCache.IpAddress == NULL) { + FreePool (NewDnsCache->DnsCache.HostName); + FreePool (NewDnsCache); return EFI_OUT_OF_RESOURCES; } - + CopyMem (NewDnsCache->DnsCache.IpAddress, DnsCacheEntry.IpAddress, sizeof (EFI_IPv6_ADDRESS)); NewDnsCache->DnsCache.Timeout = DnsCacheEntry.Timeout; - + InsertTailList (Dns6CacheList, &NewDnsCache->AllCacheLink); - + return EFI_SUCCESS; } /** - Add Dns4 ServerIp to common list of addresses of all configured DNSv4 server. + Add Dns4 ServerIp to common list of addresses of all configured DNSv4 server. - @param Dns4ServerList Common list of addresses of all configured DNSv4 server. - @param ServerIp DNS server Ip. + @param Dns4ServerList Common list of addresses of all configured DNSv4 server. + @param ServerIp DNS server Ip. @retval EFI_SUCCESS Add Dns4 ServerIp to common list successfully. @retval Others Failed to add Dns4 ServerIp to common list. - -**/ + +**/ EFI_STATUS EFIAPI AddDns4ServerIp ( @@ -944,14 +960,14 @@ AddDns4ServerIp ( IN EFI_IPv4_ADDRESS ServerIp ) { - DNS4_SERVER_IP *NewServerIp; + DNS4_SERVER_IP *NewServerIp; DNS4_SERVER_IP *Item; LIST_ENTRY *Entry; LIST_ENTRY *Next; NewServerIp = NULL; Item = NULL; - + // // Search the database for the matching ServerIp // @@ -960,7 +976,7 @@ AddDns4ServerIp ( if (CompareMem (&Item->Dns4ServerIp, &ServerIp, sizeof (EFI_IPv4_ADDRESS)) == 0) { // // Already done. - // + // return EFI_SUCCESS; } } @@ -969,29 +985,29 @@ AddDns4ServerIp ( // Add new one // NewServerIp = AllocatePool (sizeof (DNS4_SERVER_IP)); - if (NewServerIp == NULL) { + if (NewServerIp == NULL) { return EFI_OUT_OF_RESOURCES; } - + InitializeListHead (&NewServerIp->AllServerLink); - + CopyMem (&NewServerIp->Dns4ServerIp, &ServerIp, sizeof (EFI_IPv4_ADDRESS)); - + InsertTailList (Dns4ServerList, &NewServerIp->AllServerLink); - + return EFI_SUCCESS; } /** - Add Dns6 ServerIp to common list of addresses of all configured DNSv6 server. + Add Dns6 ServerIp to common list of addresses of all configured DNSv6 server. - @param Dns6ServerList Common list of addresses of all configured DNSv6 server. - @param ServerIp DNS server Ip. + @param Dns6ServerList Common list of addresses of all configured DNSv6 server. + @param ServerIp DNS server Ip. @retval EFI_SUCCESS Add Dns6 ServerIp to common list successfully. @retval Others Failed to add Dns6 ServerIp to common list. - -**/ + +**/ EFI_STATUS EFIAPI AddDns6ServerIp ( @@ -999,14 +1015,14 @@ AddDns6ServerIp ( IN EFI_IPv6_ADDRESS ServerIp ) { - DNS6_SERVER_IP *NewServerIp; + DNS6_SERVER_IP *NewServerIp; DNS6_SERVER_IP *Item; LIST_ENTRY *Entry; LIST_ENTRY *Next; NewServerIp = NULL; Item = NULL; - + // // Search the database for the matching ServerIp // @@ -1015,7 +1031,7 @@ AddDns6ServerIp ( if (CompareMem (&Item->Dns6ServerIp, &ServerIp, sizeof (EFI_IPv6_ADDRESS)) == 0) { // // Already done. - // + // return EFI_SUCCESS; } } @@ -1024,91 +1040,38 @@ AddDns6ServerIp ( // Add new one // NewServerIp = AllocatePool (sizeof (DNS6_SERVER_IP)); - if (NewServerIp == NULL) { + if (NewServerIp == NULL) { return EFI_OUT_OF_RESOURCES; } - + InitializeListHead (&NewServerIp->AllServerLink); - + CopyMem (&NewServerIp->Dns6ServerIp, &ServerIp, sizeof (EFI_IPv6_ADDRESS)); - - InsertTailList (Dns6ServerList, &NewServerIp->AllServerLink); - - return EFI_SUCCESS; -} -/** - Fill QName for IP querying. QName is a domain name represented as - a sequence of labels, where each label consists of a length octet - followed by that number of octets. The domain name terminates with - the zero length octet for the null label of the root. Caller should - take responsibility to the buffer in QName. - - @param HostName Queried HostName - - @retval NULL Failed to fill QName. - @return QName filled successfully. - -**/ -CHAR8 * -EFIAPI -DnsFillinQNameForQueryIp ( - IN CHAR16 *HostName - ) -{ - CHAR8 *QueryName; - CHAR8 *Header; - CHAR8 *Tail; - UINTN Len; - UINTN Index; - - QueryName = NULL; - Header = NULL; - Tail = NULL; - - QueryName = AllocateZeroPool (DNS_DEFAULT_BLKSIZE); - if (QueryName == NULL) { - return NULL; - } - - Header = QueryName; - Tail = Header + 1; - Len = 0; - for (Index = 0; HostName[Index] != 0; Index++) { - *Tail = (CHAR8) HostName[Index]; - if (*Tail == '.') { - *Header = (CHAR8) Len; - Header = Tail; - Tail ++; - Len = 0; - } else { - Tail++; - Len++; - } - } - *Header = (CHAR8) Len; - *Tail = 0; + InsertTailList (Dns6ServerList, &NewServerIp->AllServerLink); - return QueryName; + return EFI_SUCCESS; } /** Find out whether the response is valid or invalid. - @param TokensMap All DNS transmittal Tokens entry. - @param Identification Identification for queried packet. + @param TokensMap All DNS transmittal Tokens entry. + @param Identification Identification for queried packet. @param Type Type for queried packet. + @param Class Class for queried packet. @param Item Return corresponding Token entry. @retval TRUE The response is valid. @retval FALSE The response is invalid. - -**/ + +**/ BOOLEAN IsValidDnsResponse ( IN NET_MAP *TokensMap, IN UINT16 Identification, IN UINT16 Type, + IN UINT16 Class, OUT NET_MAP_ITEM **Item ) { @@ -1124,7 +1087,7 @@ IsValidDnsResponse ( *Item = NET_LIST_USER_STRUCT (Entry, NET_MAP_ITEM, Link); Packet = (NET_BUF *) ((*Item)->Value); if (Packet == NULL){ - + continue; } else { TxString = NetbufGetByte (Packet, 0, NULL); @@ -1133,17 +1096,16 @@ IsValidDnsResponse ( QueryName = (CHAR8 *) (TxString + sizeof (*DnsHeader)); QuerySection = (DNS_QUERY_SECTION *) (QueryName + AsciiStrLen (QueryName) + 1); - DnsHeader->Identification = NTOHS (DnsHeader->Identification); - QuerySection->Type = NTOHS (QuerySection->Type); - - if (DnsHeader->Identification == Identification && QuerySection->Type == Type) { + if (NTOHS (DnsHeader->Identification) == Identification && + NTOHS (QuerySection->Type) == Type && + NTOHS (QuerySection->Class) == Class) { return TRUE; } - } + } } - - *Item =NULL; - + + *Item = NULL; + return FALSE; } @@ -1152,12 +1114,12 @@ IsValidDnsResponse ( @param Instance The DNS instance @param RxString Received buffer. - @param Completed Flag to indicate that Dns response is valid. - + @param Completed Flag to indicate that Dns response is valid. + @retval EFI_SUCCESS Parse Dns Response successfully. @retval Others Failed to parse Dns Response. - -**/ + +**/ EFI_STATUS ParseDnsResponse ( IN OUT DNS_INSTANCE *Instance, @@ -1166,10 +1128,10 @@ ParseDnsResponse ( ) { DNS_HEADER *DnsHeader; - + CHAR8 *QueryName; DNS_QUERY_SECTION *QuerySection; - + CHAR8 *AnswerName; DNS_ANSWER_SECTION *AnswerSection; UINT8 *AnswerData; @@ -1177,11 +1139,12 @@ ParseDnsResponse ( NET_MAP_ITEM *Item; DNS4_TOKEN_ENTRY *Dns4TokenEntry; DNS6_TOKEN_ENTRY *Dns6TokenEntry; - + UINT32 IpCount; UINT32 RRCount; UINT32 AnswerSectionNum; - + UINT32 CNameTtl; + EFI_IPv4_ADDRESS *HostAddr4; EFI_IPv6_ADDRESS *HostAddr6; @@ -1194,32 +1157,33 @@ ParseDnsResponse ( EFI_STATUS Status; EFI_TPL OldTpl; - + Item = NULL; Dns4TokenEntry = NULL; Dns6TokenEntry = NULL; - + IpCount = 0; RRCount = 0; AnswerSectionNum = 0; - + CNameTtl = 0; + HostAddr4 = NULL; HostAddr6 = NULL; - + Dns4CacheEntry = NULL; Dns6CacheEntry = NULL; - + Dns4RR = NULL; Dns6RR = NULL; *Completed = TRUE; Status = EFI_SUCCESS; - + // // Get header // DnsHeader = (DNS_HEADER *) RxString; - + DnsHeader->Identification = NTOHS (DnsHeader->Identification); DnsHeader->Flags.Uint16 = NTOHS (DnsHeader->Flags.Uint16); DnsHeader->QuestionsNum = NTOHS (DnsHeader->QuestionsNum); @@ -1250,7 +1214,13 @@ ParseDnsResponse ( // Check DnsResponse Validity, if so, also get a valid NET_MAP_ITEM. // if (Instance->Service->IpVersion == IP_VERSION_4) { - if (!IsValidDnsResponse (&Instance->Dns4TxTokens, DnsHeader->Identification, QuerySection->Type, &Item)) { + if (!IsValidDnsResponse ( + &Instance->Dns4TxTokens, + DnsHeader->Identification, + QuerySection->Type, + QuerySection->Class, + &Item + )) { *Completed = FALSE; Status = EFI_ABORTED; goto ON_EXIT; @@ -1258,7 +1228,13 @@ ParseDnsResponse ( ASSERT (Item != NULL); Dns4TokenEntry = (DNS4_TOKEN_ENTRY *) (Item->Key); } else { - if (!IsValidDnsResponse (&Instance->Dns6TxTokens, DnsHeader->Identification, QuerySection->Type, &Item)) { + if (!IsValidDnsResponse ( + &Instance->Dns6TxTokens, + DnsHeader->Identification, + QuerySection->Type, + QuerySection->Class, + &Item + )) { *Completed = FALSE; Status = EFI_ABORTED; goto ON_EXIT; @@ -1266,23 +1242,24 @@ ParseDnsResponse ( ASSERT (Item != NULL); Dns6TokenEntry = (DNS6_TOKEN_ENTRY *) (Item->Key); } - + // // Continue Check Some Errors. // if (DnsHeader->Flags.Bits.RCode != DNS_FLAGS_RCODE_NO_ERROR || DnsHeader->AnswersNum < 1 || \ - DnsHeader->Flags.Bits.QR != DNS_FLAGS_QR_RESPONSE || QuerySection->Class != DNS_CLASS_INET) { - Status = EFI_ABORTED; - goto ON_EXIT; - } + DnsHeader->Flags.Bits.QR != DNS_FLAGS_QR_RESPONSE) { + // + // The domain name referenced in the query does not exist. + // + if (DnsHeader->Flags.Bits.RCode == DNS_FLAGS_RCODE_NAME_ERROR) { + Status = EFI_NOT_FOUND; + } else { + Status = EFI_DEVICE_ERROR; + } - // - // Free the sending packet. - // - if (Item->Value != NULL) { - NetbufFree ((NET_BUF *) (Item->Value)); + goto ON_COMPLETE; } - + // // Do some buffer allocations. // @@ -1293,12 +1270,12 @@ ParseDnsResponse ( // // It's the GeneralLookUp querying. // - Dns4TokenEntry->Token->RspData.GLookupData = AllocatePool (sizeof (DNS_RESOURCE_RECORD)); + Dns4TokenEntry->Token->RspData.GLookupData = AllocateZeroPool (sizeof (DNS_RESOURCE_RECORD)); if (Dns4TokenEntry->Token->RspData.GLookupData == NULL) { Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } - Dns4TokenEntry->Token->RspData.GLookupData->RRList = AllocatePool (DnsHeader->AnswersNum * sizeof (DNS_RESOURCE_RECORD)); + Dns4TokenEntry->Token->RspData.GLookupData->RRList = AllocateZeroPool (DnsHeader->AnswersNum * sizeof (DNS_RESOURCE_RECORD)); if (Dns4TokenEntry->Token->RspData.GLookupData->RRList == NULL) { Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; @@ -1308,12 +1285,12 @@ ParseDnsResponse ( // It's not the GeneralLookUp querying. Check the Query type. // if (QuerySection->Type == DNS_TYPE_A) { - Dns4TokenEntry->Token->RspData.H2AData = AllocatePool (sizeof (DNS_HOST_TO_ADDR_DATA)); + Dns4TokenEntry->Token->RspData.H2AData = AllocateZeroPool (sizeof (DNS_HOST_TO_ADDR_DATA)); if (Dns4TokenEntry->Token->RspData.H2AData == NULL) { Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } - Dns4TokenEntry->Token->RspData.H2AData->IpList = AllocatePool (DnsHeader->AnswersNum * sizeof (EFI_IPv4_ADDRESS)); + Dns4TokenEntry->Token->RspData.H2AData->IpList = AllocateZeroPool (DnsHeader->AnswersNum * sizeof (EFI_IPv4_ADDRESS)); if (Dns4TokenEntry->Token->RspData.H2AData->IpList == NULL) { Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; @@ -1330,14 +1307,14 @@ ParseDnsResponse ( // // It's the GeneralLookUp querying. // - Dns6TokenEntry->Token->RspData.GLookupData = AllocatePool (sizeof (DNS_RESOURCE_RECORD)); + Dns6TokenEntry->Token->RspData.GLookupData = AllocateZeroPool (sizeof (DNS_RESOURCE_RECORD)); if (Dns6TokenEntry->Token->RspData.GLookupData == NULL) { - Status = EFI_UNSUPPORTED; + Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } - Dns6TokenEntry->Token->RspData.GLookupData->RRList = AllocatePool (DnsHeader->AnswersNum * sizeof (DNS_RESOURCE_RECORD)); + Dns6TokenEntry->Token->RspData.GLookupData->RRList = AllocateZeroPool (DnsHeader->AnswersNum * sizeof (DNS_RESOURCE_RECORD)); if (Dns6TokenEntry->Token->RspData.GLookupData->RRList == NULL) { - Status = EFI_UNSUPPORTED; + Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } } else { @@ -1345,14 +1322,14 @@ ParseDnsResponse ( // It's not the GeneralLookUp querying. Check the Query type. // if (QuerySection->Type == DNS_TYPE_AAAA) { - Dns6TokenEntry->Token->RspData.H2AData = AllocatePool (sizeof (DNS6_HOST_TO_ADDR_DATA)); + Dns6TokenEntry->Token->RspData.H2AData = AllocateZeroPool (sizeof (DNS6_HOST_TO_ADDR_DATA)); if (Dns6TokenEntry->Token->RspData.H2AData == NULL) { - Status = EFI_UNSUPPORTED; + Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } - Dns6TokenEntry->Token->RspData.H2AData->IpList = AllocatePool (DnsHeader->AnswersNum * sizeof (EFI_IPv6_ADDRESS)); + Dns6TokenEntry->Token->RspData.H2AData->IpList = AllocateZeroPool (DnsHeader->AnswersNum * sizeof (EFI_IPv6_ADDRESS)); if (Dns6TokenEntry->Token->RspData.H2AData->IpList == NULL) { - Status = EFI_UNSUPPORTED; + Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } } else { @@ -1362,15 +1339,20 @@ ParseDnsResponse ( } } + Status = EFI_NOT_FOUND; + // // Processing AnswerSection. // while (AnswerSectionNum < DnsHeader->AnswersNum) { // - // Answer name should be PTR. + // Answer name should be PTR, else EFI_UNSUPPORTED returned. // - ASSERT ((*(UINT8 *) AnswerName & 0xC0) == 0xC0); - + if ((*(UINT8 *) AnswerName & 0xC0) != 0xC0) { + Status = EFI_UNSUPPORTED; + goto ON_EXIT; + } + // // Get Answer section. // @@ -1392,7 +1374,7 @@ ParseDnsResponse ( // Dns4RR[RRCount].QName = AllocateZeroPool (AsciiStrLen (QueryName) + 1); if (Dns4RR[RRCount].QName == NULL) { - Status = EFI_UNSUPPORTED; + Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } CopyMem (Dns4RR[RRCount].QName, QueryName, AsciiStrLen (QueryName)); @@ -1402,12 +1384,13 @@ ParseDnsResponse ( Dns4RR[RRCount].DataLength = AnswerSection->DataLength; Dns4RR[RRCount].RData = AllocateZeroPool (Dns4RR[RRCount].DataLength); if (Dns4RR[RRCount].RData == NULL) { - Status = EFI_UNSUPPORTED; + Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } CopyMem (Dns4RR[RRCount].RData, AnswerData, Dns4RR[RRCount].DataLength); - + RRCount ++; + Status = EFI_SUCCESS; } else if (Instance->Service->IpVersion == IP_VERSION_6 && Dns6TokenEntry->GeneralLookUp) { Dns6RR = Dns6TokenEntry->Token->RspData.GLookupData->RRList; AnswerData = (UINT8 *) AnswerSection + sizeof (*AnswerSection); @@ -1417,7 +1400,7 @@ ParseDnsResponse ( // Dns6RR[RRCount].QName = AllocateZeroPool (AsciiStrLen (QueryName) + 1); if (Dns6RR[RRCount].QName == NULL) { - Status = EFI_UNSUPPORTED; + Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } CopyMem (Dns6RR[RRCount].QName, QueryName, AsciiStrLen (QueryName)); @@ -1427,15 +1410,16 @@ ParseDnsResponse ( Dns6RR[RRCount].DataLength = AnswerSection->DataLength; Dns6RR[RRCount].RData = AllocateZeroPool (Dns6RR[RRCount].DataLength); if (Dns6RR[RRCount].RData == NULL) { - Status = EFI_UNSUPPORTED; + Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } CopyMem (Dns6RR[RRCount].RData, AnswerData, Dns6RR[RRCount].DataLength); - + RRCount ++; + Status = EFI_SUCCESS; } else { // - // It's not the GeneralLookUp querying. + // It's not the GeneralLookUp querying. // Check the Query type, parse the response packet. // switch (AnswerSection->Type) { @@ -1443,110 +1427,134 @@ ParseDnsResponse ( // // This is address entry, get Data. // - ASSERT (Dns4TokenEntry != NULL && AnswerSection->DataLength == 4); - + ASSERT (Dns4TokenEntry != NULL); + + if (AnswerSection->DataLength != 4) { + Status = EFI_ABORTED; + goto ON_EXIT; + } + HostAddr4 = Dns4TokenEntry->Token->RspData.H2AData->IpList; AnswerData = (UINT8 *) AnswerSection + sizeof (*AnswerSection); CopyMem (&HostAddr4[IpCount], AnswerData, sizeof (EFI_IPv4_ADDRESS)); // - // Update DNS cache dynamically. - // - if (Dns4CacheEntry != NULL) { - if (Dns4CacheEntry->HostName != NULL) { - FreePool (Dns4CacheEntry->HostName); - } - - if (Dns4CacheEntry->IpAddress != NULL) { - FreePool (Dns4CacheEntry->IpAddress); - } - - FreePool (Dns4CacheEntry); - } - - // - // Allocate new CacheEntry pool. + // Allocate new CacheEntry pool to update DNS cache dynamically. // Dns4CacheEntry = AllocateZeroPool (sizeof (EFI_DNS4_CACHE_ENTRY)); if (Dns4CacheEntry == NULL) { - Status = EFI_UNSUPPORTED; + Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } Dns4CacheEntry->HostName = AllocateZeroPool (2 * (StrLen(Dns4TokenEntry->QueryHostName) + 1)); if (Dns4CacheEntry->HostName == NULL) { - Status = EFI_UNSUPPORTED; + Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } CopyMem (Dns4CacheEntry->HostName, Dns4TokenEntry->QueryHostName, 2 * (StrLen(Dns4TokenEntry->QueryHostName) + 1)); Dns4CacheEntry->IpAddress = AllocateZeroPool (sizeof (EFI_IPv4_ADDRESS)); if (Dns4CacheEntry->IpAddress == NULL) { - Status = EFI_UNSUPPORTED; + Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } CopyMem (Dns4CacheEntry->IpAddress, AnswerData, sizeof (EFI_IPv4_ADDRESS)); - Dns4CacheEntry->Timeout = AnswerSection->Ttl; - - UpdateDns4Cache (&mDriverData->Dns4CacheList, FALSE, TRUE, *Dns4CacheEntry); - IpCount ++; + if (CNameTtl != 0 && AnswerSection->Ttl != 0) { + Dns4CacheEntry->Timeout = MIN (CNameTtl, AnswerSection->Ttl); + } else { + Dns4CacheEntry->Timeout = MAX (CNameTtl, AnswerSection->Ttl); + } + + UpdateDns4Cache (&mDriverData->Dns4CacheList, FALSE, TRUE, *Dns4CacheEntry); + + // + // Free allocated CacheEntry pool. + // + FreePool (Dns4CacheEntry->HostName); + Dns4CacheEntry->HostName = NULL; + + FreePool (Dns4CacheEntry->IpAddress); + Dns4CacheEntry->IpAddress = NULL; + + FreePool (Dns4CacheEntry); + Dns4CacheEntry = NULL; + + IpCount ++; + Status = EFI_SUCCESS; break; case DNS_TYPE_AAAA: // // This is address entry, get Data. // - ASSERT (Dns6TokenEntry != NULL && AnswerSection->DataLength == 16); - + ASSERT (Dns6TokenEntry != NULL); + + if (AnswerSection->DataLength != 16) { + Status = EFI_ABORTED; + goto ON_EXIT; + } + HostAddr6 = Dns6TokenEntry->Token->RspData.H2AData->IpList; AnswerData = (UINT8 *) AnswerSection + sizeof (*AnswerSection); CopyMem (&HostAddr6[IpCount], AnswerData, sizeof (EFI_IPv6_ADDRESS)); // - // Update DNS cache dynamically. - // - if (Dns6CacheEntry != NULL) { - if (Dns6CacheEntry->HostName != NULL) { - FreePool (Dns6CacheEntry->HostName); - } - - if (Dns6CacheEntry->IpAddress != NULL) { - FreePool (Dns6CacheEntry->IpAddress); - } - - FreePool (Dns6CacheEntry); - } - - // - // Allocate new CacheEntry pool. + // Allocate new CacheEntry pool to update DNS cache dynamically. // Dns6CacheEntry = AllocateZeroPool (sizeof (EFI_DNS6_CACHE_ENTRY)); if (Dns6CacheEntry == NULL) { - Status = EFI_UNSUPPORTED; + Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } Dns6CacheEntry->HostName = AllocateZeroPool (2 * (StrLen(Dns6TokenEntry->QueryHostName) + 1)); if (Dns6CacheEntry->HostName == NULL) { - Status = EFI_UNSUPPORTED; + Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } CopyMem (Dns6CacheEntry->HostName, Dns6TokenEntry->QueryHostName, 2 * (StrLen(Dns6TokenEntry->QueryHostName) + 1)); Dns6CacheEntry->IpAddress = AllocateZeroPool (sizeof (EFI_IPv6_ADDRESS)); if (Dns6CacheEntry->IpAddress == NULL) { - Status = EFI_UNSUPPORTED; + Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } CopyMem (Dns6CacheEntry->IpAddress, AnswerData, sizeof (EFI_IPv6_ADDRESS)); - Dns6CacheEntry->Timeout = AnswerSection->Ttl; - - UpdateDns6Cache (&mDriverData->Dns6CacheList, FALSE, TRUE, *Dns6CacheEntry); - + + if (CNameTtl != 0 && AnswerSection->Ttl != 0) { + Dns6CacheEntry->Timeout = MIN (CNameTtl, AnswerSection->Ttl); + } else { + Dns6CacheEntry->Timeout = MAX (CNameTtl, AnswerSection->Ttl); + } + + UpdateDns6Cache (&mDriverData->Dns6CacheList, FALSE, TRUE, *Dns6CacheEntry); + + // + // Free allocated CacheEntry pool. + // + FreePool (Dns6CacheEntry->HostName); + Dns6CacheEntry->HostName = NULL; + + FreePool (Dns6CacheEntry->IpAddress); + Dns6CacheEntry->IpAddress = NULL; + + FreePool (Dns6CacheEntry); + Dns6CacheEntry = NULL; + IpCount ++; + Status = EFI_SUCCESS; + break; + case DNS_TYPE_CNAME: + // + // According RFC 1034 - 3.6.2, if the query name is an alias, the name server will include the CNAME + // record in the response and restart the query at the domain name specified in the data field of the + // CNAME record. So, just record the TTL value of the CNAME, then skip to parse the next record. + // + CNameTtl = AnswerSection->Ttl; break; default: Status = EFI_UNSUPPORTED; goto ON_EXIT; } } - + // // Find next one // @@ -1556,7 +1564,7 @@ ParseDnsResponse ( if (Instance->Service->IpVersion == IP_VERSION_4) { ASSERT (Dns4TokenEntry != NULL); - + if (Dns4TokenEntry->GeneralLookUp) { Dns4TokenEntry->Token->RspData.GLookupData->RRCount = RRCount; } else { @@ -1582,13 +1590,18 @@ ParseDnsResponse ( } } +ON_COMPLETE: // - // Parsing is complete, SignalEvent here. + // Parsing is complete, free the sending packet and signal Event here. // + if (Item != NULL && Item->Value != NULL) { + NetbufFree ((NET_BUF *) (Item->Value)); + } + if (Instance->Service->IpVersion == IP_VERSION_4) { ASSERT (Dns4TokenEntry != NULL); Dns4RemoveTokenEntry (&Instance->Dns4TxTokens, Dns4TokenEntry); - Dns4TokenEntry->Token->Status = EFI_SUCCESS; + Dns4TokenEntry->Token->Status = Status; if (Dns4TokenEntry->Token->Event != NULL) { gBS->SignalEvent (Dns4TokenEntry->Token->Event); DispatchDpc (); @@ -1596,41 +1609,105 @@ ParseDnsResponse ( } else { ASSERT (Dns6TokenEntry != NULL); Dns6RemoveTokenEntry (&Instance->Dns6TxTokens, Dns6TokenEntry); - Dns6TokenEntry->Token->Status = EFI_SUCCESS; + Dns6TokenEntry->Token->Status = Status; if (Dns6TokenEntry->Token->Event != NULL) { gBS->SignalEvent (Dns6TokenEntry->Token->Event); DispatchDpc (); } } - // - // Free allocated CacheEntry pool. +ON_EXIT: + // + // Free the allocated buffer if error happen. // - if (Dns4CacheEntry != NULL) { - if (Dns4CacheEntry->HostName != NULL) { - FreePool (Dns4CacheEntry->HostName); + if (EFI_ERROR (Status)) { + if (Dns4TokenEntry != NULL) { + if (Dns4TokenEntry->GeneralLookUp) { + if (Dns4TokenEntry->Token->RspData.GLookupData != NULL) { + if (Dns4TokenEntry->Token->RspData.GLookupData->RRList != NULL) { + while (RRCount != 0) { + RRCount --; + if (Dns4TokenEntry->Token->RspData.GLookupData->RRList[RRCount].QName != NULL) { + FreePool (Dns4TokenEntry->Token->RspData.GLookupData->RRList[RRCount].QName); + } + + if (Dns4TokenEntry->Token->RspData.GLookupData->RRList[RRCount].RData != NULL) { + FreePool (Dns4TokenEntry->Token->RspData.GLookupData->RRList[RRCount].RData); + } + } + + FreePool (Dns4TokenEntry->Token->RspData.GLookupData->RRList); + } + + FreePool (Dns4TokenEntry->Token->RspData.GLookupData); + } + } else { + if (QuerySection->Type == DNS_TYPE_A && Dns4TokenEntry->Token->RspData.H2AData != NULL) { + if (Dns4TokenEntry->Token->RspData.H2AData->IpList != NULL) { + FreePool (Dns4TokenEntry->Token->RspData.H2AData->IpList); + } + + FreePool (Dns4TokenEntry->Token->RspData.H2AData); + } + } } - if (Dns4CacheEntry->IpAddress != NULL) { - FreePool (Dns4CacheEntry->IpAddress); + if (Dns6TokenEntry != NULL) { + if (Dns6TokenEntry->GeneralLookUp) { + if (Dns6TokenEntry->Token->RspData.GLookupData != NULL) { + if (Dns6TokenEntry->Token->RspData.GLookupData->RRList != NULL) { + while (RRCount != 0) { + RRCount --; + if (Dns6TokenEntry->Token->RspData.GLookupData->RRList[RRCount].QName != NULL) { + FreePool (Dns6TokenEntry->Token->RspData.GLookupData->RRList[RRCount].QName); + } + + if (Dns6TokenEntry->Token->RspData.GLookupData->RRList[RRCount].RData != NULL) { + FreePool (Dns6TokenEntry->Token->RspData.GLookupData->RRList[RRCount].RData); + } + } + + FreePool (Dns6TokenEntry->Token->RspData.GLookupData->RRList); + } + + FreePool (Dns6TokenEntry->Token->RspData.GLookupData); + } + } else { + if (QuerySection->Type == DNS_TYPE_AAAA && Dns6TokenEntry->Token->RspData.H2AData != NULL) { + if (Dns6TokenEntry->Token->RspData.H2AData->IpList != NULL) { + FreePool (Dns6TokenEntry->Token->RspData.H2AData->IpList); + } + + FreePool (Dns6TokenEntry->Token->RspData.H2AData); + } + } } - FreePool (Dns4CacheEntry); - } - - if (Dns6CacheEntry != NULL) { - if (Dns6CacheEntry->HostName != NULL) { - FreePool (Dns6CacheEntry->HostName); + if (Dns4CacheEntry != NULL) { + if (Dns4CacheEntry->HostName != NULL) { + FreePool (Dns4CacheEntry->HostName); + } + + if (Dns4CacheEntry->IpAddress != NULL) { + FreePool (Dns4CacheEntry->IpAddress); + } + + FreePool (Dns4CacheEntry); } - if (Dns6CacheEntry->IpAddress != NULL) { - FreePool (Dns6CacheEntry->IpAddress); + if (Dns6CacheEntry != NULL) { + if (Dns6CacheEntry->HostName != NULL) { + FreePool (Dns6CacheEntry->HostName); + } + + if (Dns6CacheEntry->IpAddress != NULL) { + FreePool (Dns6CacheEntry->IpAddress); + } + + FreePool (Dns6CacheEntry); } - - FreePool (Dns6CacheEntry); } -ON_EXIT: gBS->RestoreTPL (OldTpl); return Status; } @@ -1643,7 +1720,7 @@ ON_EXIT: @param IoStatus The status of the UDP receive @param Context The opaque parameter to the function. -**/ +**/ VOID EFIAPI DnsOnPacketReceived ( @@ -1658,7 +1735,7 @@ DnsOnPacketReceived ( UINT8 *RcvString; BOOLEAN Completed; - + Instance = (DNS_INSTANCE *) Context; NET_CHECK_SIGNATURE (Instance, DNS_INSTANCE_SIGNATURE); @@ -1670,24 +1747,28 @@ DnsOnPacketReceived ( } ASSERT (Packet != NULL); - + + if (Packet->TotalSize <= sizeof (DNS_HEADER)) { + goto ON_EXIT; + } + RcvString = NetbufGetByte (Packet, 0, NULL); ASSERT (RcvString != NULL); - + // // Parse Dns Response // ParseDnsResponse (Instance, RcvString, &Completed); - ON_EXIT: +ON_EXIT: - if (Packet != NULL) { - NetbufFree (Packet); - } + if (Packet != NULL) { + NetbufFree (Packet); + } - if (!Completed) { - UdpIoRecvDatagram (Instance->UdpIo, DnsOnPacketReceived, Instance, 0); - } + if (!Completed) { + UdpIoRecvDatagram (Instance->UdpIo, DnsOnPacketReceived, Instance, 0); + } } /** @@ -1739,7 +1820,7 @@ DnsOnPacketSent ( } } } - + NetbufFree (Packet); } @@ -1770,14 +1851,14 @@ DoDnsQuery ( return Status; } } - + // // Transmit the DNS packet. // NET_GET_REF (Packet); Status = UdpIoSendDatagram (Instance->UdpIo, Packet, NULL, NULL, DnsOnPacketSent, Instance); - + return Status; } @@ -1785,9 +1866,9 @@ DoDnsQuery ( Construct the Packet according query section. @param Instance The DNS instance - @param QueryName Queried Name - @param Type Queried Type - @param Class Queried Class + @param QueryName Queried Name + @param Type Queried Type + @param Class Queried Class @param Packet The packet for query @retval EFI_SUCCESS The packet is constructed. @@ -1806,8 +1887,12 @@ ConstructDNSQuery ( NET_FRAGMENT Frag; DNS_HEADER *DnsHeader; DNS_QUERY_SECTION *DnsQuery; - - Frag.Bulk = AllocatePool (DNS_DEFAULT_BLKSIZE * sizeof (UINT8)); + + // + // Messages carried by UDP are restricted to 512 bytes (not counting the IP + // or UDP headers). + // + Frag.Bulk = AllocatePool (DNS_MAX_MESSAGE_SIZE * sizeof (UINT8)); if (Frag.Bulk == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -1815,7 +1900,7 @@ ConstructDNSQuery ( // // Fill header // - DnsHeader = (DNS_HEADER *) Frag.Bulk; + DnsHeader = (DNS_HEADER *) Frag.Bulk; DnsHeader->Identification = (UINT16)NET_RANDOM (NetRandomInitSeed()); DnsHeader->Flags.Uint16 = 0x0000; DnsHeader->Flags.Bits.RD = 1; @@ -1842,7 +1927,7 @@ ConstructDNSQuery ( Frag.Len = (UINT32) (Frag.Len + AsciiStrLen (QueryName)); *(Frag.Bulk + Frag.Len) = 0; Frag.Len ++; - + // // Rest query section // @@ -1861,7 +1946,7 @@ ConstructDNSQuery ( FreePool (Frag.Bulk); return EFI_OUT_OF_RESOURCES; } - + // // Store the UdpIo in ProtoData. // @@ -1874,7 +1959,7 @@ ConstructDNSQuery ( Retransmit the packet. @param Instance The DNS instance - @param Packet Retransmit the packet + @param Packet Retransmit the packet @retval EFI_SUCCESS The packet is retransmitted. @retval Others Failed to retransmit. @@ -1887,7 +1972,7 @@ DnsRetransmit ( ) { EFI_STATUS Status; - + UINT8 *Buffer; ASSERT (Packet != NULL); @@ -1968,7 +2053,7 @@ DnsOnTimerRetransmit ( // Retransmit the packet if haven't reach the maxmium retry count, // otherwise exit the transfer. // - if (++Dns4TokenEntry->Token->RetryCount < Instance->MaxRetry) { + if (++Dns4TokenEntry->RetryCounting <= Dns4TokenEntry->Token->RetryCount) { DnsRetransmit (Instance, (NET_BUF *)ItemNetMap->Value); EntryNetMap = EntryNetMap->ForwardLink; } else { @@ -1979,7 +2064,7 @@ DnsOnTimerRetransmit ( Dns4TokenEntry->Token->Status = EFI_TIMEOUT; gBS->SignalEvent (Dns4TokenEntry->Token->Event); DispatchDpc (); - + // // Free the sending packet. // @@ -1990,7 +2075,7 @@ DnsOnTimerRetransmit ( EntryNetMap = Instance->Dns4TxTokens.Used.ForwardLink; } } - } + } }else { // // Iterate through all the children of the DNS service instance. Time @@ -1998,7 +2083,7 @@ DnsOnTimerRetransmit ( // NET_LIST_FOR_EACH_SAFE (Entry, Next, &Service->Dns6ChildrenList) { Instance = NET_LIST_USER_STRUCT (Entry, DNS_INSTANCE, Link); - + EntryNetMap = Instance->Dns6TxTokens.Used.ForwardLink; while (EntryNetMap != &Instance->Dns6TxTokens.Used) { ItemNetMap = NET_LIST_USER_STRUCT (EntryNetMap, NET_MAP_ITEM, Link); @@ -2012,7 +2097,7 @@ DnsOnTimerRetransmit ( // Retransmit the packet if haven't reach the maxmium retry count, // otherwise exit the transfer. // - if (++Dns6TokenEntry->Token->RetryCount < Instance->MaxRetry) { + if (++Dns6TokenEntry->RetryCounting <= Dns6TokenEntry->Token->RetryCount) { DnsRetransmit (Instance, (NET_BUF *) ItemNetMap->Value); EntryNetMap = EntryNetMap->ForwardLink; } else { @@ -2023,7 +2108,7 @@ DnsOnTimerRetransmit ( Dns6TokenEntry->Token->Status = EFI_TIMEOUT; gBS->SignalEvent (Dns6TokenEntry->Token->Event); DispatchDpc (); - + // // Free the sending packet. // @@ -2032,10 +2117,10 @@ DnsOnTimerRetransmit ( } EntryNetMap = Instance->Dns6TxTokens.Used.ForwardLink; - } + } } } - } + } } /** @@ -2067,18 +2152,21 @@ DnsOnTimerUpdate ( Item4 = NET_LIST_USER_STRUCT (Entry, DNS4_CACHE, AllCacheLink); Item4->DnsCache.Timeout--; } - + Entry = mDriverData->Dns4CacheList.ForwardLink; while (Entry != &mDriverData->Dns4CacheList) { Item4 = NET_LIST_USER_STRUCT (Entry, DNS4_CACHE, AllCacheLink); - if (Item4->DnsCache.Timeout<=0) { + if (Item4->DnsCache.Timeout == 0) { RemoveEntryList (&Item4->AllCacheLink); + FreePool (Item4->DnsCache.HostName); + FreePool (Item4->DnsCache.IpAddress); + FreePool (Item4); Entry = mDriverData->Dns4CacheList.ForwardLink; } else { Entry = Entry->ForwardLink; } } - + // // Iterate through all the DNS6 cache list. // @@ -2086,12 +2174,15 @@ DnsOnTimerUpdate ( Item6 = NET_LIST_USER_STRUCT (Entry, DNS6_CACHE, AllCacheLink); Item6->DnsCache.Timeout--; } - + Entry = mDriverData->Dns6CacheList.ForwardLink; while (Entry != &mDriverData->Dns6CacheList) { Item6 = NET_LIST_USER_STRUCT (Entry, DNS6_CACHE, AllCacheLink); - if (Item6->DnsCache.Timeout<=0) { + if (Item6->DnsCache.Timeout == 0) { RemoveEntryList (&Item6->AllCacheLink); + FreePool (Item6->DnsCache.HostName); + FreePool (Item6->DnsCache.IpAddress); + FreePool (Item6); Entry = mDriverData->Dns6CacheList.ForwardLink; } else { Entry = Entry->ForwardLink;