Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1997-2000 Microsoft Corporation
  3. Module Name:
  4. message.h
  5. Abstract:
  6. Domain Name System (DNS) Library
  7. DNS message and associated info buffer
  8. Author:
  9. Jim Gilroy (jamesg) January 1997
  10. Revision History:
  11. --*/
  12. #ifndef _DNS_MESSAGE_INCLUDED_
  13. #define _DNS_MESSAGE_INCLUDED_
  14. #ifndef DNSSRV
  15. //
  16. // Define size of allocations, beyond message buffer itself
  17. //
  18. // - size of message info struct, outside of header
  19. //
  20. // Note: the lookname buffer is placed AFTER the message buffer.
  21. //
  22. // This allows us to avoid STRICT overwrite checking for small
  23. // items writing RR to buffer:
  24. // - compressed name
  25. // - RR (or Question) struct
  26. // - IP address (MX preference, SOA fixed fields)
  27. //
  28. // After RR write, we check whether we are over the end of the buffer
  29. // and if so, we send and do not use lookup name info again anyway.
  30. // Cool.
  31. //
  32. #define DNS_MESSAGE_INCLUDED_HEADER_LENGTH \
  33. ( sizeof(DNS_MSG_BUF) \
  34. - sizeof(DNS_HEADER) \
  35. - 1 )
  36. //
  37. // UDP allocation
  38. //
  39. #define DNS_UDP_ALLOC_LENGTH \
  40. ( DNS_MESSAGE_INCLUDED_HEADER_LENGTH + DNS_UDP_MAX_PACKET_LENGTH )
  41. //
  42. // DNS TCP allocation.
  43. //
  44. // Key point, is this is used almost entirely for zone transfer.
  45. //
  46. // - 16K is maximum compression offset (14bits) so a
  47. // good default size for sending AXFR packets
  48. //
  49. // - realloc to get 64K message maximum.
  50. //
  51. // Note: Critical that packet lengths are DWORD aligned, as
  52. // lookname buffer follows message at packet length.
  53. //
  54. #define DNS_TCP_DEFAULT_PACKET_LENGTH (0x4000)
  55. #define DNS_TCP_DEFAULT_ALLOC_LENGTH (0x4000 + \
  56. DNS_MESSAGE_INCLUDED_HEADER_LENGTH)
  57. #define DNS_TCP_REALLOC_PACKET_LENGTH (0xfffc)
  58. #define DNS_TCP_REALLOC_LENGTH (0xfffc + \
  59. DNS_MESSAGE_INCLUDED_HEADER_LENGTH)
  60. //
  61. // Set fields for new query
  62. //
  63. // Always clear suballocation ptr fields that are deallocated
  64. // by query free:
  65. // - pRecurse
  66. //
  67. // Always default to deleting on send -- fDelete set TRUE.
  68. //
  69. // For debugging purposes dwQueuingTime serves as flag to
  70. // indicate ON or OFF a packet queue.
  71. //
  72. // Lookup name buffer follows message buffer. See note above
  73. // for explanation of this.
  74. //
  75. #define SET_MESSAGE_FOR_UDP_RECV( pMsg ) \
  76. { \
  77. (pMsg)->fTcp = FALSE; \
  78. (pMsg)->fSwapped = FALSE; \
  79. (pMsg)->Timeout = 0; \
  80. }
  81. #define SET_MESSAGE_FOR_TCP_RECV( pMsg ) \
  82. { \
  83. (pMsg)->fTcp = TRUE; \
  84. (pMsg)->fSwapped = FALSE; \
  85. (pMsg)->Timeout = 0; \
  86. (pMsg)->fMessageComplete = FALSE; \
  87. (pMsg)->MessageLength = 0; \
  88. (pMsg)->pchRecv = NULL; \
  89. }
  90. //
  91. // RR count writing
  92. //
  93. #define CURRENT_RR_COUNT_FIELD( pMsg ) \
  94. (*(pMsg)->pCurrentCountField)
  95. #define SET_CURRENT_RR_COUNT_SECTION( pMsg, section ) \
  96. (pMsg)->pCurrentCountField = \
  97. &(pMsg)->MessageHead.QuestionCount + (section);
  98. #define SET_TO_WRITE_QUESTION_RECORDS(pMsg) \
  99. (pMsg)->pCurrentCountField = &(pMsg)->MessageHead.QuestionCount;
  100. #define SET_TO_WRITE_ANSWER_RECORDS(pMsg) \
  101. (pMsg)->pCurrentCountField = &(pMsg)->MessageHead.AnswerCount;
  102. #define SET_TO_WRITE_NAME_SERVER_RECORDS(pMsg) \
  103. (pMsg)->pCurrentCountField = &(pMsg)->MessageHead.NameServerCount;
  104. #define SET_TO_WRITE_AUTHORITY_RECORDS(pMsg) \
  105. SET_TO_WRITE_NAME_SERVER_RECORDS(pMsg)
  106. #define SET_TO_WRITE_ADDITIONAL_RECORDS(pMsg) \
  107. (pMsg)->pCurrentCountField = &(pMsg)->MessageHead.AdditionalCount;
  108. #define IS_SET_TO_WRITE_ANSWER_RECORDS(pMsg) \
  109. ((pMsg)->pCurrentCountField == &(pMsg)->MessageHead.AnswerCount)
  110. #define IS_SET_TO_WRITE_AUTHORITY_RECORDS(pMsg) \
  111. ((pMsg)->pCurrentCountField == &(pMsg)->MessageHead.NameServerCount)
  112. #define IS_SET_TO_WRITE_ADDITIONAL_RECORDS(pMsg) \
  113. ((pMsg)->pCurrentCountField == &(pMsg)->MessageHead.AdditionalCount)
  114. #endif // no DNSSRV
  115. //
  116. // DNS Query info blob
  117. //
  118. typedef struct _QueryInfo
  119. {
  120. PSTR pName;
  121. WORD wType;
  122. WORD wRcode;
  123. DWORD Flags;
  124. DNS_STATUS Status;
  125. DWORD MessageLength;
  126. PBYTE pMessage;
  127. PDNS_RECORD pRecordsAnswer;
  128. PDNS_RECORD pRecordsAuthority;
  129. PDNS_RECORD pRecordsAdditional;
  130. PIP_ARRAY pDnsServerArray;
  131. // private
  132. PDNS_MSG_BUF pMsgSend;
  133. PDNS_MSG_BUF pMsgRecv;
  134. PDNS_NETINFO pNetworkInfo;
  135. PVOID pfnGetIpAddressInfo;
  136. SOCKET Socket;
  137. DWORD ReturnFlags;
  138. // maybe fold into Status
  139. DNS_STATUS NetFailureStatus;
  140. // maybe fold into ReturnFlags
  141. BOOL CacheNegativeResponse;
  142. }
  143. QUERY_INFO; *PQUERY_INFO;
  144. #endif // _DNS_MESSAGE_INCLUDED_