/** @file\r
DnsDxe support functions implementation.\r
\r
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
while (!EFI_ERROR (gBS->CheckEvent (Service->TimerToGetMap))) {\r
Udp->Poll (Udp);\r
\r
- if (!EFI_ERROR (Udp->GetModeData (Udp, NULL, &Ip6Mode, NULL, NULL)) &&\r
- Ip6Mode.IsConfigured) {\r
+ if (!EFI_ERROR (Udp->GetModeData (Udp, NULL, &Ip6Mode, NULL, NULL))) {\r
+ if (Ip6Mode.AddressList != NULL) {\r
+ FreePool (Ip6Mode.AddressList);\r
+ }\r
\r
- Udp->Configure (Udp, NULL);\r
- return (BOOLEAN) (Udp->Configure (Udp, UdpCfgData) == EFI_SUCCESS);\r
+ if (Ip6Mode.GroupTable != NULL) {\r
+ FreePool (Ip6Mode.GroupTable);\r
+ }\r
+\r
+ if (Ip6Mode.RouteTable != NULL) {\r
+ FreePool (Ip6Mode.RouteTable);\r
+ }\r
+\r
+ if (Ip6Mode.NeighborCache != NULL) {\r
+ FreePool (Ip6Mode.NeighborCache);\r
+ }\r
+\r
+ if (Ip6Mode.PrefixTable != NULL) {\r
+ FreePool (Ip6Mode.PrefixTable);\r
+ }\r
+\r
+ if (Ip6Mode.IcmpTypeList != NULL) {\r
+ FreePool (Ip6Mode.IcmpTypeList);\r
+ }\r
+\r
+ if (Ip6Mode.IsConfigured) {\r
+ Udp->Configure (Udp, NULL);\r
+ return (BOOLEAN) (Udp->Configure (Udp, UdpCfgData) == EFI_SUCCESS);\r
+ }\r
}\r
}\r
\r
return EFI_SUCCESS;\r
}\r
\r
-/**\r
- Fill QName for IP querying. QName is a domain name represented as \r
- a sequence of labels, where each label consists of a length octet \r
- followed by that number of octets. The domain name terminates with \r
- the zero length octet for the null label of the root. Caller should \r
- take responsibility to the buffer in QName.\r
-\r
- @param HostName Queried HostName \r
-\r
- @retval NULL Failed to fill QName.\r
- @return QName filled successfully.\r
- \r
-**/ \r
-UINT8 *\r
-EFIAPI\r
-DnsFillinQNameForQueryIp (\r
- IN CHAR16 *HostName\r
- )\r
-{\r
- CHAR8 *QueryName;\r
- CHAR8 *Header;\r
- CHAR8 *Tail;\r
- UINTN Len;\r
- UINTN Index;\r
-\r
- QueryName = NULL;\r
- Header = NULL;\r
- Tail = NULL;\r
-\r
- QueryName = AllocateZeroPool (DNS_DEFAULT_BLKSIZE);\r
- if (QueryName == NULL) {\r
- return NULL;\r
- }\r
- \r
- Header = QueryName;\r
- Tail = Header + 1;\r
- Len = 0;\r
- for (Index = 0; HostName[Index] != 0; Index++) {\r
- *Tail = (CHAR8) HostName[Index];\r
- if (*Tail == '.') {\r
- *Header = (CHAR8) Len;\r
- Header = Tail;\r
- Tail ++;\r
- Len = 0;\r
- } else {\r
- Tail++;\r
- Len++;\r
- }\r
- }\r
- *Header = (CHAR8) Len;\r
- *Tail = 0;\r
-\r
- return QueryName;\r
-}\r
-\r
/**\r
Find out whether the response is valid or invalid.\r
\r
@param TokensMap All DNS transmittal Tokens entry. \r
@param Identification Identification for queried packet. \r
@param Type Type for queried packet.\r
+ @param Class Class for queried packet.\r
@param Item Return corresponding Token entry.\r
\r
@retval TRUE The response is valid.\r
IN NET_MAP *TokensMap,\r
IN UINT16 Identification,\r
IN UINT16 Type,\r
+ IN UINT16 Class,\r
OUT NET_MAP_ITEM **Item\r
)\r
{\r
DnsHeader = (DNS_HEADER *) TxString;\r
QueryName = (CHAR8 *) (TxString + sizeof (*DnsHeader));\r
QuerySection = (DNS_QUERY_SECTION *) (QueryName + AsciiStrLen (QueryName) + 1);\r
-\r
- DnsHeader->Identification = NTOHS (DnsHeader->Identification);\r
- QuerySection->Type = NTOHS (QuerySection->Type);\r
\r
- if (DnsHeader->Identification == Identification && QuerySection->Type == Type) {\r
+ if (NTOHS (DnsHeader->Identification) == Identification &&\r
+ NTOHS (QuerySection->Type) == Type && \r
+ NTOHS (QuerySection->Class) == Class) {\r
return TRUE;\r
}\r
} \r
}\r
\r
- *Item =NULL;\r
+ *Item = NULL;\r
\r
return FALSE;\r
}\r
// Check DnsResponse Validity, if so, also get a valid NET_MAP_ITEM.\r
//\r
if (Instance->Service->IpVersion == IP_VERSION_4) {\r
- if (!IsValidDnsResponse (&Instance->Dns4TxTokens, DnsHeader->Identification, QuerySection->Type, &Item)) {\r
+ if (!IsValidDnsResponse (\r
+ &Instance->Dns4TxTokens, \r
+ DnsHeader->Identification, \r
+ QuerySection->Type,\r
+ QuerySection->Class,\r
+ &Item\r
+ )) {\r
*Completed = FALSE;\r
Status = EFI_ABORTED;\r
goto ON_EXIT;\r
ASSERT (Item != NULL);\r
Dns4TokenEntry = (DNS4_TOKEN_ENTRY *) (Item->Key);\r
} else {\r
- if (!IsValidDnsResponse (&Instance->Dns6TxTokens, DnsHeader->Identification, QuerySection->Type, &Item)) {\r
+ if (!IsValidDnsResponse (\r
+ &Instance->Dns6TxTokens, \r
+ DnsHeader->Identification, \r
+ QuerySection->Type,\r
+ QuerySection->Class,\r
+ &Item\r
+ )) {\r
*Completed = FALSE;\r
Status = EFI_ABORTED;\r
goto ON_EXIT;\r
// Continue Check Some Errors.\r
//\r
if (DnsHeader->Flags.Bits.RCode != DNS_FLAGS_RCODE_NO_ERROR || DnsHeader->AnswersNum < 1 || \\r
- DnsHeader->Flags.Bits.QR != DNS_FLAGS_QR_RESPONSE || QuerySection->Class != DNS_CLASS_INET) {\r
+ DnsHeader->Flags.Bits.QR != DNS_FLAGS_QR_RESPONSE) {\r
Status = EFI_ABORTED;\r
goto ON_EXIT;\r
}\r
}\r
\r
ASSERT (Packet != NULL);\r
+\r
+ if (Packet->TotalSize <= sizeof (DNS_HEADER)) {\r
+ goto ON_EXIT;\r
+ }\r
\r
RcvString = NetbufGetByte (Packet, 0, NULL);\r
ASSERT (RcvString != NULL);\r
//\r
ParseDnsResponse (Instance, RcvString, &Completed);\r
\r
- ON_EXIT:\r
+ON_EXIT:\r
\r
- if (Packet != NULL) {\r
- NetbufFree (Packet);\r
- }\r
+ if (Packet != NULL) {\r
+ NetbufFree (Packet);\r
+ }\r
\r
- if (!Completed) {\r
- UdpIoRecvDatagram (Instance->UdpIo, DnsOnPacketReceived, Instance, 0);\r
- }\r
+ if (!Completed) {\r
+ UdpIoRecvDatagram (Instance->UdpIo, DnsOnPacketReceived, Instance, 0);\r
+ }\r
}\r
\r
/**\r
NET_FRAGMENT Frag;\r
DNS_HEADER *DnsHeader;\r
DNS_QUERY_SECTION *DnsQuery;\r
- \r
- Frag.Bulk = AllocatePool (DNS_DEFAULT_BLKSIZE * sizeof (UINT8));\r
+\r
+ //\r
+ // Messages carried by UDP are restricted to 512 bytes (not counting the IP\r
+ // or UDP headers).\r
+ //\r
+ Frag.Bulk = AllocatePool (DNS_MAX_MESSAGE_SIZE * sizeof (UINT8));\r
if (Frag.Bulk == NULL) {\r
return EFI_OUT_OF_RESOURCES;\r
}\r