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.

279 lines
16 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. .h
  5. Abstract:
  6. Author:
  7. Revision History:
  8. --*/
  9. #ifndef __DEFS__
  10. #define __DEFS__
  11. #define is ==
  12. #define isnot !=
  13. #define and &&
  14. #define or ||
  15. typedef unsigned long DWORD;
  16. typedef DWORD *PDWORD;
  17. typedef unsigned short WORD;
  18. typedef WORD *PWORD;
  19. typedef unsigned char BYTE;
  20. typedef BYTE *PBYTE;
  21. typedef int BOOL;
  22. typedef BOOL *PBOOL;
  23. #define IN_FILTER_SET 0
  24. #define OUT_FILTER_SET 1
  25. #define UNKNOWN_IP_INDEX MAXULONG
  26. typedef struct _MRSW_LOCK
  27. {
  28. NDIS_RW_LOCK NdisLock;
  29. }MRSW_LOCK, *PMRSW_LOCK;
  30. //
  31. // NOTE. The following structure is superimposed on top of IPAddressEntry.
  32. // See the code in GetIpStackIndex. If you add anything to this make
  33. // sure that it can still overly an IPAddressEntry. If it can't then
  34. // you've some real work on your hands.
  35. //
  36. typedef struct _AddressArray
  37. {
  38. ULONG ulAddress;
  39. ULONG ulIndex;
  40. ULONG ulSubnetBcastAddress;
  41. struct _AddressArray * pNext;
  42. struct _AddressArray * pNextSubnet;
  43. } ADDRESSARRAY, *PADDRESSARRAY;
  44. #define InitializeMRSWLock(pLock) { \
  45. NdisInitializeReadWriteLock(&((pLock)->NdisLock)); \
  46. }
  47. #define AcquireReadLock(pLock,pLockState) { \
  48. NdisAcquireReadWriteLock(&((pLock)->NdisLock),FALSE,(pLockState)); \
  49. }
  50. #define ReleaseReadLock(pLock,pLockState) { \
  51. NdisReleaseReadWriteLock(&((pLock)->NdisLock),(pLockState)); \
  52. }
  53. #define AcquireWriteLock(pLock,pLockState) { \
  54. NdisAcquireReadWriteLock(&((pLock)->NdisLock),TRUE,(pLockState)); \
  55. }
  56. #define ReleaseWriteLock(pLock,pLockState) { \
  57. NdisReleaseReadWriteLock(&((pLock)->NdisLock),(pLockState)); \
  58. }
  59. #define UnLockLogDpc(pLog) KeReleaseSpinLockFromDpcLevel(&pLog->LogLock)
  60. #define UnLockLog(pLog, kIrql) KeReleaseSpinLock(&pLog->LogLock, kIrql)
  61. #define SRC_ADDR uliSrcDstAddr.LowPart
  62. #define DEST_ADDR uliSrcDstAddr.HighPart
  63. #define SRC_MASK uliSrcDstMask.LowPart
  64. #define DEST_MASK uliSrcDstMask.HighPart
  65. #define PROTO uliProtoSrcDstPort.LowPart
  66. //
  67. // Flags passed to SetFilters
  68. //
  69. // none defined
  70. #define FREE_LIST_SIZE 16
  71. //
  72. // Nominal size of the address hash table.
  73. //
  74. #define ADDRHASHLOW 31
  75. #define ADDRHASHLOWLEVEL 16
  76. #define ADDRHASHMED 257
  77. #define ADDRHASHMEDLEVEL 130
  78. #define ADDRHASHHIGH 511
  79. #define ADDRHASHX(x) (x % AddrModulus)
  80. #define SIZEOF_FILTERS1(X) (((((X)->dwNumInFilters + (X)->dwNumOutFilters) is 0)?0:((X)->dwNumInFilters + (X)->dwNumOutFilters - 1) * sizeof(FILTER_STATS)))
  81. #define SIZEOF_FILTERS(X) (sizeof(FILTER_DRIVER_GET_FILTERS) + SIZEOF_FILTERS1(X))
  82. #ifdef DRIVER_DEBUG
  83. #define TRACE0(X) DbgPrint(X)
  84. #define TRACE1(X,Y) DbgPrint(X,(Y))
  85. #define TRACE2(X,Y,Z) DbgPrint(X,(Y),(Z))
  86. #define TRACE3(W,X,Y,Z) DbgPrint(W,(X),(Y),(Z))
  87. #define TRACE4(V,W,X,Y,Z) DbgPrint(V,(W),(X),(Y),(Z))
  88. #define TRACE5(U,V,W,X,Y,Z) DbgPrint(U,(V),(W),(X),(Y),(Z))
  89. #else
  90. #define TRACE0(X)
  91. #define TRACE1(X,Y)
  92. #define TRACE2(X,Y,Z)
  93. #define TRACE3(W,X,Y,Z)
  94. #define TRACE4(V,W,X,Y,Z)
  95. #define TRACE5(U,V,W,X,Y,Z)
  96. #endif
  97. //
  98. // protocol definitions
  99. //
  100. #define ICMP_DEST_UNREACH 3
  101. #define ICMP_REDIRECT 5
  102. #define ANYWILDFILTER(x) (x->dwFlags & \
  103. (FILTER_FLAGS_SRCWILD | FILTER_FLAGS_DSTWILD))
  104. #define MCASTSTART 224
  105. #define MCASTEND 239
  106. #define BCASTADDR 0xffffffff
  107. //
  108. // Fragments cache related constants.
  109. //
  110. #define INACTIVITY_PERIOD (2 * 60)
  111. #define TIMER_IN_MILLISECS (2 * 60 * 1000)
  112. #define SYS_UNITS_IN_ONE_MILLISEC (1000 * 10)
  113. #define MAX_FRAG_ALLOCS 2000
  114. #define MILLISECS_TO_TICKS(ms) \
  115. ((ULONGLONG)(ms) * SYS_UNITS_IN_ONE_MILLISEC / KeQueryTimeIncrement())
  116. #define SECS_TO_TICKS(s) \
  117. ((ULONGLONG)MILLISECS_TO_TICKS((s) * 1000))
  118. //
  119. // Kernel-debugger output definitions
  120. //
  121. #undef ERROR
  122. #if DBG
  123. #define TRACE(Class,Args) \
  124. if ((TRACE_CLASS_ ## Class) & (TraceClassesEnabled)) { DbgPrint Args; }
  125. #define ERROR(Args) DbgPrint Args
  126. #define CALLTRACE(Args) TRACE(CALLS, Args)
  127. #else
  128. #define TRACE(Class,Args)
  129. #define ERROR(Args)
  130. #define CALLTRACE(Args)
  131. #endif
  132. #define TRACE_CLASS_CALLS 0x00000001
  133. #define TRACE_CLASS_CONFIG 0x00000002
  134. #define TRACE_CLASS_ACTION 0x00000004
  135. #define TRACE_CLASS_CACHE 0x00000008
  136. #define TRACE_CLASS_FRAG 0x00000010
  137. #define TRACE_CLASS_LOGGER 0x00000020
  138. #define TRACE_CLASS_LOOKUP 0x00000040
  139. #define TRACE_CLASS_TIMER 0x00000080
  140. #define TRACE_CLASS_FLDES 0x00000100
  141. #define TRACE_CLASS_SPECIAL (TRACE_CLASS_CONFIG)
  142. #define TRACE_FILTER_DESCRIPTION(p) \
  143. if ((((PBYTE) &((p)->uliProtoSrcDstPort))[0] == 0x6) || (((PBYTE) &((p)->uliProtoSrcDstPort))[0] == 0x11)) { \
  144. TRACE(FLDES,(" TCP/UDP Filter <%d:%d> %d.%d.%d.%d:%d * %d.%d.%d.%d:%d -> %d.%d.%d.%d:%d * %d.%d.%d.%d:%d\n", \
  145. ((PBYTE) &((p)->uliProtoSrcDstPort))[0], \
  146. ((PBYTE) &((p)->uliProtoSrcDstMask))[0], \
  147. ((PBYTE) &((p)->uliSrcDstAddr))[0], \
  148. ((PBYTE) &((p)->uliSrcDstAddr))[1], \
  149. ((PBYTE) &((p)->uliSrcDstAddr))[2], \
  150. ((PBYTE) &((p)->uliSrcDstAddr))[3], \
  151. ((ULONG)(((PBYTE) &((p)->uliProtoSrcDstPort))[4]) << 8) + ((PBYTE) &((p)->uliProtoSrcDstPort))[5], \
  152. ((PBYTE) &(p->uliSrcDstMask))[0], \
  153. ((PBYTE) &(p->uliSrcDstMask))[1], \
  154. ((PBYTE) &(p->uliSrcDstMask))[2], \
  155. ((PBYTE) &(p->uliSrcDstMask))[3], \
  156. ((ULONG)(((PBYTE) &((p)->uliProtoSrcDstMask))[4]) << 8) + ((PBYTE) &((p)->uliProtoSrcDstMask))[5], \
  157. ((PBYTE) &((p)->uliSrcDstAddr))[4], \
  158. ((PBYTE) &((p)->uliSrcDstAddr))[5], \
  159. ((PBYTE) &((p)->uliSrcDstAddr))[6], \
  160. ((PBYTE) &((p)->uliSrcDstAddr))[7], \
  161. ((ULONG)(((PBYTE) &((p)->uliProtoSrcDstPort))[6]) << 8) + ((PBYTE) &((p)->uliProtoSrcDstPort))[7], \
  162. ((PBYTE) &((p)->uliSrcDstMask))[4], \
  163. ((PBYTE) &((p)->uliSrcDstMask))[5], \
  164. ((PBYTE) &((p)->uliSrcDstMask))[6], \
  165. ((PBYTE) &((p)->uliSrcDstMask))[7], \
  166. ((ULONG)(((PBYTE) &((p)->uliProtoSrcDstMask))[6]) << 8) + ((PBYTE) &((p)->uliProtoSrcDstMask))[7] \
  167. )); \
  168. } else if (((PBYTE) &((p)->uliProtoSrcDstPort))[0] == 0x1) { \
  169. TRACE(FLDES,(" ICMP filter <%d:%d> %d.%d.%d.%d * %d.%d.%d.%d -> %d.%d.%d.%d * %d.%d.%d.%d, Type/Code: %d/%d * %d/%d\n", \
  170. ((PBYTE) &((p)->uliProtoSrcDstPort))[0], \
  171. ((PBYTE) &((p)->uliProtoSrcDstMask))[0], \
  172. ((PBYTE) &((p)->uliSrcDstAddr))[0], \
  173. ((PBYTE) &((p)->uliSrcDstAddr))[1], \
  174. ((PBYTE) &((p)->uliSrcDstAddr))[2], \
  175. ((PBYTE) &((p)->uliSrcDstAddr))[3], \
  176. ((PBYTE) &((p)->uliSrcDstMask))[0], \
  177. ((PBYTE) &((p)->uliSrcDstMask))[1], \
  178. ((PBYTE) &((p)->uliSrcDstMask))[2], \
  179. ((PBYTE) &((p)->uliSrcDstMask))[3], \
  180. ((PBYTE) &((p)->uliSrcDstAddr))[4], \
  181. ((PBYTE) &((p)->uliSrcDstAddr))[5], \
  182. ((PBYTE) &((p)->uliSrcDstAddr))[6], \
  183. ((PBYTE) &((p)->uliSrcDstAddr))[7], \
  184. ((PBYTE) &((p)->uliSrcDstMask))[4], \
  185. ((PBYTE) &((p)->uliSrcDstMask))[5], \
  186. ((PBYTE) &((p)->uliSrcDstMask))[6], \
  187. ((PBYTE) &((p)->uliSrcDstMask))[7], \
  188. ((PBYTE) &((p)->uliProtoSrcDstPort))[4], \
  189. ((PBYTE) &((p)->uliProtoSrcDstPort))[5], \
  190. ((PBYTE) &((p)->uliProtoSrcDstMask))[4], \
  191. ((PBYTE) &((p)->uliProtoSrcDstMask))[5] \
  192. )); \
  193. } else { \
  194. TRACE(FLDES,(" filter <%d:%d> %d.%d.%d.%d * %d.%d.%d.%d -> %d.%d.%d.%d * %d.%d.%d.%d\n", \
  195. ((PBYTE) &((p)->uliProtoSrcDstPort))[0], \
  196. ((PBYTE) &((p)->uliProtoSrcDstMask))[0], \
  197. ((PBYTE) &((p)->uliSrcDstAddr))[0], \
  198. ((PBYTE) &((p)->uliSrcDstAddr))[1], \
  199. ((PBYTE) &((p)->uliSrcDstAddr))[2], \
  200. ((PBYTE) &((p)->uliSrcDstAddr))[3], \
  201. ((PBYTE) &((p)->uliSrcDstMask))[0], \
  202. ((PBYTE) &((p)->uliSrcDstMask))[1], \
  203. ((PBYTE) &((p)->uliSrcDstMask))[2], \
  204. ((PBYTE) &((p)->uliSrcDstMask))[3], \
  205. ((PBYTE) &((p)->uliSrcDstAddr))[4], \
  206. ((PBYTE) &((p)->uliSrcDstAddr))[5], \
  207. ((PBYTE) &((p)->uliSrcDstAddr))[6], \
  208. ((PBYTE) &((p)->uliSrcDstAddr))[7], \
  209. ((PBYTE) &((p)->uliSrcDstMask))[4], \
  210. ((PBYTE) &((p)->uliSrcDstMask))[5], \
  211. ((PBYTE) &((p)->uliSrcDstMask))[6], \
  212. ((PBYTE) &((p)->uliSrcDstMask))[7] \
  213. )); \
  214. }
  215. #endif