UINT32 IpCount;\r
UINT32 RRCount;\r
UINT32 AnswerSectionNum;\r
+ UINT32 CNameTtl;\r
\r
EFI_IPv4_ADDRESS *HostAddr4;\r
EFI_IPv6_ADDRESS *HostAddr6;\r
IpCount = 0;\r
RRCount = 0;\r
AnswerSectionNum = 0;\r
+ CNameTtl = 0;\r
\r
HostAddr4 = NULL;\r
HostAddr6 = NULL;\r
Status = EFI_ABORTED;\r
goto ON_EXIT;\r
}\r
-\r
- //\r
- // Free the sending packet.\r
- //\r
- if (Item->Value != NULL) {\r
- NetbufFree ((NET_BUF *) (Item->Value));\r
- }\r
\r
//\r
// Do some buffer allocations.\r
//\r
Dns6TokenEntry->Token->RspData.GLookupData = AllocatePool (sizeof (DNS_RESOURCE_RECORD));\r
if (Dns6TokenEntry->Token->RspData.GLookupData == NULL) {\r
- Status = EFI_UNSUPPORTED;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
goto ON_EXIT;\r
}\r
Dns6TokenEntry->Token->RspData.GLookupData->RRList = AllocatePool (DnsHeader->AnswersNum * sizeof (DNS_RESOURCE_RECORD));\r
if (Dns6TokenEntry->Token->RspData.GLookupData->RRList == NULL) {\r
- Status = EFI_UNSUPPORTED;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
goto ON_EXIT;\r
}\r
} else {\r
if (QuerySection->Type == DNS_TYPE_AAAA) {\r
Dns6TokenEntry->Token->RspData.H2AData = AllocatePool (sizeof (DNS6_HOST_TO_ADDR_DATA));\r
if (Dns6TokenEntry->Token->RspData.H2AData == NULL) {\r
- Status = EFI_UNSUPPORTED;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
goto ON_EXIT;\r
}\r
Dns6TokenEntry->Token->RspData.H2AData->IpList = AllocatePool (DnsHeader->AnswersNum * sizeof (EFI_IPv6_ADDRESS));\r
if (Dns6TokenEntry->Token->RspData.H2AData->IpList == NULL) {\r
- Status = EFI_UNSUPPORTED;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
goto ON_EXIT;\r
}\r
} else {\r
}\r
}\r
\r
+ Status = EFI_NOT_FOUND;\r
+\r
//\r
// Processing AnswerSection.\r
//\r
//\r
Dns4RR[RRCount].QName = AllocateZeroPool (AsciiStrLen (QueryName) + 1);\r
if (Dns4RR[RRCount].QName == NULL) {\r
- Status = EFI_UNSUPPORTED;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
goto ON_EXIT;\r
}\r
CopyMem (Dns4RR[RRCount].QName, QueryName, AsciiStrLen (QueryName));\r
Dns4RR[RRCount].DataLength = AnswerSection->DataLength;\r
Dns4RR[RRCount].RData = AllocateZeroPool (Dns4RR[RRCount].DataLength);\r
if (Dns4RR[RRCount].RData == NULL) {\r
- Status = EFI_UNSUPPORTED;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
goto ON_EXIT;\r
}\r
CopyMem (Dns4RR[RRCount].RData, AnswerData, Dns4RR[RRCount].DataLength);\r
\r
RRCount ++;\r
+ Status = EFI_SUCCESS;\r
} else if (Instance->Service->IpVersion == IP_VERSION_6 && Dns6TokenEntry->GeneralLookUp) {\r
Dns6RR = Dns6TokenEntry->Token->RspData.GLookupData->RRList;\r
AnswerData = (UINT8 *) AnswerSection + sizeof (*AnswerSection);\r
//\r
Dns6RR[RRCount].QName = AllocateZeroPool (AsciiStrLen (QueryName) + 1);\r
if (Dns6RR[RRCount].QName == NULL) {\r
- Status = EFI_UNSUPPORTED;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
goto ON_EXIT;\r
}\r
CopyMem (Dns6RR[RRCount].QName, QueryName, AsciiStrLen (QueryName));\r
Dns6RR[RRCount].DataLength = AnswerSection->DataLength;\r
Dns6RR[RRCount].RData = AllocateZeroPool (Dns6RR[RRCount].DataLength);\r
if (Dns6RR[RRCount].RData == NULL) {\r
- Status = EFI_UNSUPPORTED;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
goto ON_EXIT;\r
}\r
CopyMem (Dns6RR[RRCount].RData, AnswerData, Dns6RR[RRCount].DataLength);\r
\r
RRCount ++;\r
+ Status = EFI_SUCCESS;\r
} else {\r
//\r
// It's not the GeneralLookUp querying. \r
//\r
Dns4CacheEntry = AllocateZeroPool (sizeof (EFI_DNS4_CACHE_ENTRY));\r
if (Dns4CacheEntry == NULL) {\r
- Status = EFI_UNSUPPORTED;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
goto ON_EXIT;\r
}\r
Dns4CacheEntry->HostName = AllocateZeroPool (2 * (StrLen(Dns4TokenEntry->QueryHostName) + 1));\r
if (Dns4CacheEntry->HostName == NULL) {\r
- Status = EFI_UNSUPPORTED;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
goto ON_EXIT;\r
}\r
CopyMem (Dns4CacheEntry->HostName, Dns4TokenEntry->QueryHostName, 2 * (StrLen(Dns4TokenEntry->QueryHostName) + 1));\r
Dns4CacheEntry->IpAddress = AllocateZeroPool (sizeof (EFI_IPv4_ADDRESS));\r
if (Dns4CacheEntry->IpAddress == NULL) {\r
- Status = EFI_UNSUPPORTED;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
goto ON_EXIT;\r
}\r
CopyMem (Dns4CacheEntry->IpAddress, AnswerData, sizeof (EFI_IPv4_ADDRESS));\r
- Dns4CacheEntry->Timeout = AnswerSection->Ttl;\r
+\r
+ if (CNameTtl != 0 && AnswerSection->Ttl != 0) {\r
+ Dns4CacheEntry->Timeout = MIN (CNameTtl, AnswerSection->Ttl);\r
+ } else {\r
+ Dns4CacheEntry->Timeout = MAX (CNameTtl, AnswerSection->Ttl);\r
+ }\r
\r
UpdateDns4Cache (&mDriverData->Dns4CacheList, FALSE, TRUE, *Dns4CacheEntry); \r
\r
- IpCount ++; \r
+ IpCount ++;\r
+ Status = EFI_SUCCESS;\r
break;\r
case DNS_TYPE_AAAA:\r
//\r
//\r
Dns6CacheEntry = AllocateZeroPool (sizeof (EFI_DNS6_CACHE_ENTRY));\r
if (Dns6CacheEntry == NULL) {\r
- Status = EFI_UNSUPPORTED;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
goto ON_EXIT;\r
}\r
Dns6CacheEntry->HostName = AllocateZeroPool (2 * (StrLen(Dns6TokenEntry->QueryHostName) + 1));\r
if (Dns6CacheEntry->HostName == NULL) {\r
- Status = EFI_UNSUPPORTED;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
goto ON_EXIT;\r
}\r
CopyMem (Dns6CacheEntry->HostName, Dns6TokenEntry->QueryHostName, 2 * (StrLen(Dns6TokenEntry->QueryHostName) + 1));\r
Dns6CacheEntry->IpAddress = AllocateZeroPool (sizeof (EFI_IPv6_ADDRESS));\r
if (Dns6CacheEntry->IpAddress == NULL) {\r
- Status = EFI_UNSUPPORTED;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
goto ON_EXIT;\r
}\r
CopyMem (Dns6CacheEntry->IpAddress, AnswerData, sizeof (EFI_IPv6_ADDRESS));\r
- Dns6CacheEntry->Timeout = AnswerSection->Ttl;\r
+\r
+ if (CNameTtl != 0 && AnswerSection->Ttl != 0) {\r
+ Dns6CacheEntry->Timeout = MIN (CNameTtl, AnswerSection->Ttl);\r
+ } else {\r
+ Dns6CacheEntry->Timeout = MAX (CNameTtl, AnswerSection->Ttl);\r
+ }\r
\r
UpdateDns6Cache (&mDriverData->Dns6CacheList, FALSE, TRUE, *Dns6CacheEntry); \r
\r
IpCount ++;\r
+ Status = EFI_SUCCESS;\r
+ break;\r
+ case DNS_TYPE_CNAME:\r
+ //\r
+ // According RFC 1034 - 3.6.2, if the query name is an alias, the name server will include the CNAME \r
+ // record in the response and restart the query at the domain name specified in the data field of the \r
+ // CNAME record. So, just record the TTL value of the CNAME, then skip to parse the next record.\r
+ //\r
+ CNameTtl = AnswerSection->Ttl;\r
break;\r
default:\r
Status = EFI_UNSUPPORTED;\r
}\r
\r
//\r
- // Parsing is complete, SignalEvent here.\r
+ // Parsing is complete, free the sending packet and signal Event here.\r
//\r
+ if (Item != NULL && Item->Value != NULL) {\r
+ NetbufFree ((NET_BUF *) (Item->Value));\r
+ }\r
+ \r
if (Instance->Service->IpVersion == IP_VERSION_4) {\r
ASSERT (Dns4TokenEntry != NULL);\r
Dns4RemoveTokenEntry (&Instance->Dns4TxTokens, Dns4TokenEntry);\r
- Dns4TokenEntry->Token->Status = EFI_SUCCESS;\r
+ Dns4TokenEntry->Token->Status = Status;\r
if (Dns4TokenEntry->Token->Event != NULL) {\r
gBS->SignalEvent (Dns4TokenEntry->Token->Event);\r
DispatchDpc ();\r
} else {\r
ASSERT (Dns6TokenEntry != NULL);\r
Dns6RemoveTokenEntry (&Instance->Dns6TxTokens, Dns6TokenEntry);\r
- Dns6TokenEntry->Token->Status = EFI_SUCCESS;\r
+ Dns6TokenEntry->Token->Status = Status;\r
if (Dns6TokenEntry->Token->Event != NULL) {\r
gBS->SignalEvent (Dns6TokenEntry->Token->Event);\r
DispatchDpc ();\r
Entry = mDriverData->Dns4CacheList.ForwardLink;\r
while (Entry != &mDriverData->Dns4CacheList) {\r
Item4 = NET_LIST_USER_STRUCT (Entry, DNS4_CACHE, AllCacheLink);\r
- if (Item4->DnsCache.Timeout<=0) {\r
+ if (Item4->DnsCache.Timeout == 0) {\r
RemoveEntryList (&Item4->AllCacheLink);\r
Entry = mDriverData->Dns4CacheList.ForwardLink;\r
} else {\r
Entry = mDriverData->Dns6CacheList.ForwardLink;\r
while (Entry != &mDriverData->Dns6CacheList) {\r
Item6 = NET_LIST_USER_STRUCT (Entry, DNS6_CACHE, AllCacheLink);\r
- if (Item6->DnsCache.Timeout<=0) {\r
+ if (Item6->DnsCache.Timeout == 0) {\r
RemoveEntryList (&Item6->AllCacheLink);\r
Entry = mDriverData->Dns6CacheList.ForwardLink;\r
} else {\r