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.

288 lines
12 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 SetAsnCounter(dstBuf,val){ \
  23. if ((dstBuf)->asnType) \
  24. { \
  25. ASSERT((dstBuf)->asnType==ASN_RFC1155_COUNTER); \
  26. (dstBuf)->asnValue.counter = (AsnCounter)(val); \
  27. } \
  28. }
  29. #define SetAsnGauge(dstBuf,val){ \
  30. if ((dstBuf)->asnType) \
  31. { \
  32. ASSERT((dstBuf)->asnType==ASN_RFC1155_GAUGE); \
  33. (dstBuf)->asnValue.gauge = (AsnGauge)(val); \
  34. } \
  35. }
  36. #define SetAsnTimeTicks(dstBuf,val){ \
  37. if ((dstBuf)->asnType) \
  38. { \
  39. ASSERT((dstBuf)->asnType==ASN_RFC1155_TIMETICKS); \
  40. (dstBuf)->asnValue.ticks = (AsnTimeticks)(val); \
  41. } \
  42. }
  43. #define SetAsnOctetString(dstBuf,buffer,src,len){ \
  44. if ((dstBuf)->asnType) \
  45. { \
  46. ASSERT((dstBuf)->asnType==ASN_OCTETSTRING); \
  47. if ((dstBuf)->asnValue.string.dynamic) \
  48. { \
  49. SnmpUtilMemFree((dstBuf)->asnValue.string.stream); \
  50. } \
  51. (dstBuf)->asnValue.string.length = len; \
  52. (dstBuf)->asnValue.string.stream = (BYTE*)memcpy(buffer,src,len);\
  53. (dstBuf)->asnValue.string.dynamic = FALSE; \
  54. } \
  55. }
  56. #define ForceSetAsnOctetString(dstBuf,buffer,src,len){ \
  57. (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. #define SetAsnIPAddress(dstBuf,buffer,val){ \
  67. if ((dstBuf)->asnType) \
  68. { \
  69. ASSERT((dstBuf)->asnType==ASN_RFC1155_IPADDRESS); \
  70. (dstBuf)->asnValue.address.length = IP_ADDRESS_LEN; \
  71. if(!(dstBuf)->asnValue.address.stream) \
  72. { \
  73. (dstBuf)->asnValue.address.stream = (PBYTE)buffer; \
  74. (dstBuf)->asnValue.address.dynamic = FALSE; \
  75. } \
  76. (*(DWORD*)((dstBuf)->asnValue.address.stream)) = val; \
  77. } \
  78. }
  79. #define ForceSetAsnIPAddress(dstBuf,buffer,val){ \
  80. (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. #define SetAsnUshort(dstBuf,buffer,val){ \
  90. if ((dstBuf)->asnType) \
  91. { \
  92. ASSERT((dstBuf)->asnType==ASN_OCTETSTRING); \
  93. (dstBuf)->asnValue.string.length = 2; \
  94. (buffer)[0] = (BYTE)(val&0xFF); \
  95. (buffer)[1] = (BYTE)((val>>8)&0xFF); \
  96. (dstBuf)->asnValue.string.stream = (BYTE *)buffer; \
  97. (dstBuf)->asnValue.string.dynamic = FALSE; \
  98. } \
  99. }
  100. #define SetAsnDispString(dstBuf,buffer,src,len){ \
  101. if ((dstBuf)->asnType) \
  102. { \
  103. ASSERT((dstBuf)->asnType==ASN_RFC1213_DISPSTRING); \
  104. (dstBuf)->asnValue.string.length = strlen(src); \
  105. if ((dstBuf)->asnValue.string.length>len) \
  106. { \
  107. (dstBuf)->asnValue.string.length = len; \
  108. (dstBuf)->asnValue.string.stream = (BYTE *)strncpy (buffer,src,\
  109. (dstBuf)->asnValue.string.length);\
  110. (dstBuf)->asnValue.string.dynamic = FALSE; \
  111. } \
  112. } \
  113. }
  114. #define SetToZeroOid(dstBuf){ \
  115. if ((dstBuf)->asnType) \
  116. { \
  117. ASSERT((dstBuf)->asnType==ASN_OBJECTIDENTIFIER); \
  118. (dstBuf)->asnValue.object.idLength = NULL_OID_LEN; \
  119. (dstBuf)->asnValue.object.ids = \
  120. SnmpUtilMemAlloc(NULL_OID_LEN * sizeof(UINT)); \
  121. } \
  122. }
  123. #define GetAsnInteger(srcBuf,defVal) \
  124. (((srcBuf)->asnType)? ((srcBuf)->asnValue.number):(defVal))
  125. #define GetAsnCounter(srcBuf,defVal) \
  126. (((srcBuf)->asnType)? ((srcBuf)->asnValue.counter):(defVal))
  127. #define GetAsnOctetString(dst,srcBuf) \
  128. (((srcBuf)->asnType)? \
  129. (memcpy(dst,(srcBuf)->asnValue.string.stream,(srcBuf)->asnValue.string.length)) \
  130. :NULL)
  131. #define GetAsnIPAddress(srcBuf,defVal) \
  132. (DWORD)(((srcBuf)->asnType && (srcBuf)->asnValue.string.length)? \
  133. (*(DWORD*)((srcBuf)->asnValue.address.stream)) : (defVal))
  134. #define IsAsnTypeNull(asnObj) (!((asnObj)->asnType))
  135. #define IsAsnIPAddressTypeNull(asnObj) (!((asnObj)->asnType && (asnObj)->asnValue.address.length))
  136. #define IsAsnOctetStringTypeNull(asnObj) (!((asnObj)->asnType && (asnObj)->asnValue.string.length))
  137. #define MIB_II_SYS 0
  138. #define MIB_II_IF MIB_II_SYS + 1
  139. #define MIB_II_IPADDR MIB_II_IF + 1
  140. #define FORWARD_MIB MIB_II_IPADDR + 1
  141. #define MIB_II_IPNET FORWARD_MIB + 1
  142. #define MIB_II_TCP MIB_II_IPNET + 1
  143. #define MIB_II_UDP MIB_II_TCP + 1
  144. #define MIB_II_TCP6 MIB_II_UDP + 1
  145. #define MIB_II_UDP6_LISTENER MIB_II_TCP6 + 1
  146. #define NUM_CACHE MIB_II_UDP6_LISTENER + 1
  147. #define MIB_II_TRAP NUM_CACHE
  148. #define NUM_LOCKS MIB_II_TRAP + 1
  149. //
  150. // Timeouts for the caches in millisecs
  151. //
  152. #define SYSTEM_CACHE_TIMEOUT (60 * 1000)
  153. #define IF_CACHE_TIMEOUT (10 * 1000)
  154. #define IP_ADDR_CACHE_TIMEOUT (20 * 1000)
  155. #define IP_FORWARD_CACHE_TIMEOUT (20 * 1000)
  156. #define IP_NET_CACHE_TIMEOUT (30 * 1000)
  157. #define TCP_CACHE_TIMEOUT (30 * 1000)
  158. #define UDP_CACHE_TIMEOUT (30 * 1000)
  159. //
  160. // Cant poll faster than twice IF cache timeout
  161. //
  162. #define MIN_POLL_TIME (IF_CACHE_TIMEOUT * 2)
  163. //
  164. // Default poll interval is 15 seconds
  165. //
  166. #define DEFAULT_POLL_TIME 15000
  167. #define MAX_DIFF 20
  168. #define SPILLOVER 10
  169. #define is ==
  170. #define isnot !=
  171. #define and &&
  172. #define or ||
  173. #define INVALID_IFINDEX 0xffffffff
  174. #ifdef MIB_DEBUG
  175. #define TRACE0(Z) TracePrintf(g_hTrace,Z)
  176. #define TRACE1(Y,Z) TracePrintf(g_hTrace,Y,Z)
  177. #define TRACE2(X,Y,Z) TracePrintf(g_hTrace,X,Y,Z)
  178. #define TRACE3(W,X,Y,Z) TracePrintf(g_hTrace,W,X,Y,Z)
  179. #define TRACE4(V,W,X,Y,Z) TracePrintf(g_hTrace,V,W,X,Y,Z)
  180. #define TRACE5(U,V,W,X,Y,Z) TracePrintf(g_hTrace,U,W,X,Y,Z)
  181. #define TraceEnter(X) TracePrintf(g_hTrace,"Entering " X)
  182. #define TraceLeave(X) TracePrintf(g_hTrace,"Leaving " X "\n")
  183. #else
  184. #define TRACE0(Z)
  185. #define TRACE1(Y,Z)
  186. #define TRACE2(X,Y,Z)
  187. #define TRACE3(W,X,Y,Z)
  188. #define TRACE4(V,W,X,Y,Z)
  189. #define TRACE5(U,V,W,X,Y,Z)
  190. #define TraceEnter(X)
  191. #define TraceLeave(X)
  192. #endif
  193. extern RTL_RESOURCE g_LockTable[NUM_LOCKS];
  194. #ifdef DEADLOCK_DEBUG
  195. extern PBYTE g_pszLockNames[];
  196. #define ReleaseLock(id) { \
  197. TRACE1("Exit lock %s",g_pszLockNames[id]); \
  198. RtlReleaseResource(&(g_LockTable[(id)])); \
  199. TRACE1("Exited lock %s",g_pszLockNames[id]); \
  200. }
  201. #define EnterReader(id) { \
  202. TRACE1("Entering Reader %s",g_pszLockNames[id]); \
  203. RtlAcquireResourceShared(&(g_LockTable[(id)]),TRUE); \
  204. TRACE1("Entered %s",g_pszLockNames[id]); \
  205. }
  206. #define EnterWriter(id) { \
  207. TRACE1("Entering Writer %s",g_pszLockNames[id]); \
  208. RtlAcquireResourceExclusive(&(g_LockTable[(id)]),TRUE); \
  209. TRACE1("Entered %s",g_pszLockNames[id]); \
  210. }
  211. #else // DEADLOCK_DEBUG
  212. #define ReleaseLock(id) RtlReleaseResource(&(g_LockTable[(id)]))
  213. #define EnterReader(id) RtlAcquireResourceShared(&(g_LockTable[(id)]),TRUE)
  214. #define EnterWriter(id) RtlAcquireResourceExclusive(&(g_LockTable[(id)]),TRUE)
  215. #endif // DEADLOCK_DEBUG
  216. #define InvalidateCache(X) g_dwLastUpdateTable[(X)] = 0
  217. //
  218. // SYS UNITS is 100s of NS. 1 millisec would be 1 * 10^4 sys units
  219. //
  220. #define SYS_UNITS_IN_1_MILLISEC 10000
  221. #define MilliSecsToSysUnits(X) \
  222. RtlEnlargedIntegerMultiply((X),SYS_UNITS_IN_1_MILLISEC)
  223. #define REG_KEY_CPU \
  224. TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0")
  225. #define REG_KEY_SYSTEM \
  226. TEXT("HARDWARE\\DESCRIPTION\\System")
  227. #define REG_KEY_VERSION \
  228. TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion")
  229. #define REG_KEY_MIB2 \
  230. TEXT("System\\CurrentControlSet\\Services\\SNMP\\Parameters\\RFC1156Agent")
  231. #define REG_KEY_MIB2SUBAGENT_PARAMETERS \
  232. TEXT("Software\\Microsoft\\RFC1156Agent\\CurrentVersion\\Parameters")
  233. #define REG_VALUE_POLL L"TrapPollTimeMilliSecs"
  234. #endif