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.

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