DnsImpl.h 43 KB

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