2 Implementation of EFI_DNS4_PROTOCOL and EFI_DNS6_PROTOCOL interfaces.
4 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 EFI_DNS4_PROTOCOL mDns4Protocol
= {
28 EFI_DNS6_PROTOCOL mDns6Protocol
= {
40 This function is used to retrieve DNS mode data for this DNS instance.
42 @param[in] This Pointer to EFI_DNS4_PROTOCOL instance.
43 @param[out] DnsModeData Pointer to the caller-allocated storage for the EFI_DNS4_MODE_DATA structure.
45 @retval EFI_SUCCESS The operation completed successfully.
46 @retval EFI_NOT_STARTED When DnsConfigData is queried, no configuration data is
47 available because this instance has not been configured.
48 @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.
49 @retval EFI_INVALID_PARAMETER This is NULL or DnsModeData is NULL.
55 IN EFI_DNS4_PROTOCOL
*This
,
56 OUT EFI_DNS4_MODE_DATA
*DnsModeData
59 DNS_INSTANCE
*Instance
;
68 DNS4_SERVER_IP
*ServerItem
;
69 EFI_IPv4_ADDRESS
*ServerList
;
70 DNS4_CACHE
*CacheItem
;
71 EFI_DNS4_CACHE_ENTRY
*CacheList
;
81 if ((This
== NULL
) || (DnsModeData
== NULL
)) {
82 return EFI_INVALID_PARAMETER
;
85 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
87 Instance
= DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This
);
88 if (Instance
->State
== DNS_STATE_UNCONFIGED
) {
89 gBS
->RestoreTPL (OldTpl
);
90 return EFI_NOT_STARTED
;
93 ZeroMem (DnsModeData
, sizeof (EFI_DNS4_MODE_DATA
));
96 // Get the current configuration data of this instance.
98 Status
= Dns4CopyConfigure (&DnsModeData
->DnsConfigData
, &Instance
->Dns4CfgData
);
99 if (EFI_ERROR (Status
)) {
100 gBS
->RestoreTPL (OldTpl
);
105 // Get the DnsServerCount and DnsServerList
108 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &mDriverData
->Dns4ServerList
) {
111 DnsModeData
->DnsServerCount
= (UINT32
) Index
;
112 ServerList
= AllocatePool (sizeof (EFI_IPv4_ADDRESS
) * DnsModeData
->DnsServerCount
);
113 ASSERT (ServerList
!= NULL
);
115 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &mDriverData
->Dns4ServerList
) {
116 ServerItem
= NET_LIST_USER_STRUCT (Entry
, DNS4_SERVER_IP
, AllServerLink
);
117 CopyMem (ServerList
+ Index
, &ServerItem
->Dns4ServerIp
, sizeof (EFI_IPv4_ADDRESS
));
120 DnsModeData
->DnsServerList
= ServerList
;
123 // Get the DnsCacheCount and DnsCacheList
126 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &mDriverData
->Dns4CacheList
) {
129 DnsModeData
->DnsCacheCount
= (UINT32
) Index
;
130 CacheList
= AllocatePool (sizeof (EFI_DNS4_CACHE_ENTRY
) * DnsModeData
->DnsCacheCount
);
131 ASSERT (CacheList
!= NULL
);
133 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &mDriverData
->Dns4CacheList
) {
134 CacheItem
= NET_LIST_USER_STRUCT (Entry
, DNS4_CACHE
, AllCacheLink
);
135 CopyMem (CacheList
+ Index
, &CacheItem
->DnsCache
, sizeof (EFI_DNS4_CACHE_ENTRY
));
138 DnsModeData
->DnsCacheList
= CacheList
;
140 gBS
->RestoreTPL (OldTpl
);
146 This function is used to configure DNS configuration data for this DNS instance.
148 @param[in] This Pointer to EFI_DNS4_PROTOCOL instance.
149 @param[in] DnsConfigData Pointer to caller-allocated buffer containing EFI_DNS4_CONFIG_DATA structure.
150 If NULL, the driver will reinitialize the protocol instance to the unconfigured state.
152 @retval EFI_SUCCESS The operation completed successfully.
153 @retval EFI_UNSUPPORTED The designated protocol is not supported.
154 @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.
155 @retval EFI_INVALID_PARAMETER This is NULL.
156 The StationIp address provided in DnsConfigData is not a valid unicast.
157 DnsServerList is NULL while DnsServerListCount is not equal to Zero.
158 DnsServerListCount is Zero while DnsServerListCount is not equal to NULL.
159 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI DNSv4 Protocol instance is not configured.
165 IN EFI_DNS4_PROTOCOL
*This
,
166 IN EFI_DNS4_CONFIG_DATA
*DnsConfigData
170 DNS_INSTANCE
*Instance
;
176 UINT32 ServerListCount
;
177 EFI_IPv4_ADDRESS
*ServerList
;
179 Status
= EFI_SUCCESS
;
183 (DnsConfigData
!= NULL
&& ((DnsConfigData
->DnsServerListCount
!= 0 && DnsConfigData
->DnsServerList
== NULL
) ||
184 (DnsConfigData
->DnsServerListCount
== 0 && DnsConfigData
->DnsServerList
!= NULL
)))) {
185 return EFI_INVALID_PARAMETER
;
188 if (DnsConfigData
!= NULL
&& DnsConfigData
->Protocol
!= DNS_PROTOCOL_UDP
) {
189 return EFI_UNSUPPORTED
;
192 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
194 Instance
= DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This
);
196 if (DnsConfigData
== NULL
) {
197 ZeroMem (&Instance
->SessionDnsServer
, sizeof (EFI_IP_ADDRESS
));
200 // Reset the Instance if ConfigData is NULL
202 if (!NetMapIsEmpty(&Instance
->Dns4TxTokens
)) {
203 Dns4InstanceCancelToken(Instance
, NULL
);
206 Instance
->MaxRetry
= 0;
208 if (Instance
->UdpIo
!= NULL
){
209 UdpIoCleanIo (Instance
->UdpIo
);
212 if (Instance
->Dns4CfgData
.DnsServerList
!= NULL
) {
213 FreePool (Instance
->Dns4CfgData
.DnsServerList
);
215 ZeroMem (&Instance
->Dns4CfgData
, sizeof (EFI_DNS4_CONFIG_DATA
));
217 Instance
->State
= DNS_STATE_UNCONFIGED
;
220 // Configure the parameters for new operation.
222 CopyMem (&Ip
, &DnsConfigData
->StationIp
, sizeof (IP4_ADDR
));
223 CopyMem (&Netmask
, &DnsConfigData
->SubnetMask
, sizeof (IP4_ADDR
));
226 Netmask
= NTOHL (Netmask
);
228 if (!DnsConfigData
->UseDefaultSetting
&&
229 ((!IP4_IS_VALID_NETMASK (Netmask
) || !NetIp4IsUnicast (Ip
, Netmask
)))) {
230 Status
= EFI_INVALID_PARAMETER
;
234 Status
= Dns4CopyConfigure (&Instance
->Dns4CfgData
, DnsConfigData
);
235 if (EFI_ERROR (Status
)) {
239 if (DnsConfigData
->DnsServerListCount
== 0 || DnsConfigData
->DnsServerList
== NULL
) {
240 gBS
->RestoreTPL (OldTpl
);
243 // The DNS instance will retrieve DNS server from DHCP Server
245 Status
= GetDns4ServerFromDhcp4 (
250 if (EFI_ERROR (Status
)) {
254 ASSERT(ServerList
!= NULL
);
256 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
258 CopyMem (&Instance
->SessionDnsServer
.v4
, &ServerList
[0], sizeof (EFI_IPv4_ADDRESS
));
260 CopyMem (&Instance
->SessionDnsServer
.v4
, &DnsConfigData
->DnsServerList
[0], sizeof (EFI_IPv4_ADDRESS
));
266 Status
= Dns4ConfigUdp (Instance
, Instance
->UdpIo
);
267 if (EFI_ERROR (Status
)) {
268 if (Instance
->Dns4CfgData
.DnsServerList
!= NULL
) {
269 FreePool (Instance
->Dns4CfgData
.DnsServerList
);
275 // Add configured DNS server used by this instance to ServerList.
277 Status
= AddDns4ServerIp (&mDriverData
->Dns4ServerList
, Instance
->SessionDnsServer
.v4
);
278 if (EFI_ERROR (Status
)) {
279 if (Instance
->Dns4CfgData
.DnsServerList
!= NULL
) {
280 FreePool (Instance
->Dns4CfgData
.DnsServerList
);
285 Instance
->State
= DNS_STATE_CONFIGED
;
289 gBS
->RestoreTPL (OldTpl
);
294 The function is used to translate the host name to host IP address.
295 A type A query is used to get the one or more IP addresses for this host.
297 @param[in] This Pointer to EFI_DNS4_PROTOCOL instance.
298 @param[in] HostName Pointer to caller-supplied buffer containing Host name to be translated.
299 This buffer contains 16 bit characters but these are translated to ASCII for use with
300 DNSv4 server and there is no requirement for driver to support non-ASCII Unicode characters.
301 @param[in] Token Pointer to the caller-allocated completion token to return at the completion of the process to translate host name to host address.
303 @retval EFI_SUCCESS The operation completed successfully.
304 @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.
305 @retval EFI_INVALID_PARAMETER This is NULL.
309 @retval EFI_NO_MAPPING There's no source address is available for use.
310 @retval EFI_NOT_STARTED This instance has not been started.
316 IN EFI_DNS4_PROTOCOL
*This
,
318 IN EFI_DNS4_COMPLETION_TOKEN
*Token
323 DNS_INSTANCE
*Instance
;
325 EFI_DNS4_CONFIG_DATA
*ConfigData
;
332 DNS4_TOKEN_ENTRY
*TokenEntry
;
337 Status
= EFI_SUCCESS
;
343 // Validate the parameters
345 if ((This
== NULL
) || (HostName
== NULL
) || Token
== NULL
) {
346 return EFI_INVALID_PARAMETER
;
349 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
351 Instance
= DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This
);
353 ConfigData
= &(Instance
->Dns4CfgData
);
355 Instance
->MaxRetry
= ConfigData
->RetryCount
;
357 Token
->Status
= EFI_NOT_READY
;
358 Token
->RetryCount
= 0;
359 Token
->RetryInterval
= ConfigData
->RetryInterval
;
361 if (Instance
->State
!= DNS_STATE_CONFIGED
) {
362 Status
= EFI_NOT_STARTED
;
367 // Check the MaxRetry and RetryInterval values.
369 if (Instance
->MaxRetry
== 0) {
370 Instance
->MaxRetry
= DNS_DEFAULT_RETRY
;
373 if (Token
->RetryInterval
< DNS_DEFAULT_TIMEOUT
) {
374 Token
->RetryInterval
= DNS_DEFAULT_TIMEOUT
;
380 if (ConfigData
->EnableDnsCache
) {
382 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &mDriverData
->Dns4CacheList
) {
383 Item
= NET_LIST_USER_STRUCT (Entry
, DNS4_CACHE
, AllCacheLink
);
384 if (StrCmp (HostName
, Item
->DnsCache
.HostName
) == 0) {
390 Token
->RspData
.H2AData
= AllocatePool (sizeof (DNS_HOST_TO_ADDR_DATA
));
391 if (Token
->RspData
.H2AData
== NULL
) {
392 Status
= EFI_OUT_OF_RESOURCES
;
396 Token
->RspData
.H2AData
->IpCount
= (UINT32
)Index
;
397 Token
->RspData
.H2AData
->IpList
= AllocatePool (sizeof (EFI_IPv4_ADDRESS
) * Index
);
398 if (Token
->RspData
.H2AData
->IpList
== NULL
) {
399 if (Token
->RspData
.H2AData
!= NULL
) {
400 FreePool (Token
->RspData
.H2AData
);
403 Status
= EFI_OUT_OF_RESOURCES
;
408 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &mDriverData
->Dns4CacheList
) {
409 Item
= NET_LIST_USER_STRUCT (Entry
, DNS4_CACHE
, AllCacheLink
);
410 if ((UINT32
)Index
< Token
->RspData
.H2AData
->IpCount
&& StrCmp (HostName
, Item
->DnsCache
.HostName
) == 0) {
411 CopyMem ((Token
->RspData
.H2AData
->IpList
) + Index
, Item
->DnsCache
.IpAddress
, sizeof (EFI_IPv4_ADDRESS
));
416 Token
->Status
= EFI_SUCCESS
;
418 if (Token
->Event
!= NULL
) {
419 gBS
->SignalEvent (Token
->Event
);
423 Status
= Token
->Status
;
429 // Construct DNS TokenEntry.
431 TokenEntry
= AllocateZeroPool (sizeof(DNS4_TOKEN_ENTRY
));
432 if (TokenEntry
== NULL
) {
433 Status
= EFI_OUT_OF_RESOURCES
;
437 TokenEntry
->PacketToLive
= Token
->RetryInterval
;
438 TokenEntry
->QueryHostName
= HostName
;
439 TokenEntry
->Token
= Token
;
442 // Construct DNS Query Packet.
444 Status
= ConstructDNSQueryIp (Instance
, TokenEntry
->QueryHostName
, DNS_TYPE_A
, &Packet
);
445 if (EFI_ERROR (Status
)) {
446 if (TokenEntry
!= NULL
) {
447 FreePool (TokenEntry
);
454 // Save the token into the Dns4TxTokens map.
456 Status
= NetMapInsertTail (&Instance
->Dns4TxTokens
, TokenEntry
, Packet
);
457 if (EFI_ERROR (Status
)) {
458 if (TokenEntry
!= NULL
) {
459 FreePool (TokenEntry
);
470 Status
= DoDnsQuery (Instance
, Packet
);
471 if (EFI_ERROR (Status
)) {
472 if (TokenEntry
!= NULL
) {
473 FreePool (TokenEntry
);
480 gBS
->RestoreTPL (OldTpl
);
485 The function is used to translate the host address to host name.
486 A type PTR query is used to get the primary name of the host.
488 @param[in] This Pointer to EFI_DNS4_PROTOCOL instance.
489 @param[in] IpAddress IP address.
490 @param[in] Token Pointer to the caller-allocated completion used token to translate host address to host name.
492 @retval EFI_SUCCESS The operation completed successfully.
493 @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.
494 @retval EFI_INVALID_PARAMETER This is NULL.
497 IpAddress is not valid IP address.
498 @retval EFI_NO_MAPPING There's no source address is available for use.
499 @retval EFI_NOT_STARTED This instance has not been started.
500 @retval EFI_UNSUPPORTED This function is not supported.
506 IN EFI_DNS4_PROTOCOL
*This
,
507 IN EFI_IPv4_ADDRESS IpAddress
,
508 IN EFI_DNS4_COMPLETION_TOKEN
*Token
511 return EFI_UNSUPPORTED
;
515 This function retrieves arbitrary information from the DNS.
516 The caller supplies a QNAME, QTYPE, and QCLASS, and all of the matching RRs are returned.
517 All RR content (e.g., Ttl) was returned.
518 The caller need parse the returned RR to get required information. This function is optional.
520 @param[in] This Pointer to EFI_DNS4_PROTOCOL instance.
521 @param[in] QName Pointer to Query Name.
522 @param[in] QType Query Type.
523 @param[in] QClass Query Name.
524 @param[in] Token Point to the caller-allocated completion token to retrieve arbitrary information.
526 @retval EFI_SUCCESS The operation completed successfully.
527 @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.
528 @retval EFI_INVALID_PARAMETER This is NULL.
532 @retval EFI_NO_MAPPING There's no source address is available for use.
533 @retval EFI_ALREADY_STARTED This Token is being used in another DNS session.
534 @retval EFI_UNSUPPORTED This function is not supported. Or the requested QType is not supported
540 IN EFI_DNS4_PROTOCOL
*This
,
544 IN EFI_DNS4_COMPLETION_TOKEN
*Token
547 return EFI_UNSUPPORTED
;
551 This function is used to add/delete/modify DNS cache entry.
552 DNS cache can be normally dynamically updated after the DNS resolve succeeds.
553 This function provided capability to manually add/delete/modify the DNS cache.
555 @param[in] This Pointer to EFI_DNS4_PROTOCOL instance.
556 @param[in] DeleteFlag If FALSE, this function is to add one entry to the DNS Cache.
557 If TRUE, this function will delete matching DNS Cache entry.
558 @param[in] Override If TRUE, the matching DNS cache entry will be overwritten with the supplied parameter.
559 If FALSE, EFI_ACCESS_DENIED will be returned if the entry to be added is already exists.
560 @param[in] DnsCacheEntry Pointer to DNS Cache entry.
562 @retval EFI_SUCCESS The operation completed successfully.
563 @retval EFI_INVALID_PARAMETER This is NULL.
564 DnsCacheEntry.HostName is NULL.
565 DnsCacheEntry.IpAddress is NULL.
566 DnsCacheEntry.Timeout is zero.
567 @retval EFI_ACCESS_DENIED The DNS cache entry already exists and Override is not TRUE.
573 IN EFI_DNS4_PROTOCOL
*This
,
574 IN BOOLEAN DeleteFlag
,
576 IN EFI_DNS4_CACHE_ENTRY DnsCacheEntry
582 Status
= EFI_SUCCESS
;
584 if (DnsCacheEntry
.HostName
== NULL
|| DnsCacheEntry
.IpAddress
== NULL
|| DnsCacheEntry
.Timeout
== 0) {
585 return EFI_INVALID_PARAMETER
;
588 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
591 // Update Dns4Cache here.
593 Status
= UpdateDns4Cache (&mDriverData
->Dns4CacheList
, DeleteFlag
, Override
, DnsCacheEntry
);
595 gBS
->RestoreTPL (OldTpl
);
601 This function can be used by network drivers and applications to increase the rate that data packets are moved between
602 the communications device and the transmit and receive queues. In some systems, the periodic timer event in the managed
603 network driver may not poll the underlying communications device fast enough to transmit and/or receive all data packets
604 without missing incoming packets or dropping outgoing packets.
606 @param[in] This Pointer to EFI_DNS4_PROTOCOL instance.
608 @retval EFI_SUCCESS Incoming or outgoing data was processed.
609 @retval EFI_INVALID_PARAMETER This is NULL.
610 @retval EFI_NOT_STARTED This EFI DNS Protocol instance has not been started.
611 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
612 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
613 Consider increasing the polling rate.
619 IN EFI_DNS4_PROTOCOL
*This
622 DNS_INSTANCE
*Instance
;
623 EFI_UDP4_PROTOCOL
*Udp
;
626 return EFI_INVALID_PARAMETER
;
629 Instance
= DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This
);
631 if (Instance
->State
== DNS_STATE_UNCONFIGED
) {
632 return EFI_NOT_STARTED
;
633 } else if (Instance
->State
== DNS_STATE_DESTROY
) {
634 return EFI_DEVICE_ERROR
;
637 Udp
= Instance
->UdpIo
->Protocol
.Udp4
;
639 return Udp
->Poll (Udp
);
643 This function is used to abort a pending resolution request.
644 After calling this function, Token.Status will be set to EFI_ABORTED and then Token.
646 @param[in] This Pointer to EFI_DNS4_PROTOCOL instance.
647 @param[in] Token Pointer to a token that has been issued by EFI_DNS4_PROTOCOL.HostNameToIp(),
648 EFI_DNS4_PROTOCOL.IpToHostName() or EFI_DNS4_PROTOCOL.GeneralLookup().
649 If NULL, all pending tokens are aborted.
651 @retval EFI_SUCCESS Incoming or outgoing data was processed.
652 @retval EFI_INVALID_PARAMETER This is NULL.
653 @retval EFI_NOT_STARTED This EFI DNS Protocol instance has not been started.
654 @retval EFI_NOT_FOUND When Token is not NULL, and the asynchronous DNS operation was not found in the transmit queue.
655 It was either completed or was not issued by HostNameToIp(), IpToHostName() or GeneralLookup().
661 IN EFI_DNS4_PROTOCOL
*This
,
662 IN EFI_DNS4_COMPLETION_TOKEN
*Token
666 DNS_INSTANCE
*Instance
;
670 return EFI_INVALID_PARAMETER
;
673 Instance
= DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This
);
675 if (Instance
->State
== DNS_STATE_UNCONFIGED
) {
676 return EFI_NOT_STARTED
;
679 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
682 // Cancle the tokens specified by Token for this instance.
684 Status
= Dns4InstanceCancelToken (Instance
, Token
);
687 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
691 gBS
->RestoreTPL (OldTpl
);
697 This function is used to retrieve DNS mode data for this DNS instance.
699 @param[in] This Pointer to EFI_DNS6_PROTOCOL instance.
700 @param[out] DnsModeData Pointer to the caller-allocated storage for the EFI_DNS6_MODE_DATA structure.
702 @retval EFI_SUCCESS The operation completed successfully.
703 @retval EFI_NOT_STARTED When DnsConfigData is queried, no configuration data is
704 available because this instance has not been configured.
705 @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.
706 @retval EFI_INVALID_PARAMETER This is NULL or DnsModeData is NULL.
712 IN EFI_DNS6_PROTOCOL
*This
,
713 OUT EFI_DNS6_MODE_DATA
*DnsModeData
716 DNS_INSTANCE
*Instance
;
725 DNS6_SERVER_IP
*ServerItem
;
726 EFI_IPv6_ADDRESS
*ServerList
;
727 DNS6_CACHE
*CacheItem
;
728 EFI_DNS6_CACHE_ENTRY
*CacheList
;
735 Status
= EFI_SUCCESS
;
737 if ((This
== NULL
) || (DnsModeData
== NULL
)) {
738 return EFI_INVALID_PARAMETER
;
741 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
743 Instance
= DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This
);
744 if (Instance
->State
== DNS_STATE_UNCONFIGED
) {
745 gBS
->RestoreTPL (OldTpl
);
746 return EFI_NOT_STARTED
;
749 ZeroMem (DnsModeData
, sizeof (EFI_DNS6_MODE_DATA
));
752 // Get the current configuration data of this instance.
754 Status
= Dns6CopyConfigure(&DnsModeData
->DnsConfigData
, &Instance
->Dns6CfgData
);
755 if (EFI_ERROR (Status
)) {
756 gBS
->RestoreTPL (OldTpl
);
761 // Get the DnsServerCount and DnsServerList
764 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &mDriverData
->Dns6ServerList
) {
767 DnsModeData
->DnsServerCount
= (UINT32
) Index
;
768 ServerList
= AllocatePool (sizeof(EFI_IPv6_ADDRESS
) * DnsModeData
->DnsServerCount
);
769 ASSERT (ServerList
!= NULL
);
771 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &mDriverData
->Dns6ServerList
) {
772 ServerItem
= NET_LIST_USER_STRUCT (Entry
, DNS6_SERVER_IP
, AllServerLink
);
773 CopyMem (ServerList
+ Index
, &ServerItem
->Dns6ServerIp
, sizeof (EFI_IPv6_ADDRESS
));
776 DnsModeData
->DnsServerList
= ServerList
;
779 // Get the DnsCacheCount and DnsCacheList
782 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &mDriverData
->Dns6CacheList
) {
785 DnsModeData
->DnsCacheCount
= (UINT32
) Index
;
786 CacheList
= AllocatePool (sizeof(EFI_DNS6_CACHE_ENTRY
) * DnsModeData
->DnsCacheCount
);
787 ASSERT (CacheList
!= NULL
);
789 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &mDriverData
->Dns6CacheList
) {
790 CacheItem
= NET_LIST_USER_STRUCT (Entry
, DNS6_CACHE
, AllCacheLink
);
791 CopyMem (CacheList
+ Index
, &CacheItem
->DnsCache
, sizeof (EFI_DNS6_CACHE_ENTRY
));
794 DnsModeData
->DnsCacheList
= CacheList
;
796 gBS
->RestoreTPL (OldTpl
);
802 The function is used to set and change the configuration data for this EFI DNSv6 Protocol driver instance.
803 Reset the DNS instance if DnsConfigData is NULL.
805 @param[in] This Pointer to EFI_DNS6_PROTOCOL instance.
806 @param[in] DnsConfigData Pointer to the configuration data structure.
807 All associated storage to be allocated and released by caller.
809 @retval EFI_SUCCESS The operation completed successfully.
810 @retval EFI_UNSUPPORTED The designated protocol is not supported.
811 @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.
812 @retval EFI_INVALID_PARAMETER This is NULL.
813 The StationIp address provided in DnsConfigData is not a valid unicast.
814 DnsServerList is NULL while DnsServerListCount is not equal to Zero.
815 DnsServerListCount is Zero while DnsServerList is not equal to NULL.
816 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI DNSv6 Protocol instance is not configured.
822 IN EFI_DNS6_PROTOCOL
*This
,
823 IN EFI_DNS6_CONFIG_DATA
*DnsConfigData
827 DNS_INSTANCE
*Instance
;
831 UINT32 ServerListCount
;
832 EFI_IPv6_ADDRESS
*ServerList
;
834 Status
= EFI_SUCCESS
;
838 (DnsConfigData
!= NULL
&& ((DnsConfigData
->DnsServerCount
!= 0 && DnsConfigData
->DnsServerList
== NULL
) ||
839 (DnsConfigData
->DnsServerCount
== 0 && DnsConfigData
->DnsServerList
!= NULL
)))) {
840 return EFI_INVALID_PARAMETER
;
843 if (DnsConfigData
!= NULL
&& DnsConfigData
->Protocol
!= DNS_PROTOCOL_UDP
) {
844 return EFI_UNSUPPORTED
;
847 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
849 Instance
= DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This
);
851 if (DnsConfigData
== NULL
) {
852 ZeroMem (&Instance
->SessionDnsServer
, sizeof (EFI_IP_ADDRESS
));
855 // Reset the Instance if ConfigData is NULL
857 if (!NetMapIsEmpty(&Instance
->Dns6TxTokens
)) {
858 Dns6InstanceCancelToken(Instance
, NULL
);
861 Instance
->MaxRetry
= 0;
863 if (Instance
->UdpIo
!= NULL
){
864 UdpIoCleanIo (Instance
->UdpIo
);
867 if (Instance
->Dns6CfgData
.DnsServerList
!= NULL
) {
868 FreePool (Instance
->Dns6CfgData
.DnsServerList
);
870 ZeroMem (&Instance
->Dns6CfgData
, sizeof (EFI_DNS6_CONFIG_DATA
));
872 Instance
->State
= DNS_STATE_UNCONFIGED
;
875 // Configure the parameters for new operation.
877 if (!NetIp6IsUnspecifiedAddr (&DnsConfigData
->StationIp
) && !NetIp6IsValidUnicast (&DnsConfigData
->StationIp
)) {
878 Status
= EFI_INVALID_PARAMETER
;
882 Status
= Dns6CopyConfigure (&Instance
->Dns6CfgData
, DnsConfigData
);
883 if (EFI_ERROR (Status
)) {
887 if (DnsConfigData
->DnsServerCount
== 0 || DnsConfigData
->DnsServerList
== NULL
) {
888 gBS
->RestoreTPL (OldTpl
);
891 //The DNS instance will retrieve DNS server from DHCP Server.
893 Status
= GetDns6ServerFromDhcp6 (
894 Instance
->Service
->ImageHandle
,
895 Instance
->Service
->ControllerHandle
,
899 if (EFI_ERROR (Status
)) {
903 ASSERT(ServerList
!= NULL
);
905 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
907 CopyMem (&Instance
->SessionDnsServer
.v6
, &ServerList
[0], sizeof (EFI_IPv6_ADDRESS
));
909 CopyMem (&Instance
->SessionDnsServer
.v6
, &DnsConfigData
->DnsServerList
[0], sizeof (EFI_IPv6_ADDRESS
));
915 Status
= Dns6ConfigUdp (Instance
, Instance
->UdpIo
);
916 if (EFI_ERROR (Status
)) {
917 if (Instance
->Dns6CfgData
.DnsServerList
!= NULL
) {
918 FreePool (Instance
->Dns6CfgData
.DnsServerList
);
924 // Add configured DNS server used by this instance to ServerList.
926 Status
= AddDns6ServerIp (&mDriverData
->Dns6ServerList
, Instance
->SessionDnsServer
.v6
);
927 if (EFI_ERROR (Status
)) {
928 if (Instance
->Dns6CfgData
.DnsServerList
!= NULL
) {
929 FreePool (Instance
->Dns6CfgData
.DnsServerList
);
934 Instance
->State
= DNS_STATE_CONFIGED
;
938 gBS
->RestoreTPL (OldTpl
);
943 The function is used to translate the host name to host IP address.
944 A type AAAA query is used to get the one or more IPv6 addresses for this host.
946 @param[in] This Pointer to EFI_DNS6_PROTOCOL instance.
947 @param[in] HostName Pointer to caller-supplied buffer containing Host name to be translated.
948 This buffer contains 16 bit characters but these are translated to ASCII for use with
949 DNSv4 server and there is no requirement for driver to support non-ASCII Unicode characters.
950 @param[in] Token Pointer to the caller-allocated completion token to return at the completion of the process to translate host name to host address.
952 @retval EFI_SUCCESS The operation completed successfully.
953 @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.
954 @retval EFI_INVALID_PARAMETER This is NULL.
958 @retval EFI_NO_MAPPING There's no source address is available for use.
959 @retval EFI_NOT_STARTED This instance has not been started.
965 IN EFI_DNS6_PROTOCOL
*This
,
967 IN EFI_DNS6_COMPLETION_TOKEN
*Token
972 DNS_INSTANCE
*Instance
;
974 EFI_DNS6_CONFIG_DATA
*ConfigData
;
981 DNS6_TOKEN_ENTRY
*TokenEntry
;
986 Status
= EFI_SUCCESS
;
992 // Validate the parameters
994 if ((This
== NULL
) || (HostName
== NULL
) || Token
== NULL
) {
995 return EFI_INVALID_PARAMETER
;
998 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1000 Instance
= DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This
);
1002 ConfigData
= &(Instance
->Dns6CfgData
);
1004 Instance
->MaxRetry
= ConfigData
->RetryCount
;
1006 Token
->Status
= EFI_NOT_READY
;
1007 Token
->RetryCount
= 0;
1008 Token
->RetryInterval
= ConfigData
->RetryInterval
;
1010 if (Instance
->State
!= DNS_STATE_CONFIGED
) {
1011 Status
= EFI_NOT_STARTED
;
1016 // Check the MaxRetry and RetryInterval values.
1018 if (Instance
->MaxRetry
== 0) {
1019 Instance
->MaxRetry
= DNS_DEFAULT_RETRY
;
1022 if (Token
->RetryInterval
< DNS_DEFAULT_TIMEOUT
) {
1023 Token
->RetryInterval
= DNS_DEFAULT_TIMEOUT
;
1029 if (ConfigData
->EnableDnsCache
) {
1031 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &mDriverData
->Dns6CacheList
) {
1032 Item
= NET_LIST_USER_STRUCT (Entry
, DNS6_CACHE
, AllCacheLink
);
1033 if (StrCmp (HostName
, Item
->DnsCache
.HostName
) == 0) {
1039 Token
->RspData
.H2AData
= AllocatePool (sizeof (DNS6_HOST_TO_ADDR_DATA
));
1040 if (Token
->RspData
.H2AData
== NULL
) {
1041 Status
= EFI_OUT_OF_RESOURCES
;
1045 Token
->RspData
.H2AData
->IpCount
= (UINT32
)Index
;
1046 Token
->RspData
.H2AData
->IpList
= AllocatePool (sizeof (EFI_IPv6_ADDRESS
) * Index
);
1047 if (Token
->RspData
.H2AData
->IpList
== NULL
) {
1048 if (Token
->RspData
.H2AData
!= NULL
) {
1049 FreePool (Token
->RspData
.H2AData
);
1052 Status
= EFI_OUT_OF_RESOURCES
;
1057 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &mDriverData
->Dns6CacheList
) {
1058 Item
= NET_LIST_USER_STRUCT (Entry
, DNS6_CACHE
, AllCacheLink
);
1059 if ((UINT32
)Index
< Token
->RspData
.H2AData
->IpCount
&& StrCmp (HostName
, Item
->DnsCache
.HostName
) == 0) {
1060 CopyMem ((Token
->RspData
.H2AData
->IpList
) + Index
, Item
->DnsCache
.IpAddress
, sizeof (EFI_IPv6_ADDRESS
));
1065 Token
->Status
= EFI_SUCCESS
;
1067 if (Token
->Event
!= NULL
) {
1068 gBS
->SignalEvent (Token
->Event
);
1072 Status
= Token
->Status
;
1078 // Construct DNS TokenEntry.
1080 TokenEntry
= AllocateZeroPool (sizeof (DNS6_TOKEN_ENTRY
));
1081 if (TokenEntry
== NULL
) {
1082 Status
= EFI_OUT_OF_RESOURCES
;
1086 TokenEntry
->PacketToLive
= Token
->RetryInterval
;
1087 TokenEntry
->QueryHostName
= HostName
;
1088 TokenEntry
->Token
= Token
;
1091 // Construct DNS Query Packet.
1093 Status
= ConstructDNSQueryIp (Instance
, TokenEntry
->QueryHostName
, DNS_TYPE_AAAA
, &Packet
);
1094 if (EFI_ERROR (Status
)) {
1095 if (TokenEntry
!= NULL
) {
1096 FreePool (TokenEntry
);
1103 // Save the token into the Dns6TxTokens map.
1105 Status
= NetMapInsertTail (&Instance
->Dns6TxTokens
, TokenEntry
, Packet
);
1106 if (EFI_ERROR (Status
)) {
1107 if (TokenEntry
!= NULL
) {
1108 FreePool (TokenEntry
);
1111 NetbufFree (Packet
);
1119 Status
= DoDnsQuery (Instance
, Packet
);
1120 if (EFI_ERROR (Status
)) {
1121 if (TokenEntry
!= NULL
) {
1122 FreePool (TokenEntry
);
1125 NetbufFree (Packet
);
1129 gBS
->RestoreTPL (OldTpl
);
1134 The function is used to translate the host address to host name.
1135 A type PTR query is used to get the primary name of the host.
1137 @param[in] This Pointer to EFI_DNS6_PROTOCOL instance.
1138 @param[in] IpAddress IP address.
1139 @param[in] Token Pointer to the caller-allocated completion used token to translate host address to host name.
1141 @retval EFI_SUCCESS The operation completed successfully.
1142 @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.
1143 @retval EFI_INVALID_PARAMETER This is NULL.
1145 Token.Event is NULL.
1146 IpAddress is not valid IP address.
1147 @retval EFI_NO_MAPPING There's no source address is available for use.
1148 @retval EFI_NOT_STARTED This instance has not been started.
1149 @retval EFI_UNSUPPORTED This function is not supported.
1155 IN EFI_DNS6_PROTOCOL
*This
,
1156 IN EFI_IPv6_ADDRESS IpAddress
,
1157 IN EFI_DNS6_COMPLETION_TOKEN
*Token
1160 return EFI_UNSUPPORTED
;
1164 This function retrieves arbitrary information from the DNS.
1165 The caller supplies a QNAME, QTYPE, and QCLASS, and all of the matching RRs are returned.
1166 All RR content (e.g., Ttl) was returned.
1167 The caller need parse the returned RR to get required information. This function is optional.
1169 @param[in] This Pointer to EFI_DNS6_PROTOCOL instance.
1170 @param[in] QName Pointer to Query Name.
1171 @param[in] QType Query Type.
1172 @param[in] QClass Query Name.
1173 @param[in] Token Point to the caller-allocated completion token to retrieve arbitrary information.
1175 @retval EFI_SUCCESS The operation completed successfully.
1176 @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.
1177 @retval EFI_INVALID_PARAMETER This is NULL.
1179 Token.Event is NULL.
1181 @retval EFI_NO_MAPPING There's no source address is available for use.
1182 @retval EFI_NOT_STARTED This instance has not been started.
1183 @retval EFI_UNSUPPORTED This function is not supported. Or the requested QType is not supported
1189 IN EFI_DNS6_PROTOCOL
*This
,
1193 IN EFI_DNS6_COMPLETION_TOKEN
*Token
1196 return EFI_UNSUPPORTED
;
1200 This function is used to add/delete/modify DNS cache entry.
1201 DNS cache can be normally dynamically updated after the DNS resolve succeeds.
1202 This function provided capability to manually add/delete/modify the DNS cache.
1204 @param[in] This Pointer to EFI_DNS6_PROTOCOL instance.
1205 @param[in] DeleteFlag If FALSE, this function is to add one entry to the DNS Cache.
1206 If TRUE, this function will delete matching DNS Cache entry.
1207 @param[in] Override If TRUE, the matching DNS cache entry will be overwritten with the supplied parameter.
1208 If FALSE, EFI_ACCESS_DENIED will be returned if the entry to be added is already exists.
1209 @param[in] DnsCacheEntry Pointer to DNS Cache entry.
1211 @retval EFI_SUCCESS The operation completed successfully.
1212 @retval EFI_INVALID_PARAMETER This is NULL.
1213 DnsCacheEntry.HostName is NULL.
1214 DnsCacheEntry.IpAddress is NULL.
1215 DnsCacheEntry.Timeout is zero.
1216 @retval EFI_ACCESS_DENIED The DNS cache entry already exists and Override is not TRUE.
1221 Dns6UpdateDnsCache (
1222 IN EFI_DNS6_PROTOCOL
*This
,
1223 IN BOOLEAN DeleteFlag
,
1224 IN BOOLEAN Override
,
1225 IN EFI_DNS6_CACHE_ENTRY DnsCacheEntry
1231 Status
= EFI_SUCCESS
;
1233 if (DnsCacheEntry
.HostName
== NULL
|| DnsCacheEntry
.IpAddress
== NULL
|| DnsCacheEntry
.Timeout
== 0) {
1234 return EFI_INVALID_PARAMETER
;
1237 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1240 // Update Dns6Cache here.
1242 Status
= UpdateDns6Cache (&mDriverData
->Dns6CacheList
, DeleteFlag
, Override
, DnsCacheEntry
);
1244 gBS
->RestoreTPL (OldTpl
);
1250 This function can be used by network drivers and applications to increase the rate that data packets are moved between
1251 the communications device and the transmit and receive queues. In some systems, the periodic timer event in the managed
1252 network driver may not poll the underlying communications device fast enough to transmit and/or receive all data packets
1253 without missing incoming packets or dropping outgoing packets.
1255 @param[in] This Pointer to EFI_DNS6_PROTOCOL instance.
1257 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1258 @retval EFI_INVALID_PARAMETER This is NULL.
1259 @retval EFI_NOT_STARTED This EFI DNS Protocol instance has not been started.
1260 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1261 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
1262 Consider increasing the polling rate.
1268 IN EFI_DNS6_PROTOCOL
*This
1271 DNS_INSTANCE
*Instance
;
1272 EFI_UDP6_PROTOCOL
*Udp
;
1275 return EFI_INVALID_PARAMETER
;
1278 Instance
= DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This
);
1280 if (Instance
->State
== DNS_STATE_UNCONFIGED
) {
1281 return EFI_NOT_STARTED
;
1282 } else if (Instance
->State
== DNS_STATE_DESTROY
) {
1283 return EFI_DEVICE_ERROR
;
1286 Udp
= Instance
->UdpIo
->Protocol
.Udp6
;
1288 return Udp
->Poll (Udp
);
1292 This function is used to abort a pending resolution request.
1293 After calling this function, Token.Status will be set to EFI_ABORTED and then Token.
1295 @param[in] This Pointer to EFI_DNS6_PROTOCOL instance.
1296 @param[in] Token Pointer to a token that has been issued by EFI_DNS6_PROTOCOL.HostNameToIp(),
1297 EFI_DNS6_PROTOCOL.IpToHostName() or EFI_DNS6_PROTOCOL.GeneralLookup().
1298 If NULL, all pending tokens are aborted.
1300 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1301 @retval EFI_INVALID_PARAMETER This is NULL.
1302 @retval EFI_NOT_STARTED This EFI DNS Protocol instance has not been started.
1303 @retval EFI_NOT_FOUND When Token is not NULL, and the asynchronous DNS operation was not found in the transmit queue.
1304 It was either completed or was not issued by HostNameToIp(), IpToHostName() or GeneralLookup().
1310 IN EFI_DNS6_PROTOCOL
*This
,
1311 IN EFI_DNS6_COMPLETION_TOKEN
*Token
1315 DNS_INSTANCE
*Instance
;
1319 return EFI_INVALID_PARAMETER
;
1322 Instance
= DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This
);
1324 if (Instance
->State
== DNS_STATE_UNCONFIGED
) {
1325 return EFI_NOT_STARTED
;
1328 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1331 // Cancle the tokens specified by Token for this instance.
1333 Status
= Dns6InstanceCancelToken (Instance
, Token
);
1336 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
1340 gBS
->RestoreTPL (OldTpl
);