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.

355 lines
15 KiB

  1. #ifndef _IGMPAGNT_DEFS_H_
  2. #define _IGMPAGNT_DEFS_H_
  3. //------------------------------------------------------------------------------
  4. // Global config default values
  5. //------------------------------------------------------------------------------
  6. #define IGMP_DEF_LOGGING_LEVEL IGMP_LOGGING_ERROR
  7. #define IGMP_DEF_RAS_CLIENT_STATS FALSE
  8. #define IP_ADDRESS_LEN 4
  9. //------------------------------------------------------------------------------
  10. // Interface config default values
  11. //------------------------------------------------------------------------------
  12. //------------------------------------------------------------------------------
  13. // Memory allocation/deallocation macros
  14. //------------------------------------------------------------------------------
  15. #define IGMP_MIB_ALLOC(size) HeapAlloc(GetProcessHeap(), 0, (size))
  16. #define IGMP_MIB_FREE(ptr) HeapFree(GetProcessHeap(), 0, (ptr))
  17. //------------------------------------------------------------------------------
  18. // Macros to simplify use of DIM MIB functions
  19. //------------------------------------------------------------------------------
  20. #define CONNECT_TO_ROUTER(retval) \
  21. retval = (g_hMibServer) ? NO_ERROR : ConnectToRouter()
  22. #define MIB_GET(type, pQuery, szQuery, ppResponse, pdwOutSize, dwErr) {\
  23. CONNECT_TO_ROUTER(dwErr); \
  24. \
  25. if ((dwErr) == NO_ERROR) { \
  26. (dwErr) = MprAdminMIBEntry ## type( \
  27. g_hMibServer, \
  28. PID_IP, \
  29. MS_IP_IGMP, \
  30. (LPVOID) (pQuery), \
  31. (szQuery), \
  32. (LPVOID *) (ppResponse), \
  33. (pdwOutSize) \
  34. ); \
  35. } \
  36. }
  37. #define IGMP_MIB_SET(x, y, retval) { \
  38. CONNECT_TO_ROUTER(retval); \
  39. \
  40. if ((retval)==NO_ERROR) { \
  41. (retval) = MprAdminMIBEntrySet ( \
  42. g_hMibServer, \
  43. PID_IP, \
  44. MS_IP_IGMP, \
  45. (LPVOID)(x), \
  46. (y) \
  47. ); \
  48. } \
  49. }
  50. #define IGMP_MIB_GET(pQuery, szQuery, ppResponse, pdwOutSize, dwErr) \
  51. { \
  52. MIB_GET(Get, pQuery, szQuery, ppResponse, pdwOutSize, dwErr) \
  53. \
  54. if ( ( (dwErr) == RPC_S_SERVER_UNAVAILABLE ) || \
  55. ( (dwErr) == RPC_S_UNKNOWN_IF ) || \
  56. ( (dwErr) == ERROR_CAN_NOT_COMPLETE ) ) \
  57. { \
  58. TraceError( (dwErr) ); \
  59. (dwErr) = MIB_S_NO_MORE_ENTRIES; \
  60. } \
  61. }
  62. #define IGMP_MIB_GETFIRST(pQuery, szQuery, ppResponse, pdwOutSize, dwErr)\
  63. { \
  64. MIB_GET(GetFirst, pQuery, szQuery, ppResponse, pdwOutSize, dwErr) \
  65. \
  66. if ( ( (dwErr) == RPC_S_SERVER_UNAVAILABLE ) || \
  67. ( (dwErr) == RPC_S_UNKNOWN_IF ) || \
  68. ( (dwErr) == ERROR_CAN_NOT_COMPLETE ) ) \
  69. { \
  70. TraceError( (dwErr) ); \
  71. (dwErr) = MIB_S_NO_MORE_ENTRIES; \
  72. } \
  73. }
  74. #define IGMP_MIB_GETNEXT(pQuery, szQuery, ppResponse, pdwOutSize, dwErr)\
  75. { \
  76. MIB_GET(GetNext, pQuery, szQuery, ppResponse, pdwOutSize, dwErr) \
  77. \
  78. if ( ( (dwErr) == RPC_S_SERVER_UNAVAILABLE ) || \
  79. ( (dwErr) == RPC_S_UNKNOWN_IF ) || \
  80. ( (dwErr) == ERROR_CAN_NOT_COMPLETE ) ) \
  81. { \
  82. TraceError( (dwErr) ); \
  83. (dwErr) = MIB_S_NO_MORE_ENTRIES; \
  84. } \
  85. }
  86. //------------------------------------------------------------------------------
  87. // Macros to convert between Asn and Win32 data types
  88. //------------------------------------------------------------------------------
  89. #define SET_ASN_INTEGER(dstBuf, val) { \
  90. if ((dstBuf)->asnType) { \
  91. ASSERT((dstBuf)->asnType==ASN_INTEGER); \
  92. (dstBuf)->asnValue.number = (AsnInteger)(val); \
  93. } \
  94. }
  95. #define FORCE_SET_ASN_INTEGER(dstBuf, val) { \
  96. (dstBuf)->asnType = ASN_INTEGER; \
  97. (dstBuf)->asnValue.number = (AsnInteger)(val); \
  98. }
  99. #define SET_ASN_COUNTER(dstBuf, val) { \
  100. if ((dstBuf)->asnType) { \
  101. ASSERT((dstBuf)->asnType==ASN_RFC1155_COUNTER); \
  102. (dstBuf)->asnValue.counter = (AsnCounter)(val); \
  103. } \
  104. }
  105. #define SET_ASN_GAUGE(dstBuf, val) { \
  106. if ((dstBuf)->asnType) { \
  107. ASSERT((dstBuf)->asnType==ASN_RFC1155_GAUGE); \
  108. (dstBuf)->asnValue.gauge = (AsnGauge)(val); \
  109. } \
  110. }
  111. #define SET_ASN_TIME_TICKS(dstBuf, val) { \
  112. if ((dstBuf)->asnType) { \
  113. ASSERT((dstBuf)->asnType==ASN_RFC1155_TIMETICKS); \
  114. (dstBuf)->asnValue.ticks = (AsnTimeticks)(val); \
  115. } \
  116. }
  117. #define SET_ASN_OCTET_STRING(dstBuf, buffer, src, len) {\
  118. if ((dstBuf)->asnType) { \
  119. ASSERT((dstBuf)->asnType==ASN_OCTETSTRING); \
  120. (dstBuf)->asnValue.string.length = len; \
  121. (dstBuf)->asnValue.string.stream = (BYTE*)memcpy(buffer,src,len);\
  122. (dstBuf)->asnValue.string.dynamic = FALSE; \
  123. } \
  124. }
  125. #define SET_ASN_IP_ADDR(dstBuf, val) { \
  126. if ((dstBuf)->asnType) \
  127. { \
  128. ASSERT((dstBuf)->asnType==ASN_RFC1155_IPADDRESS); \
  129. (dstBuf)->asnValue.address.length = IP_ADDRESS_LEN; \
  130. if( (dstBuf)->asnValue.address.stream) \
  131. { \
  132. (*(DWORD*)((dstBuf)->asnValue.address.stream)) = val;\
  133. } \
  134. } \
  135. }
  136. #define SET_ASN_IP_ADDRESS(dstBuf,buffer,val){ \
  137. if ((dstBuf)->asnType) \
  138. { \
  139. ASSERT((dstBuf)->asnType==ASN_RFC1155_IPADDRESS); \
  140. (dstBuf)->asnValue.address.length = IP_ADDRESS_LEN; \
  141. if(!(dstBuf)->asnValue.address.stream) \
  142. { \
  143. (dstBuf)->asnValue.address.stream = (PBYTE)buffer; \
  144. (dstBuf)->asnValue.address.dynamic = FALSE; \
  145. } \
  146. (*(DWORD*)((dstBuf)->asnValue.address.stream)) = val; \
  147. } \
  148. }
  149. #define FORCE_SET_ASN_IP_ADDRESS(dstBuf,buffer,val){ \
  150. (dstBuf)->asnType = ASN_RFC1155_IPADDRESS; \
  151. (dstBuf)->asnValue.address.length = IP_ADDRESS_LEN; \
  152. if(!((dstBuf)->asnValue.address.stream)) \
  153. { \
  154. (dstBuf)->asnValue.address.stream = (PBYTE)buffer; \
  155. (dstBuf)->asnValue.address.dynamic = FALSE; \
  156. } \
  157. (*(DWORD*)((dstBuf)->asnValue.address.stream)) = val; \
  158. }
  159. #define FORCE_ASN_USHORT(dstBuf,buffer,val){ \
  160. if ((dstBuf)->asnType) \
  161. { \
  162. ASSERT((dstBuf)->asnType==ASN_OCTETSTRING); \
  163. (dstBuf)->asnValue.string.length = 2; \
  164. (buffer)[0] = (BYTE)(val&0xFF); \
  165. (buffer)[1] = (BYTE)((val>>8)&0xFF); \
  166. (dstBuf)->asnValue.string.stream = (BYTE *)buffer; \
  167. (dstBuf)->asnValue.string.dynamic = FALSE; \
  168. } \
  169. }
  170. #define SetAsnDispString(dstBuf,buffer,src,len){ \
  171. if ((dstBuf)->asnType) \
  172. { \
  173. ASSERT((dstBuf)->asnType==ASN_RFC1213_DISPSTRING); \
  174. (dstBuf)->asnValue.string.length = strlen(src); \
  175. if ((dstBuf)->asnValue.string.length>len) \
  176. { \
  177. (dstBuf)->asnValue.string.length = len; \
  178. (dstBuf)->asnValue.string.stream = (BYTE *)strncpy (buffer,src,\
  179. (dstBuf)->asnValue.string.length);\
  180. (dstBuf)->asnValue.string.dynamic = FALSE; \
  181. } \
  182. } \
  183. }
  184. #define SetToZeroOid(dstBuf,buffer){ \
  185. if ((dstBuf)->asnType) \
  186. { \
  187. ASSERT((dstBuf)->asnType==ASN_OBJECTIDENTIFIER); \
  188. (dstBuf)->asnValue.object.idLength = NULL_OID_LEN; \
  189. (dstBuf)->asnValue.object.ids = buffer; \
  190. (dstBuf)->asnValue.object.ids[0] = 0; \
  191. (dstBuf)->asnValue.object.ids[1] = 0; \
  192. } \
  193. }
  194. #define GET_ASN_INTEGER(srcBuf,defVal) \
  195. (((srcBuf)->asnType)? ((srcBuf)->asnValue.number):(defVal))
  196. #define GetAsnCounter(srcBuf,defVal) \
  197. (((srcBuf)->asnType)? ((srcBuf)->asnValue.counter):(defVal))
  198. #define GetAsnTimeTicks(srcBuf, defval) \
  199. ( ( (srcBuf)-> asnType ) ? (srcBuf)-> asnValue.ticks : (defval) )
  200. #define GetAsnOctetString(dst,srcBuf) \
  201. (((srcBuf)->asnType)? \
  202. (memcpy(dst,(srcBuf)->asnValue.string.stream,(srcBuf)->asnValue.string.length)) \
  203. :NULL)
  204. #define GET_ASN_IP_ADDRESS(srcBuf,defVal) \
  205. (DWORD)(((srcBuf)->asnType && (srcBuf)->asnValue.string.length)? \
  206. (*(DWORD*)((srcBuf)->asnValue.address.stream)) : (defVal))
  207. #define IsAsnTypeNull(asnObj) (!((asnObj)->asnType))
  208. #define IsAsnIPAddressTypeNull(asnObj) (!((asnObj)->asnType && (asnObj)->asnValue.address.length))
  209. //------------------------------------------------------------------------------
  210. // IP address comparison macros
  211. //------------------------------------------------------------------------------
  212. //
  213. // LONG
  214. // Cmp(DWORD dwFirst, DWORD dwSecond, LONG lResult)
  215. //
  216. #define Cmp(dwFirst,dwSecond,lResult) ((LONG)((lResult) = ((dwFirst) - (dwSecond))))
  217. // The addresses are in Network order
  218. //
  219. // LONG
  220. // InetCmp(DWORD IpAddr1, DWORD IpAddr2, LONG lResult)
  221. //
  222. #define InetCmp(dwIpAddr1,dwIpAddr2,res) \
  223. ((LONG)(((res) = (((dwIpAddr1) & 0x000000ff) - ((dwIpAddr2) & 0x000000ff))) ? (res) : \
  224. (((res) = (((dwIpAddr1) & 0x0000ff00) - ((dwIpAddr2) & 0x0000ff00))) ? (res) : \
  225. (((res) = (((dwIpAddr1) & 0x00ff0000) - ((dwIpAddr2) & 0x00ff0000))) ? (res) : \
  226. (((dwIpAddr1) & 0xff000000) - ((dwIpAddr2) & 0xff000000))))))
  227. //------------------------------------------------------------------------------
  228. // breakout from block macros
  229. //------------------------------------------------------------------------------
  230. #define BEGIN_BREAKOUT_BLOCK do
  231. #define END_BREAKOUT_BLOCK while(FALSE)
  232. //------------------------------------------------------------------------------
  233. // Debug tracing macros
  234. //------------------------------------------------------------------------------
  235. #if DBG
  236. #define TRACE0(Z) TracePrintf(g_dwTraceId,Z)
  237. #define TRACE1(Y,Z) TracePrintf(g_dwTraceId,Y,Z)
  238. #define TRACE2(X,Y,Z) TracePrintf(g_dwTraceId,X,Y,Z)
  239. #define TRACE3(W,X,Y,Z) TracePrintf(g_dwTraceId,W,X,Y,Z)
  240. #define TRACE4(V,W,X,Y,Z) TracePrintf(g_dwTraceId,V,W,X,Y,Z)
  241. #define TRACE5(U,V,W,X,Y,Z) TracePrintf(g_dwTraceId,U,W,X,Y,Z)
  242. #define TRACEW0(Z) TracePrintfW(g_dwTraceId,Z)
  243. #define TraceEnter(X) TracePrintf(g_dwTraceId,"Entering " X)
  244. #define TraceLeave(X) TracePrintf(g_dwTraceId,"Leaving " X "\n")
  245. #define TraceError(X) \
  246. TracePrintf( g_dwTraceId, "MprAdminMIB API returned : %d", (X) );
  247. #define TraceError1(x) \
  248. { \
  249. LPWSTR __lpwszErr = NULL; \
  250. \
  251. TRACE1( "MprAdminMIB API returned : %d", (x) ); \
  252. MprAdminGetErrorString( (x), &__lpwszErr ); \
  253. \
  254. if ( __lpwszErr ) \
  255. { \
  256. TRACEW0( __lpwszErr ); \
  257. LocalFree( __lpwszErr ); \
  258. } \
  259. }
  260. #else
  261. #define TRACE0(Z)
  262. #define TRACE1(Y,Z)
  263. #define TRACE2(X,Y,Z)
  264. #define TRACE3(W,X,Y,Z)
  265. #define TRACE4(V,W,X,Y,Z)
  266. #define TRACE5(U,V,W,X,Y,Z)
  267. #define TRACEW0(Z)
  268. #define TraceEnter(X)
  269. #define TraceLeave(X)
  270. #define TraceError(x)
  271. #endif
  272. #define EnterReader(X)
  273. #define ReleaseLock(X)
  274. #define ReaderToWriter(X)
  275. #define EnterWriter(x)
  276. #define PRINT_IPADDR(x) \
  277. ((x)&0x000000ff),(((x)&0x0000ff00)>>8),(((x)&0x00ff0000)>>16),(((x)&0xff000000)>>24)
  278. #endif //_IGMPAGNT_DEFS_H_