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.

431 lines
22 KiB

  1. #ifndef __DEFS_H__
  2. #define __DEFS_H__
  3. //------------------------------------------------------------------------------
  4. // Global config default values
  5. //------------------------------------------------------------------------------
  6. #define IPRIP_DEF_LOG_LEVEL d_globalLoggingLevel_none
  7. #define IPRIP_DEF_SEND_Q_SIZE 1024 * 1024
  8. #define IPRIP_DEF_RECV_Q_SIZE 1024 * 1024
  9. #define IPRIP_DEF_MIN_TRIG_UPDATE_INTR 5
  10. #define IPRIP_DEF_PEER_FILTER_MODE d_globalPeerFilterMode_disable
  11. #define IP_ADDRESS_LEN 4
  12. //------------------------------------------------------------------------------
  13. // Interface Config default values
  14. //------------------------------------------------------------------------------
  15. #define MAX_PROTOCOL_FLAG_VALUE (DWORD) 0x1ff
  16. //------------------------------------------------------------------------------
  17. // Memory allocation/deallocation macros
  18. //------------------------------------------------------------------------------
  19. #define RIP_MIB_ALLOC( x ) HeapAlloc( GetProcessHeap(), 0, (x) )
  20. #define RIP_MIB_FREE( x ) HeapFree( GetProcessHeap(), 0, (x) )
  21. //------------------------------------------------------------------------------
  22. // Macro to simplify use of DIM MIB functions
  23. //------------------------------------------------------------------------------
  24. #define CONNECT_TO_ROUTER(res) \
  25. (res) = ( g_hMIBServer ) ? NO_ERROR : ConnectToRouter()
  26. #define MIB_GET(type, w, x, y, z, res) \
  27. { \
  28. CONNECT_TO_ROUTER(res); \
  29. \
  30. if ( (res) == NO_ERROR ) \
  31. { \
  32. (res) = MprAdminMIBEntry ## type( \
  33. g_hMIBServer, \
  34. PID_IP, \
  35. MS_IP_RIP, \
  36. (LPVOID) (w), \
  37. (x), \
  38. (LPVOID *) (y), \
  39. (z) \
  40. ); \
  41. } \
  42. }
  43. #define RIP_MIB_SET(x, y, res) \
  44. { \
  45. CONNECT_TO_ROUTER(res); \
  46. \
  47. if ( (res) == NO_ERROR ) \
  48. { \
  49. (res) = MprAdminMIBEntrySet( \
  50. g_hMIBServer, \
  51. PID_IP, \
  52. MS_IP_RIP, \
  53. (LPVOID) (x), \
  54. (y) \
  55. ); \
  56. } \
  57. }
  58. #define RIP_MIB_GET(w, x, y, z, res) \
  59. { \
  60. MIB_GET(Get, w, x, y, z, res) \
  61. \
  62. if ( ( (res) == RPC_S_SERVER_UNAVAILABLE ) || \
  63. ( (res) == RPC_S_UNKNOWN_IF ) || \
  64. ( (res) == ERROR_CAN_NOT_COMPLETE ) ) \
  65. { \
  66. TraceError( (res) ); \
  67. (res) = MIB_S_ENTRY_NOT_FOUND; \
  68. } \
  69. }
  70. #define RIP_MIB_GETFIRST(w, x, y, z, res) \
  71. { \
  72. MIB_GET(GetFirst, w, x, y, z, res) \
  73. \
  74. if ( ( (res) == RPC_S_SERVER_UNAVAILABLE ) || \
  75. ( (res) == RPC_S_UNKNOWN_IF ) || \
  76. ( (res) == ERROR_CAN_NOT_COMPLETE ) ) \
  77. { \
  78. TraceError( (res) ); \
  79. (res) = MIB_S_NO_MORE_ENTRIES; \
  80. } \
  81. }
  82. #define RIP_MIB_GETNEXT(w, x, y, z, res) \
  83. { \
  84. MIB_GET(GetNext, w, x, y, z, res) \
  85. \
  86. if ( ( (res) == RPC_S_SERVER_UNAVAILABLE ) || \
  87. ( (res) == RPC_S_UNKNOWN_IF ) || \
  88. ( (res) == ERROR_CAN_NOT_COMPLETE ) ) \
  89. { \
  90. TraceError( (res) ); \
  91. (res) = MIB_S_NO_MORE_ENTRIES; \
  92. } \
  93. }
  94. //------------------------------------------------------------------------------
  95. // Macros to simplify opertions on peer address tables
  96. //------------------------------------------------------------------------------
  97. #define FIND_PEER_ENTRY(Item, Count, Table, Index) \
  98. { \
  99. DWORD __dwInd = 0; \
  100. for ( ; __dwInd < (Count); __dwInd++ ) \
  101. { \
  102. DWORD __dwTmp; \
  103. if ( !InetCmp( (Item), (Table)[ __dwInd ], __dwTmp ) ) { break; } \
  104. } \
  105. (Index) = __dwInd; \
  106. }
  107. #define DELETE_PEER_ENTRY(Index, Count, Src, Dst) \
  108. { \
  109. DWORD __dwSrc = 0, __dwDst = 0; \
  110. for ( ; __dwSrc < (Count); __dwSrc++ ) \
  111. { \
  112. if ( __dwSrc == (Index) ) { continue; } \
  113. (Dst)[ __dwDst++ ] = (Src)[ __dwSrc ]; \
  114. } \
  115. }
  116. //------------------------------------------------------------------------------
  117. // Macros to simplify opertions on IP address table
  118. //------------------------------------------------------------------------------
  119. #define FIND_IP_ADDRESS(Addr, Count, Table, Index) \
  120. { \
  121. DWORD __dwInd = 0; \
  122. for ( ; __dwInd < (Count); __dwInd++ ) \
  123. { \
  124. DWORD __dwTmp; \
  125. if ( !InetCmp( \
  126. (Addr).IA_Address, \
  127. (Table)[ __dwInd].IA_Address, \
  128. __dwTmp \
  129. ) && \
  130. !InetCmp( \
  131. (Addr).IA_Netmask, \
  132. (Table)[__dwInd].IA_Netmask, \
  133. __dwTmp \
  134. ) ) \
  135. { break; } \
  136. } \
  137. Index = __dwInd; \
  138. }
  139. //------------------------------------------------------------------------------
  140. // Macros to simplify opertions on peer statistcs tables
  141. //------------------------------------------------------------------------------
  142. #define GetPeerStatsInfo GetInterfaceInfo
  143. //------------------------------------------------------------------------------
  144. // Macros to simplify operations on filter tables
  145. //------------------------------------------------------------------------------
  146. #define RIP_MIB_ACCEPT_FILTER 1
  147. #define RIP_MIB_ANNOUNCE_FILTER 2
  148. #define FIND_FILTER(pFilt, Count, pFiltLst, Index) \
  149. { \
  150. DWORD __dwInd = 0; \
  151. for ( ; __dwInd < (Count); __dwInd++ ) \
  152. { \
  153. DWORD __dwTmp; \
  154. if ( !InetCmp( \
  155. (pFilt)-> RF_LoAddress, \
  156. (pFiltLst)[ __dwInd].RF_LoAddress, \
  157. __dwTmp \
  158. ) && \
  159. !InetCmp( \
  160. (pFilt)-> RF_HiAddress, \
  161. (pFiltLst)[__dwInd].RF_HiAddress, \
  162. __dwTmp \
  163. ) ) \
  164. { break; } \
  165. } \
  166. Index = __dwInd; \
  167. }
  168. #define DELETE_FILTER(Index, Count, Src, Dst) \
  169. DELETE_PEER_ENTRY(Index, Count, Src, Dst)
  170. //------------------------------------------------------------------------------
  171. // Macros to convert between Asn and Win32 data types
  172. //------------------------------------------------------------------------------
  173. #define SetAsnInteger(dstBuf,val){ \
  174. if ((dstBuf)->asnType) \
  175. { \
  176. ASSERT((dstBuf)->asnType==ASN_INTEGER); \
  177. (dstBuf)->asnValue.number = (AsnInteger)(val); \
  178. } \
  179. }
  180. #define ForceSetAsnInteger(dstBuf,val){ \
  181. (dstBuf)->asnType = ASN_INTEGER; \
  182. (dstBuf)->asnValue.number = (AsnInteger)(val); \
  183. }
  184. #define SetAsnCounter(dstBuf,val){ \
  185. if ((dstBuf)->asnType) \
  186. { \
  187. ASSERT((dstBuf)->asnType==ASN_RFC1155_COUNTER); \
  188. (dstBuf)->asnValue.counter = (AsnCounter)(val); \
  189. } \
  190. }
  191. #define SetAsnGauge(dstBuf,val){ \
  192. if ((dstBuf)->asnType) \
  193. { \
  194. ASSERT((dstBuf)->asnType==ASN_RFC1155_GAUGE); \
  195. (dstBuf)->asnValue.gauge = (AsnGauge)(val); \
  196. } \
  197. }
  198. #define SetAsnTimeTicks(dstBuf,val){ \
  199. if ((dstBuf)->asnType) \
  200. { \
  201. ASSERT((dstBuf)->asnType==ASN_RFC1155_TIMETICKS); \
  202. (dstBuf)->asnValue.ticks = (AsnTimeticks)(val); \
  203. } \
  204. }
  205. #define SetAsnOctetString(dstBuf,buffer,src,len){ \
  206. if ((dstBuf)->asnType) \
  207. { \
  208. ASSERT((dstBuf)->asnType==ASN_OCTETSTRING); \
  209. (dstBuf)->asnValue.string.length = len; \
  210. (dstBuf)->asnValue.string.stream = (BYTE*)memcpy(buffer,src,len);\
  211. (dstBuf)->asnValue.string.dynamic = FALSE; \
  212. } \
  213. }
  214. #define SetAsnIPAddr( dstBuf, val ) \
  215. { \
  216. if ((dstBuf)->asnType) \
  217. { \
  218. ASSERT((dstBuf)->asnType==ASN_RFC1155_IPADDRESS); \
  219. (dstBuf)->asnValue.address.length = IP_ADDRESS_LEN; \
  220. if( (dstBuf)->asnValue.address.stream) \
  221. { \
  222. (*(DWORD*)((dstBuf)->asnValue.address.stream)) = val;\
  223. } \
  224. } \
  225. }
  226. #define SetAsnIPAddress(dstBuf,buffer,val){ \
  227. if ((dstBuf)->asnType) \
  228. { \
  229. ASSERT((dstBuf)->asnType==ASN_RFC1155_IPADDRESS); \
  230. (dstBuf)->asnValue.address.length = IP_ADDRESS_LEN; \
  231. if(!(dstBuf)->asnValue.address.stream) \
  232. { \
  233. (dstBuf)->asnValue.address.stream = (PBYTE)buffer; \
  234. (dstBuf)->asnValue.address.dynamic = FALSE; \
  235. } \
  236. (*(DWORD*)((dstBuf)->asnValue.address.stream)) = val; \
  237. } \
  238. }
  239. #define ForceSetAsnIPAddress(dstBuf,buffer,val){ \
  240. (dstBuf)->asnType = ASN_RFC1155_IPADDRESS; \
  241. (dstBuf)->asnValue.address.length = IP_ADDRESS_LEN; \
  242. if(!((dstBuf)->asnValue.address.stream)) \
  243. { \
  244. (dstBuf)->asnValue.address.stream = (PBYTE)buffer; \
  245. (dstBuf)->asnValue.address.dynamic = FALSE; \
  246. } \
  247. (*(DWORD*)((dstBuf)->asnValue.address.stream)) = val; \
  248. }
  249. #define SetAsnUshort(dstBuf,buffer,val){ \
  250. if ((dstBuf)->asnType) \
  251. { \
  252. ASSERT((dstBuf)->asnType==ASN_OCTETSTRING); \
  253. (dstBuf)->asnValue.string.length = 2; \
  254. (buffer)[0] = (BYTE)(val&0xFF); \
  255. (buffer)[1] = (BYTE)((val>>8)&0xFF); \
  256. (dstBuf)->asnValue.string.stream = (BYTE *)buffer; \
  257. (dstBuf)->asnValue.string.dynamic = FALSE; \
  258. } \
  259. }
  260. #define SetAsnDispString(dstBuf,buffer,src,len){ \
  261. if ((dstBuf)->asnType) \
  262. { \
  263. ASSERT((dstBuf)->asnType==ASN_RFC1213_DISPSTRING); \
  264. (dstBuf)->asnValue.string.length = strlen(src); \
  265. if ((dstBuf)->asnValue.string.length>len) \
  266. { \
  267. (dstBuf)->asnValue.string.length = len; \
  268. (dstBuf)->asnValue.string.stream = (BYTE *)strncpy (buffer,src,\
  269. (dstBuf)->asnValue.string.length);\
  270. (dstBuf)->asnValue.string.dynamic = FALSE; \
  271. } \
  272. } \
  273. }
  274. #define SetToZeroOid(dstBuf,buffer){ \
  275. if ((dstBuf)->asnType) \
  276. { \
  277. ASSERT((dstBuf)->asnType==ASN_OBJECTIDENTIFIER); \
  278. (dstBuf)->asnValue.object.idLength = NULL_OID_LEN; \
  279. (dstBuf)->asnValue.object.ids = buffer; \
  280. (dstBuf)->asnValue.object.ids[0] = 0; \
  281. (dstBuf)->asnValue.object.ids[1] = 0; \
  282. } \
  283. }
  284. #define GetAsnInteger(srcBuf,defVal) \
  285. (((srcBuf)->asnType)? ((srcBuf)->asnValue.number):(defVal))
  286. #define GetAsnCounter(srcBuf,defVal) \
  287. (((srcBuf)->asnType)? ((srcBuf)->asnValue.counter):(defVal))
  288. #define GetAsnTimeTicks(srcBuf, defval) \
  289. ( ( (srcBuf)-> asnType ) ? (srcBuf)-> asnValue.ticks : (defval) )
  290. #define GetAsnOctetString(dst,srcBuf) \
  291. (((srcBuf)->asnType)? \
  292. (memcpy(dst,(srcBuf)->asnValue.string.stream,(srcBuf)->asnValue.string.length)) \
  293. :NULL)
  294. #define GetAsnIPAddress(srcBuf,defVal) \
  295. (DWORD)(((srcBuf)->asnType && (srcBuf)->asnValue.string.length)? \
  296. (*(DWORD*)((srcBuf)->asnValue.address.stream)) : (defVal))
  297. #define IsAsnTypeNull(asnObj) (!((asnObj)->asnType))
  298. #define IsAsnIPAddressTypeNull(asnObj) (!((asnObj)->asnType && (asnObj)->asnValue.address.length))
  299. //------------------------------------------------------------------------------
  300. // IP address / port comparison macros
  301. //------------------------------------------------------------------------------
  302. //
  303. // LONG
  304. // Cmp(DWORD dwFirst, DWORD dwSecond, LONG lResult)
  305. //
  306. #define Cmp(dwFirst,dwSecond,lResult) ((LONG)((lResult) = ((dwFirst) - (dwSecond))))
  307. //
  308. // LONG
  309. // PortCmp(DWORD wPort1, DWORD wPort2, LONG lResult)
  310. //
  311. #define PortCmp(dwPort1, dwPort2,lResult) ((LONG)((lResult) = ((ntohs((WORD)dwPort1)) - (ntohs((WORD)dwPort2)))))
  312. // The addresses are in Network order
  313. //
  314. // LONG
  315. // InetCmp(DWORD IpAddr1, DWORD IpAddr2, LONG lResult)
  316. //
  317. #define InetCmp(dwIpAddr1,dwIpAddr2,res) \
  318. ((LONG)(((res) = (((dwIpAddr1) & 0x000000ff) - ((dwIpAddr2) & 0x000000ff))) ? (res) : \
  319. (((res) = (((dwIpAddr1) & 0x0000ff00) - ((dwIpAddr2) & 0x0000ff00))) ? (res) : \
  320. (((res) = (((dwIpAddr1) & 0x00ff0000) - ((dwIpAddr2) & 0x00ff0000))) ? (res) : \
  321. (((dwIpAddr1) & 0xff000000) - ((dwIpAddr2) & 0xff000000))))))
  322. //------------------------------------------------------------------------------
  323. // Debug tracing macros
  324. //------------------------------------------------------------------------------
  325. #ifdef MIB_DEBUG
  326. #define TRACE0(Z) TracePrintf(g_dwTraceId,Z)
  327. #define TRACE1(Y,Z) TracePrintf(g_dwTraceId,Y,Z)
  328. #define TRACE2(X,Y,Z) TracePrintf(g_dwTraceId,X,Y,Z)
  329. #define TRACE3(W,X,Y,Z) TracePrintf(g_dwTraceId,W,X,Y,Z)
  330. #define TRACE4(V,W,X,Y,Z) TracePrintf(g_dwTraceId,V,W,X,Y,Z)
  331. #define TRACE5(U,V,W,X,Y,Z) TracePrintf(g_dwTraceId,U,W,X,Y,Z)
  332. #define TRACEW0(Z) TracePrintfW(g_dwTraceId,Z)
  333. #define TraceEnter(X) TracePrintf(g_dwTraceId,"Entering " X)
  334. #define TraceLeave(X) TracePrintf(g_dwTraceId,"Leaving " X "\n")
  335. #define TraceError(X) \
  336. TracePrintf( g_dwTraceId, "MprAdminMIB API returned : %d", (X) );
  337. #define TraceError1(x) \
  338. { \
  339. LPWSTR __lpwszErr = NULL; \
  340. \
  341. TRACE1( "MprAdminMIB API returned : %d", (x) ); \
  342. MprAdminGetErrorString( (x), &__lpwszErr ); \
  343. \
  344. if ( __lpwszErr ) \
  345. { \
  346. TRACEW0( __lpwszErr ); \
  347. LocalFree( __lpwszErr ); \
  348. } \
  349. }
  350. #else
  351. #define TRACE0(Z)
  352. #define TRACE1(Y,Z)
  353. #define TRACE2(X,Y,Z)
  354. #define TRACE3(W,X,Y,Z)
  355. #define TRACE4(V,W,X,Y,Z)
  356. #define TRACE5(U,V,W,X,Y,Z)
  357. #define TRACEW0(Z)
  358. #define TraceEnter(X)
  359. #define TraceLeave(X)
  360. #define TraceError(x)
  361. #endif
  362. #define EnterReader(X)
  363. #define ReleaseLock(X)
  364. #define ReaderToWriter(X)
  365. #define EnterWriter(x)
  366. #endif