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.

660 lines
21 KiB

  1. //=============================================================================
  2. // Copyright (c) 1997 Microsoft Corporation
  3. //
  4. // File Name: macros.h
  5. //
  6. // Abstract:
  7. // This file contains many macros and #defines.
  8. //
  9. // Author: K.S.Lokesh (lokeshs@) 11-1-97
  10. //
  11. // Revision History:
  12. //
  13. //=============================================================================
  14. #ifndef _MACROS_H_
  15. #define _MACROS_H
  16. //------------------------------------------------------------------------------
  17. // DEBUG FLAGS
  18. //------------------------------------------------------------------------------
  19. //kslksl
  20. #define SET_MOST_DEBUG 0
  21. // check for memory leaks
  22. #define DEBUG_FLAGS_MEM_ALLOC (1 | SET_MOST_DEBUG)
  23. //#define DEBUG_FLAGS_MEM_LEAK (DBG | DEBUG_FLAGS_MEM_ALLOC)
  24. // set it to above
  25. #define DEBUG_FLAGS_MEM_LEAK 0
  26. // assert on error //deldel replace 1 with 0
  27. #define DEBUG_FLAGS_ASSERT_ON_ERRORS (0 | SET_MOST_DEBUG)
  28. // DebugCheck
  29. #define CALL_MSG(str) {\
  30. DbgPrint("\nCall Lokeshs with this stack. dont hit go. " str ,__FILE__,__LINE__,NULL);\
  31. IgmpDbgBreakPoint();\
  32. DbgPrint("\nCall Lokeshs with this stack. dont hit go. " str ,__FILE__,__LINE__,NULL);\
  33. }
  34. //------------------------------------------------------------------------------
  35. // TMP DEBUGGING //DebugCheck
  36. //------------------------------------------------------------------------------
  37. extern DWORD DEBUG_CHECK_LOW_INDEX_ARRAY[100][2];
  38. extern DWORD DebugIgmpIndex;
  39. #define DEBUG_CHECK_LOW_INDEX(i) {\
  40. DebugIgmpIndex = (++DebugIgmpIndex) % 100; \
  41. DEBUG_CHECK_LOW_INDEX_ARRAY[DebugIgmpIndex][0] = i;\
  42. DEBUG_CHECK_LOW_INDEX_ARRAY[DebugIgmpIndex][1] = g_TimerStruct.TableLowIndex;\
  43. if (g_TimerStruct.TableLowIndex>64 && g_TimerStruct.TableLowIndex!=~0) IgmpDbgBreakPoint();\
  44. if (g_TimerStruct.TableLowIndex>64 && g_TimerStruct.NumTimers!=0) IgmpDbgBreakPoint();\
  45. }
  46. // Trace2(ENTER, "%%%%%%LowIndex:(%d) %0x:%d", i, g_TimerStruct.TableLowIndex); \
  47. //------------------------------------------------------------------------------
  48. // some global definitions
  49. //------------------------------------------------------------------------------
  50. #ifndef IPADDR
  51. typedef DWORD IPADDR;
  52. #endif
  53. #define PROTO_IP_IGMP_PROXY 11
  54. #define INTERSECTION 3
  55. #define RULE5 5
  56. //------------------------------------------------------------------------------
  57. // interface table macros
  58. //------------------------------------------------------------------------------
  59. #define IF_HASH_VALUE(_index) ((_index) % g_pIfTable->NumBuckets)
  60. #define ACQUIRE_IF_LOCK_EXCLUSIVE(_IfIndex, _proc) \
  61. AcquireDynamicRWLock(&g_pIfTable->aIfBucketDRWL[IF_HASH_VALUE(_IfIndex)],\
  62. LOCK_MODE_WRITE, \
  63. &g_DynamicRWLStore)
  64. #define RELEASE_IF_LOCK_EXCLUSIVE(_IfIndex, _proc) \
  65. ReleaseDynamicRWLock(&g_pIfTable->aIfBucketDRWL[IF_HASH_VALUE(_IfIndex)], \
  66. LOCK_MODE_WRITE, \
  67. &g_DynamicRWLStore)
  68. #define ACQUIRE_IF_LOCK_SHARED(_IfIndex, _proc) \
  69. AcquireDynamicRWLock(&g_pIfTable->aIfBucketDRWL[IF_HASH_VALUE(_IfIndex)], \
  70. LOCK_MODE_READ, \
  71. &g_DynamicRWLStore)
  72. #define RELEASE_IF_LOCK_SHARED(_IfIndex, _proc) \
  73. ReleaseDynamicRWLock(&g_pIfTable->aIfBucketDRWL[IF_HASH_VALUE(_IfIndex)], \
  74. LOCK_MODE_READ, \
  75. &g_DynamicRWLStore)
  76. #define ACQUIRE_IF_LIST_LOCK(_proc) \
  77. ENTER_CRITICAL_SECTION(&g_pIfTable->IfLists_CS, "g_IfListsCS", _proc);
  78. #define RELEASE_IF_LIST_LOCK(_proc) \
  79. LEAVE_CRITICAL_SECTION(&g_pIfTable->IfLists_CS, "g_IfListsCS", _proc);
  80. #define ACQUIRE_IF_GROUP_LIST_LOCK(_IfIndex, _proc) \
  81. AcquireDynamicCSLock(&g_pIfTable->aIfBucketDCS[IF_HASH_VALUE(_IfIndex)],\
  82. &g_DynamicCSStore)
  83. #define RELEASE_IF_GROUP_LIST_LOCK(_IfIndex, _proc) \
  84. ReleaseDynamicCSLock(&g_pIfTable->aIfBucketDCS[IF_HASH_VALUE(_IfIndex)],\
  85. &g_DynamicCSStore)
  86. //------------------------------------------------------------------------------
  87. // Proxy table macros
  88. //------------------------------------------------------------------------------
  89. #define PROXY_HASH_VALUE(_group) \
  90. (( ((_group)&0xFF000000)+((_group)&0xFF)) % (PROXY_HASH_TABLE_SZ))
  91. //------------------------------------------------------------------------------
  92. // protocol type macros/interface type macros
  93. //------------------------------------------------------------------------------
  94. #define IS_PROTOCOL_TYPE_PROXY(_pite) \
  95. ((_pite)->Config.IgmpProtocolType==IGMP_PROXY \
  96. ||(_pite)->Config.IgmpProtocolType==IGMP_PROXY_V3)
  97. #define IS_PROTOCOL_TYPE_PROXY_V2(_pite) \
  98. ((_pite)->Config.IgmpProtocolType==IGMP_PROXY)
  99. #define IS_PROTOCOL_TYPE_PROXY_V3(_pite) \
  100. ((_pite)->Config.IgmpProtocolType==IGMP_PROXY_V3)
  101. #define IS_PROTOCOL_TYPE_IGMPV1(_pite) \
  102. ((_pite)->Config.IgmpProtocolType==IGMP_ROUTER_V1)
  103. #define IS_PROTOCOL_TYPE_IGMPV2(_pite) \
  104. ((_pite)->Config.IgmpProtocolType==IGMP_ROUTER_V2)
  105. #define IS_PROTOCOL_TYPE_IGMPV3(_pite) \
  106. ((_pite)->Config.IgmpProtocolType==IGMP_ROUTER_V3)
  107. #define IS_PROTOCOL_TYPE_ROUTER(_pite) \
  108. (!IS_PROTOCOL_TYPE_PROXY(_pite))
  109. #define IGMP_MIB_IF_CONFIG_SIZE_V3(pConfig) \
  110. IgmpMibIfConfigSize(pConfig)
  111. // internally, FfType does not have protocol type, but when I expose it outside,
  112. // I have to add proxy type if it is a proxy interface.
  113. #define GET_EXTERNAL_IF_TYPE(_pite) \
  114. IS_PROTOCOL_TYPE_PROXY(_pite) ? ((_pite->IfType)|IGMP_IF_PROXY) \
  115. : (_pite)->IfType
  116. #define ACQUIRE_PROXY_ALERT_LOCK(proc) \
  117. ENTER_CRITICAL_SECTION(&g_ProxyAlertCS, "g_ProxyAlertCS", proc)
  118. #define RELEASE_PROXY_ALERT_LOCK(proc) \
  119. LEAVE_CRITICAL_SECTION(&g_ProxyAlertCS, "g_ProxyAlertCS", proc)
  120. //-------------------------------------------------------------------
  121. // ENUM MACROS
  122. //-------------------------------------------------------------------
  123. #define ACQUIRE_ENUM_LOCK_EXCLUSIVE(_proc) \
  124. ACQUIRE_WRITE_LOCK(&g_EnumRWLock, "g_EnumRWLock", _proc);
  125. #define RELEASE_ENUM_LOCK_EXCLUSIVE(_proc) \
  126. RELEASE_WRITE_LOCK(&g_EnumRWLock, "g_EnumRWLock", _proc);
  127. #define ACQUIRE_ENUM_LOCK_SHARED(_proc) \
  128. ACQUIRE_READ_LOCK(&g_EnumRWLock, "g_EnumRWLock", _proc);
  129. #define RELEASE_ENUM_LOCK_SHARED(_proc) \
  130. RELEASE_READ_LOCK(&g_EnumRWLock, "g_EnumRWLock", _proc);
  131. //------------------------------------------------------------------------------
  132. // group table macros
  133. //------------------------------------------------------------------------------
  134. #define GROUP_HASH_VALUE(_group) \
  135. (((_group) & 0xFF)%GROUP_HASH_TABLE_SZ)
  136. #define ACQUIRE_GROUP_LOCK(_group, _proc) {\
  137. ACQUIRE_ENUM_LOCK_SHARED(_proc);\
  138. AcquireDynamicCSLockedList( \
  139. &g_pGroupTable->HashTableByGroup[GROUP_HASH_VALUE(_group)],\
  140. &g_DynamicCSStore);\
  141. }
  142. #define RELEASE_GROUP_LOCK(_group, _proc) {\
  143. ReleaseDynamicCSLockedList( \
  144. &g_pGroupTable->HashTableByGroup[GROUP_HASH_VALUE(_group)],\
  145. &g_DynamicCSStore);\
  146. RELEASE_ENUM_LOCK_SHARED(_proc);\
  147. }
  148. #define ACQUIRE_GROUP_LIST_LOCK(_proc) { \
  149. ACQUIRE_LIST_LOCK(&g_pGroupTable->ListByGroup, \
  150. "g_pGroupTable->ListByGroup", _proc);\
  151. }
  152. #define RELEASE_GROUP_LIST_LOCK(_proc) { \
  153. RELEASE_LIST_LOCK(&g_pGroupTable->ListByGroup, \
  154. "g_pGroupTable->ListByGroup", _proc);\
  155. }
  156. //
  157. // merge the groups list if the number of entries in the new list is more than 50
  158. // or if the size of new list is greater than 4 times the size of actual list
  159. // but in any case not smaller than 10
  160. //
  161. #define MERGE_GROUP_LISTS_REQUIRED() \
  162. ( (g_pGroupTable->NumGroupsInNewList > 50) \
  163. || ( (g_pGroupTable->NumGroupsInNewList > \
  164. g_Info.CurrentGroupMemberships/4) \
  165. && (g_pGroupTable->NumGroupsInNewList>10) ))
  166. // insert all elements in l2 at the end of l1, and reinitialize l2
  167. #define CONCATENATE_LISTS(l1, l2) { \
  168. l2.Flink->Blink = l1.Blink; \
  169. l1.Blink->Flink = l2.Flink; \
  170. l2.Blink->Flink = &l1; \
  171. l1.Blink = l2.Blink; \
  172. InitializeListHead(&l2); \
  173. }
  174. #define MERGE_IF_GROUPS_LISTS_REQUIRED(_pite) \
  175. (_pite->NumGIEntriesInNewList > 20)
  176. #define MERGE_PROXY_LISTS_REQUIRED(_pite) \
  177. (_pite->NumGIEntriesInNewList > 20)
  178. //------------------------------------------------------------------------------
  179. // SOCKETS MACROS
  180. //------------------------------------------------------------------------------
  181. #define ACQUIRE_SOCKETS_LOCK_EXCLUSIVE(_proc) \
  182. ACQUIRE_WRITE_LOCK(&g_SocketsRWLock, "g_SocketsRWLock", _proc);
  183. #define RELEASE_SOCKETS_LOCK_EXCLUSIVE(_proc) \
  184. RELEASE_WRITE_LOCK(&g_SocketsRWLock, "g_SocketsRWLock", _proc);
  185. #define ACQUIRE_SOCKETS_LOCK_SHARED(_proc) \
  186. ACQUIRE_READ_LOCK(&g_SocketsRWLock, "g_SocketsRWLock", _proc);
  187. #define RELEASE_SOCKETS_LOCK_SHARED(_proc) \
  188. RELEASE_READ_LOCK(&g_SocketsRWLock, "g_SocketsRWLock", _proc);
  189. //------------------------------------------------------------------------------
  190. // RAS MACROS
  191. //------------------------------------------------------------------------------
  192. #define IS_NOT_RAS_IF(flag) ((flag) == IGMP_IF_NOT_RAS)
  193. #define IS_RAS_SERVER_IF(flag) ((flag) == IGMP_IF_RAS_SERVER)
  194. #define IS_RAS_CLIENT_IF(flag) ((flag) == IGMP_IF_RAS_CLIENT)
  195. #define IS_RAS_ROUTER_IF(flag) ((flag) == IGMP_IF_RAS_ROUTER)
  196. #define RAS_HASH_VALUE(ClientAddr) \
  197. (((ClientAddr) & 0xFF)%(RAS_HASH_TABLE_SZ))
  198. //------------------------------------------------------------------------------
  199. // PACKET MACROS
  200. //------------------------------------------------------------------------------
  201. // This macro compares two IP addresses in network order by
  202. // masking off each pair of octets and doing a subtraction;
  203. // the result of the final subtraction is stored in the third argument.
  204. //
  205. #define INET_CMP(a,b,c) \
  206. (((c) = (((a) & 0x000000ff) - ((b) & 0x000000ff))) ? (c) : \
  207. (((c) = (((a) & 0x0000ff00) - ((b) & 0x0000ff00))) ? (c) : \
  208. (((c) = (((a) & 0x00ff0000) - ((b) & 0x00ff0000))) ? (c) : \
  209. (((c) = ((((a)>>8) & 0x00ff0000) - (((b)>>8) & 0x00ff0000)))))))
  210. #define PRINT_IPADDR(x) \
  211. ((x)&0x000000ff),(((x)&0x0000ff00)>>8),(((x)&0x00ff0000)>>16),(((x)&0xff000000)>>24)
  212. //------------------------------------------------------------------------------
  213. // Interface #defines and Macros
  214. //------------------------------------------------------------------------------
  215. //
  216. // status flags
  217. //
  218. #define IF_CREATED_FLAG 0x00000001
  219. #define CREATED_FLAG 0x00000001
  220. #define IF_BOUND_FLAG 0x00000002
  221. #define IF_ENABLED_FLAG 0x00000004
  222. #define IF_DELETED_FLAG 0x80000000
  223. #define DELETED_FLAG 0x80000000
  224. #define MGM_ENABLED_IGMPRTR_FLAG 0x00001000
  225. #define IGMPRTR_MPROTOCOL_PRESENT_FLAG 0x00002000
  226. // interface timers etc have not been set. socket not activated. so enumeration
  227. // might not be correct. Further, if deleting the entry, timers/sockets can
  228. // be ignored
  229. #define IF_ACTIVATED_FLAG 0x00000008
  230. #define IF_DEACTIVATE_DELETE_FLAG 0x00000010
  231. //
  232. // macros for status flags
  233. //
  234. #define IS_IGMPRTR_ENABLED_BY_MGM(pite) \
  235. (pite->Status & MGM_ENABLED_IGMPRTR_FLAG)
  236. #define MGM_ENABLE_IGMPRTR(pite) \
  237. (pite->Status |= MGM_ENABLED_IGMPRTR_FLAG)
  238. #define MGM_DISABLE_IGMPRTR(pite) {\
  239. (pite->Status &= ~MGM_ENABLED_IGMPRTR_FLAG); \
  240. (pite->Status &= ~IGMPRTR_MPROTOCOL_PRESENT_FLAG);\
  241. }
  242. #define IS_MPROTOCOL_PRESENT_ON_IGMPRTR(pite) \
  243. (pite->Status & IGMPRTR_MPROTOCOL_PRESENT_FLAG)
  244. #define SET_MPROTOCOL_PRESENT_ON_IGMPRTR(pite) \
  245. (pite->Status |= IGMPRTR_MPROTOCOL_PRESENT_FLAG)
  246. #define SET_MPROTOCOL_ABSENT_ON_IGMPRTR(pite) \
  247. (pite->Status &= ~IGMPRTR_MPROTOCOL_PRESENT_FLAG)
  248. #define IS_IF_BOUND(pite) \
  249. ((pite)->Status&IF_BOUND_FLAG)
  250. #define IS_IF_ENABLED_BY_RTRMGR(pite) \
  251. ((pite)->Status&IF_ENABLED_FLAG)
  252. #define IS_IF_ENABLED_IN_CONFIG(pite) \
  253. (IGMP_ENABLED_FLAG_SET((pite)->Config.Flags))
  254. #define IS_IF_ENABLED(pite) \
  255. ( IS_IF_ENABLED_BY_RTRMGR(pite) && IS_IF_ENABLED_IN_CONFIG(pite) )
  256. #define IS_IF_ENABLED_BOUND(pite) \
  257. (IS_IF_ENABLED(pite)&&IS_IF_BOUND(pite))
  258. #define IS_IF_DELETED(pite) \
  259. ((pite)->Status&IF_DELETED_FLAG)
  260. #define IS_IF_NOT_DELETED(pite) \
  261. (!((pite)->Status&IF_DELETED_FLAG))
  262. #define IS_IF_ACTIVATED(pite) \
  263. ( !((pite)->Status&IF_DELETED_FLAG) && ((pite)->Status&IF_ACTIVATED_FLAG) )
  264. //-------------------------------
  265. // QUERIER STATES 0x<Querier><0>
  266. //-------------------------------
  267. #define QUERIER 0x10
  268. #define IS_IF_VER2(pite) IS_PROTOCOL_TYPE_IGMPV2(pite)
  269. #define IS_IF_VER1(pite) IS_PROTOCOL_TYPE_IGMPV1(pite)
  270. #define IS_IF_VER3(pite) IS_PROTOCOL_TYPE_IGMPV3(pite)
  271. #define GET_IF_VERSION(_pite) (_pite)->Config.IgmpProtocolType
  272. #define IS_QUERIER(pite) ((pite)->Info.QuerierState & QUERIER)
  273. //
  274. // interlocked operations not required, as state is of type uchar
  275. //
  276. #define SET_QUERIER_STATE_QUERIER(state) (state |= 0x10)
  277. #define SET_QUERIER_STATE_NON_QUERIER(state) (state &= 0x01)
  278. #define IF_PROCESS_GRPQUERY(pite) \
  279. ( (IS_IF_VER2(pite)||IS_IF_VER3(pite)) && !IS_RAS_SERVER_IF(pite->IfType) )
  280. #define IF_PROCESS_LEAVES(pite) \
  281. ( IS_IF_VER2(pite) && (IS_QUERIER(pite)) && !IS_RAS_SERVER_IF(pite->IfType))
  282. #define GI_PROCESS_GRPQUERY(pite, pgie) \
  283. ( IF_PROCESS_GRPQUERY(pite)&& ((pgie->Version==2)||(pgie->Version==3)) )
  284. #define CAN_ADD_GROUPS_TO_MGM(pite) \
  285. ( (IS_IGMPRTR_ENABLED_BY_MGM(pite)) \
  286. && (IS_MPROTOCOL_PRESENT_ON_IGMPRTR(pite) || (IS_QUERIER(pite))) \
  287. )
  288. //
  289. // INTERFACE STATE
  290. //
  291. #define GET_EXTERNAL_IF_STATE(pite, State) {\
  292. State = 0;\
  293. if (IS_IF_ENABLED_BY_RTRMGR(pite)) \
  294. State |= IGMP_STATE_ENABLED_BY_RTRMGR; \
  295. if (IS_IF_ENABLED_IN_CONFIG(pite))\
  296. State |= IGMP_STATE_ENABLED_IN_CONFIG; \
  297. if (IS_PROTOCOL_TYPE_ROUTER(pite)) {\
  298. if (IS_IGMPRTR_ENABLED_BY_MGM(pite)) \
  299. State |= IGMP_STATE_ENABLED_BY_MGM; \
  300. if (CAN_ADD_GROUPS_TO_MGM(pite)) \
  301. State |= IGMP_STATE_MGM_JOINS_ENABLED; \
  302. } \
  303. else \
  304. State |= IGMP_STATE_ENABLED_BY_MGM; \
  305. \
  306. if (IS_IF_BOUND(pite)) \
  307. State |= IGMP_STATE_BOUND;\
  308. }
  309. //
  310. //filter macros
  311. //
  312. #define GMI TRUE
  313. #define LMI FALSE
  314. #define STATIC 0xff
  315. #define MGM_YES TRUE
  316. #define MGM_NO FALSE
  317. //------------------------------------------------------------------------------
  318. // other locking macros
  319. //------------------------------------------------------------------------------
  320. #define ACQUIRE_GLOBAL_LOCK(proc) ENTER_CRITICAL_SECTION(&g_CS, "g_CS", proc)
  321. #define RELEASE_GLOBAL_LOCK(proc) LEAVE_CRITICAL_SECTION(&g_CS, "g_CS", proc)
  322. //
  323. // instead of using goto:end to go to the end of the block, use the following
  324. //
  325. #define BEGIN_BREAKOUT_BLOCK1 do
  326. #define GOTO_END_BLOCK1 goto END_BREAKOUT_BLOCK_1
  327. #define END_BREAKOUT_BLOCK1 while(FALSE); END_BREAKOUT_BLOCK_1:
  328. #define BEGIN_BREAKOUT_BLOCK2 do
  329. #define GOTO_END_BLOCK2 goto END_BREAKOUT_BLOCK_2
  330. #define END_BREAKOUT_BLOCK2 while(FALSE); END_BREAKOUT_BLOCK_2:
  331. //------------------------------------------------------------------------------
  332. // memory allocation/deallocation macros
  333. //------------------------------------------------------------------------------
  334. #if DEBUG_FLAGS_MEM_ALLOC
  335. typedef struct _MEM_HDR {
  336. LIST_ENTRY Link;
  337. ULONG Signature;
  338. ULONG Id;
  339. ULONG IfIndex;
  340. PDWORD Tail;
  341. } MEM_HDR, *PMEM_HDR;
  342. PVOID
  343. IgmpDebugAlloc(
  344. DWORD sz,
  345. DWORD Flags,
  346. DWORD Id,
  347. DWORD IfIndex
  348. );
  349. VOID
  350. IgmpDebugFree(
  351. PVOID mem
  352. );
  353. VOID
  354. DebugScanMemory(
  355. );
  356. VOID
  357. DebugScanMemoryInterface(
  358. DWORD IfIndex
  359. );
  360. #define IGMP_ALLOC(sz,Id,If) IgmpDebugAlloc((sz),0,Id,If)
  361. #define IGMP_ALLOC_AND_ZERO(sz,Id,If) IgmpDebugAlloc((sz),HEAP_ZERO_MEMORY,Id,If)
  362. #define IGMP_FREE(p) {\
  363. IgmpDebugFree(p);\
  364. }
  365. #define IGMP_FREE_NOT_NULL(p) if (p) IGMP_FREE(p)
  366. #else
  367. #define IGMP_ALLOC(sz,Id,If) HeapAlloc(g_Heap,0,(sz))
  368. #define IGMP_ALLOC_AND_ZERO(sz,Id,If) HeapAlloc(g_Heap,HEAP_ZERO_MEMORY,(sz))
  369. //deldel
  370. //#define IGMP_FREE(p) HeapFree(g_Heap, 0, (p))
  371. //#define IGMP_FREE_NOT_NULL(p) ((p) ? IGMP_FREE(p) : TRUE)
  372. #define IGMP_FREE(p) {\
  373. HeapFree(g_Heap, 0, (p));\
  374. }
  375. // Trace1(ENTER1, "Freed heap:%0x", PtrToUlong(p));\
  376. #define IGMP_FREE_NOT_NULL(p) if (p)IGMP_FREE(p)
  377. #define IgmpDebugAlloc(sz,Flags,Id,IfIndex)
  378. #define IgmpDebugFree(mem)
  379. #define DebugScanMemoryInterface(IfIndex)
  380. #define DebugScanMemory()
  381. #endif
  382. #define PROCESS_ALLOC_FAILURE2(ptr, TraceMsg, Error,arg2, GotoStmt) \
  383. if (ptr==NULL) {\
  384. Error = ERROR_NOT_ENOUGH_MEMORY;\
  385. Trace2(ERR, TraceMsg, Error, arg2); \
  386. GotoStmt;\
  387. }
  388. #define PROCESS_ALLOC_FAILURE3(ptr, TraceMsg, Error,arg2,arg3, GotoStmt) \
  389. if (ptr==NULL) {\
  390. Error = ERROR_NOT_ENOUGH_MEMORY;\
  391. Trace3(ERR, TraceMsg, Error, arg2, arg3); \
  392. GotoStmt;\
  393. }
  394. //
  395. // assert macros
  396. //
  397. #if DBG
  398. #define IgmpAssert(exp){ \
  399. if(!(exp)) \
  400. { \
  401. TracePrintf(TRACEID, \
  402. "Assertion failed in %s : %d \n",__FILE__,__LINE__);\
  403. RouterAssert(#exp,__FILE__,__LINE__,NULL); \
  404. } \
  405. }
  406. #if DEBUG_FLAGS_ASSERT_ON_ERRORS
  407. #define IgmpAssertOnError(exp) IgmpAssert(exp)
  408. #define IgmpDbgBreakPoint() DbgBreakPoint()
  409. #else
  410. #define IgmpAssertOnError(exp) ;
  411. #define IgmpDbgBreakPoint() ;
  412. #endif
  413. // if not DBG
  414. #else
  415. #define IgmpAssert(exp) ;
  416. #define IgmpAssertOnError(exp) ;
  417. #define IgmpDbgBreakPoint() /*deldel*/
  418. #endif
  419. #define INSERT_IN_SORTED_LIST(_pInsertList, _pEntry, _Field, _STRUCT, _Link) {\
  420. \
  421. _STRUCT *pTmp;\
  422. PLIST_ENTRY pHead, ple;\
  423. \
  424. pHead = _pInsertList;\
  425. for (ple=pHead->Flink; ple!=pHead; ple=ple->Flink) {\
  426. \
  427. pTmp = CONTAINING_RECORD(ple, _STRUCT, _Link);\
  428. if (pTmp->_Field > _pEntry->_Field)\
  429. break;\
  430. }\
  431. \
  432. InsertTailList(ple, &_pEntry->_Link);\
  433. }
  434. #define SEARCH_IN_SORTED_LIST(_pList,_Value,_Field,_STRUCT,_Link,_pEntry) {\
  435. PLIST_ENTRY ple;\
  436. _pEntry = NULL;\
  437. \
  438. for (ple=(_pList)->Flink; ple!=_pList; ple=ple->Flink) {\
  439. _pEntry = CONTAINING_RECORD(ple, _STRUCT, _Link);\
  440. if ((_Value >= _pEntry)->_Field) {\
  441. if ((_pEntry)->_Field != _Value) \
  442. _pEntry = NULL;\
  443. break;\
  444. }\
  445. }\
  446. }
  447. //
  448. // NETWORK_TO_LITTLE_ENDIAN macro
  449. //
  450. #define NETWORK_TO_LITTLE_ENDIAN(Group) ( (((Group)&0x000000ff)<<24) \
  451. +(((Group)&0x0000ff00)<<8) \
  452. +(((Group)&0x00ff0000)>>8) \
  453. +(((Group)&0xff000000)>>24) )
  454. #define MIN(a,b) ((a)<(b) ? (a) : (b))
  455. #define MAX(a,b) ((a)>(b) ? (a) : (b))
  456. #define IS_NOT_EQ_ANY2(a, A,B) ((a!=A)&&(a!=B))
  457. #define IS_EQ_ANY(a,A,B) ((a==A)||(a==B))
  458. //
  459. // signature macros for Interface-Group lists enumeration
  460. //
  461. #define GET_NEXT_SIGNATURE() (g_GlobalIfGroupEnumSignature++ | 0x10 )
  462. //#define SET_SIGNATURE(a,b) ((a) = ((b)<<16) | (a&0x00FF))
  463. #define SET_SIGNATURE(a,b) (a = (b))
  464. //
  465. // define enum values
  466. //
  467. #define ADD_FLAG 1
  468. #define DELETE_FLAG 0
  469. #define NON_QUERIER_FLAG 1
  470. #define QUERIER_FLAG 2
  471. #define QUERIER_CHANGE_V1_ONLY 4
  472. #define STATIC_GROUP 1
  473. #define NOT_STATIC_GROUP 0
  474. #define ANY_GROUP_TYPE 2
  475. #define NOT_RAS_CLIENT 0
  476. #define RAS_CLIENT 1
  477. #endif