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.

319 lines
13 KiB

  1. #ifndef __DEFS_H__
  2. #define __DEFS_H__
  3. #define IP_ADDRESS_LEN 4
  4. //
  5. // Since the query types map to MIB_ACTION_XXX we can just pass the action Id onto
  6. // the Locator functions
  7. //
  8. #define GET_FIRST MIB_ACTION_GETFIRST
  9. #define GET_EXACT MIB_ACTION_GET
  10. #define GET_NEXT MIB_ACTION_GETNEXT
  11. #define SetAsnInteger(dstBuf,val){ \
  12. if ((dstBuf)->asnType) \
  13. { \
  14. ASSERT((dstBuf)->asnType==ASN_INTEGER); \
  15. (dstBuf)->asnValue.number = (AsnInteger)(val); \
  16. } \
  17. }
  18. #define ForceSetAsnInteger(dstBuf,val){ \
  19. (dstBuf)->asnType = ASN_INTEGER; \
  20. (dstBuf)->asnValue.number = (AsnInteger)(val); \
  21. }
  22. #define SetAsnUnsigned32(dstBuf,val){ \
  23. if ((dstBuf)->asnType) \
  24. { \
  25. ASSERT((dstBuf)->asnType==ASN_RFC2578_UNSIGNED32); \
  26. (dstBuf)->asnValue.number = (AsnInteger)(val); \
  27. } \
  28. }
  29. #define ForceSetAsnUnsigned32(dstBuf,val){ \
  30. (dstBuf)->asnType = ASN_RFC2578_UNSIGNED32; \
  31. (dstBuf)->asnValue.number = (AsnInteger)(val); \
  32. }
  33. #define SetAsnCounter(dstBuf,val){ \
  34. if ((dstBuf)->asnType) \
  35. { \
  36. ASSERT((dstBuf)->asnType==ASN_RFC1155_COUNTER); \
  37. (dstBuf)->asnValue.counter = (AsnCounter)(val); \
  38. } \
  39. }
  40. #define SetAsnGauge(dstBuf,val){ \
  41. if ((dstBuf)->asnType) \
  42. { \
  43. ASSERT((dstBuf)->asnType==ASN_RFC1155_GAUGE); \
  44. (dstBuf)->asnValue.gauge = (AsnGauge)(val); \
  45. } \
  46. }
  47. #define SetAsnTimeTicks(dstBuf,val){ \
  48. if ((dstBuf)->asnType) \
  49. { \
  50. ASSERT((dstBuf)->asnType==ASN_RFC1155_TIMETICKS); \
  51. (dstBuf)->asnValue.ticks = (AsnTimeticks)(val); \
  52. } \
  53. }
  54. #define SetAsnOctetString(dstBuf,buffer,src,len){ \
  55. if ((dstBuf)->asnType) \
  56. { \
  57. ASSERT((dstBuf)->asnType==ASN_OCTETSTRING); \
  58. if ((dstBuf)->asnValue.string.dynamic) \
  59. { \
  60. SnmpUtilMemFree((dstBuf)->asnValue.string.stream); \
  61. } \
  62. (dstBuf)->asnValue.string.length = len; \
  63. (dstBuf)->asnValue.string.stream = (BYTE*)memcpy(buffer,src,len);\
  64. (dstBuf)->asnValue.string.dynamic = FALSE; \
  65. } \
  66. }
  67. #define ForceSetAsnOctetString(dstBuf,buffer,src,len){ \
  68. (dstBuf)->asnType = ASN_OCTETSTRING; \
  69. if ((dstBuf)->asnValue.string.dynamic) \
  70. { \
  71. SnmpUtilMemFree((dstBuf)->asnValue.string.stream); \
  72. } \
  73. (dstBuf)->asnValue.string.length = len; \
  74. (dstBuf)->asnValue.string.stream = (BYTE*)memcpy(buffer,src,len);\
  75. (dstBuf)->asnValue.string.dynamic = FALSE; \
  76. }
  77. #define SetAsnIPAddress(dstBuf,buffer,val){ \
  78. if ((dstBuf)->asnType) \
  79. { \
  80. ASSERT((dstBuf)->asnType==ASN_RFC1155_IPADDRESS); \
  81. (dstBuf)->asnValue.address.length = IP_ADDRESS_LEN; \
  82. if(!(dstBuf)->asnValue.address.stream) \
  83. { \
  84. (dstBuf)->asnValue.address.stream = (PBYTE)buffer; \
  85. (dstBuf)->asnValue.address.dynamic = FALSE; \
  86. } \
  87. (*(DWORD*)((dstBuf)->asnValue.address.stream)) = val; \
  88. } \
  89. }
  90. #define ForceSetAsnIPAddress(dstBuf,buffer,val){ \
  91. (dstBuf)->asnType = ASN_RFC1155_IPADDRESS; \
  92. (dstBuf)->asnValue.address.length = IP_ADDRESS_LEN; \
  93. if(!((dstBuf)->asnValue.address.stream)) \
  94. { \
  95. (dstBuf)->asnValue.address.stream = (PBYTE)buffer; \
  96. (dstBuf)->asnValue.address.dynamic = FALSE; \
  97. } \
  98. (*(DWORD*)((dstBuf)->asnValue.address.stream)) = val; \
  99. }
  100. #define SetAsnUshort(dstBuf,buffer,val){ \
  101. if ((dstBuf)->asnType) \
  102. { \
  103. ASSERT((dstBuf)->asnType==ASN_OCTETSTRING); \
  104. (dstBuf)->asnValue.string.length = 2; \
  105. (buffer)[0] = (BYTE)(val&0xFF); \
  106. (buffer)[1] = (BYTE)((val>>8)&0xFF); \
  107. (dstBuf)->asnValue.string.stream = (BYTE *)buffer; \
  108. (dstBuf)->asnValue.string.dynamic = FALSE; \
  109. } \
  110. }
  111. #define SetAsnDispString(dstBuf,buffer,src,len){ \
  112. if ((dstBuf)->asnType) \
  113. { \
  114. ASSERT((dstBuf)->asnType==ASN_RFC1213_DISPSTRING); \
  115. (dstBuf)->asnValue.string.length = strlen(src); \
  116. if ((dstBuf)->asnValue.string.length>len) \
  117. { \
  118. (dstBuf)->asnValue.string.length = len; \
  119. (dstBuf)->asnValue.string.stream = (BYTE *)strncpy (buffer,src,\
  120. (dstBuf)->asnValue.string.length);\
  121. (dstBuf)->asnValue.string.dynamic = FALSE; \
  122. } \
  123. } \
  124. }
  125. #define SetToZeroOid(dstBuf){ \
  126. if ((dstBuf)->asnType) \
  127. { \
  128. ASSERT((dstBuf)->asnType==ASN_OBJECTIDENTIFIER); \
  129. (dstBuf)->asnValue.object.idLength = NULL_OID_LEN; \
  130. (dstBuf)->asnValue.object.ids = \
  131. SnmpUtilMemAlloc(NULL_OID_LEN * sizeof(UINT)); \
  132. } \
  133. }
  134. #define GetAsnInteger(srcBuf,defVal) \
  135. (((srcBuf)->asnType)? ((srcBuf)->asnValue.number):(defVal))
  136. #define GetAsnCounter(srcBuf,defVal) \
  137. (((srcBuf)->asnType)? ((srcBuf)->asnValue.counter):(defVal))
  138. #define GetAsnOctetString(dst,srcBuf) \
  139. (((srcBuf)->asnType)? \
  140. (memcpy(dst,(srcBuf)->asnValue.string.stream,(srcBuf)->asnValue.string.length)) \
  141. :NULL)
  142. #define GetAsnIPAddress(srcBuf,defVal) \
  143. (DWORD)(((srcBuf)->asnType && (srcBuf)->asnValue.string.length)? \
  144. (*(DWORD*)((srcBuf)->asnValue.address.stream)) : (defVal))
  145. #define IsAsnTypeNull(asnObj) (!((asnObj)->asnType))
  146. #define IsAsnIPAddressTypeNull(asnObj) (!((asnObj)->asnType && (asnObj)->asnValue.address.length))
  147. #define IsAsnOctetStringTypeNull(asnObj) (!((asnObj)->asnType && (asnObj)->asnValue.string.length))
  148. //
  149. // When adding to this list, update the arrays in init.c.
  150. //
  151. typedef enum {
  152. MIB_II_SYS = 0,
  153. MIB_II_IF,
  154. MIB_II_IPADDR,
  155. FORWARD_MIB,
  156. MIB_II_IPNET,
  157. MIB_II_TCP,
  158. MIB_II_UDP,
  159. MIB_II_TCP6,
  160. MIB_II_UDP6_LISTENER,
  161. MIB_II_IPV6_IF,
  162. MIB_II_IPV6_NET_TO_MEDIA,
  163. MIB_II_IPV6_ROUTE,
  164. MIB_II_ICMP,
  165. NUM_CACHE
  166. } MIB_II_IDS;
  167. #define MIB_II_TRAP NUM_CACHE
  168. #define NUM_LOCKS MIB_II_TRAP + 1
  169. //
  170. // Timeouts for the caches in millisecs
  171. //
  172. #define SYSTEM_CACHE_TIMEOUT (60 * 1000)
  173. #define IF_CACHE_TIMEOUT (10 * 1000)
  174. #define IP_ADDR_CACHE_TIMEOUT (20 * 1000)
  175. #define IP_FORWARD_CACHE_TIMEOUT (20 * 1000)
  176. #define IP_NET_CACHE_TIMEOUT (30 * 1000)
  177. #define TCP_CACHE_TIMEOUT (30 * 1000)
  178. #define UDP_CACHE_TIMEOUT (30 * 1000)
  179. #define IPV6_IF_CACHE_TIMEOUT (10 * 1000)
  180. #define IPV6_NEIGHBOR_CACHE_TIMEOUT (30 * 1000)
  181. #define IPV6_ROUTE_TABLE_TIMEOUT (20 * 1000)
  182. #define ICMP_CACHE_TIMEOUT (10 * 1000)
  183. //
  184. // Cant poll faster than twice IF cache timeout
  185. //
  186. #define MIN_POLL_TIME (IF_CACHE_TIMEOUT * 2)
  187. //
  188. // Default poll interval is 15 seconds
  189. //
  190. #define DEFAULT_POLL_TIME 15000
  191. #define MAX_DIFF 20
  192. #define SPILLOVER 10
  193. #define is ==
  194. #define isnot !=
  195. #define and &&
  196. #define or ||
  197. #define INVALID_IFINDEX 0xffffffff
  198. #ifdef MIB_DEBUG
  199. #define TRACE0(Z) TracePrintf(g_hTrace,Z)
  200. #define TRACE1(Y,Z) TracePrintf(g_hTrace,Y,Z)
  201. #define TRACE2(X,Y,Z) TracePrintf(g_hTrace,X,Y,Z)
  202. #define TRACE3(W,X,Y,Z) TracePrintf(g_hTrace,W,X,Y,Z)
  203. #define TRACE4(V,W,X,Y,Z) TracePrintf(g_hTrace,V,W,X,Y,Z)
  204. #define TRACE5(U,V,W,X,Y,Z) TracePrintf(g_hTrace,U,W,X,Y,Z)
  205. #define TraceEnter(X) TracePrintf(g_hTrace,"Entering " X)
  206. #define TraceLeave(X) TracePrintf(g_hTrace,"Leaving " X "\n")
  207. #else
  208. #define TRACE0(Z)
  209. #define TRACE1(Y,Z)
  210. #define TRACE2(X,Y,Z)
  211. #define TRACE3(W,X,Y,Z)
  212. #define TRACE4(V,W,X,Y,Z)
  213. #define TRACE5(U,V,W,X,Y,Z)
  214. #define TraceEnter(X)
  215. #define TraceLeave(X)
  216. #endif
  217. extern RTL_RESOURCE g_LockTable[NUM_LOCKS];
  218. #ifdef DEADLOCK_DEBUG
  219. extern PBYTE g_pszLockNames[];
  220. #define ReleaseLock(id) { \
  221. TRACE1("Exit lock %s",g_pszLockNames[id]); \
  222. RtlReleaseResource(&(g_LockTable[(id)])); \
  223. TRACE1("Exited lock %s",g_pszLockNames[id]); \
  224. }
  225. #define EnterReader(id) { \
  226. TRACE1("Entering Reader %s",g_pszLockNames[id]); \
  227. RtlAcquireResourceShared(&(g_LockTable[(id)]),TRUE); \
  228. TRACE1("Entered %s",g_pszLockNames[id]); \
  229. }
  230. #define EnterWriter(id) { \
  231. TRACE1("Entering Writer %s",g_pszLockNames[id]); \
  232. RtlAcquireResourceExclusive(&(g_LockTable[(id)]),TRUE); \
  233. TRACE1("Entered %s",g_pszLockNames[id]); \
  234. }
  235. #else // DEADLOCK_DEBUG
  236. #define ReleaseLock(id) RtlReleaseResource(&(g_LockTable[(id)]))
  237. #define EnterReader(id) RtlAcquireResourceShared(&(g_LockTable[(id)]),TRUE)
  238. #define EnterWriter(id) RtlAcquireResourceExclusive(&(g_LockTable[(id)]),TRUE)
  239. #endif // DEADLOCK_DEBUG
  240. #define InvalidateCache(X) g_dwLastUpdateTable[(X)] = 0
  241. //
  242. // SYS UNITS is 100s of NS. 1 millisec would be 1 * 10^4 sys units
  243. //
  244. #define SYS_UNITS_IN_1_MILLISEC 10000
  245. #define MilliSecsToSysUnits(X) \
  246. RtlEnlargedIntegerMultiply((X),SYS_UNITS_IN_1_MILLISEC)
  247. #define REG_KEY_CPU \
  248. TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0")
  249. #define REG_KEY_SYSTEM \
  250. TEXT("HARDWARE\\DESCRIPTION\\System")
  251. #define REG_KEY_VERSION \
  252. TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion")
  253. #define REG_KEY_MIB2 \
  254. TEXT("System\\CurrentControlSet\\Services\\SNMP\\Parameters\\RFC1156Agent")
  255. #define REG_KEY_MIB2SUBAGENT_PARAMETERS \
  256. TEXT("Software\\Microsoft\\RFC1156Agent\\CurrentVersion\\Parameters")
  257. #define REG_VALUE_POLL L"TrapPollTimeMilliSecs"
  258. //
  259. // some constant strings
  260. //
  261. #define TEXT_SOFTWARE_WINDOWS_VERSION \
  262. TEXT("- Software: Windows Version ")
  263. #endif