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.

390 lines
20 KiB

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