Leaked source code of windows server 2003
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.

283 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name :
  4. dnsrec.h
  5. Abstract:
  6. This file contains type definitions for async DNS
  7. Author:
  8. Rohan Phillips (Rohanp) June-19-1998
  9. Revision History:
  10. --*/
  11. # ifndef _ADNS_STRUCT_HXX_
  12. # define _ADNS_STRUCT_HXX_
  13. #define TCP_REG_LIST_SIGNATURE 'TgeR'
  14. #define DNS_FLAGS_NONE 0x0
  15. #define DNS_FLAGS_TCP_ONLY 0x1
  16. #define DNS_FLAGS_UDP_ONLY 0x2
  17. #define SMTP_MAX_DNS_ENTRIES 100
  18. typedef void (WINAPI * USERDELETEFUNC) (PVOID);
  19. //-----------------------------------------------------------------------------
  20. //
  21. // Description:
  22. // Encapsulates a list of IP addresses (for DNS servers) and maintains
  23. // state information on them... whether the servers are up or down, and
  24. // provides retry logic for down servers.
  25. //
  26. // Some member functions to control the state-tracking logic and error-
  27. // logging are listed as pure virtual functions (see the bottom of this
  28. // class declaration). To use this class, derive from it and implement
  29. // those functions.
  30. //-----------------------------------------------------------------------------
  31. class CDnsServerList
  32. {
  33. protected:
  34. typedef enum _SERVER_STATE
  35. {
  36. DNS_STATE_DOWN = 0,
  37. DNS_STATE_UP,
  38. DNS_STATE_PROBATION
  39. }
  40. SERVER_STATE;
  41. DWORD m_dwSig;
  42. int m_cUpServers;
  43. PIP_ARRAY m_IpListPtr;
  44. DWORD *m_prgdwFailureTick;
  45. SERVER_STATE *m_prgServerState;
  46. DWORD *m_prgdwFailureCount;
  47. DWORD *m_prgdwConnections;
  48. CShareLockNH m_sl;
  49. public:
  50. CDnsServerList();
  51. ~CDnsServerList();
  52. BOOL Update(PIP_ARRAY IpPtr);
  53. BOOL UpdateIfChanged(PIP_ARRAY IpPtr);
  54. DWORD GetWorkingServerIp(DWORD *dwIp, BOOL fThrottle);
  55. void MarkDown(DWORD dwIp, DWORD dwErr, BOOL fUdp);
  56. void ResetTimeoutServersIfNeeded();
  57. void ResetServerOnConnect(DWORD dwIp);
  58. BOOL CopyList(PIP_ARRAY *ppipArray);
  59. DWORD GetCount()
  60. {
  61. DWORD dwCount;
  62. m_sl.ShareLock();
  63. dwCount = m_IpListPtr ? m_IpListPtr->cAddrCount : 0;
  64. m_sl.ShareUnlock();
  65. return dwCount;
  66. }
  67. DWORD GetUpServerCount()
  68. {
  69. DWORD dwCount;
  70. m_sl.ShareLock();
  71. dwCount = m_cUpServers;
  72. m_sl.ShareUnlock();
  73. return dwCount;
  74. }
  75. DWORD GetAnyServerIp(PDWORD pdwIp)
  76. {
  77. m_sl.ShareLock();
  78. if(!m_IpListPtr || 0 == m_IpListPtr->cAddrCount) {
  79. m_sl.ShareUnlock();
  80. return DNS_ERROR_NO_DNS_SERVERS;
  81. }
  82. *pdwIp = m_IpListPtr->aipAddrs[0];
  83. m_sl.ShareUnlock();
  84. return ERROR_SUCCESS;
  85. }
  86. BOOL AllowConnection(DWORD iServer)
  87. {
  88. // Note: Sharelock must have been acquired by caller
  89. if(m_prgServerState[iServer] == DNS_STATE_UP)
  90. return TRUE;
  91. if(m_prgServerState[iServer] == DNS_STATE_PROBATION &&
  92. m_prgdwConnections[iServer] < ConnectsAllowedInProbation())
  93. {
  94. m_prgdwConnections[iServer]++;
  95. return TRUE;
  96. }
  97. return FALSE;
  98. }
  99. //
  100. // Pure virtual methods to be overridden by a class to implement processing
  101. // specific to the application/component.
  102. //
  103. virtual DWORD ConnectsAllowedInProbation() = 0;
  104. virtual DWORD ErrorsBeforeFailover() = 0;
  105. virtual void LogServerDown(
  106. DWORD dwServerIp,
  107. BOOL fUdp,
  108. DWORD dwErr,
  109. DWORD cUpServers) = 0;
  110. };
  111. //-----------------------------------------------------------------------------
  112. // Description:
  113. // This class adds SMTP DNS specific error-controls and error-logging to
  114. // the generic DNS server state tracking class.
  115. //-----------------------------------------------------------------------------
  116. class CTcpRegIpList : public CDnsServerList
  117. {
  118. public:
  119. DWORD ConnectsAllowedInProbation();
  120. DWORD ErrorsBeforeFailover();
  121. void LogServerDown(
  122. DWORD dwServerIp,
  123. BOOL fUdp,
  124. DWORD dwErr,
  125. DWORD cUpServers);
  126. };
  127. typedef struct _MXIPLISTENTRY_
  128. {
  129. DWORD IpAddress;
  130. LIST_ENTRY ListEntry;
  131. }MXIPLIST_ENTRY, *PMXIPLIST_ENTRY;
  132. typedef struct _MX_NAMES_
  133. {
  134. char DnsName[MAX_INTERNET_NAME];
  135. DWORD NumEntries;
  136. LIST_ENTRY IpListHead;
  137. }MX_NAMES, *PMX_NAMES;
  138. typedef struct _SMTPDNS_REC_
  139. {
  140. DWORD NumRecords; //number of record in DnsArray
  141. DWORD StartRecord; //the starting index
  142. PVOID pMailMsgObj; //pointer to a mailmsg obj
  143. PVOID pAdvQContext;
  144. PVOID pRcptIdxList;
  145. DWORD dwNumRcpts;
  146. MX_NAMES *DnsArray[SMTP_MAX_DNS_ENTRIES];
  147. } SMTPDNS_RECS, *PSMTPDNS_RECS;
  148. class CDnsLogger
  149. {
  150. public:
  151. virtual void DnsPrintfMsg(char *szFormat, ...) = 0;
  152. virtual void DnsPrintfErr(char *szFormat, ...) = 0;
  153. virtual void DnsPrintfDbg(char *szFormat, ...) = 0;
  154. virtual void DnsLogAsyncQuery(
  155. char *pszQuestionName,
  156. WORD wQuestionType,
  157. DWORD dwSmtpFlags,
  158. BOOL fUdp,
  159. CDnsServerList *pDnsServerList) = 0;
  160. virtual void DnsLogApiQuery(
  161. char *pszQuestionName,
  162. WORD wQuestionType,
  163. DWORD dwDnsApiFlags,
  164. BOOL fGlobal,
  165. PIP_ARRAY pipServers) = 0;
  166. virtual void DnsLogResponse(
  167. DWORD dwStatus,
  168. PDNS_RECORD pDnsRecordList,
  169. PBYTE pbMsg,
  170. DWORD dwMessageLength) = 0;
  171. virtual void DnsPrintRecord(PDNS_RECORD pDnsRecord) = 0;
  172. };
  173. extern CDnsLogger *g_pDnsLogger;
  174. // The following are defined as macros since they wrap functions that
  175. // take a variable number of arguments
  176. #define DNS_PRINTF_MSG \
  177. if(g_pDnsLogger) \
  178. g_pDnsLogger->DnsPrintfMsg
  179. #define DNS_PRINTF_ERR \
  180. if(g_pDnsLogger) \
  181. g_pDnsLogger->DnsPrintfErr
  182. #define DNS_PRINTF_DBG \
  183. if(g_pDnsLogger) \
  184. g_pDnsLogger->DnsPrintfDbg
  185. inline void DNS_LOG_ASYNC_QUERY(
  186. IN DNS_NAME pszQuestionName,
  187. IN WORD wQuestionType,
  188. IN DWORD dwSmtpFlags,
  189. IN BOOL fUdp,
  190. IN CDnsServerList *pDnsServerList)
  191. {
  192. if(g_pDnsLogger)
  193. {
  194. g_pDnsLogger->DnsLogAsyncQuery(pszQuestionName,
  195. wQuestionType, dwSmtpFlags, fUdp, pDnsServerList);
  196. }
  197. }
  198. inline void DNS_LOG_API_QUERY(
  199. IN DNS_NAME pszQuestionName,
  200. IN WORD wQuestionType,
  201. IN DWORD dwDnsApiFlags,
  202. IN BOOL fGlobal,
  203. IN PIP_ARRAY pipServers)
  204. {
  205. if(g_pDnsLogger)
  206. {
  207. g_pDnsLogger->DnsLogApiQuery(pszQuestionName,
  208. wQuestionType, dwDnsApiFlags, fGlobal, pipServers);
  209. }
  210. }
  211. inline void DNS_LOG_RESPONSE(
  212. IN DWORD dwStatus,
  213. IN PDNS_RECORD pDnsRecordList,
  214. PBYTE pbMsg,
  215. DWORD dwMessageLength)
  216. {
  217. if(g_pDnsLogger)
  218. {
  219. g_pDnsLogger->DnsLogResponse(dwStatus,
  220. pDnsRecordList, pbMsg, dwMessageLength);
  221. }
  222. }
  223. inline void DNS_PRINT_RECORD(
  224. IN PDNS_RECORD pDnsRecord)
  225. {
  226. if(g_pDnsLogger)
  227. g_pDnsLogger->DnsPrintRecord(pDnsRecord);
  228. }
  229. #endif