• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 DnsDxe support functions implementation.
3 
4 Copyright (c) 2015 - 2016, 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
9 
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.
12 
13 **/
14 
15 #ifndef __EFI_DNS_IMPL_H_
16 #define __EFI_DNS_IMPL_H_
17 
18 #include <Uefi.h>
19 
20 //
21 // Libraries classes
22 //
23 #include <Library/BaseLib.h>
24 #include <Library/UefiLib.h>
25 #include <Library/UefiBootServicesTableLib.h>
26 #include <Library/UefiDriverEntryPoint.h>
27 #include <Library/UefiRuntimeServicesTableLib.h>
28 #include <Library/BaseMemoryLib.h>
29 #include <Library/MemoryAllocationLib.h>
30 #include <Library/NetLib.h>
31 #include <Library/DebugLib.h>
32 #include <Library/DpcLib.h>
33 #include <Library/PrintLib.h>
34 #include <Library/UdpIoLib.h>
35 
36 //
37 // UEFI Driver Model Protocols
38 //
39 #include <Protocol/DriverBinding.h>
40 #include <Protocol/ComponentName2.h>
41 #include <Protocol/ComponentName.h>
42 
43 #include <Protocol/Udp4.h>
44 #include <Protocol/Dhcp4.h>
45 #include <Protocol/Dns4.h>
46 
47 #include <Protocol/Udp6.h>
48 #include <Protocol/Dhcp6.h>
49 #include <Protocol/Dns6.h>
50 
51 #include <Protocol/Ip4Config2.h>
52 
53 #include "DnsDriver.h"
54 #include "DnsDhcp.h"
55 
56 //
57 // Driver Version
58 //
59 #define DNS_VERSION  0x00000000
60 
61 //
62 // Protocol instances
63 //
64 extern EFI_COMPONENT_NAME_PROTOCOL   gDnsComponentName;
65 extern EFI_COMPONENT_NAME2_PROTOCOL  gDnsComponentName2;
66 extern EFI_UNICODE_STRING_TABLE      *gDnsControllerNameTable;
67 
68 extern EFI_DRIVER_BINDING_PROTOCOL   gDns4DriverBinding;
69 extern EFI_SERVICE_BINDING_PROTOCOL  mDns4ServiceBinding;
70 extern EFI_DNS4_PROTOCOL             mDns4Protocol;
71 
72 extern EFI_DRIVER_BINDING_PROTOCOL   gDns6DriverBinding;
73 extern EFI_SERVICE_BINDING_PROTOCOL  mDns6ServiceBinding;
74 extern EFI_DNS6_PROTOCOL             mDns6Protocol;
75 
76 //
77 // DNS related
78 //
79 #define DNS_SERVER_PORT   53
80 
81 #define DNS_PROTOCOL_UDP   EFI_IP_PROTO_UDP
82 #define DNS_PROTOCOL_TCP   EFI_IP_PROTO_TCP
83 
84 #define DNS_STATE_UNCONFIGED     0
85 #define DNS_STATE_CONFIGED       1
86 #define DNS_STATE_DESTROY        2
87 
88 #define DNS_DEFAULT_TIMEOUT      2
89 #define DNS_DEFAULT_RETRY        3
90 
91 #define DNS_TIME_TO_GETMAP       5
92 
93 #pragma pack(1)
94 
95 typedef union _DNS_FLAGS  DNS_FLAGS;
96 
97 typedef struct {
98   LIST_ENTRY             AllCacheLink;
99   EFI_DNS4_CACHE_ENTRY   DnsCache;
100 } DNS4_CACHE;
101 
102 typedef struct {
103   LIST_ENTRY             AllCacheLink;
104   EFI_DNS6_CACHE_ENTRY   DnsCache;
105 } DNS6_CACHE;
106 
107 typedef struct {
108   LIST_ENTRY             AllServerLink;
109   EFI_IPv4_ADDRESS       Dns4ServerIp;
110 } DNS4_SERVER_IP;
111 
112 typedef struct {
113   LIST_ENTRY             AllServerLink;
114   EFI_IPv6_ADDRESS       Dns6ServerIp;
115 } DNS6_SERVER_IP;
116 
117 typedef struct {
118   UINT32                     PacketToLive;
119   CHAR16                     *QueryHostName;
120   EFI_IPv4_ADDRESS           QueryIpAddress;
121   BOOLEAN                    GeneralLookUp;
122   EFI_DNS4_COMPLETION_TOKEN  *Token;
123 } DNS4_TOKEN_ENTRY;
124 
125 typedef struct {
126   UINT32                     PacketToLive;
127   CHAR16                     *QueryHostName;
128   EFI_IPv6_ADDRESS           QueryIpAddress;
129   BOOLEAN                    GeneralLookUp;
130   EFI_DNS6_COMPLETION_TOKEN  *Token;
131 } DNS6_TOKEN_ENTRY;
132 
133 union _DNS_FLAGS{
134   struct {
135     UINT16     RCode:4;
136     UINT16     Zero:3;
137     UINT16     RA:1;
138     UINT16     RD:1;
139     UINT16     TC:1;
140     UINT16     AA:1;
141     UINT16     OpCode:4;
142     UINT16     QR:1;
143   } Bits;
144   UINT16  Uint16;
145 };
146 
147 #define DNS_FLAGS_QR_QUERY     0
148 #define DNS_FLAGS_QR_RESPONSE  1
149 
150 #define DNS_FLAGS_OPCODE_STANDARD     0
151 #define DNS_FLAGS_OPCODE_INVERSE      1
152 #define DNS_FLAGS_OPCODE_SERVER_STATE 2
153 
154 #define DNS_FLAGS_RCODE_NO_ERROR    0
155 #define DNS_FLAGS_RCODE_NAME_ERROR  3
156 
157 typedef struct {
158   UINT16      Identification;
159   DNS_FLAGS   Flags;
160   UINT16      QuestionsNum;
161   UINT16      AnswersNum;
162   UINT16      AuthorityNum;
163   UINT16      AditionalNum;
164 } DNS_HEADER;
165 
166 typedef struct {
167   UINT16      Type;
168   UINT16      Class;
169 } DNS_QUERY_SECTION;
170 
171 typedef struct {
172   UINT16      Type;
173   UINT16      Class;
174   UINT32      Ttl;
175   UINT16      DataLength;
176 } DNS_ANSWER_SECTION;
177 
178 #define DNS4_DOMAIN  L"in-addr.arpa"
179 #define DNS6_DOMAIN  L"IP6.ARPA"
180 
181 
182 #pragma pack()
183 
184 /**
185   Remove TokenEntry from TokenMap.
186 
187   @param[in] TokenMap          All DNSv4 Token entrys.
188   @param[in] TokenEntry        TokenEntry need to be removed.
189 
190   @retval EFI_SUCCESS          Remove TokenEntry from TokenMap sucessfully.
191   @retval EFI_NOT_FOUND        TokenEntry is not found in TokenMap.
192 
193 **/
194 EFI_STATUS
195 Dns4RemoveTokenEntry (
196   IN NET_MAP                    *TokenMap,
197   IN DNS4_TOKEN_ENTRY           *TokenEntry
198   );
199 
200 /**
201   Remove TokenEntry from TokenMap.
202 
203   @param[in] TokenMap           All DNSv6 Token entrys.
204   @param[in] TokenEntry         TokenEntry need to be removed.
205 
206   @retval EFI_SUCCESS           Remove TokenEntry from TokenMap sucessfully.
207   @retval EFI_NOT_FOUND         TokenEntry is not found in TokenMap.
208 
209 **/
210 EFI_STATUS
211 Dns6RemoveTokenEntry (
212   IN NET_MAP                    *TokenMap,
213   IN DNS6_TOKEN_ENTRY           *TokenEntry
214   );
215 
216 /**
217   This function cancle the token specified by Arg in the Map.
218 
219   @param[in]  Map             Pointer to the NET_MAP.
220   @param[in]  Item            Pointer to the NET_MAP_ITEM.
221   @param[in]  Arg             Pointer to the token to be cancelled. If NULL, all
222                               the tokens in this Map will be cancelled.
223                               This parameter is optional and may be NULL.
224 
225   @retval EFI_SUCCESS         The token is cancelled if Arg is NULL, or the token
226                               is not the same as that in the Item, if Arg is not
227                               NULL.
228   @retval EFI_ABORTED         Arg is not NULL, and the token specified by Arg is
229                               cancelled.
230 
231 **/
232 EFI_STATUS
233 EFIAPI
234 Dns4CancelTokens (
235   IN NET_MAP       *Map,
236   IN NET_MAP_ITEM  *Item,
237   IN VOID          *Arg OPTIONAL
238   );
239 
240 /**
241   This function cancle the token specified by Arg in the Map.
242 
243   @param[in]  Map             Pointer to the NET_MAP.
244   @param[in]  Item            Pointer to the NET_MAP_ITEM.
245   @param[in]  Arg             Pointer to the token to be cancelled. If NULL, all
246                               the tokens in this Map will be cancelled.
247                               This parameter is optional and may be NULL.
248 
249   @retval EFI_SUCCESS         The token is cancelled if Arg is NULL, or the token
250                               is not the same as that in the Item, if Arg is not
251                               NULL.
252   @retval EFI_ABORTED         Arg is not NULL, and the token specified by Arg is
253                               cancelled.
254 
255 **/
256 EFI_STATUS
257 EFIAPI
258 Dns6CancelTokens (
259   IN NET_MAP       *Map,
260   IN NET_MAP_ITEM  *Item,
261   IN VOID          *Arg OPTIONAL
262   );
263 
264 /**
265   Get the TokenEntry from the TokensMap.
266 
267   @param[in]  TokensMap           All DNSv4 Token entrys
268   @param[in]  Token               Pointer to the token to be get.
269   @param[out] TokenEntry          Pointer to TokenEntry corresponding Token.
270 
271   @retval EFI_SUCCESS             Get the TokenEntry from the TokensMap sucessfully.
272   @retval EFI_NOT_FOUND           TokenEntry is not found in TokenMap.
273 
274 **/
275 EFI_STATUS
276 EFIAPI
277 GetDns4TokenEntry (
278   IN     NET_MAP                   *TokensMap,
279   IN     EFI_DNS4_COMPLETION_TOKEN *Token,
280      OUT DNS4_TOKEN_ENTRY          **TokenEntry
281   );
282 
283 /**
284   Get the TokenEntry from the TokensMap.
285 
286   @param[in]  TokensMap           All DNSv6 Token entrys
287   @param[in]  Token               Pointer to the token to be get.
288   @param[out] TokenEntry          Pointer to TokenEntry corresponding Token.
289 
290   @retval EFI_SUCCESS             Get the TokenEntry from the TokensMap sucessfully.
291   @retval EFI_NOT_FOUND           TokenEntry is not found in TokenMap.
292 
293 **/
294 EFI_STATUS
295 EFIAPI
296 GetDns6TokenEntry (
297   IN     NET_MAP                   *TokensMap,
298   IN     EFI_DNS6_COMPLETION_TOKEN *Token,
299      OUT DNS6_TOKEN_ENTRY          **TokenEntry
300   );
301 
302 /**
303   Cancel DNS4 tokens from the DNS4 instance.
304 
305   @param[in]  Instance           Pointer to the DNS instance context data.
306   @param[in]  Token              Pointer to the token to be canceled. If NULL, all
307                                  tokens in this instance will be cancelled.
308                                  This parameter is optional and may be NULL.
309 
310   @retval EFI_SUCCESS            The Token is cancelled.
311   @retval EFI_NOT_FOUND          The Token is not found.
312 
313 **/
314 EFI_STATUS
315 Dns4InstanceCancelToken (
316   IN DNS_INSTANCE               *Instance,
317   IN EFI_DNS4_COMPLETION_TOKEN  *Token
318   );
319 
320 /**
321   Cancel DNS6 tokens from the DNS6 instance.
322 
323   @param[in]  Instance           Pointer to the DNS instance context data.
324   @param[in]  Token              Pointer to the token to be canceled. If NULL, all
325                                  tokens in this instance will be cancelled.
326                                  This parameter is optional and may be NULL.
327 
328   @retval EFI_SUCCESS            The Token is cancelled.
329   @retval EFI_NOT_FOUND          The Token is not found.
330 
331 **/
332 EFI_STATUS
333 Dns6InstanceCancelToken (
334   IN DNS_INSTANCE               *Instance,
335   IN EFI_DNS6_COMPLETION_TOKEN  *Token
336   );
337 
338 /**
339   Free the resource related to the configure parameters.
340 
341   @param  Config                 The DNS configure data
342 
343 **/
344 VOID
345 Dns4CleanConfigure (
346   IN OUT EFI_DNS4_CONFIG_DATA  *Config
347   );
348 
349 /**
350   Free the resource related to the configure parameters.
351 
352   @param  Config                 The DNS configure data
353 
354 **/
355 VOID
356 Dns6CleanConfigure (
357   IN OUT EFI_DNS6_CONFIG_DATA  *Config
358   );
359 
360 /**
361   Allocate memory for configure parameter such as timeout value for Dst,
362   then copy the configure parameter from Src to Dst.
363 
364   @param[out]  Dst               The destination DHCP configure data.
365   @param[in]   Src               The source DHCP configure data.
366 
367   @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.
368   @retval EFI_SUCCESS            The configure is copied.
369 
370 **/
371 EFI_STATUS
372 Dns4CopyConfigure (
373   OUT EFI_DNS4_CONFIG_DATA  *Dst,
374   IN  EFI_DNS4_CONFIG_DATA  *Src
375   );
376 
377 /**
378   Allocate memory for configure parameter such as timeout value for Dst,
379   then copy the configure parameter from Src to Dst.
380 
381   @param[out]  Dst               The destination DHCP configure data.
382   @param[in]   Src               The source DHCP configure data.
383 
384   @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.
385   @retval EFI_SUCCESS            The configure is copied.
386 
387 **/
388 EFI_STATUS
389 Dns6CopyConfigure (
390   OUT EFI_DNS6_CONFIG_DATA  *Dst,
391   IN  EFI_DNS6_CONFIG_DATA  *Src
392   );
393 
394 /**
395   Callback of Dns packet. Does nothing.
396 
397   @param Arg           The context.
398 
399 **/
400 VOID
401 EFIAPI
402 DnsDummyExtFree (
403   IN VOID                   *Arg
404   );
405 
406 /**
407   Poll the UDP to get the IP4 default address, which may be retrieved
408   by DHCP.
409 
410   The default time out value is 5 seconds. If IP has retrieved the default address,
411   the UDP is reconfigured.
412 
413   @param  Instance               The DNS instance
414   @param  UdpIo                  The UDP_IO to poll
415   @param  UdpCfgData             The UDP configure data to reconfigure the UDP_IO
416 
417   @retval TRUE                   The default address is retrieved and UDP is reconfigured.
418   @retval FALSE                  Some error occured.
419 
420 **/
421 BOOLEAN
422 Dns4GetMapping (
423   IN DNS_INSTANCE           *Instance,
424   IN UDP_IO                 *UdpIo,
425   IN EFI_UDP4_CONFIG_DATA   *UdpCfgData
426   );
427 
428 /**
429   Configure the opened Udp6 instance until the corresponding Ip6 instance
430   has been configured.
431 
432   @param  Instance               The DNS instance
433   @param  UdpIo                  The UDP_IO to poll
434   @param  UdpCfgData             The UDP configure data to reconfigure the UDP_IO
435 
436   @retval TRUE                   Configure the Udp6 instance successfully.
437   @retval FALSE                  Some error occured.
438 
439 **/
440 BOOLEAN
441 Dns6GetMapping (
442   IN DNS_INSTANCE           *Instance,
443   IN UDP_IO                 *UdpIo,
444   IN EFI_UDP6_CONFIG_DATA   *UdpCfgData
445   );
446 
447 /**
448   Configure the UDP.
449 
450   @param  Instance               The DNS session
451   @param  UdpIo                  The UDP_IO instance
452 
453   @retval EFI_SUCCESS            The UDP is successfully configured for the
454                                  session.
455 
456 **/
457 EFI_STATUS
458 Dns4ConfigUdp (
459   IN DNS_INSTANCE           *Instance,
460   IN UDP_IO                 *UdpIo
461   );
462 
463 /**
464   Configure the UDP.
465 
466   @param  Instance               The DNS session
467   @param  UdpIo                  The UDP_IO instance
468 
469   @retval EFI_SUCCESS            The UDP is successfully configured for the
470                                  session.
471 
472 **/
473 EFI_STATUS
474 Dns6ConfigUdp (
475   IN DNS_INSTANCE           *Instance,
476   IN UDP_IO                 *UdpIo
477   );
478 
479 /**
480   Update Dns4 cache to shared list of caches of all DNSv4 instances.
481 
482   @param  Dns4CacheList      All Dns4 cache list.
483   @param  DeleteFlag         If FALSE, this function is to add one entry to the DNS Cache.
484                              If TRUE, this function will delete matching DNS Cache entry.
485   @param  Override           If TRUE, the matching DNS cache entry will be overwritten with the supplied parameter.
486                              If FALSE, EFI_ACCESS_DENIED will be returned if the entry to be added is already exists.
487   @param  DnsCacheEntry      Entry Pointer to DNS Cache entry.
488 
489   @retval EFI_SUCCESS        Update Dns4 cache successfully.
490   @retval Others             Failed to update Dns4 cache.
491 
492 **/
493 EFI_STATUS
494 EFIAPI
495 UpdateDns4Cache (
496   IN LIST_ENTRY             *Dns4CacheList,
497   IN BOOLEAN                DeleteFlag,
498   IN BOOLEAN                Override,
499   IN EFI_DNS4_CACHE_ENTRY   DnsCacheEntry
500   );
501 
502 /**
503   Update Dns6 cache to shared list of caches of all DNSv6 instances.
504 
505   @param  Dns6CacheList      All Dns6 cache list.
506   @param  DeleteFlag         If FALSE, this function is to add one entry to the DNS Cache.
507                              If TRUE, this function will delete matching DNS Cache entry.
508   @param  Override           If TRUE, the matching DNS cache entry will be overwritten with the supplied parameter.
509                              If FALSE, EFI_ACCESS_DENIED will be returned if the entry to be added is already exists.
510   @param  DnsCacheEntry      Entry Pointer to DNS Cache entry.
511 
512   @retval EFI_SUCCESS        Update Dns6 cache successfully.
513   @retval Others             Failed to update Dns6 cache.
514 **/
515 EFI_STATUS
516 EFIAPI
517 UpdateDns6Cache (
518   IN LIST_ENTRY             *Dns6CacheList,
519   IN BOOLEAN                DeleteFlag,
520   IN BOOLEAN                Override,
521   IN EFI_DNS6_CACHE_ENTRY   DnsCacheEntry
522   );
523 
524 /**
525   Add Dns4 ServerIp to common list of addresses of all configured DNSv4 server.
526 
527   @param  Dns4ServerList    Common list of addresses of all configured DNSv4 server.
528   @param  ServerIp          DNS server Ip.
529 
530   @retval EFI_SUCCESS       Add Dns4 ServerIp to common list successfully.
531   @retval Others            Failed to add Dns4 ServerIp to common list.
532 
533 **/
534 EFI_STATUS
535 EFIAPI
536 AddDns4ServerIp (
537   IN LIST_ENTRY                *Dns4ServerList,
538   IN EFI_IPv4_ADDRESS           ServerIp
539   );
540 
541 /**
542   Add Dns6 ServerIp to common list of addresses of all configured DNSv6 server.
543 
544   @param  Dns6ServerList    Common list of addresses of all configured DNSv6 server.
545   @param  ServerIp          DNS server Ip.
546 
547   @retval EFI_SUCCESS       Add Dns6 ServerIp to common list successfully.
548   @retval Others            Failed to add Dns6 ServerIp to common list.
549 
550 **/
551 EFI_STATUS
552 EFIAPI
553 AddDns6ServerIp (
554   IN LIST_ENTRY                *Dns6ServerList,
555   IN EFI_IPv6_ADDRESS           ServerIp
556   );
557 
558 /**
559   Find out whether the response is valid or invalid.
560 
561   @param  TokensMap       All DNS transmittal Tokens entry.
562   @param  Identification  Identification for queried packet.
563   @param  Type            Type for queried packet.
564   @param  Class           Class for queried packet.
565   @param  Item            Return corresponding Token entry.
566 
567   @retval TRUE            The response is valid.
568   @retval FALSE           The response is invalid.
569 
570 **/
571 BOOLEAN
572 IsValidDnsResponse (
573   IN     NET_MAP      *TokensMap,
574   IN     UINT16       Identification,
575   IN     UINT16       Type,
576   IN     UINT16       Class,
577      OUT NET_MAP_ITEM **Item
578   );
579 
580 /**
581   Parse Dns Response.
582 
583   @param  Instance              The DNS instance
584   @param  RxString              Received buffer.
585   @param  Completed             Flag to indicate that Dns response is valid.
586 
587   @retval EFI_SUCCESS           Parse Dns Response successfully.
588   @retval Others                Failed to parse Dns Response.
589 
590 **/
591 EFI_STATUS
592 ParseDnsResponse (
593   IN OUT DNS_INSTANCE              *Instance,
594   IN     UINT8                     *RxString,
595      OUT BOOLEAN                   *Completed
596   );
597 
598 /**
599   Parse response packet.
600 
601   @param  Packet                The packets received.
602   @param  EndPoint              The local/remote UDP access point
603   @param  IoStatus              The status of the UDP receive
604   @param  Context               The opaque parameter to the function.
605 
606 **/
607 VOID
608 EFIAPI
609 DnsOnPacketReceived (
610   NET_BUF                   *Packet,
611   UDP_END_POINT             *EndPoint,
612   EFI_STATUS                IoStatus,
613   VOID                      *Context
614   );
615 
616 /**
617   Release the net buffer when packet is sent.
618 
619   @param  Packet                The packets received.
620   @param  EndPoint              The local/remote UDP access point
621   @param  IoStatus              The status of the UDP receive
622   @param  Context               The opaque parameter to the function.
623 
624 **/
625 VOID
626 EFIAPI
627 DnsOnPacketSent (
628   NET_BUF                   *Packet,
629   UDP_END_POINT             *EndPoint,
630   EFI_STATUS                IoStatus,
631   VOID                      *Context
632   );
633 
634 /**
635   Query request information.
636 
637   @param  Instance              The DNS instance
638   @param  Packet                The packet for querying request information.
639 
640   @retval EFI_SUCCESS           Query request information successfully.
641   @retval Others                Failed to query request information.
642 
643 **/
644 EFI_STATUS
645 DoDnsQuery (
646   IN  DNS_INSTANCE              *Instance,
647   IN  NET_BUF                   *Packet
648   );
649 
650 /**
651   Construct the Packet according query section.
652 
653   @param  Instance              The DNS instance
654   @param  QueryName             Queried Name
655   @param  Type                  Queried Type
656   @param  Class                 Queried Class
657   @param  Packet                The packet for query
658 
659   @retval EFI_SUCCESS           The packet is constructed.
660   @retval Others                Failed to construct the Packet.
661 
662 **/
663 EFI_STATUS
664 ConstructDNSQuery (
665   IN  DNS_INSTANCE              *Instance,
666   IN  CHAR8                     *QueryName,
667   IN  UINT16                    Type,
668   IN  UINT16                    Class,
669   OUT NET_BUF                   **Packet
670   );
671 
672 /**
673   Retransmit the packet.
674 
675   @param  Instance              The DNS instance
676   @param  Packet                Retransmit the packet
677 
678   @retval EFI_SUCCESS           The packet is retransmitted.
679   @retval Others                Failed to retransmit.
680 
681 **/
682 EFI_STATUS
683 DnsRetransmit (
684   IN DNS_INSTANCE        *Instance,
685   IN NET_BUF             *Packet
686   );
687 
688 /**
689   The timer ticking function for the DNS service.
690 
691   @param  Event                 The ticking event
692   @param  Context               The DNS service instance
693 
694 **/
695 VOID
696 EFIAPI
697 DnsOnTimerRetransmit (
698   IN EFI_EVENT              Event,
699   IN VOID                   *Context
700   );
701 
702 /**
703   The timer ticking function for the DNS driver.
704 
705   @param  Event                 The ticking event
706   @param  Context               NULL
707 
708 **/
709 VOID
710 EFIAPI
711 DnsOnTimerUpdate (
712   IN EFI_EVENT              Event,
713   IN VOID                   *Context
714   );
715 
716 
717 /**
718   Retrieve mode data of this DNS instance.
719 
720   This function is used to retrieve DNS mode data for this DNS instance.
721 
722   @param[in]   This               Pointer to EFI_DNS4_PROTOCOL instance.
723   @param[out]  DnsModeData        Point to the mode data.
724 
725   @retval EFI_SUCCESS             The operation completed successfully.
726   @retval EFI_NOT_STARTED         When DnsConfigData is queried, no configuration data
727                                   is available because this instance has not been
728                                   configured.
729   @retval EFI_INVALID_PARAMETER   This is NULL or DnsModeData is NULL.
730   @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.
731 **/
732 EFI_STATUS
733 EFIAPI
734 Dns4GetModeData (
735   IN  EFI_DNS4_PROTOCOL          *This,
736   OUT EFI_DNS4_MODE_DATA         *DnsModeData
737   );
738 
739 /**
740   Configure this DNS instance.
741 
742   This function is used to configure DNS mode data for this DNS instance.
743 
744   @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.
745   @param[in]  DnsConfigData       Point to the Configuration data.
746 
747   @retval EFI_SUCCESS             The operation completed successfully.
748   @retval EFI_UNSUPPORTED         The designated protocol is not supported.
749   @retval EFI_INVALID_PARAMTER    Thisis NULL.
750                                   The StationIp address provided in DnsConfigData is not a
751                                   valid unicast.
752                                   DnsServerList is NULL while DnsServerListCount
753                                   is not ZERO.
754                                   DnsServerListCount is ZERO while DnsServerList
755                                   is not NULL
756   @retval EFI_OUT_OF_RESOURCES    The DNS instance data or required space could not be
757                                   allocated.
758   @retval EFI_DEVICE_ERROR        An unexpected system or network error occurred. The
759                                   EFI DNSv4 Protocol instance is not configured.
760   @retval EFI_ALREADY_STARTED     Second call to Configure() with DnsConfigData. To
761                                   reconfigure the instance the caller must call Configure()
762                                   with NULL first to return driver to unconfigured state.
763 **/
764 EFI_STATUS
765 EFIAPI
766 Dns4Configure (
767   IN EFI_DNS4_PROTOCOL           *This,
768   IN EFI_DNS4_CONFIG_DATA        *DnsConfigData
769   );
770 
771 /**
772   Host name to host address translation.
773 
774   The HostNameToIp () function is used to translate the host name to host IP address. A
775   type A query is used to get the one or more IP addresses for this host.
776 
777   @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.
778   @param[in]  HostName            Host name.
779   @param[in]  Token               Point to the completion token to translate host name
780                                   to host address.
781 
782   @retval EFI_SUCCESS             The operation completed successfully.
783   @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:
784                                   This is NULL.
785                                   Token is NULL.
786                                   Token.Event is NULL.
787                                   HostName is NULL. HostName string is unsupported format.
788   @retval EFI_NO_MAPPING          There's no source address is available for use.
789   @retval EFI_NOT_STARTED         This instance has not been started.
790 **/
791 EFI_STATUS
792 EFIAPI
793 Dns4HostNameToIp (
794   IN  EFI_DNS4_PROTOCOL          *This,
795   IN  CHAR16                    *HostName,
796   IN  EFI_DNS4_COMPLETION_TOKEN  *Token
797   );
798 
799 /**
800   IPv4 address to host name translation also known as Reverse DNS lookup.
801 
802   The IpToHostName() function is used to translate the host address to host name. A type PTR
803   query is used to get the primary name of the host. Support of this function is optional.
804 
805   @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.
806   @param[in]  IpAddress           Ip Address.
807   @param[in]  Token               Point to the completion token to translate host
808                                   address to host name.
809 
810   @retval EFI_SUCCESS             The operation completed successfully.
811   @retval EFI_UNSUPPORTED         This function is not supported.
812   @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:
813                                   This is NULL.
814                                   Token is NULL.
815                                   Token.Event is NULL.
816                                   IpAddress is not valid IP address .
817   @retval EFI_NO_MAPPING          There's no source address is available for use.
818   @retval EFI_ALREADY_STARTED     This Token is being used in another DNS session.
819   @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.
820 **/
821 EFI_STATUS
822 EFIAPI
823 Dns4IpToHostName (
824   IN  EFI_DNS4_PROTOCOL             *This,
825   IN  EFI_IPv4_ADDRESS              IpAddress,
826   IN  EFI_DNS4_COMPLETION_TOKEN     *Token
827   );
828 
829 /**
830   Retrieve arbitrary information from the DNS server.
831 
832   This GeneralLookup() function retrieves arbitrary information from the DNS. The caller
833   supplies a QNAME, QTYPE, and QCLASS, and all of the matching RRs are returned. All
834   RR content (e.g., TTL) was returned. The caller need parse the returned RR to get
835   required information. The function is optional.
836 
837   @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.
838   @param[in]  QName               Pointer to Query Name.
839   @param[in]  QType               Query Type.
840   @param[in]  QClass              Query Name.
841   @param[in]  Token               Point to the completion token to retrieve arbitrary
842                                   information.
843 
844   @retval EFI_SUCCESS             The operation completed successfully.
845   @retval EFI_UNSUPPORTED         This function is not supported. Or the requested
846                                   QType is not supported
847   @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:
848                                   This is NULL.
849                                   Token is NULL.
850                                   Token.Event is NULL.
851                                   QName is NULL.
852   @retval EFI_NO_MAPPING          There's no source address is available for use.
853   @retval EFI_ALREADY_STARTED     This Token is being used in another DNS session.
854   @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.
855 **/
856 EFI_STATUS
857 EFIAPI
858 Dns4GeneralLookUp (
859   IN  EFI_DNS4_PROTOCOL                *This,
860   IN  CHAR8                            *QName,
861   IN  UINT16                           QType,
862   IN  UINT16                           QClass,
863   IN  EFI_DNS4_COMPLETION_TOKEN        *Token
864   );
865 
866 /**
867   This function is to update the DNS Cache.
868 
869   The UpdateDnsCache() function is used to add/delete/modify DNS cache entry. DNS cache
870   can be normally dynamically updated after the DNS resolve succeeds. This function
871   provided capability to manually add/delete/modify the DNS cache.
872 
873   @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.
874   @param[in]  DeleteFlag          If FALSE, this function is to add one entry to the
875                                   DNS Cahce. If TRUE, this function will delete
876                                   matching DNS Cache entry.
877   @param[in]  Override            If TRUE, the maching DNS cache entry will be
878                                   overwritten with the supplied parameter. If FALSE,
879                                   EFI_ACCESS_DENIED will be returned if the entry to
880                                   be added is already existed.
881   @param[in]  DnsCacheEntry       Pointer to DNS Cache entry.
882 
883   @retval EFI_SUCCESS             The operation completed successfully.
884   @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:
885                                   This is NULL.
886                                   DnsCacheEntry.HostName is NULL.
887                                   DnsCacheEntry.IpAddress is NULL.
888                                   DnsCacheEntry.Timeout is zero.
889   @retval EFI_ACCESS_DENIED       The DNS cache entry already exists and Override is
890                                   not TRUE.
891 **/
892 EFI_STATUS
893 EFIAPI
894 Dns4UpdateDnsCache (
895   IN EFI_DNS4_PROTOCOL      *This,
896   IN BOOLEAN               DeleteFlag,
897   IN BOOLEAN               Override,
898   IN EFI_DNS4_CACHE_ENTRY   DnsCacheEntry
899   );
900 
901 /**
902   Polls for incoming data packets and processes outgoing data packets.
903 
904   The Poll() function can be used by network drivers and applications to increase the
905   rate that data packets are moved between the communications device and the transmit
906   and receive queues.
907   In some systems, the periodic timer event in the managed network driver may not poll
908   the underlying communications device fast enough to transmit and/or receive all data
909   packets without missing incoming packets or dropping outgoing packets. Drivers and
910   applications that are experiencing packet loss should try calling the Poll()
911   function more often.
912 
913   @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.
914 
915   @retval EFI_SUCCESS             Incoming or outgoing data was processed.
916   @retval EFI_NOT_STARTED         This EFI DNS Protocol instance has not been started.
917   @retval EFI_INVALID_PARAMETER   This is NULL.
918   @retval EFI_DEVICE_ERROR        An unexpected system or network error occurred.
919   @retval EFI_TIMEOUT             Data was dropped out of the transmit and/or receive
920                                   queue. Consider increasing the polling rate.
921 **/
922 EFI_STATUS
923 EFIAPI
924 Dns4Poll (
925   IN EFI_DNS4_PROTOCOL    *This
926   );
927 
928 /**
929   Abort an asynchronous DNS operation, including translation between IP and Host, and
930   general look up behavior.
931 
932   The Cancel() function is used to abort a pending resolution request. After calling
933   this function, Token.Status will be set to EFI_ABORTED and then Token.Event will be
934   signaled. If the token is not in one of the queues, which usually means that the
935   asynchronous operation has completed, this function will not signal the token and
936   EFI_NOT_FOUND is returned.
937 
938   @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.
939   @param[in]  Token               Pointer to a token that has been issued by
940                                   EFI_DNS4_PROTOCOL.HostNameToIp (),
941                                   EFI_DNS4_PROTOCOL.IpToHostName() or
942                                   EFI_DNS4_PROTOCOL.GeneralLookup().
943                                   If NULL, all pending tokens are aborted.
944 
945   @retval EFI_SUCCESS             Incoming or outgoing data was processed.
946   @retval EFI_NOT_STARTED         This EFI DNS4 Protocol instance has not been started.
947   @retval EFI_INVALID_PARAMETER   This is NULL.
948   @retval EFI_NOT_FOUND           When Token is not NULL, and the asynchronous DNS
949                                   operation was not found in the transmit queue. It
950                                   was either completed or was not issued by
951                                   HostNameToIp(), IpToHostName() or GeneralLookup().
952 **/
953 EFI_STATUS
954 EFIAPI
955 Dns4Cancel (
956   IN  EFI_DNS4_PROTOCOL          *This,
957   IN  EFI_DNS4_COMPLETION_TOKEN  *Token
958   );
959 
960 
961 /**
962   Retrieve mode data of this DNS instance.
963 
964   This function is used to retrieve DNS mode data for this DNS instance.
965 
966   @param[in]   This                Pointer to EFI_DNS6_PROTOCOL instance.
967   @param[out]  DnsModeData         Pointer to the caller-allocated storage for the
968                                    EFI_DNS6_MODE_DATA data.
969 
970   @retval EFI_SUCCESS             The operation completed successfully.
971   @retval EFI_NOT_STARTED         When DnsConfigData is queried, no configuration data
972                                   is available because this instance has not been
973                                   configured.
974   @retval EFI_INVALID_PARAMETER   This is NULL or DnsModeData is NULL.
975   @retval EFI_OUT_OF_RESOURCE     Failed to allocate needed resources.
976 **/
977 EFI_STATUS
978 EFIAPI
979 Dns6GetModeData (
980   IN  EFI_DNS6_PROTOCOL          *This,
981   OUT EFI_DNS6_MODE_DATA         *DnsModeData
982   );
983 
984 /**
985   Configure this DNS instance.
986 
987   The Configure() function is used to set and change the configuration data for this
988   EFI DNSv6 Protocol driver instance. Reset the DNS instance if DnsConfigData is NULL.
989 
990   @param[in]  This                Pointer to EFI_DNS6_PROTOCOL instance.
991   @param[in]  DnsConfigData       Pointer to the configuration data structure. All associated
992                                   storage to be allocated and released by caller.
993 
994   @retval EFI_SUCCESS             The operation completed successfully.
995   @retval EFI_INVALID_PARAMTER    This is NULL.
996                                   The StationIp address provided in DnsConfigData is not zero and not a valid unicast.
997                                   DnsServerList is NULL while DnsServerList Count is not ZERO.
998                                   DnsServerList Count is ZERO while DnsServerList is not NULL.
999   @retval EFI_OUT_OF_RESOURCES    The DNS instance data or required space could not be allocated.
1000   @retval EFI_DEVICE_ERROR        An unexpected system or network error occurred. The
1001                                   EFI DNSv6 Protocol instance is not configured.
1002   @retval EFI_UNSUPPORTED         The designated protocol is not supported.
1003   @retval EFI_ALREADY_STARTED     Second call to Configure() with DnsConfigData. To
1004                                   reconfigure the instance the caller must call Configure() with
1005                                   NULL first to return driver to unconfigured state.
1006 **/
1007 EFI_STATUS
1008 EFIAPI
1009 Dns6Configure (
1010   IN EFI_DNS6_PROTOCOL           *This,
1011   IN EFI_DNS6_CONFIG_DATA        *DnsConfigData
1012   );
1013 
1014 /**
1015   Host name to host address translation.
1016 
1017   The HostNameToIp () function is used to translate the host name to host IP address. A
1018   type AAAA query is used to get the one or more IPv6 addresses for this host.
1019 
1020   @param[in]  This                Pointer to EFI_DNS6_PROTOCOL instance.
1021   @param[in]  HostName            Host name.
1022   @param[in]  Token               Point to the completion token to translate host name
1023                                   to host address.
1024 
1025   @retval EFI_SUCCESS             The operation completed successfully.
1026   @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:
1027                                   This is NULL.
1028                                   Token is NULL.
1029                                   Token.Event is NULL.
1030                                   HostName is NULL or buffer contained unsupported characters.
1031   @retval EFI_NO_MAPPING          There's no source address is available for use.
1032   @retval EFI_ALREADY_STARTED     This Token is being used in another DNS session.
1033   @retval EFI_NOT_STARTED         This instance has not been started.
1034   @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.
1035 **/
1036 EFI_STATUS
1037 EFIAPI
1038 Dns6HostNameToIp (
1039   IN  EFI_DNS6_PROTOCOL          *This,
1040   IN  CHAR16                     *HostName,
1041   IN  EFI_DNS6_COMPLETION_TOKEN  *Token
1042   );
1043 
1044 /**
1045   Host address to host name translation.
1046 
1047   The IpToHostName () function is used to translate the host address to host name. A
1048   type PTR query is used to get the primary name of the host. Implementation can choose
1049   to support this function or not.
1050 
1051   @param[in]  This                Pointer to EFI_DNS6_PROTOCOL instance.
1052   @param[in]  IpAddress           Ip Address.
1053   @param[in]  Token               Point to the completion token to translate host
1054                                   address to host name.
1055 
1056   @retval EFI_SUCCESS             The operation completed successfully.
1057   @retval EFI_UNSUPPORTED         This function is not supported.
1058   @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:
1059                                   This is NULL.
1060                                   Token is NULL.
1061                                   Token.Event is NULL.
1062                                   IpAddress is not valid IP address.
1063   @retval EFI_NO_MAPPING          There's no source address is available for use.
1064   @retval EFI_NOT_STARTED         This instance has not been started.
1065   @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.
1066 **/
1067 EFI_STATUS
1068 EFIAPI
1069 Dns6IpToHostName (
1070   IN  EFI_DNS6_PROTOCOL             *This,
1071   IN  EFI_IPv6_ADDRESS              IpAddress,
1072   IN  EFI_DNS6_COMPLETION_TOKEN     *Token
1073   );
1074 
1075 /**
1076   This function provides capability to retrieve arbitrary information from the DNS
1077   server.
1078 
1079   This GeneralLookup() function retrieves arbitrary information from the DNS. The caller
1080   supplies a QNAME, QTYPE, and QCLASS, and all of the matching RRs are returned. All
1081   RR content (e.g., TTL) was returned. The caller need parse the returned RR to get
1082   required information. The function is optional. Implementation can choose to support
1083   it or not.
1084 
1085   @param[in]  This                Pointer to EFI_DNS6_PROTOCOL instance.
1086   @param[in]  QName               Pointer to Query Name.
1087   @param[in]  QType               Query Type.
1088   @param[in]  QClass              Query Name.
1089   @param[in]  Token               Point to the completion token to retrieve arbitrary
1090                                   information.
1091 
1092   @retval EFI_SUCCESS             The operation completed successfully.
1093   @retval EFI_UNSUPPORTED         This function is not supported. Or the requested
1094                                   QType is not supported
1095   @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:
1096                                   This is NULL.
1097                                   Token is NULL.
1098                                   Token.Event is NULL.
1099                                   QName is NULL.
1100   @retval EFI_NO_MAPPING          There's no source address is available for use.
1101   @retval EFI_NOT_STARTED         This instance has not been started.
1102   @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.
1103 **/
1104 EFI_STATUS
1105 EFIAPI
1106 Dns6GeneralLookUp (
1107   IN  EFI_DNS6_PROTOCOL                *This,
1108   IN  CHAR8                            *QName,
1109   IN  UINT16                           QType,
1110   IN  UINT16                           QClass,
1111   IN  EFI_DNS6_COMPLETION_TOKEN        *Token
1112   );
1113 
1114 /**
1115   This function is to update the DNS Cache.
1116 
1117   The UpdateDnsCache() function is used to add/delete/modify DNS cache entry. DNS cache
1118   can be normally dynamically updated after the DNS resolve succeeds. This function
1119   provided capability to manually add/delete/modify the DNS cache.
1120 
1121   @param[in]  This                Pointer to EFI_DNS6_PROTOCOL instance.
1122   @param[in]  DeleteFlag          If FALSE, this function is to add one entry to the
1123                                   DNS Cahce. If TRUE, this function will delete
1124                                   matching DNS Cache entry.
1125   @param[in]  Override            If TRUE, the maching DNS cache entry will be
1126                                   overwritten with the supplied parameter. If FALSE,
1127                                   EFI_ACCESS_DENIED will be returned if the entry to
1128                                   be added is already existed.
1129   @param[in]  DnsCacheEntry       Pointer to DNS Cache entry.
1130 
1131   @retval EFI_SUCCESS             The operation completed successfully.
1132   @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:
1133                                   This is NULL.
1134                                   DnsCacheEntry.HostName is NULL.
1135                                   DnsCacheEntry.IpAddress is NULL.
1136                                   DnsCacheEntry.Timeout is zero.
1137   @retval EFI_ACCESS_DENIED       The DNS cache entry already exists and Override is
1138                                   not TRUE.
1139   @retval EFI_OUT_OF_RESOURCE     Failed to allocate needed resources.
1140 **/
1141 EFI_STATUS
1142 EFIAPI
1143 Dns6UpdateDnsCache (
1144   IN EFI_DNS6_PROTOCOL      *This,
1145   IN BOOLEAN               DeleteFlag,
1146   IN BOOLEAN               Override,
1147   IN EFI_DNS6_CACHE_ENTRY   DnsCacheEntry
1148   );
1149 
1150 /**
1151   Polls for incoming data packets and processes outgoing data packets.
1152 
1153   The Poll() function can be used by network drivers and applications to increase the
1154   rate that data packets are moved between the communications device and the transmit
1155   and receive queues.
1156 
1157   In some systems, the periodic timer event in the managed network driver may not poll
1158   the underlying communications device fast enough to transmit and/or receive all data
1159   packets without missing incoming packets or dropping outgoing packets. Drivers and
1160   applications that are experiencing packet loss should try calling the Poll()
1161   function more often.
1162 
1163   @param[in]  This                Pointer to EFI_DNS6_PROTOCOL instance.
1164 
1165   @retval EFI_SUCCESS             Incoming or outgoing data was processed.
1166   @retval EFI_NOT_STARTED         This EFI DNS Protocol instance has not been started.
1167   @retval EFI_INVALID_PARAMETER   This is NULL.
1168   @retval EFI_NO_MAPPING          There is no source address is available for use.
1169   @retval EFI_DEVICE_ERROR        An unexpected system or network error occurred.
1170   @retval EFI_TIMEOUT             Data was dropped out of the transmit and/or receive
1171                                   queue. Consider increasing the polling rate.
1172 **/
1173 EFI_STATUS
1174 EFIAPI
1175 Dns6Poll (
1176   IN EFI_DNS6_PROTOCOL    *This
1177   );
1178 
1179 /**
1180   Abort an asynchronous DNS operation, including translation between IP and Host, and
1181   general look up behavior.
1182 
1183   The Cancel() function is used to abort a pending resolution request. After calling
1184   this function, Token.Status will be set to EFI_ABORTED and then Token.Event will be
1185   signaled. If the token is not in one of the queues, which usually means that the
1186   asynchronous operation has completed, this function will not signal the token and
1187   EFI_NOT_FOUND is returned.
1188 
1189   @param[in]  This                Pointer to EFI_DNS6_PROTOCOL instance.
1190   @param[in]  Token               Pointer to a token that has been issued by
1191                                   EFI_DNS6_PROTOCOL.HostNameToIp (),
1192                                   EFI_DNS6_PROTOCOL.IpToHostName() or
1193                                   EFI_DNS6_PROTOCOL.GeneralLookup().
1194                                   If NULL, all pending tokens are aborted.
1195 
1196   @retval EFI_SUCCESS             Incoming or outgoing data was processed.
1197   @retval EFI_NOT_STARTED         This EFI DNS6 Protocol instance has not been started.
1198   @retval EFI_INVALID_PARAMETER   This is NULL.
1199   @retval EFI_NO_MAPPING          There's no source address is available for use.
1200   @retval EFI_NOT_FOUND           When Token is not NULL, and the asynchronous DNS
1201                                   operation was not found in the transmit queue. It
1202                                   was either completed or was not issued by
1203                                   HostNameToIp(), IpToHostName() or GeneralLookup().
1204 **/
1205 EFI_STATUS
1206 EFIAPI
1207 Dns6Cancel (
1208   IN  EFI_DNS6_PROTOCOL          *This,
1209   IN  EFI_DNS6_COMPLETION_TOKEN  *Token
1210   );
1211 
1212 #endif
1213