]>
Commit | Line | Data |
---|---|---|
99c048ef | 1 | /** @file\r |
2 | Implementation of EFI_DNS4_PROTOCOL and EFI_DNS6_PROTOCOL interfaces.\r | |
3 | \r | |
f75a7f56 | 4 | Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r |
ecf98fbc | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
99c048ef | 6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include "DnsImpl.h"\r | |
10 | \r | |
11 | EFI_DNS4_PROTOCOL mDns4Protocol = {\r | |
12 | Dns4GetModeData,\r | |
13 | Dns4Configure,\r | |
14 | Dns4HostNameToIp,\r | |
15 | Dns4IpToHostName,\r | |
16 | Dns4GeneralLookUp,\r | |
17 | Dns4UpdateDnsCache,\r | |
18 | Dns4Poll,\r | |
19 | Dns4Cancel\r | |
20 | };\r | |
21 | \r | |
22 | EFI_DNS6_PROTOCOL mDns6Protocol = {\r | |
23 | Dns6GetModeData,\r | |
24 | Dns6Configure,\r | |
25 | Dns6HostNameToIp,\r | |
26 | Dns6IpToHostName,\r | |
27 | Dns6GeneralLookUp,\r | |
28 | Dns6UpdateDnsCache,\r | |
29 | Dns6Poll,\r | |
30 | Dns6Cancel\r | |
31 | };\r | |
32 | \r | |
33 | /**\r | |
0f4e123f | 34 | Retrieve mode data of this DNS instance.\r |
99c048ef | 35 | \r |
0f4e123f | 36 | This function is used to retrieve DNS mode data for this DNS instance.\r |
99c048ef | 37 | \r |
0f4e123f JW |
38 | @param[in] This Pointer to EFI_DNS4_PROTOCOL instance.\r |
39 | @param[out] DnsModeData Point to the mode data.\r | |
99c048ef | 40 | \r |
0f4e123f JW |
41 | @retval EFI_SUCCESS The operation completed successfully.\r |
42 | @retval EFI_NOT_STARTED When DnsConfigData is queried, no configuration data\r | |
43 | is available because this instance has not been\r | |
44 | configured.\r | |
45 | @retval EFI_INVALID_PARAMETER This is NULL or DnsModeData is NULL.\r | |
46 | @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.\r | |
99c048ef | 47 | **/\r |
48 | EFI_STATUS\r | |
49 | EFIAPI\r | |
50 | Dns4GetModeData (\r | |
d1050b9d MK |
51 | IN EFI_DNS4_PROTOCOL *This,\r |
52 | OUT EFI_DNS4_MODE_DATA *DnsModeData\r | |
99c048ef | 53 | )\r |
54 | {\r | |
d1050b9d | 55 | DNS_INSTANCE *Instance;\r |
f75a7f56 | 56 | \r |
d1050b9d | 57 | EFI_TPL OldTpl;\r |
99c048ef | 58 | \r |
d1050b9d | 59 | UINTN Index;\r |
f75a7f56 | 60 | \r |
d1050b9d MK |
61 | LIST_ENTRY *Entry;\r |
62 | LIST_ENTRY *Next;\r | |
f75a7f56 | 63 | \r |
d1050b9d MK |
64 | DNS4_SERVER_IP *ServerItem;\r |
65 | EFI_IPv4_ADDRESS *ServerList;\r | |
66 | DNS4_CACHE *CacheItem;\r | |
67 | EFI_DNS4_CACHE_ENTRY *CacheList;\r | |
68 | EFI_STATUS Status;\r | |
99c048ef | 69 | \r |
70 | ServerItem = NULL;\r | |
71 | ServerList = NULL;\r | |
72 | CacheItem = NULL;\r | |
73 | CacheList = NULL;\r | |
74 | Status = EFI_SUCCESS;\r | |
f75a7f56 | 75 | \r |
99c048ef | 76 | if ((This == NULL) || (DnsModeData == NULL)) {\r |
77 | return EFI_INVALID_PARAMETER;\r | |
78 | }\r | |
79 | \r | |
80 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
f75a7f56 | 81 | \r |
99c048ef | 82 | Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This);\r |
83 | if (Instance->State == DNS_STATE_UNCONFIGED) {\r | |
ac0f5843 JW |
84 | Status = EFI_NOT_STARTED;\r |
85 | goto ON_EXIT;\r | |
99c048ef | 86 | }\r |
f75a7f56 | 87 | \r |
99c048ef | 88 | ZeroMem (DnsModeData, sizeof (EFI_DNS4_MODE_DATA));\r |
89 | \r | |
90 | //\r | |
f75a7f56 | 91 | // Get the current configuration data of this instance.\r |
99c048ef | 92 | //\r |
93 | Status = Dns4CopyConfigure (&DnsModeData->DnsConfigData, &Instance->Dns4CfgData);\r | |
94 | if (EFI_ERROR (Status)) {\r | |
ac0f5843 | 95 | goto ON_EXIT;\r |
99c048ef | 96 | }\r |
97 | \r | |
98 | //\r | |
99 | // Get the DnsServerCount and DnsServerList\r | |
100 | //\r | |
101 | Index = 0;\r | |
102 | NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns4ServerList) {\r | |
103 | Index++;\r | |
104 | }\r | |
d1050b9d MK |
105 | DnsModeData->DnsServerCount = (UINT32)Index;\r |
106 | ServerList = AllocatePool (sizeof (EFI_IPv4_ADDRESS) * DnsModeData->DnsServerCount);\r | |
ac0f5843 JW |
107 | if (ServerList == NULL) {\r |
108 | Status = EFI_OUT_OF_RESOURCES;\r | |
109 | Dns4CleanConfigure (&DnsModeData->DnsConfigData);\r | |
110 | goto ON_EXIT;\r | |
111 | }\r | |
f75a7f56 | 112 | \r |
99c048ef | 113 | Index = 0;\r |
114 | NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns4ServerList) {\r | |
115 | ServerItem = NET_LIST_USER_STRUCT (Entry, DNS4_SERVER_IP, AllServerLink);\r | |
116 | CopyMem (ServerList + Index, &ServerItem->Dns4ServerIp, sizeof (EFI_IPv4_ADDRESS));\r | |
117 | Index++;\r | |
118 | }\r | |
119 | DnsModeData->DnsServerList = ServerList;\r | |
120 | \r | |
121 | //\r | |
122 | // Get the DnsCacheCount and DnsCacheList\r | |
123 | //\r | |
d1050b9d | 124 | Index = 0;\r |
99c048ef | 125 | NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns4CacheList) {\r |
126 | Index++;\r | |
127 | }\r | |
d1050b9d MK |
128 | DnsModeData->DnsCacheCount = (UINT32)Index;\r |
129 | CacheList = AllocatePool (sizeof (EFI_DNS4_CACHE_ENTRY) * DnsModeData->DnsCacheCount);\r | |
ac0f5843 JW |
130 | if (CacheList == NULL) {\r |
131 | Status = EFI_OUT_OF_RESOURCES;\r | |
132 | Dns4CleanConfigure (&DnsModeData->DnsConfigData);\r | |
133 | FreePool (ServerList);\r | |
134 | goto ON_EXIT;\r | |
135 | }\r | |
f75a7f56 | 136 | \r |
d1050b9d | 137 | Index = 0;\r |
99c048ef | 138 | NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns4CacheList) {\r |
139 | CacheItem = NET_LIST_USER_STRUCT (Entry, DNS4_CACHE, AllCacheLink);\r | |
140 | CopyMem (CacheList + Index, &CacheItem->DnsCache, sizeof (EFI_DNS4_CACHE_ENTRY));\r | |
141 | Index++;\r | |
142 | }\r | |
143 | DnsModeData->DnsCacheList = CacheList;\r | |
144 | \r | |
ac0f5843 | 145 | ON_EXIT:\r |
99c048ef | 146 | gBS->RestoreTPL (OldTpl);\r |
ac0f5843 | 147 | return Status;\r |
99c048ef | 148 | }\r |
149 | \r | |
150 | /**\r | |
0f4e123f JW |
151 | Configure this DNS instance.\r |
152 | \r | |
153 | This function is used to configure DNS mode data for this DNS instance.\r | |
154 | \r | |
155 | @param[in] This Pointer to EFI_DNS4_PROTOCOL instance.\r | |
156 | @param[in] DnsConfigData Point to the Configuration data.\r | |
157 | \r | |
158 | @retval EFI_SUCCESS The operation completed successfully.\r | |
159 | @retval EFI_UNSUPPORTED The designated protocol is not supported.\r | |
81a46615 | 160 | @retval EFI_INVALID_PARAMETER This is NULL.\r |
f75a7f56 | 161 | The StationIp address provided in DnsConfigData is not a\r |
0f4e123f JW |
162 | valid unicast.\r |
163 | DnsServerList is NULL while DnsServerListCount\r | |
164 | is not ZERO.\r | |
165 | DnsServerListCount is ZERO while DnsServerList\r | |
166 | is not NULL\r | |
167 | @retval EFI_OUT_OF_RESOURCES The DNS instance data or required space could not be\r | |
168 | allocated.\r | |
169 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The\r | |
170 | EFI DNSv4 Protocol instance is not configured.\r | |
f75a7f56 LG |
171 | @retval EFI_ALREADY_STARTED Second call to Configure() with DnsConfigData. To\r |
172 | reconfigure the instance the caller must call Configure()\r | |
0f4e123f | 173 | with NULL first to return driver to unconfigured state.\r |
99c048ef | 174 | **/\r |
175 | EFI_STATUS\r | |
176 | EFIAPI\r | |
177 | Dns4Configure (\r | |
d1050b9d MK |
178 | IN EFI_DNS4_PROTOCOL *This,\r |
179 | IN EFI_DNS4_CONFIG_DATA *DnsConfigData\r | |
99c048ef | 180 | )\r |
181 | {\r | |
d1050b9d MK |
182 | EFI_STATUS Status;\r |
183 | DNS_INSTANCE *Instance;\r | |
f75a7f56 | 184 | \r |
d1050b9d MK |
185 | EFI_TPL OldTpl;\r |
186 | IP4_ADDR Ip;\r | |
187 | IP4_ADDR Netmask;\r | |
99c048ef | 188 | \r |
d1050b9d MK |
189 | UINT32 ServerListCount;\r |
190 | EFI_IPv4_ADDRESS *ServerList;\r | |
99c048ef | 191 | \r |
192 | Status = EFI_SUCCESS;\r | |
193 | ServerList = NULL;\r | |
f75a7f56 | 194 | \r |
d1050b9d MK |
195 | if ((This == NULL) ||\r |
196 | ((DnsConfigData != NULL) && (((DnsConfigData->DnsServerListCount != 0) && (DnsConfigData->DnsServerList == NULL)) ||\r | |
197 | ((DnsConfigData->DnsServerListCount == 0) && (DnsConfigData->DnsServerList != NULL)))))\r | |
198 | {\r | |
99c048ef | 199 | return EFI_INVALID_PARAMETER;\r |
200 | }\r | |
201 | \r | |
d1050b9d | 202 | if ((DnsConfigData != NULL) && (DnsConfigData->Protocol != DNS_PROTOCOL_UDP)) {\r |
99c048ef | 203 | return EFI_UNSUPPORTED;\r |
204 | }\r | |
205 | \r | |
206 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
207 | \r | |
208 | Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This);\r | |
209 | \r | |
210 | if (DnsConfigData == NULL) {\r | |
211 | ZeroMem (&Instance->SessionDnsServer, sizeof (EFI_IP_ADDRESS));\r | |
f75a7f56 | 212 | \r |
99c048ef | 213 | //\r |
214 | // Reset the Instance if ConfigData is NULL\r | |
215 | //\r | |
d1050b9d MK |
216 | if (!NetMapIsEmpty (&Instance->Dns4TxTokens)) {\r |
217 | Dns4InstanceCancelToken (Instance, NULL);\r | |
99c048ef | 218 | }\r |
219 | \r | |
4ad1bd63 | 220 | if (Instance->UdpIo != NULL) {\r |
99c048ef | 221 | UdpIoCleanIo (Instance->UdpIo);\r |
222 | }\r | |
f75a7f56 | 223 | \r |
99c048ef | 224 | if (Instance->Dns4CfgData.DnsServerList != NULL) {\r |
225 | FreePool (Instance->Dns4CfgData.DnsServerList);\r | |
226 | }\r | |
d1050b9d | 227 | \r |
99c048ef | 228 | ZeroMem (&Instance->Dns4CfgData, sizeof (EFI_DNS4_CONFIG_DATA));\r |
f75a7f56 | 229 | \r |
99c048ef | 230 | Instance->State = DNS_STATE_UNCONFIGED;\r |
231 | } else {\r | |
232 | //\r | |
233 | // Configure the parameters for new operation.\r | |
234 | //\r | |
235 | CopyMem (&Ip, &DnsConfigData->StationIp, sizeof (IP4_ADDR));\r | |
236 | CopyMem (&Netmask, &DnsConfigData->SubnetMask, sizeof (IP4_ADDR));\r | |
237 | \r | |
d1050b9d MK |
238 | Ip = NTOHL (Ip);\r |
239 | Netmask = NTOHL (Netmask);\r | |
99c048ef | 240 | \r |
241 | if (!DnsConfigData->UseDefaultSetting &&\r | |
d1050b9d MK |
242 | ((!IP4_IS_VALID_NETMASK (Netmask) || ((Netmask != 0) && !NetIp4IsUnicast (Ip, Netmask)))))\r |
243 | {\r | |
99c048ef | 244 | Status = EFI_INVALID_PARAMETER;\r |
245 | goto ON_EXIT;\r | |
246 | }\r | |
247 | \r | |
248 | Status = Dns4CopyConfigure (&Instance->Dns4CfgData, DnsConfigData);\r | |
249 | if (EFI_ERROR (Status)) {\r | |
250 | goto ON_EXIT;\r | |
251 | }\r | |
252 | \r | |
1b59de84 | 253 | if (DnsConfigData->DnsServerListCount == 0) {\r |
f75a7f56 LG |
254 | gBS->RestoreTPL (OldTpl);\r |
255 | \r | |
99c048ef | 256 | //\r |
257 | // The DNS instance will retrieve DNS server from DHCP Server\r | |
258 | //\r | |
259 | Status = GetDns4ServerFromDhcp4 (\r | |
260 | Instance,\r | |
f75a7f56 | 261 | &ServerListCount,\r |
99c048ef | 262 | &ServerList\r |
263 | );\r | |
264 | if (EFI_ERROR (Status)) {\r | |
265 | return Status;\r | |
266 | }\r | |
267 | \r | |
d1050b9d | 268 | ASSERT (ServerList != NULL);\r |
f75a7f56 | 269 | \r |
99c048ef | 270 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
271 | \r | |
272 | CopyMem (&Instance->SessionDnsServer.v4, &ServerList[0], sizeof (EFI_IPv4_ADDRESS));\r | |
273 | } else {\r | |
274 | CopyMem (&Instance->SessionDnsServer.v4, &DnsConfigData->DnsServerList[0], sizeof (EFI_IPv4_ADDRESS));\r | |
275 | }\r | |
276 | \r | |
277 | //\r | |
278 | // Config UDP\r | |
279 | //\r | |
280 | Status = Dns4ConfigUdp (Instance, Instance->UdpIo);\r | |
281 | if (EFI_ERROR (Status)) {\r | |
282 | if (Instance->Dns4CfgData.DnsServerList != NULL) {\r | |
283 | FreePool (Instance->Dns4CfgData.DnsServerList);\r | |
8aa2cdd7 | 284 | Instance->Dns4CfgData.DnsServerList = NULL;\r |
99c048ef | 285 | }\r |
d1050b9d | 286 | \r |
99c048ef | 287 | goto ON_EXIT;\r |
288 | }\r | |
289 | \r | |
290 | //\r | |
291 | // Add configured DNS server used by this instance to ServerList.\r | |
292 | //\r | |
293 | Status = AddDns4ServerIp (&mDriverData->Dns4ServerList, Instance->SessionDnsServer.v4);\r | |
294 | if (EFI_ERROR (Status)) {\r | |
295 | if (Instance->Dns4CfgData.DnsServerList != NULL) {\r | |
296 | FreePool (Instance->Dns4CfgData.DnsServerList);\r | |
8aa2cdd7 | 297 | Instance->Dns4CfgData.DnsServerList = NULL;\r |
99c048ef | 298 | }\r |
d1050b9d | 299 | \r |
99c048ef | 300 | goto ON_EXIT;\r |
301 | }\r | |
f75a7f56 | 302 | \r |
99c048ef | 303 | Instance->State = DNS_STATE_CONFIGED;\r |
304 | }\r | |
305 | \r | |
306 | ON_EXIT:\r | |
307 | gBS->RestoreTPL (OldTpl);\r | |
308 | return Status;\r | |
309 | }\r | |
310 | \r | |
311 | /**\r | |
0f4e123f JW |
312 | Host name to host address translation.\r |
313 | \r | |
314 | The HostNameToIp () function is used to translate the host name to host IP address. A\r | |
315 | type A query is used to get the one or more IP addresses for this host.\r | |
316 | \r | |
317 | @param[in] This Pointer to EFI_DNS4_PROTOCOL instance.\r | |
318 | @param[in] HostName Host name.\r | |
319 | @param[in] Token Point to the completion token to translate host name\r | |
320 | to host address.\r | |
321 | \r | |
322 | @retval EFI_SUCCESS The operation completed successfully.\r | |
323 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
324 | This is NULL.\r | |
325 | Token is NULL.\r | |
326 | Token.Event is NULL.\r | |
327 | HostName is NULL. HostName string is unsupported format.\r | |
328 | @retval EFI_NO_MAPPING There's no source address is available for use.\r | |
329 | @retval EFI_NOT_STARTED This instance has not been started.\r | |
99c048ef | 330 | **/\r |
331 | EFI_STATUS\r | |
332 | EFIAPI\r | |
333 | Dns4HostNameToIp (\r | |
334 | IN EFI_DNS4_PROTOCOL *This,\r | |
335 | IN CHAR16 *HostName,\r | |
336 | IN EFI_DNS4_COMPLETION_TOKEN *Token\r | |
337 | )\r | |
338 | {\r | |
d1050b9d | 339 | EFI_STATUS Status;\r |
f75a7f56 | 340 | \r |
d1050b9d | 341 | DNS_INSTANCE *Instance;\r |
f75a7f56 | 342 | \r |
99c048ef | 343 | EFI_DNS4_CONFIG_DATA *ConfigData;\r |
f75a7f56 | 344 | \r |
d1050b9d MK |
345 | UINTN Index;\r |
346 | DNS4_CACHE *Item;\r | |
347 | LIST_ENTRY *Entry;\r | |
348 | LIST_ENTRY *Next;\r | |
f75a7f56 | 349 | \r |
d1050b9d | 350 | CHAR8 *QueryName;\r |
f75a7f56 | 351 | \r |
d1050b9d MK |
352 | DNS4_TOKEN_ENTRY *TokenEntry;\r |
353 | NET_BUF *Packet;\r | |
f75a7f56 | 354 | \r |
d1050b9d | 355 | EFI_TPL OldTpl;\r |
f75a7f56 | 356 | \r |
99c048ef | 357 | Status = EFI_SUCCESS;\r |
358 | Item = NULL;\r | |
fcae1a99 | 359 | QueryName = NULL;\r |
99c048ef | 360 | TokenEntry = NULL;\r |
361 | Packet = NULL;\r | |
f75a7f56 | 362 | \r |
99c048ef | 363 | //\r |
364 | // Validate the parameters\r | |
365 | //\r | |
d1050b9d | 366 | if ((This == NULL) || (HostName == NULL) || (Token == NULL)) {\r |
99c048ef | 367 | return EFI_INVALID_PARAMETER;\r |
368 | }\r | |
f75a7f56 | 369 | \r |
d1050b9d | 370 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
f75a7f56 | 371 | \r |
99c048ef | 372 | Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This);\r |
f75a7f56 | 373 | \r |
99c048ef | 374 | ConfigData = &(Instance->Dns4CfgData);\r |
f75a7f56 | 375 | \r |
99c048ef | 376 | if (Instance->State != DNS_STATE_CONFIGED) {\r |
377 | Status = EFI_NOT_STARTED;\r | |
378 | goto ON_EXIT;\r | |
379 | }\r | |
380 | \r | |
cd2a6240 JW |
381 | Token->Status = EFI_NOT_READY;\r |
382 | \r | |
99c048ef | 383 | //\r |
cd2a6240 | 384 | // If zero, use the parameter configured through Dns.Configure() interface.\r |
99c048ef | 385 | //\r |
cd2a6240 JW |
386 | if (Token->RetryCount == 0) {\r |
387 | Token->RetryCount = ConfigData->RetryCount;\r | |
99c048ef | 388 | }\r |
389 | \r | |
cd2a6240 JW |
390 | //\r |
391 | // If zero, use the parameter configured through Dns.Configure() interface.\r | |
392 | //\r | |
393 | if (Token->RetryInterval == 0) {\r | |
394 | Token->RetryInterval = ConfigData->RetryInterval;\r | |
395 | }\r | |
f75a7f56 | 396 | \r |
cd2a6240 | 397 | //\r |
f75a7f56 | 398 | // Minimum interval of retry is 2 second. If the retry interval is less than 2 second, then use the 2 second.\r |
cd2a6240 | 399 | //\r |
99c048ef | 400 | if (Token->RetryInterval < DNS_DEFAULT_TIMEOUT) {\r |
401 | Token->RetryInterval = DNS_DEFAULT_TIMEOUT;\r | |
402 | }\r | |
403 | \r | |
404 | //\r | |
405 | // Check cache\r | |
406 | //\r | |
407 | if (ConfigData->EnableDnsCache) {\r | |
408 | Index = 0;\r | |
409 | NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns4CacheList) {\r | |
410 | Item = NET_LIST_USER_STRUCT (Entry, DNS4_CACHE, AllCacheLink);\r | |
411 | if (StrCmp (HostName, Item->DnsCache.HostName) == 0) {\r | |
412 | Index++;\r | |
413 | }\r | |
414 | }\r | |
415 | \r | |
416 | if (Index != 0) {\r | |
417 | Token->RspData.H2AData = AllocatePool (sizeof (DNS_HOST_TO_ADDR_DATA));\r | |
418 | if (Token->RspData.H2AData == NULL) {\r | |
419 | Status = EFI_OUT_OF_RESOURCES;\r | |
420 | goto ON_EXIT;\r | |
421 | }\r | |
422 | \r | |
423 | Token->RspData.H2AData->IpCount = (UINT32)Index;\r | |
d1050b9d | 424 | Token->RspData.H2AData->IpList = AllocatePool (sizeof (EFI_IPv4_ADDRESS) * Index);\r |
99c048ef | 425 | if (Token->RspData.H2AData->IpList == NULL) {\r |
426 | if (Token->RspData.H2AData != NULL) {\r | |
427 | FreePool (Token->RspData.H2AData);\r | |
428 | }\r | |
f75a7f56 | 429 | \r |
99c048ef | 430 | Status = EFI_OUT_OF_RESOURCES;\r |
431 | goto ON_EXIT;\r | |
432 | }\r | |
433 | \r | |
434 | Index = 0;\r | |
435 | NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns4CacheList) {\r | |
436 | Item = NET_LIST_USER_STRUCT (Entry, DNS4_CACHE, AllCacheLink);\r | |
d1050b9d | 437 | if (((UINT32)Index < Token->RspData.H2AData->IpCount) && (StrCmp (HostName, Item->DnsCache.HostName) == 0)) {\r |
99c048ef | 438 | CopyMem ((Token->RspData.H2AData->IpList) + Index, Item->DnsCache.IpAddress, sizeof (EFI_IPv4_ADDRESS));\r |
f75a7f56 | 439 | Index++;\r |
99c048ef | 440 | }\r |
441 | }\r | |
f75a7f56 | 442 | \r |
99c048ef | 443 | Token->Status = EFI_SUCCESS;\r |
f75a7f56 | 444 | \r |
99c048ef | 445 | if (Token->Event != NULL) {\r |
446 | gBS->SignalEvent (Token->Event);\r | |
447 | DispatchDpc ();\r | |
448 | }\r | |
449 | \r | |
450 | Status = Token->Status;\r | |
451 | goto ON_EXIT;\r | |
f75a7f56 | 452 | }\r |
99c048ef | 453 | }\r |
454 | \r | |
455 | //\r | |
456 | // Construct DNS TokenEntry.\r | |
457 | //\r | |
d1050b9d | 458 | TokenEntry = AllocateZeroPool (sizeof (DNS4_TOKEN_ENTRY));\r |
99c048ef | 459 | if (TokenEntry == NULL) {\r |
460 | Status = EFI_OUT_OF_RESOURCES;\r | |
461 | goto ON_EXIT;\r | |
462 | }\r | |
f75a7f56 | 463 | \r |
d1050b9d MK |
464 | TokenEntry->PacketToLive = Token->RetryInterval;\r |
465 | TokenEntry->Token = Token;\r | |
0c6108b6 JW |
466 | TokenEntry->QueryHostName = AllocateZeroPool (StrSize (HostName));\r |
467 | if (TokenEntry->QueryHostName == NULL) {\r | |
468 | Status = EFI_OUT_OF_RESOURCES;\r | |
469 | goto ON_EXIT;\r | |
470 | }\r | |
f75a7f56 | 471 | \r |
0c6108b6 | 472 | CopyMem (TokenEntry->QueryHostName, HostName, StrSize (HostName));\r |
f75a7f56 | 473 | \r |
fcae1a99 JW |
474 | //\r |
475 | // Construct QName.\r | |
476 | //\r | |
3700da73 | 477 | QueryName = NetLibCreateDnsQName (TokenEntry->QueryHostName);\r |
fcae1a99 JW |
478 | if (QueryName == NULL) {\r |
479 | Status = EFI_OUT_OF_RESOURCES;\r | |
480 | goto ON_EXIT;\r | |
481 | }\r | |
f75a7f56 | 482 | \r |
99c048ef | 483 | //\r |
484 | // Construct DNS Query Packet.\r | |
485 | //\r | |
fcae1a99 | 486 | Status = ConstructDNSQuery (Instance, QueryName, DNS_TYPE_A, DNS_CLASS_INET, &Packet);\r |
f75a7f56 | 487 | if (EFI_ERROR (Status)) {\r |
99c048ef | 488 | goto ON_EXIT;\r |
489 | }\r | |
490 | \r | |
8339166d JW |
491 | ASSERT (Packet != NULL);\r |
492 | \r | |
99c048ef | 493 | //\r |
494 | // Save the token into the Dns4TxTokens map.\r | |
495 | //\r | |
496 | Status = NetMapInsertTail (&Instance->Dns4TxTokens, TokenEntry, Packet);\r | |
497 | if (EFI_ERROR (Status)) {\r | |
99c048ef | 498 | goto ON_EXIT;\r |
499 | }\r | |
f75a7f56 | 500 | \r |
99c048ef | 501 | //\r |
502 | // Dns Query Ip\r | |
503 | //\r | |
504 | Status = DoDnsQuery (Instance, Packet);\r | |
505 | if (EFI_ERROR (Status)) {\r | |
520a0746 | 506 | Dns4RemoveTokenEntry (&Instance->Dns4TxTokens, TokenEntry);\r |
0c6108b6 | 507 | }\r |
f75a7f56 | 508 | \r |
0c6108b6 | 509 | ON_EXIT:\r |
520a0746 | 510 | \r |
0c6108b6 | 511 | if (EFI_ERROR (Status)) {\r |
99c048ef | 512 | if (TokenEntry != NULL) {\r |
0c6108b6 JW |
513 | if (TokenEntry->QueryHostName != NULL) {\r |
514 | FreePool (TokenEntry->QueryHostName);\r | |
515 | }\r | |
f75a7f56 | 516 | \r |
99c048ef | 517 | FreePool (TokenEntry);\r |
518 | }\r | |
f75a7f56 | 519 | \r |
0c6108b6 JW |
520 | if (Packet != NULL) {\r |
521 | NetbufFree (Packet);\r | |
522 | }\r | |
99c048ef | 523 | }\r |
f75a7f56 | 524 | \r |
fcae1a99 JW |
525 | if (QueryName != NULL) {\r |
526 | FreePool (QueryName);\r | |
527 | }\r | |
f75a7f56 | 528 | \r |
99c048ef | 529 | gBS->RestoreTPL (OldTpl);\r |
530 | return Status;\r | |
531 | }\r | |
532 | \r | |
533 | /**\r | |
0f4e123f JW |
534 | IPv4 address to host name translation also known as Reverse DNS lookup.\r |
535 | \r | |
f75a7f56 | 536 | The IpToHostName() function is used to translate the host address to host name. A type PTR\r |
0f4e123f JW |
537 | query is used to get the primary name of the host. Support of this function is optional.\r |
538 | \r | |
539 | @param[in] This Pointer to EFI_DNS4_PROTOCOL instance.\r | |
540 | @param[in] IpAddress Ip Address.\r | |
541 | @param[in] Token Point to the completion token to translate host\r | |
542 | address to host name.\r | |
543 | \r | |
544 | @retval EFI_SUCCESS The operation completed successfully.\r | |
545 | @retval EFI_UNSUPPORTED This function is not supported.\r | |
546 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
547 | This is NULL.\r | |
548 | Token is NULL.\r | |
549 | Token.Event is NULL.\r | |
550 | IpAddress is not valid IP address .\r | |
551 | @retval EFI_NO_MAPPING There's no source address is available for use.\r | |
552 | @retval EFI_ALREADY_STARTED This Token is being used in another DNS session.\r | |
553 | @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.\r | |
99c048ef | 554 | **/\r |
555 | EFI_STATUS\r | |
556 | EFIAPI\r | |
557 | Dns4IpToHostName (\r | |
d1050b9d MK |
558 | IN EFI_DNS4_PROTOCOL *This,\r |
559 | IN EFI_IPv4_ADDRESS IpAddress,\r | |
560 | IN EFI_DNS4_COMPLETION_TOKEN *Token\r | |
99c048ef | 561 | )\r |
562 | {\r | |
563 | return EFI_UNSUPPORTED;\r | |
564 | }\r | |
565 | \r | |
566 | /**\r | |
f75a7f56 | 567 | Retrieve arbitrary information from the DNS server.\r |
0f4e123f JW |
568 | \r |
569 | This GeneralLookup() function retrieves arbitrary information from the DNS. The caller\r | |
570 | supplies a QNAME, QTYPE, and QCLASS, and all of the matching RRs are returned. All\r | |
571 | RR content (e.g., TTL) was returned. The caller need parse the returned RR to get\r | |
572 | required information. The function is optional.\r | |
573 | \r | |
574 | @param[in] This Pointer to EFI_DNS4_PROTOCOL instance.\r | |
575 | @param[in] QName Pointer to Query Name.\r | |
576 | @param[in] QType Query Type.\r | |
577 | @param[in] QClass Query Name.\r | |
578 | @param[in] Token Point to the completion token to retrieve arbitrary\r | |
579 | information.\r | |
580 | \r | |
581 | @retval EFI_SUCCESS The operation completed successfully.\r | |
582 | @retval EFI_UNSUPPORTED This function is not supported. Or the requested\r | |
583 | QType is not supported\r | |
584 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
585 | This is NULL.\r | |
586 | Token is NULL.\r | |
587 | Token.Event is NULL.\r | |
588 | QName is NULL.\r | |
589 | @retval EFI_NO_MAPPING There's no source address is available for use.\r | |
590 | @retval EFI_ALREADY_STARTED This Token is being used in another DNS session.\r | |
591 | @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.\r | |
99c048ef | 592 | **/\r |
593 | EFI_STATUS\r | |
594 | EFIAPI\r | |
595 | Dns4GeneralLookUp (\r | |
d1050b9d MK |
596 | IN EFI_DNS4_PROTOCOL *This,\r |
597 | IN CHAR8 *QName,\r | |
598 | IN UINT16 QType,\r | |
599 | IN UINT16 QClass,\r | |
600 | IN EFI_DNS4_COMPLETION_TOKEN *Token\r | |
99c048ef | 601 | )\r |
602 | {\r | |
d1050b9d | 603 | EFI_STATUS Status;\r |
f75a7f56 | 604 | \r |
d1050b9d | 605 | DNS_INSTANCE *Instance;\r |
f75a7f56 | 606 | \r |
fcae1a99 | 607 | EFI_DNS4_CONFIG_DATA *ConfigData;\r |
f75a7f56 | 608 | \r |
d1050b9d MK |
609 | DNS4_TOKEN_ENTRY *TokenEntry;\r |
610 | NET_BUF *Packet;\r | |
f75a7f56 | 611 | \r |
d1050b9d | 612 | EFI_TPL OldTpl;\r |
f75a7f56 | 613 | \r |
fcae1a99 JW |
614 | Status = EFI_SUCCESS;\r |
615 | TokenEntry = NULL;\r | |
616 | Packet = NULL;\r | |
f75a7f56 | 617 | \r |
fcae1a99 JW |
618 | //\r |
619 | // Validate the parameters\r | |
620 | //\r | |
d1050b9d | 621 | if ((This == NULL) || (QName == NULL) || (Token == NULL)) {\r |
fcae1a99 JW |
622 | return EFI_INVALID_PARAMETER;\r |
623 | }\r | |
f75a7f56 | 624 | \r |
d1050b9d | 625 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
f75a7f56 | 626 | \r |
fcae1a99 | 627 | Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This);\r |
f75a7f56 | 628 | \r |
fcae1a99 | 629 | ConfigData = &(Instance->Dns4CfgData);\r |
fcae1a99 JW |
630 | \r |
631 | if (Instance->State != DNS_STATE_CONFIGED) {\r | |
632 | Status = EFI_NOT_STARTED;\r | |
633 | goto ON_EXIT;\r | |
634 | }\r | |
635 | \r | |
cd2a6240 | 636 | Token->Status = EFI_NOT_READY;\r |
f75a7f56 | 637 | \r |
cd2a6240 JW |
638 | //\r |
639 | // If zero, use the parameter configured through Dns.Configure() interface.\r | |
fcae1a99 | 640 | //\r |
cd2a6240 JW |
641 | if (Token->RetryCount == 0) {\r |
642 | Token->RetryCount = ConfigData->RetryCount;\r | |
643 | }\r | |
f75a7f56 | 644 | \r |
cd2a6240 JW |
645 | //\r |
646 | // If zero, use the parameter configured through Dns.Configure() interface.\r | |
fcae1a99 | 647 | //\r |
cd2a6240 JW |
648 | if (Token->RetryInterval == 0) {\r |
649 | Token->RetryInterval = ConfigData->RetryInterval;\r | |
fcae1a99 JW |
650 | }\r |
651 | \r | |
cd2a6240 | 652 | //\r |
f75a7f56 | 653 | // Minimum interval of retry is 2 second. If the retry interval is less than 2 second, then use the 2 second.\r |
cd2a6240 | 654 | //\r |
fcae1a99 JW |
655 | if (Token->RetryInterval < DNS_DEFAULT_TIMEOUT) {\r |
656 | Token->RetryInterval = DNS_DEFAULT_TIMEOUT;\r | |
657 | }\r | |
658 | \r | |
659 | //\r | |
660 | // Construct DNS TokenEntry.\r | |
661 | //\r | |
d1050b9d | 662 | TokenEntry = AllocateZeroPool (sizeof (DNS4_TOKEN_ENTRY));\r |
fcae1a99 JW |
663 | if (TokenEntry == NULL) {\r |
664 | Status = EFI_OUT_OF_RESOURCES;\r | |
665 | goto ON_EXIT;\r | |
666 | }\r | |
f75a7f56 | 667 | \r |
d1050b9d | 668 | TokenEntry->PacketToLive = Token->RetryInterval;\r |
fcae1a99 | 669 | TokenEntry->GeneralLookUp = TRUE;\r |
d1050b9d | 670 | TokenEntry->Token = Token;\r |
fcae1a99 JW |
671 | \r |
672 | //\r | |
673 | // Construct DNS Query Packet.\r | |
674 | //\r | |
675 | Status = ConstructDNSQuery (Instance, QName, QType, QClass, &Packet);\r | |
676 | if (EFI_ERROR (Status)) {\r | |
677 | if (TokenEntry != NULL) {\r | |
678 | FreePool (TokenEntry);\r | |
679 | }\r | |
f75a7f56 | 680 | \r |
fcae1a99 JW |
681 | goto ON_EXIT;\r |
682 | }\r | |
683 | \r | |
8339166d JW |
684 | ASSERT (Packet != NULL);\r |
685 | \r | |
fcae1a99 JW |
686 | //\r |
687 | // Save the token into the Dns4TxTokens map.\r | |
688 | //\r | |
689 | Status = NetMapInsertTail (&Instance->Dns4TxTokens, TokenEntry, Packet);\r | |
690 | if (EFI_ERROR (Status)) {\r | |
691 | if (TokenEntry != NULL) {\r | |
692 | FreePool (TokenEntry);\r | |
693 | }\r | |
f75a7f56 | 694 | \r |
fcae1a99 | 695 | NetbufFree (Packet);\r |
f75a7f56 | 696 | \r |
fcae1a99 JW |
697 | goto ON_EXIT;\r |
698 | }\r | |
f75a7f56 | 699 | \r |
fcae1a99 JW |
700 | //\r |
701 | // Dns Query Ip\r | |
702 | //\r | |
703 | Status = DoDnsQuery (Instance, Packet);\r | |
704 | if (EFI_ERROR (Status)) {\r | |
520a0746 JW |
705 | Dns4RemoveTokenEntry (&Instance->Dns4TxTokens, TokenEntry);\r |
706 | \r | |
fcae1a99 JW |
707 | if (TokenEntry != NULL) {\r |
708 | FreePool (TokenEntry);\r | |
709 | }\r | |
f75a7f56 | 710 | \r |
fcae1a99 JW |
711 | NetbufFree (Packet);\r |
712 | }\r | |
f75a7f56 | 713 | \r |
fcae1a99 JW |
714 | ON_EXIT:\r |
715 | gBS->RestoreTPL (OldTpl);\r | |
716 | return Status;\r | |
99c048ef | 717 | }\r |
718 | \r | |
719 | /**\r | |
0f4e123f JW |
720 | This function is to update the DNS Cache.\r |
721 | \r | |
722 | The UpdateDnsCache() function is used to add/delete/modify DNS cache entry. DNS cache\r | |
723 | can be normally dynamically updated after the DNS resolve succeeds. This function\r | |
724 | provided capability to manually add/delete/modify the DNS cache.\r | |
725 | \r | |
726 | @param[in] This Pointer to EFI_DNS4_PROTOCOL instance.\r | |
727 | @param[in] DeleteFlag If FALSE, this function is to add one entry to the\r | |
81a46615 | 728 | DNS Cache. If TRUE, this function will delete\r |
0f4e123f | 729 | matching DNS Cache entry.\r |
81a46615 | 730 | @param[in] Override If TRUE, the matching DNS cache entry will be\r |
0f4e123f JW |
731 | overwritten with the supplied parameter. If FALSE,\r |
732 | EFI_ACCESS_DENIED will be returned if the entry to\r | |
733 | be added is already existed.\r | |
734 | @param[in] DnsCacheEntry Pointer to DNS Cache entry.\r | |
735 | \r | |
736 | @retval EFI_SUCCESS The operation completed successfully.\r | |
737 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
738 | This is NULL.\r | |
739 | DnsCacheEntry.HostName is NULL.\r | |
740 | DnsCacheEntry.IpAddress is NULL.\r | |
741 | DnsCacheEntry.Timeout is zero.\r | |
742 | @retval EFI_ACCESS_DENIED The DNS cache entry already exists and Override is\r | |
743 | not TRUE.\r | |
99c048ef | 744 | **/\r |
745 | EFI_STATUS\r | |
746 | EFIAPI\r | |
747 | Dns4UpdateDnsCache (\r | |
d1050b9d MK |
748 | IN EFI_DNS4_PROTOCOL *This,\r |
749 | IN BOOLEAN DeleteFlag,\r | |
750 | IN BOOLEAN Override,\r | |
751 | IN EFI_DNS4_CACHE_ENTRY DnsCacheEntry\r | |
99c048ef | 752 | )\r |
753 | {\r | |
d1050b9d MK |
754 | EFI_STATUS Status;\r |
755 | EFI_TPL OldTpl;\r | |
99c048ef | 756 | \r |
757 | Status = EFI_SUCCESS;\r | |
f75a7f56 | 758 | \r |
d1050b9d | 759 | if ((DnsCacheEntry.HostName == NULL) || (DnsCacheEntry.IpAddress == NULL) || (DnsCacheEntry.Timeout == 0)) {\r |
f75a7f56 | 760 | return EFI_INVALID_PARAMETER;\r |
99c048ef | 761 | }\r |
f75a7f56 | 762 | \r |
99c048ef | 763 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
764 | \r | |
765 | //\r | |
766 | // Update Dns4Cache here.\r | |
767 | //\r | |
768 | Status = UpdateDns4Cache (&mDriverData->Dns4CacheList, DeleteFlag, Override, DnsCacheEntry);\r | |
769 | \r | |
770 | gBS->RestoreTPL (OldTpl);\r | |
f75a7f56 | 771 | \r |
99c048ef | 772 | return Status;\r |
773 | }\r | |
774 | \r | |
775 | /**\r | |
0f4e123f JW |
776 | Polls for incoming data packets and processes outgoing data packets.\r |
777 | \r | |
778 | The Poll() function can be used by network drivers and applications to increase the\r | |
779 | rate that data packets are moved between the communications device and the transmit\r | |
780 | and receive queues.\r | |
781 | In some systems, the periodic timer event in the managed network driver may not poll\r | |
782 | the underlying communications device fast enough to transmit and/or receive all data\r | |
783 | packets without missing incoming packets or dropping outgoing packets. Drivers and\r | |
784 | applications that are experiencing packet loss should try calling the Poll()\r | |
785 | function more often.\r | |
786 | \r | |
787 | @param[in] This Pointer to EFI_DNS4_PROTOCOL instance.\r | |
788 | \r | |
789 | @retval EFI_SUCCESS Incoming or outgoing data was processed.\r | |
790 | @retval EFI_NOT_STARTED This EFI DNS Protocol instance has not been started.\r | |
791 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
792 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
793 | @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive\r | |
794 | queue. Consider increasing the polling rate.\r | |
99c048ef | 795 | **/\r |
796 | EFI_STATUS\r | |
797 | EFIAPI\r | |
798 | Dns4Poll (\r | |
d1050b9d | 799 | IN EFI_DNS4_PROTOCOL *This\r |
99c048ef | 800 | )\r |
801 | {\r | |
d1050b9d MK |
802 | DNS_INSTANCE *Instance;\r |
803 | EFI_UDP4_PROTOCOL *Udp;\r | |
99c048ef | 804 | \r |
805 | if (This == NULL) {\r | |
806 | return EFI_INVALID_PARAMETER;\r | |
807 | }\r | |
808 | \r | |
809 | Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This);\r | |
810 | \r | |
811 | if (Instance->State == DNS_STATE_UNCONFIGED) {\r | |
812 | return EFI_NOT_STARTED;\r | |
813 | } else if (Instance->State == DNS_STATE_DESTROY) {\r | |
814 | return EFI_DEVICE_ERROR;\r | |
815 | }\r | |
816 | \r | |
817 | Udp = Instance->UdpIo->Protocol.Udp4;\r | |
f75a7f56 | 818 | \r |
99c048ef | 819 | return Udp->Poll (Udp);\r |
820 | }\r | |
821 | \r | |
822 | /**\r | |
0f4e123f JW |
823 | Abort an asynchronous DNS operation, including translation between IP and Host, and\r |
824 | general look up behavior.\r | |
825 | \r | |
826 | The Cancel() function is used to abort a pending resolution request. After calling\r | |
827 | this function, Token.Status will be set to EFI_ABORTED and then Token.Event will be\r | |
828 | signaled. If the token is not in one of the queues, which usually means that the\r | |
829 | asynchronous operation has completed, this function will not signal the token and\r | |
830 | EFI_NOT_FOUND is returned.\r | |
831 | \r | |
832 | @param[in] This Pointer to EFI_DNS4_PROTOCOL instance.\r | |
833 | @param[in] Token Pointer to a token that has been issued by\r | |
834 | EFI_DNS4_PROTOCOL.HostNameToIp (),\r | |
835 | EFI_DNS4_PROTOCOL.IpToHostName() or\r | |
836 | EFI_DNS4_PROTOCOL.GeneralLookup().\r | |
837 | If NULL, all pending tokens are aborted.\r | |
838 | \r | |
839 | @retval EFI_SUCCESS Incoming or outgoing data was processed.\r | |
840 | @retval EFI_NOT_STARTED This EFI DNS4 Protocol instance has not been started.\r | |
841 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
842 | @retval EFI_NOT_FOUND When Token is not NULL, and the asynchronous DNS\r | |
843 | operation was not found in the transmit queue. It\r | |
844 | was either completed or was not issued by\r | |
845 | HostNameToIp(), IpToHostName() or GeneralLookup().\r | |
99c048ef | 846 | **/\r |
847 | EFI_STATUS\r | |
848 | EFIAPI\r | |
849 | Dns4Cancel (\r | |
850 | IN EFI_DNS4_PROTOCOL *This,\r | |
851 | IN EFI_DNS4_COMPLETION_TOKEN *Token\r | |
852 | )\r | |
853 | {\r | |
d1050b9d MK |
854 | EFI_STATUS Status;\r |
855 | DNS_INSTANCE *Instance;\r | |
856 | EFI_TPL OldTpl;\r | |
99c048ef | 857 | \r |
858 | if (This == NULL) {\r | |
859 | return EFI_INVALID_PARAMETER;\r | |
860 | }\r | |
861 | \r | |
862 | Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This);\r | |
863 | \r | |
864 | if (Instance->State == DNS_STATE_UNCONFIGED) {\r | |
865 | return EFI_NOT_STARTED;\r | |
866 | }\r | |
867 | \r | |
868 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
869 | \r | |
870 | //\r | |
81a46615 | 871 | // Cancel the tokens specified by Token for this instance.\r |
99c048ef | 872 | //\r |
873 | Status = Dns4InstanceCancelToken (Instance, Token);\r | |
874 | \r | |
875 | //\r | |
876 | // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.\r | |
877 | //\r | |
878 | DispatchDpc ();\r | |
879 | \r | |
880 | gBS->RestoreTPL (OldTpl);\r | |
881 | \r | |
882 | return Status;\r | |
883 | }\r | |
884 | \r | |
885 | /**\r | |
0f4e123f | 886 | Retrieve mode data of this DNS instance.\r |
99c048ef | 887 | \r |
0f4e123f | 888 | This function is used to retrieve DNS mode data for this DNS instance.\r |
99c048ef | 889 | \r |
0f4e123f | 890 | @param[in] This Pointer to EFI_DNS6_PROTOCOL instance.\r |
f75a7f56 | 891 | @param[out] DnsModeData Pointer to the caller-allocated storage for the\r |
0f4e123f | 892 | EFI_DNS6_MODE_DATA data.\r |
99c048ef | 893 | \r |
0f4e123f JW |
894 | @retval EFI_SUCCESS The operation completed successfully.\r |
895 | @retval EFI_NOT_STARTED When DnsConfigData is queried, no configuration data\r | |
896 | is available because this instance has not been\r | |
897 | configured.\r | |
898 | @retval EFI_INVALID_PARAMETER This is NULL or DnsModeData is NULL.\r | |
899 | @retval EFI_OUT_OF_RESOURCE Failed to allocate needed resources.\r | |
99c048ef | 900 | **/\r |
901 | EFI_STATUS\r | |
902 | EFIAPI\r | |
903 | Dns6GetModeData (\r | |
d1050b9d MK |
904 | IN EFI_DNS6_PROTOCOL *This,\r |
905 | OUT EFI_DNS6_MODE_DATA *DnsModeData\r | |
99c048ef | 906 | )\r |
907 | {\r | |
d1050b9d | 908 | DNS_INSTANCE *Instance;\r |
f75a7f56 | 909 | \r |
d1050b9d | 910 | EFI_TPL OldTpl;\r |
99c048ef | 911 | \r |
d1050b9d | 912 | UINTN Index;\r |
f75a7f56 | 913 | \r |
d1050b9d MK |
914 | LIST_ENTRY *Entry;\r |
915 | LIST_ENTRY *Next;\r | |
99c048ef | 916 | \r |
d1050b9d MK |
917 | DNS6_SERVER_IP *ServerItem;\r |
918 | EFI_IPv6_ADDRESS *ServerList;\r | |
919 | DNS6_CACHE *CacheItem;\r | |
920 | EFI_DNS6_CACHE_ENTRY *CacheList;\r | |
921 | EFI_STATUS Status;\r | |
99c048ef | 922 | \r |
923 | ServerItem = NULL;\r | |
924 | ServerList = NULL;\r | |
925 | CacheItem = NULL;\r | |
926 | CacheList = NULL;\r | |
927 | Status = EFI_SUCCESS;\r | |
928 | \r | |
929 | if ((This == NULL) || (DnsModeData == NULL)) {\r | |
930 | return EFI_INVALID_PARAMETER;\r | |
931 | }\r | |
932 | \r | |
933 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
f75a7f56 | 934 | \r |
d1050b9d | 935 | Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This);\r |
99c048ef | 936 | if (Instance->State == DNS_STATE_UNCONFIGED) {\r |
ac0f5843 JW |
937 | Status = EFI_NOT_STARTED;\r |
938 | goto ON_EXIT;\r | |
99c048ef | 939 | }\r |
940 | \r | |
941 | ZeroMem (DnsModeData, sizeof (EFI_DNS6_MODE_DATA));\r | |
942 | \r | |
943 | //\r | |
f75a7f56 | 944 | // Get the current configuration data of this instance.\r |
99c048ef | 945 | //\r |
ac0f5843 | 946 | Status = Dns6CopyConfigure (&DnsModeData->DnsConfigData, &Instance->Dns6CfgData);\r |
99c048ef | 947 | if (EFI_ERROR (Status)) {\r |
ac0f5843 | 948 | goto ON_EXIT;\r |
99c048ef | 949 | }\r |
f75a7f56 | 950 | \r |
99c048ef | 951 | //\r |
952 | // Get the DnsServerCount and DnsServerList\r | |
953 | //\r | |
954 | Index = 0;\r | |
955 | NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns6ServerList) {\r | |
956 | Index++;\r | |
957 | }\r | |
d1050b9d MK |
958 | DnsModeData->DnsServerCount = (UINT32)Index;\r |
959 | ServerList = AllocatePool (sizeof (EFI_IPv6_ADDRESS) * DnsModeData->DnsServerCount);\r | |
ac0f5843 JW |
960 | if (ServerList == NULL) {\r |
961 | Status = EFI_OUT_OF_RESOURCES;\r | |
962 | Dns6CleanConfigure (&DnsModeData->DnsConfigData);\r | |
963 | goto ON_EXIT;\r | |
964 | }\r | |
f75a7f56 | 965 | \r |
99c048ef | 966 | Index = 0;\r |
967 | NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns6ServerList) {\r | |
968 | ServerItem = NET_LIST_USER_STRUCT (Entry, DNS6_SERVER_IP, AllServerLink);\r | |
969 | CopyMem (ServerList + Index, &ServerItem->Dns6ServerIp, sizeof (EFI_IPv6_ADDRESS));\r | |
970 | Index++;\r | |
971 | }\r | |
972 | DnsModeData->DnsServerList = ServerList;\r | |
973 | \r | |
974 | //\r | |
975 | // Get the DnsCacheCount and DnsCacheList\r | |
976 | //\r | |
d1050b9d | 977 | Index = 0;\r |
99c048ef | 978 | NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns6CacheList) {\r |
979 | Index++;\r | |
980 | }\r | |
d1050b9d MK |
981 | DnsModeData->DnsCacheCount = (UINT32)Index;\r |
982 | CacheList = AllocatePool (sizeof (EFI_DNS6_CACHE_ENTRY) * DnsModeData->DnsCacheCount);\r | |
ac0f5843 JW |
983 | if (CacheList == NULL) {\r |
984 | Status = EFI_OUT_OF_RESOURCES;\r | |
985 | Dns6CleanConfigure (&DnsModeData->DnsConfigData);\r | |
986 | FreePool (ServerList);\r | |
987 | goto ON_EXIT;\r | |
988 | }\r | |
f75a7f56 | 989 | \r |
d1050b9d | 990 | Index = 0;\r |
99c048ef | 991 | NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns6CacheList) {\r |
992 | CacheItem = NET_LIST_USER_STRUCT (Entry, DNS6_CACHE, AllCacheLink);\r | |
993 | CopyMem (CacheList + Index, &CacheItem->DnsCache, sizeof (EFI_DNS6_CACHE_ENTRY));\r | |
994 | Index++;\r | |
995 | }\r | |
996 | DnsModeData->DnsCacheList = CacheList;\r | |
f75a7f56 | 997 | \r |
ac0f5843 JW |
998 | ON_EXIT:\r |
999 | gBS->RestoreTPL (OldTpl);\r | |
1000 | return Status;\r | |
99c048ef | 1001 | }\r |
1002 | \r | |
1003 | /**\r | |
0f4e123f JW |
1004 | Configure this DNS instance.\r |
1005 | \r | |
1006 | The Configure() function is used to set and change the configuration data for this\r | |
1007 | EFI DNSv6 Protocol driver instance. Reset the DNS instance if DnsConfigData is NULL.\r | |
1008 | \r | |
1009 | @param[in] This Pointer to EFI_DNS6_PROTOCOL instance.\r | |
f75a7f56 | 1010 | @param[in] DnsConfigData Pointer to the configuration data structure. All associated\r |
0f4e123f JW |
1011 | storage to be allocated and released by caller.\r |
1012 | \r | |
1013 | @retval EFI_SUCCESS The operation completed successfully.\r | |
81a46615 | 1014 | @retval EFI_INVALID_PARAMETER This is NULL.\r |
0f4e123f JW |
1015 | The StationIp address provided in DnsConfigData is not zero and not a valid unicast.\r |
1016 | DnsServerList is NULL while DnsServerList Count is not ZERO.\r | |
1017 | DnsServerList Count is ZERO while DnsServerList is not NULL.\r | |
1018 | @retval EFI_OUT_OF_RESOURCES The DNS instance data or required space could not be allocated.\r | |
1019 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The\r | |
1020 | EFI DNSv6 Protocol instance is not configured.\r | |
1021 | @retval EFI_UNSUPPORTED The designated protocol is not supported.\r | |
f75a7f56 LG |
1022 | @retval EFI_ALREADY_STARTED Second call to Configure() with DnsConfigData. To\r |
1023 | reconfigure the instance the caller must call Configure() with\r | |
0f4e123f | 1024 | NULL first to return driver to unconfigured state.\r |
99c048ef | 1025 | **/\r |
1026 | EFI_STATUS\r | |
1027 | EFIAPI\r | |
1028 | Dns6Configure (\r | |
d1050b9d MK |
1029 | IN EFI_DNS6_PROTOCOL *This,\r |
1030 | IN EFI_DNS6_CONFIG_DATA *DnsConfigData\r | |
99c048ef | 1031 | )\r |
1032 | {\r | |
d1050b9d MK |
1033 | EFI_STATUS Status;\r |
1034 | DNS_INSTANCE *Instance;\r | |
f75a7f56 | 1035 | \r |
d1050b9d | 1036 | EFI_TPL OldTpl;\r |
99c048ef | 1037 | \r |
d1050b9d MK |
1038 | UINT32 ServerListCount;\r |
1039 | EFI_IPv6_ADDRESS *ServerList;\r | |
99c048ef | 1040 | \r |
1041 | Status = EFI_SUCCESS;\r | |
1042 | ServerList = NULL;\r | |
1043 | \r | |
d1050b9d MK |
1044 | if ((This == NULL) ||\r |
1045 | ((DnsConfigData != NULL) && (((DnsConfigData->DnsServerCount != 0) && (DnsConfigData->DnsServerList == NULL)) ||\r | |
1046 | ((DnsConfigData->DnsServerCount == 0) && (DnsConfigData->DnsServerList != NULL)))))\r | |
1047 | {\r | |
99c048ef | 1048 | return EFI_INVALID_PARAMETER;\r |
1049 | }\r | |
1050 | \r | |
d1050b9d | 1051 | if ((DnsConfigData != NULL) && (DnsConfigData->Protocol != DNS_PROTOCOL_UDP)) {\r |
99c048ef | 1052 | return EFI_UNSUPPORTED;\r |
1053 | }\r | |
1054 | \r | |
1055 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
1056 | \r | |
1057 | Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This);\r | |
1058 | \r | |
1059 | if (DnsConfigData == NULL) {\r | |
1060 | ZeroMem (&Instance->SessionDnsServer, sizeof (EFI_IP_ADDRESS));\r | |
1061 | \r | |
1062 | //\r | |
1063 | // Reset the Instance if ConfigData is NULL\r | |
1064 | //\r | |
d1050b9d MK |
1065 | if (!NetMapIsEmpty (&Instance->Dns6TxTokens)) {\r |
1066 | Dns6InstanceCancelToken (Instance, NULL);\r | |
99c048ef | 1067 | }\r |
1068 | \r | |
4ad1bd63 | 1069 | if (Instance->UdpIo != NULL) {\r |
99c048ef | 1070 | UdpIoCleanIo (Instance->UdpIo);\r |
1071 | }\r | |
1072 | \r | |
1073 | if (Instance->Dns6CfgData.DnsServerList != NULL) {\r | |
1074 | FreePool (Instance->Dns6CfgData.DnsServerList);\r | |
1075 | }\r | |
d1050b9d | 1076 | \r |
99c048ef | 1077 | ZeroMem (&Instance->Dns6CfgData, sizeof (EFI_DNS6_CONFIG_DATA));\r |
f75a7f56 | 1078 | \r |
99c048ef | 1079 | Instance->State = DNS_STATE_UNCONFIGED;\r |
1080 | } else {\r | |
1081 | //\r | |
1082 | // Configure the parameters for new operation.\r | |
1083 | //\r | |
90ae1f02 | 1084 | if (!NetIp6IsUnspecifiedAddr (&DnsConfigData->StationIp) && !NetIp6IsValidUnicast (&DnsConfigData->StationIp)) {\r |
99c048ef | 1085 | Status = EFI_INVALID_PARAMETER;\r |
1086 | goto ON_EXIT;\r | |
1087 | }\r | |
1088 | \r | |
1089 | Status = Dns6CopyConfigure (&Instance->Dns6CfgData, DnsConfigData);\r | |
1090 | if (EFI_ERROR (Status)) {\r | |
1091 | goto ON_EXIT;\r | |
1092 | }\r | |
1093 | \r | |
1b59de84 | 1094 | if (DnsConfigData->DnsServerCount == 0) {\r |
99c048ef | 1095 | gBS->RestoreTPL (OldTpl);\r |
1096 | \r | |
1097 | //\r | |
d1050b9d | 1098 | // The DNS instance will retrieve DNS server from DHCP Server.\r |
99c048ef | 1099 | //\r |
1100 | Status = GetDns6ServerFromDhcp6 (\r | |
1101 | Instance->Service->ImageHandle,\r | |
f75a7f56 LG |
1102 | Instance->Service->ControllerHandle,\r |
1103 | &ServerListCount,\r | |
99c048ef | 1104 | &ServerList\r |
1105 | );\r | |
1106 | if (EFI_ERROR (Status)) {\r | |
1107 | goto ON_EXIT;\r | |
1108 | }\r | |
f75a7f56 | 1109 | \r |
d1050b9d | 1110 | ASSERT (ServerList != NULL);\r |
99c048ef | 1111 | \r |
1112 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
1113 | \r | |
1114 | CopyMem (&Instance->SessionDnsServer.v6, &ServerList[0], sizeof (EFI_IPv6_ADDRESS));\r | |
1115 | } else {\r | |
1116 | CopyMem (&Instance->SessionDnsServer.v6, &DnsConfigData->DnsServerList[0], sizeof (EFI_IPv6_ADDRESS));\r | |
1117 | }\r | |
1118 | \r | |
1119 | //\r | |
1120 | // Config UDP\r | |
1121 | //\r | |
eed4585b | 1122 | gBS->RestoreTPL (OldTpl);\r |
99c048ef | 1123 | Status = Dns6ConfigUdp (Instance, Instance->UdpIo);\r |
eed4585b | 1124 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
99c048ef | 1125 | if (EFI_ERROR (Status)) {\r |
1126 | if (Instance->Dns6CfgData.DnsServerList != NULL) {\r | |
1127 | FreePool (Instance->Dns6CfgData.DnsServerList);\r | |
8aa2cdd7 | 1128 | Instance->Dns6CfgData.DnsServerList = NULL;\r |
99c048ef | 1129 | }\r |
d1050b9d | 1130 | \r |
99c048ef | 1131 | goto ON_EXIT;\r |
1132 | }\r | |
1133 | \r | |
1134 | //\r | |
1135 | // Add configured DNS server used by this instance to ServerList.\r | |
1136 | //\r | |
1137 | Status = AddDns6ServerIp (&mDriverData->Dns6ServerList, Instance->SessionDnsServer.v6);\r | |
1138 | if (EFI_ERROR (Status)) {\r | |
1139 | if (Instance->Dns6CfgData.DnsServerList != NULL) {\r | |
1140 | FreePool (Instance->Dns6CfgData.DnsServerList);\r | |
8aa2cdd7 | 1141 | Instance->Dns6CfgData.DnsServerList = NULL;\r |
99c048ef | 1142 | }\r |
d1050b9d | 1143 | \r |
99c048ef | 1144 | goto ON_EXIT;\r |
1145 | }\r | |
f75a7f56 | 1146 | \r |
99c048ef | 1147 | Instance->State = DNS_STATE_CONFIGED;\r |
1148 | }\r | |
1149 | \r | |
1150 | ON_EXIT:\r | |
1151 | gBS->RestoreTPL (OldTpl);\r | |
1152 | return Status;\r | |
1153 | }\r | |
1154 | \r | |
1155 | /**\r | |
0f4e123f JW |
1156 | Host name to host address translation.\r |
1157 | \r | |
1158 | The HostNameToIp () function is used to translate the host name to host IP address. A\r | |
1159 | type AAAA query is used to get the one or more IPv6 addresses for this host.\r | |
1160 | \r | |
1161 | @param[in] This Pointer to EFI_DNS6_PROTOCOL instance.\r | |
1162 | @param[in] HostName Host name.\r | |
1163 | @param[in] Token Point to the completion token to translate host name\r | |
1164 | to host address.\r | |
1165 | \r | |
1166 | @retval EFI_SUCCESS The operation completed successfully.\r | |
1167 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
1168 | This is NULL.\r | |
1169 | Token is NULL.\r | |
1170 | Token.Event is NULL.\r | |
1171 | HostName is NULL or buffer contained unsupported characters.\r | |
1172 | @retval EFI_NO_MAPPING There's no source address is available for use.\r | |
1173 | @retval EFI_ALREADY_STARTED This Token is being used in another DNS session.\r | |
1174 | @retval EFI_NOT_STARTED This instance has not been started.\r | |
1175 | @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.\r | |
99c048ef | 1176 | **/\r |
1177 | EFI_STATUS\r | |
1178 | EFIAPI\r | |
1179 | Dns6HostNameToIp (\r | |
1180 | IN EFI_DNS6_PROTOCOL *This,\r | |
1181 | IN CHAR16 *HostName,\r | |
1182 | IN EFI_DNS6_COMPLETION_TOKEN *Token\r | |
1183 | )\r | |
1184 | {\r | |
d1050b9d | 1185 | EFI_STATUS Status;\r |
f75a7f56 | 1186 | \r |
d1050b9d | 1187 | DNS_INSTANCE *Instance;\r |
99c048ef | 1188 | \r |
1189 | EFI_DNS6_CONFIG_DATA *ConfigData;\r | |
f75a7f56 | 1190 | \r |
d1050b9d MK |
1191 | UINTN Index;\r |
1192 | DNS6_CACHE *Item;\r | |
1193 | LIST_ENTRY *Entry;\r | |
1194 | LIST_ENTRY *Next;\r | |
f75a7f56 | 1195 | \r |
d1050b9d | 1196 | CHAR8 *QueryName;\r |
f75a7f56 | 1197 | \r |
d1050b9d MK |
1198 | DNS6_TOKEN_ENTRY *TokenEntry;\r |
1199 | NET_BUF *Packet;\r | |
f75a7f56 | 1200 | \r |
d1050b9d | 1201 | EFI_TPL OldTpl;\r |
f75a7f56 | 1202 | \r |
99c048ef | 1203 | Status = EFI_SUCCESS;\r |
1204 | Item = NULL;\r | |
fcae1a99 | 1205 | QueryName = NULL;\r |
99c048ef | 1206 | TokenEntry = NULL;\r |
1207 | Packet = NULL;\r | |
1208 | \r | |
1209 | //\r | |
1210 | // Validate the parameters\r | |
1211 | //\r | |
d1050b9d | 1212 | if ((This == NULL) || (HostName == NULL) || (Token == NULL)) {\r |
99c048ef | 1213 | return EFI_INVALID_PARAMETER;\r |
1214 | }\r | |
1215 | \r | |
d1050b9d | 1216 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
f75a7f56 | 1217 | \r |
99c048ef | 1218 | Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This);\r |
f75a7f56 | 1219 | \r |
99c048ef | 1220 | ConfigData = &(Instance->Dns6CfgData);\r |
99c048ef | 1221 | \r |
1222 | if (Instance->State != DNS_STATE_CONFIGED) {\r | |
1223 | Status = EFI_NOT_STARTED;\r | |
1224 | goto ON_EXIT;\r | |
1225 | }\r | |
1226 | \r | |
cd2a6240 JW |
1227 | Token->Status = EFI_NOT_READY;\r |
1228 | \r | |
99c048ef | 1229 | //\r |
cd2a6240 | 1230 | // If zero, use the parameter configured through Dns.Configure() interface.\r |
99c048ef | 1231 | //\r |
cd2a6240 JW |
1232 | if (Token->RetryCount == 0) {\r |
1233 | Token->RetryCount = ConfigData->RetryCount;\r | |
99c048ef | 1234 | }\r |
1235 | \r | |
cd2a6240 JW |
1236 | //\r |
1237 | // If zero, use the parameter configured through Dns.Configure() interface.\r | |
1238 | //\r | |
1239 | if (Token->RetryInterval == 0) {\r | |
1240 | Token->RetryInterval = ConfigData->RetryInterval;\r | |
1241 | }\r | |
f75a7f56 | 1242 | \r |
cd2a6240 | 1243 | //\r |
f75a7f56 | 1244 | // Minimum interval of retry is 2 second. If the retry interval is less than 2 second, then use the 2 second.\r |
cd2a6240 | 1245 | //\r |
99c048ef | 1246 | if (Token->RetryInterval < DNS_DEFAULT_TIMEOUT) {\r |
1247 | Token->RetryInterval = DNS_DEFAULT_TIMEOUT;\r | |
cd2a6240 | 1248 | }\r |
99c048ef | 1249 | \r |
1250 | //\r | |
1251 | // Check cache\r | |
1252 | //\r | |
1253 | if (ConfigData->EnableDnsCache) {\r | |
1254 | Index = 0;\r | |
1255 | NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns6CacheList) {\r | |
1256 | Item = NET_LIST_USER_STRUCT (Entry, DNS6_CACHE, AllCacheLink);\r | |
1257 | if (StrCmp (HostName, Item->DnsCache.HostName) == 0) {\r | |
1258 | Index++;\r | |
1259 | }\r | |
1260 | }\r | |
1261 | \r | |
1262 | if (Index != 0) {\r | |
1263 | Token->RspData.H2AData = AllocatePool (sizeof (DNS6_HOST_TO_ADDR_DATA));\r | |
1264 | if (Token->RspData.H2AData == NULL) {\r | |
1265 | Status = EFI_OUT_OF_RESOURCES;\r | |
1266 | goto ON_EXIT;\r | |
1267 | }\r | |
1268 | \r | |
1269 | Token->RspData.H2AData->IpCount = (UINT32)Index;\r | |
d1050b9d | 1270 | Token->RspData.H2AData->IpList = AllocatePool (sizeof (EFI_IPv6_ADDRESS) * Index);\r |
99c048ef | 1271 | if (Token->RspData.H2AData->IpList == NULL) {\r |
1272 | if (Token->RspData.H2AData != NULL) {\r | |
1273 | FreePool (Token->RspData.H2AData);\r | |
1274 | }\r | |
f75a7f56 | 1275 | \r |
99c048ef | 1276 | Status = EFI_OUT_OF_RESOURCES;\r |
1277 | goto ON_EXIT;\r | |
1278 | }\r | |
1279 | \r | |
1280 | Index = 0;\r | |
1281 | NET_LIST_FOR_EACH_SAFE (Entry, Next, &mDriverData->Dns6CacheList) {\r | |
1282 | Item = NET_LIST_USER_STRUCT (Entry, DNS6_CACHE, AllCacheLink);\r | |
d1050b9d | 1283 | if (((UINT32)Index < Token->RspData.H2AData->IpCount) && (StrCmp (HostName, Item->DnsCache.HostName) == 0)) {\r |
99c048ef | 1284 | CopyMem ((Token->RspData.H2AData->IpList) + Index, Item->DnsCache.IpAddress, sizeof (EFI_IPv6_ADDRESS));\r |
1285 | Index++;\r | |
1286 | }\r | |
1287 | }\r | |
f75a7f56 | 1288 | \r |
99c048ef | 1289 | Token->Status = EFI_SUCCESS;\r |
f75a7f56 | 1290 | \r |
99c048ef | 1291 | if (Token->Event != NULL) {\r |
1292 | gBS->SignalEvent (Token->Event);\r | |
1293 | DispatchDpc ();\r | |
1294 | }\r | |
f75a7f56 | 1295 | \r |
99c048ef | 1296 | Status = Token->Status;\r |
1297 | goto ON_EXIT;\r | |
f75a7f56 | 1298 | }\r |
99c048ef | 1299 | }\r |
1300 | \r | |
1301 | //\r | |
1302 | // Construct DNS TokenEntry.\r | |
1303 | //\r | |
1304 | TokenEntry = AllocateZeroPool (sizeof (DNS6_TOKEN_ENTRY));\r | |
1305 | if (TokenEntry == NULL) {\r | |
1306 | Status = EFI_OUT_OF_RESOURCES;\r | |
1307 | goto ON_EXIT;\r | |
1308 | }\r | |
f75a7f56 | 1309 | \r |
d1050b9d MK |
1310 | TokenEntry->PacketToLive = Token->RetryInterval;\r |
1311 | TokenEntry->Token = Token;\r | |
0c6108b6 JW |
1312 | TokenEntry->QueryHostName = AllocateZeroPool (StrSize (HostName));\r |
1313 | if (TokenEntry->QueryHostName == NULL) {\r | |
1314 | Status = EFI_OUT_OF_RESOURCES;\r | |
1315 | goto ON_EXIT;\r | |
1316 | }\r | |
f75a7f56 | 1317 | \r |
0c6108b6 | 1318 | CopyMem (TokenEntry->QueryHostName, HostName, StrSize (HostName));\r |
fcae1a99 JW |
1319 | \r |
1320 | //\r | |
1321 | // Construct QName.\r | |
1322 | //\r | |
3700da73 | 1323 | QueryName = NetLibCreateDnsQName (TokenEntry->QueryHostName);\r |
fcae1a99 JW |
1324 | if (QueryName == NULL) {\r |
1325 | Status = EFI_OUT_OF_RESOURCES;\r | |
1326 | goto ON_EXIT;\r | |
1327 | }\r | |
f75a7f56 | 1328 | \r |
99c048ef | 1329 | //\r |
1330 | // Construct DNS Query Packet.\r | |
1331 | //\r | |
fcae1a99 | 1332 | Status = ConstructDNSQuery (Instance, QueryName, DNS_TYPE_AAAA, DNS_CLASS_INET, &Packet);\r |
99c048ef | 1333 | if (EFI_ERROR (Status)) {\r |
99c048ef | 1334 | goto ON_EXIT;\r |
1335 | }\r | |
1336 | \r | |
8339166d JW |
1337 | ASSERT (Packet != NULL);\r |
1338 | \r | |
99c048ef | 1339 | //\r |
1340 | // Save the token into the Dns6TxTokens map.\r | |
1341 | //\r | |
1342 | Status = NetMapInsertTail (&Instance->Dns6TxTokens, TokenEntry, Packet);\r | |
1343 | if (EFI_ERROR (Status)) {\r | |
99c048ef | 1344 | goto ON_EXIT;\r |
1345 | }\r | |
f75a7f56 | 1346 | \r |
99c048ef | 1347 | //\r |
1348 | // Dns Query Ip\r | |
1349 | //\r | |
1350 | Status = DoDnsQuery (Instance, Packet);\r | |
1351 | if (EFI_ERROR (Status)) {\r | |
520a0746 | 1352 | Dns6RemoveTokenEntry (&Instance->Dns6TxTokens, TokenEntry);\r |
0c6108b6 | 1353 | }\r |
f75a7f56 | 1354 | \r |
0c6108b6 JW |
1355 | ON_EXIT:\r |
1356 | \r | |
1357 | if (EFI_ERROR (Status)) {\r | |
99c048ef | 1358 | if (TokenEntry != NULL) {\r |
0c6108b6 JW |
1359 | if (TokenEntry->QueryHostName != NULL) {\r |
1360 | FreePool (TokenEntry->QueryHostName);\r | |
1361 | }\r | |
f75a7f56 | 1362 | \r |
99c048ef | 1363 | FreePool (TokenEntry);\r |
1364 | }\r | |
f75a7f56 | 1365 | \r |
0c6108b6 JW |
1366 | if (Packet != NULL) {\r |
1367 | NetbufFree (Packet);\r | |
1368 | }\r | |
99c048ef | 1369 | }\r |
f75a7f56 | 1370 | \r |
fcae1a99 JW |
1371 | if (QueryName != NULL) {\r |
1372 | FreePool (QueryName);\r | |
1373 | }\r | |
f75a7f56 | 1374 | \r |
99c048ef | 1375 | gBS->RestoreTPL (OldTpl);\r |
1376 | return Status;\r | |
1377 | }\r | |
1378 | \r | |
1379 | /**\r | |
0f4e123f JW |
1380 | Host address to host name translation.\r |
1381 | \r | |
1382 | The IpToHostName () function is used to translate the host address to host name. A\r | |
1383 | type PTR query is used to get the primary name of the host. Implementation can choose\r | |
1384 | to support this function or not.\r | |
1385 | \r | |
1386 | @param[in] This Pointer to EFI_DNS6_PROTOCOL instance.\r | |
1387 | @param[in] IpAddress Ip Address.\r | |
1388 | @param[in] Token Point to the completion token to translate host\r | |
1389 | address to host name.\r | |
1390 | \r | |
1391 | @retval EFI_SUCCESS The operation completed successfully.\r | |
1392 | @retval EFI_UNSUPPORTED This function is not supported.\r | |
1393 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
1394 | This is NULL.\r | |
1395 | Token is NULL.\r | |
1396 | Token.Event is NULL.\r | |
1397 | IpAddress is not valid IP address.\r | |
1398 | @retval EFI_NO_MAPPING There's no source address is available for use.\r | |
1399 | @retval EFI_NOT_STARTED This instance has not been started.\r | |
1400 | @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.\r | |
99c048ef | 1401 | **/\r |
1402 | EFI_STATUS\r | |
1403 | EFIAPI\r | |
1404 | Dns6IpToHostName (\r | |
d1050b9d MK |
1405 | IN EFI_DNS6_PROTOCOL *This,\r |
1406 | IN EFI_IPv6_ADDRESS IpAddress,\r | |
1407 | IN EFI_DNS6_COMPLETION_TOKEN *Token\r | |
99c048ef | 1408 | )\r |
1409 | {\r | |
1410 | return EFI_UNSUPPORTED;\r | |
1411 | }\r | |
1412 | \r | |
1413 | /**\r | |
0f4e123f JW |
1414 | This function provides capability to retrieve arbitrary information from the DNS\r |
1415 | server.\r | |
1416 | \r | |
1417 | This GeneralLookup() function retrieves arbitrary information from the DNS. The caller\r | |
1418 | supplies a QNAME, QTYPE, and QCLASS, and all of the matching RRs are returned. All\r | |
1419 | RR content (e.g., TTL) was returned. The caller need parse the returned RR to get\r | |
1420 | required information. The function is optional. Implementation can choose to support\r | |
1421 | it or not.\r | |
1422 | \r | |
1423 | @param[in] This Pointer to EFI_DNS6_PROTOCOL instance.\r | |
1424 | @param[in] QName Pointer to Query Name.\r | |
1425 | @param[in] QType Query Type.\r | |
1426 | @param[in] QClass Query Name.\r | |
1427 | @param[in] Token Point to the completion token to retrieve arbitrary\r | |
1428 | information.\r | |
1429 | \r | |
1430 | @retval EFI_SUCCESS The operation completed successfully.\r | |
1431 | @retval EFI_UNSUPPORTED This function is not supported. Or the requested\r | |
1432 | QType is not supported\r | |
1433 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
1434 | This is NULL.\r | |
1435 | Token is NULL.\r | |
1436 | Token.Event is NULL.\r | |
1437 | QName is NULL.\r | |
1438 | @retval EFI_NO_MAPPING There's no source address is available for use.\r | |
1439 | @retval EFI_NOT_STARTED This instance has not been started.\r | |
1440 | @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.\r | |
99c048ef | 1441 | **/\r |
1442 | EFI_STATUS\r | |
1443 | EFIAPI\r | |
1444 | Dns6GeneralLookUp (\r | |
d1050b9d MK |
1445 | IN EFI_DNS6_PROTOCOL *This,\r |
1446 | IN CHAR8 *QName,\r | |
1447 | IN UINT16 QType,\r | |
1448 | IN UINT16 QClass,\r | |
1449 | IN EFI_DNS6_COMPLETION_TOKEN *Token\r | |
99c048ef | 1450 | )\r |
1451 | {\r | |
d1050b9d | 1452 | EFI_STATUS Status;\r |
f75a7f56 | 1453 | \r |
d1050b9d | 1454 | DNS_INSTANCE *Instance;\r |
f75a7f56 | 1455 | \r |
fcae1a99 | 1456 | EFI_DNS6_CONFIG_DATA *ConfigData;\r |
f75a7f56 | 1457 | \r |
d1050b9d MK |
1458 | DNS6_TOKEN_ENTRY *TokenEntry;\r |
1459 | NET_BUF *Packet;\r | |
f75a7f56 | 1460 | \r |
d1050b9d | 1461 | EFI_TPL OldTpl;\r |
f75a7f56 | 1462 | \r |
fcae1a99 JW |
1463 | Status = EFI_SUCCESS;\r |
1464 | TokenEntry = NULL;\r | |
1465 | Packet = NULL;\r | |
f75a7f56 | 1466 | \r |
fcae1a99 JW |
1467 | //\r |
1468 | // Validate the parameters\r | |
1469 | //\r | |
d1050b9d | 1470 | if ((This == NULL) || (QName == NULL) || (Token == NULL)) {\r |
fcae1a99 JW |
1471 | return EFI_INVALID_PARAMETER;\r |
1472 | }\r | |
f75a7f56 | 1473 | \r |
d1050b9d | 1474 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
f75a7f56 | 1475 | \r |
fcae1a99 | 1476 | Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This);\r |
f75a7f56 | 1477 | \r |
fcae1a99 | 1478 | ConfigData = &(Instance->Dns6CfgData);\r |
fcae1a99 JW |
1479 | \r |
1480 | if (Instance->State != DNS_STATE_CONFIGED) {\r | |
1481 | Status = EFI_NOT_STARTED;\r | |
1482 | goto ON_EXIT;\r | |
1483 | }\r | |
1484 | \r | |
cd2a6240 | 1485 | Token->Status = EFI_NOT_READY;\r |
f75a7f56 | 1486 | \r |
fcae1a99 | 1487 | //\r |
cd2a6240 | 1488 | // If zero, use the parameter configured through Dns.Configure() interface.\r |
fcae1a99 | 1489 | //\r |
cd2a6240 JW |
1490 | if (Token->RetryCount == 0) {\r |
1491 | Token->RetryCount = ConfigData->RetryCount;\r | |
1492 | }\r | |
f75a7f56 | 1493 | \r |
cd2a6240 JW |
1494 | //\r |
1495 | // If zero, use the parameter configured through Dns.Configure() interface.\r | |
1496 | //\r | |
1497 | if (Token->RetryInterval == 0) {\r | |
1498 | Token->RetryInterval = ConfigData->RetryInterval;\r | |
fcae1a99 JW |
1499 | }\r |
1500 | \r | |
cd2a6240 | 1501 | //\r |
f75a7f56 | 1502 | // Minimum interval of retry is 2 second. If the retry interval is less than 2 second, then use the 2 second.\r |
cd2a6240 | 1503 | //\r |
fcae1a99 JW |
1504 | if (Token->RetryInterval < DNS_DEFAULT_TIMEOUT) {\r |
1505 | Token->RetryInterval = DNS_DEFAULT_TIMEOUT;\r | |
1506 | }\r | |
1507 | \r | |
1508 | //\r | |
1509 | // Construct DNS TokenEntry.\r | |
1510 | //\r | |
d1050b9d | 1511 | TokenEntry = AllocateZeroPool (sizeof (DNS6_TOKEN_ENTRY));\r |
fcae1a99 JW |
1512 | if (TokenEntry == NULL) {\r |
1513 | Status = EFI_OUT_OF_RESOURCES;\r | |
1514 | goto ON_EXIT;\r | |
1515 | }\r | |
f75a7f56 | 1516 | \r |
d1050b9d | 1517 | TokenEntry->PacketToLive = Token->RetryInterval;\r |
fcae1a99 | 1518 | TokenEntry->GeneralLookUp = TRUE;\r |
d1050b9d | 1519 | TokenEntry->Token = Token;\r |
fcae1a99 JW |
1520 | \r |
1521 | //\r | |
1522 | // Construct DNS Query Packet.\r | |
1523 | //\r | |
1524 | Status = ConstructDNSQuery (Instance, QName, QType, QClass, &Packet);\r | |
1525 | if (EFI_ERROR (Status)) {\r | |
1526 | if (TokenEntry != NULL) {\r | |
1527 | FreePool (TokenEntry);\r | |
1528 | }\r | |
f75a7f56 | 1529 | \r |
fcae1a99 JW |
1530 | goto ON_EXIT;\r |
1531 | }\r | |
1532 | \r | |
8339166d JW |
1533 | ASSERT (Packet != NULL);\r |
1534 | \r | |
fcae1a99 JW |
1535 | //\r |
1536 | // Save the token into the Dns6TxTokens map.\r | |
1537 | //\r | |
1538 | Status = NetMapInsertTail (&Instance->Dns6TxTokens, TokenEntry, Packet);\r | |
1539 | if (EFI_ERROR (Status)) {\r | |
1540 | if (TokenEntry != NULL) {\r | |
1541 | FreePool (TokenEntry);\r | |
1542 | }\r | |
f75a7f56 | 1543 | \r |
fcae1a99 | 1544 | NetbufFree (Packet);\r |
f75a7f56 | 1545 | \r |
fcae1a99 JW |
1546 | goto ON_EXIT;\r |
1547 | }\r | |
f75a7f56 | 1548 | \r |
fcae1a99 JW |
1549 | //\r |
1550 | // Dns Query Ip\r | |
1551 | //\r | |
1552 | Status = DoDnsQuery (Instance, Packet);\r | |
1553 | if (EFI_ERROR (Status)) {\r | |
520a0746 JW |
1554 | Dns6RemoveTokenEntry (&Instance->Dns6TxTokens, TokenEntry);\r |
1555 | \r | |
fcae1a99 JW |
1556 | if (TokenEntry != NULL) {\r |
1557 | FreePool (TokenEntry);\r | |
1558 | }\r | |
f75a7f56 | 1559 | \r |
fcae1a99 JW |
1560 | NetbufFree (Packet);\r |
1561 | }\r | |
f75a7f56 | 1562 | \r |
fcae1a99 JW |
1563 | ON_EXIT:\r |
1564 | gBS->RestoreTPL (OldTpl);\r | |
1565 | return Status;\r | |
99c048ef | 1566 | }\r |
1567 | \r | |
1568 | /**\r | |
0f4e123f JW |
1569 | This function is to update the DNS Cache.\r |
1570 | \r | |
1571 | The UpdateDnsCache() function is used to add/delete/modify DNS cache entry. DNS cache\r | |
1572 | can be normally dynamically updated after the DNS resolve succeeds. This function\r | |
1573 | provided capability to manually add/delete/modify the DNS cache.\r | |
1574 | \r | |
1575 | @param[in] This Pointer to EFI_DNS6_PROTOCOL instance.\r | |
1576 | @param[in] DeleteFlag If FALSE, this function is to add one entry to the\r | |
81a46615 | 1577 | DNS Cache. If TRUE, this function will delete\r |
0f4e123f | 1578 | matching DNS Cache entry.\r |
81a46615 | 1579 | @param[in] Override If TRUE, the matching DNS cache entry will be\r |
0f4e123f JW |
1580 | overwritten with the supplied parameter. If FALSE,\r |
1581 | EFI_ACCESS_DENIED will be returned if the entry to\r | |
1582 | be added is already existed.\r | |
1583 | @param[in] DnsCacheEntry Pointer to DNS Cache entry.\r | |
1584 | \r | |
1585 | @retval EFI_SUCCESS The operation completed successfully.\r | |
1586 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
1587 | This is NULL.\r | |
1588 | DnsCacheEntry.HostName is NULL.\r | |
1589 | DnsCacheEntry.IpAddress is NULL.\r | |
1590 | DnsCacheEntry.Timeout is zero.\r | |
1591 | @retval EFI_ACCESS_DENIED The DNS cache entry already exists and Override is\r | |
1592 | not TRUE.\r | |
1593 | @retval EFI_OUT_OF_RESOURCE Failed to allocate needed resources.\r | |
99c048ef | 1594 | **/\r |
1595 | EFI_STATUS\r | |
1596 | EFIAPI\r | |
1597 | Dns6UpdateDnsCache (\r | |
d1050b9d MK |
1598 | IN EFI_DNS6_PROTOCOL *This,\r |
1599 | IN BOOLEAN DeleteFlag,\r | |
1600 | IN BOOLEAN Override,\r | |
1601 | IN EFI_DNS6_CACHE_ENTRY DnsCacheEntry\r | |
99c048ef | 1602 | )\r |
1603 | {\r | |
d1050b9d MK |
1604 | EFI_STATUS Status;\r |
1605 | EFI_TPL OldTpl;\r | |
99c048ef | 1606 | \r |
1607 | Status = EFI_SUCCESS;\r | |
f75a7f56 | 1608 | \r |
d1050b9d | 1609 | if ((DnsCacheEntry.HostName == NULL) || (DnsCacheEntry.IpAddress == NULL) || (DnsCacheEntry.Timeout == 0)) {\r |
f75a7f56 | 1610 | return EFI_INVALID_PARAMETER;\r |
99c048ef | 1611 | }\r |
f75a7f56 | 1612 | \r |
99c048ef | 1613 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
1614 | \r | |
1615 | //\r | |
1616 | // Update Dns6Cache here.\r | |
1617 | //\r | |
1618 | Status = UpdateDns6Cache (&mDriverData->Dns6CacheList, DeleteFlag, Override, DnsCacheEntry);\r | |
f75a7f56 | 1619 | \r |
99c048ef | 1620 | gBS->RestoreTPL (OldTpl);\r |
f75a7f56 | 1621 | \r |
99c048ef | 1622 | return Status;\r |
1623 | }\r | |
1624 | \r | |
1625 | /**\r | |
0f4e123f JW |
1626 | Polls for incoming data packets and processes outgoing data packets.\r |
1627 | \r | |
1628 | The Poll() function can be used by network drivers and applications to increase the\r | |
1629 | rate that data packets are moved between the communications device and the transmit\r | |
1630 | and receive queues.\r | |
1631 | \r | |
1632 | In some systems, the periodic timer event in the managed network driver may not poll\r | |
1633 | the underlying communications device fast enough to transmit and/or receive all data\r | |
1634 | packets without missing incoming packets or dropping outgoing packets. Drivers and\r | |
1635 | applications that are experiencing packet loss should try calling the Poll()\r | |
1636 | function more often.\r | |
1637 | \r | |
1638 | @param[in] This Pointer to EFI_DNS6_PROTOCOL instance.\r | |
1639 | \r | |
1640 | @retval EFI_SUCCESS Incoming or outgoing data was processed.\r | |
1641 | @retval EFI_NOT_STARTED This EFI DNS Protocol instance has not been started.\r | |
1642 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
1643 | @retval EFI_NO_MAPPING There is no source address is available for use.\r | |
1644 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
1645 | @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive\r | |
1646 | queue. Consider increasing the polling rate.\r | |
99c048ef | 1647 | **/\r |
1648 | EFI_STATUS\r | |
1649 | EFIAPI\r | |
1650 | Dns6Poll (\r | |
d1050b9d | 1651 | IN EFI_DNS6_PROTOCOL *This\r |
99c048ef | 1652 | )\r |
1653 | {\r | |
d1050b9d MK |
1654 | DNS_INSTANCE *Instance;\r |
1655 | EFI_UDP6_PROTOCOL *Udp;\r | |
99c048ef | 1656 | \r |
1657 | if (This == NULL) {\r | |
1658 | return EFI_INVALID_PARAMETER;\r | |
1659 | }\r | |
1660 | \r | |
1661 | Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This);\r | |
1662 | \r | |
1663 | if (Instance->State == DNS_STATE_UNCONFIGED) {\r | |
1664 | return EFI_NOT_STARTED;\r | |
1665 | } else if (Instance->State == DNS_STATE_DESTROY) {\r | |
1666 | return EFI_DEVICE_ERROR;\r | |
1667 | }\r | |
1668 | \r | |
1669 | Udp = Instance->UdpIo->Protocol.Udp6;\r | |
f75a7f56 | 1670 | \r |
99c048ef | 1671 | return Udp->Poll (Udp);\r |
1672 | }\r | |
1673 | \r | |
1674 | /**\r | |
0f4e123f JW |
1675 | Abort an asynchronous DNS operation, including translation between IP and Host, and\r |
1676 | general look up behavior.\r | |
1677 | \r | |
1678 | The Cancel() function is used to abort a pending resolution request. After calling\r | |
1679 | this function, Token.Status will be set to EFI_ABORTED and then Token.Event will be\r | |
1680 | signaled. If the token is not in one of the queues, which usually means that the\r | |
1681 | asynchronous operation has completed, this function will not signal the token and\r | |
1682 | EFI_NOT_FOUND is returned.\r | |
1683 | \r | |
1684 | @param[in] This Pointer to EFI_DNS6_PROTOCOL instance.\r | |
1685 | @param[in] Token Pointer to a token that has been issued by\r | |
1686 | EFI_DNS6_PROTOCOL.HostNameToIp (),\r | |
1687 | EFI_DNS6_PROTOCOL.IpToHostName() or\r | |
1688 | EFI_DNS6_PROTOCOL.GeneralLookup().\r | |
1689 | If NULL, all pending tokens are aborted.\r | |
1690 | \r | |
1691 | @retval EFI_SUCCESS Incoming or outgoing data was processed.\r | |
1692 | @retval EFI_NOT_STARTED This EFI DNS6 Protocol instance has not been started.\r | |
1693 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
1694 | @retval EFI_NO_MAPPING There's no source address is available for use.\r | |
1695 | @retval EFI_NOT_FOUND When Token is not NULL, and the asynchronous DNS\r | |
1696 | operation was not found in the transmit queue. It\r | |
1697 | was either completed or was not issued by\r | |
1698 | HostNameToIp(), IpToHostName() or GeneralLookup().\r | |
99c048ef | 1699 | **/\r |
1700 | EFI_STATUS\r | |
1701 | EFIAPI\r | |
1702 | Dns6Cancel (\r | |
1703 | IN EFI_DNS6_PROTOCOL *This,\r | |
1704 | IN EFI_DNS6_COMPLETION_TOKEN *Token\r | |
1705 | )\r | |
1706 | {\r | |
d1050b9d MK |
1707 | EFI_STATUS Status;\r |
1708 | DNS_INSTANCE *Instance;\r | |
1709 | EFI_TPL OldTpl;\r | |
99c048ef | 1710 | \r |
1711 | if (This == NULL) {\r | |
1712 | return EFI_INVALID_PARAMETER;\r | |
1713 | }\r | |
1714 | \r | |
1715 | Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This);\r | |
1716 | \r | |
1717 | if (Instance->State == DNS_STATE_UNCONFIGED) {\r | |
1718 | return EFI_NOT_STARTED;\r | |
1719 | }\r | |
1720 | \r | |
1721 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
1722 | \r | |
1723 | //\r | |
81a46615 | 1724 | // Cancel the tokens specified by Token for this instance.\r |
99c048ef | 1725 | //\r |
1726 | Status = Dns6InstanceCancelToken (Instance, Token);\r | |
1727 | \r | |
1728 | //\r | |
1729 | // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.\r | |
1730 | //\r | |
1731 | DispatchDpc ();\r | |
1732 | \r | |
1733 | gBS->RestoreTPL (OldTpl);\r | |
1734 | \r | |
1735 | return Status;\r | |
1736 | }\r |