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.

377 lines
11 KiB

  1. //============================================================================
  2. // Copyright (c) 1995, Microsoft Corporation
  3. //
  4. // File: iprip.h
  5. //
  6. // History:
  7. // Abolade Gbadegesin Aug-7-1995 Created.
  8. //
  9. // Contains type definitions and declarations for IP RIP.
  10. //============================================================================
  11. #ifndef _IPRIP_H_
  12. #define _IPRIP_H_
  13. //
  14. // various codes describing states of IPRIP.
  15. //
  16. typedef enum _IPRIP_STATUS_CODE {
  17. IPRIP_STATUS_STARTING = 100,
  18. IPRIP_STATUS_RUNNING = 101,
  19. IPRIP_STATUS_STOPPING = 102,
  20. IPRIP_STATUS_STOPPED = 103
  21. } IPRIP_STATUS_CODE, *PIPRIP_STATUS_CODE;
  22. //
  23. // type: IPRIP_GLOBALS
  24. //
  25. //
  26. // The critical section IPRIP_GLOBALS::IG_CS protects the fields IG_Status,
  27. // IG_ActivityCount, IG_ActivitySemaphore, IG_InterruptReason, and
  28. // IG_InterruptSocket
  29. //
  30. // The read-write lock IPRIP_GLOBALS::IG_RWL protects the field IG_Config
  31. //
  32. // When more than one field must be locked, the order
  33. // of locking must be as follows (locks for fields listed on the same line
  34. // should never be held by the same thread at once):
  35. // IG_IfTable.IT_RWL
  36. // IG_PeerTable.PT_RWL
  37. // IG_IfTable.IT_CS
  38. // IG_BindingTable.BT_RWL
  39. // IG_RWL
  40. // IG_TimerQueue IG_EventQueue IG_SendQueue IG_RecvQueue
  41. // IG_CS
  42. //
  43. // It is assumed that the field IG_SendQueueSize will only
  44. // be accessed while the send queue is locked, and thus
  45. // it is protected implicitly by the send-queue critical section.
  46. //
  47. // Likewise, it is assumed that the field IG_RecvQueueSize will only
  48. // be accessed while the recv-queue is locked, and thus
  49. // it is protected implicitly by the recv-queue critical section.
  50. //
  51. typedef struct _IPRIP_GLOBALS {
  52. CRITICAL_SECTION IG_CS;
  53. IPRIP_STATUS_CODE IG_Status;
  54. READ_WRITE_LOCK IG_RWL;
  55. DWORD IG_TraceID;
  56. IPRIP_GLOBAL_STATS IG_Stats;
  57. PIPRIP_GLOBAL_CONFIG IG_Config;
  58. PIF_TABLE IG_IfTable;
  59. PPEER_TABLE IG_PeerTable;
  60. PBINDING_TABLE IG_BindingTable;
  61. DWORD IG_LogLevel;
  62. HANDLE IG_LogHandle;
  63. HANDLE IG_RtmHandle;
  64. HANDLE IG_RtmNotifHandle;
  65. RTM_ENTITY_INFO IG_RtmEntityInfo;
  66. RTM_REGN_PROFILE IG_RtmProfile;
  67. HANDLE IG_TimerQueueHandle;
  68. PLOCKED_LIST IG_EventQueue;
  69. PLOCKED_LIST IG_SendQueue;
  70. LONG IG_SendQueueSize;
  71. PLOCKED_LIST IG_RecvQueue;
  72. LONG IG_RecvQueueSize;
  73. HANDLE IG_EventEvent;
  74. HANDLE IG_IpripInputEvent;
  75. HANDLE IG_IpripInputEventHandle;
  76. HANDLE IG_IpripGlobalHeap;
  77. LONG IG_ActivityCount;
  78. HANDLE IG_ActivitySemaphore;
  79. DWORD IG_MibTraceID;
  80. HANDLE IG_MibTimerHandle;
  81. SUPPORT_FUNCTIONS IG_SupportFunctions;
  82. } IPRIP_GLOBALS, *PIPRIP_GLOBALS;
  83. //
  84. // external declaration of the global IPRIP struct
  85. //
  86. extern IPRIP_GLOBALS ig;
  87. //
  88. // memory-allocation constants and macros
  89. //
  90. #define GLOBAL_HEAP ig.IG_IpripGlobalHeap
  91. #define RIP_ALLOC(size) HeapAlloc(GLOBAL_HEAP, 0, size)
  92. #define RIP_FREE(ptr) HeapFree(GLOBAL_HEAP, 0, ptr)
  93. //
  94. // macros invoked when entering API or worker functions
  95. //
  96. #define ENTER_RIP_API() EnterRipAPI()
  97. #define ENTER_RIP_WORKER() EnterRipWorker()
  98. //
  99. // macro invoked when leaving API or worker functions
  100. //
  101. #define LEAVE_RIP_API() LeaveRipWorker()
  102. #define LEAVE_RIP_WORKER() LeaveRipWorker()
  103. //
  104. // macros used for locking and unlocking protected structures
  105. //
  106. #define ACQUIRE_GLOBAL_LOCK_EXCLUSIVE() \
  107. AcquireWriteLock(&ig.IG_RWL)
  108. #define RELEASE_GLOBAL_LOCK_EXCLUSIVE() \
  109. ReleaseWriteLock(&ig.IG_RWL)
  110. #define ACQUIRE_GLOBAL_LOCK_SHARED() \
  111. AcquireReadLock(&ig.IG_RWL)
  112. #define RELEASE_GLOBAL_LOCK_SHARED() \
  113. ReleaseReadLock(&ig.IG_RWL)
  114. #define ENTER_GLOBAL_SECTION() \
  115. EnterCriticalSection(&ig.IG_CS)
  116. #define LEAVE_GLOBAL_SECTION() \
  117. LeaveCriticalSection(&ig.IG_CS)
  118. #define ACQUIRE_IF_LOCK_EXCLUSIVE() \
  119. AcquireWriteLock(&ig.IG_IfTable->IT_RWL)
  120. #define RELEASE_IF_LOCK_EXCLUSIVE() \
  121. ReleaseWriteLock(&ig.IG_IfTable->IT_RWL)
  122. #define ACQUIRE_IF_LOCK_SHARED() \
  123. AcquireReadLock(&ig.IG_IfTable->IT_RWL)
  124. #define RELEASE_IF_LOCK_SHARED() \
  125. ReleaseReadLock(&ig.IG_IfTable->IT_RWL)
  126. #define ENTER_IF_SECTION() \
  127. EnterCriticalSection(&ig.IG_IfTable->IT_CS)
  128. #define LEAVE_IF_SECTION() \
  129. LeaveCriticalSection(&ig.IG_IfTable->IT_CS)
  130. #define ACQUIRE_PEER_LOCK_EXCLUSIVE() \
  131. AcquireWriteLock(&ig.IG_PeerTable->PT_RWL)
  132. #define RELEASE_PEER_LOCK_EXCLUSIVE() \
  133. ReleaseWriteLock(&ig.IG_PeerTable->PT_RWL)
  134. #define ACQUIRE_PEER_LOCK_SHARED() \
  135. AcquireReadLock(&ig.IG_PeerTable->PT_RWL)
  136. #define RELEASE_PEER_LOCK_SHARED() \
  137. ReleaseReadLock(&ig.IG_PeerTable->PT_RWL)
  138. #define ACQUIRE_BINDING_LOCK_EXCLUSIVE() \
  139. AcquireWriteLock(&ig.IG_BindingTable->BT_RWL)
  140. #define RELEASE_BINDING_LOCK_EXCLUSIVE() \
  141. ReleaseWriteLock(&ig.IG_BindingTable->BT_RWL)
  142. #define ACQUIRE_BINDING_LOCK_SHARED() \
  143. AcquireReadLock(&ig.IG_BindingTable->BT_RWL)
  144. #define RELEASE_BINDING_LOCK_SHARED() \
  145. ReleaseReadLock(&ig.IG_BindingTable->BT_RWL)
  146. //
  147. // constants and macros used for tracing
  148. //
  149. #define IPRIP_TRACE_ANY ((DWORD)0xFFFF0000 | TRACE_USE_MASK)
  150. #define IPRIP_TRACE_ENTER ((DWORD)0x00010000 | TRACE_USE_MASK)
  151. #define IPRIP_TRACE_LEAVE ((DWORD)0x00020000 | TRACE_USE_MASK)
  152. #define IPRIP_TRACE_TIMER ((DWORD)0x00040000 | TRACE_USE_MASK)
  153. #define IPRIP_TRACE_IF ((DWORD)0x00080000 | TRACE_USE_MASK)
  154. #define IPRIP_TRACE_ROUTE ((DWORD)0x00100000 | TRACE_USE_MASK)
  155. #define IPRIP_TRACE_SEND ((DWORD)0x00200000 | TRACE_USE_MASK)
  156. #define IPRIP_TRACE_RECEIVE ((DWORD)0x00400000 | TRACE_USE_MASK)
  157. #define IPRIP_TRACE_CONFIG ((DWORD)0x00800000 | TRACE_USE_MASK)
  158. #define IPRIP_TRACE_START ((DWORD)0x01000000 | TRACE_USE_MASK)
  159. #define IPRIP_TRACE_STOP ((DWORD)0x02000000 | TRACE_USE_MASK)
  160. #define IPRIP_TRACE_REQUEST ((DWORD)0x04000000 | TRACE_USE_MASK)
  161. #define IPRIP_TRACE_RESPONSE ((DWORD)0x08000000 | TRACE_USE_MASK)
  162. #define TRACEID ig.IG_TraceID
  163. #define TRACE0(l,a) \
  164. if (TRACEID != INVALID_TRACEID) TracePrintfEx(TRACEID, IPRIP_TRACE_ ## l, a)
  165. #define TRACE1(l,a,b) \
  166. if (TRACEID != INVALID_TRACEID) TracePrintfEx(TRACEID, IPRIP_TRACE_ ## l, a, b)
  167. #define TRACE2(l,a,b,c) \
  168. if (TRACEID != INVALID_TRACEID) TracePrintfEx(TRACEID, IPRIP_TRACE_ ## l, a, b, c)
  169. #define TRACE3(l,a,b,c,d) \
  170. if (TRACEID != INVALID_TRACEID) TracePrintfEx(TRACEID, IPRIP_TRACE_ ## l, a, b, c, d)
  171. #define TRACE4(l,a,b,c,d,e) \
  172. if (TRACEID != INVALID_TRACEID) TracePrintfEx(TRACEID, IPRIP_TRACE_ ## l, a, b, c, d, e)
  173. #define TRACE5(l,a,b,c,d,e,f) \
  174. if (TRACEID != INVALID_TRACEID) TracePrintfEx(TRACEID, IPRIP_TRACE_ ## l, a, b, c, d, e, f)
  175. #define TRACEDUMP(l,a,b,c) \
  176. TraceDumpEx(TRACEID,l,a,b,c,TRUE)
  177. //
  178. // Event logging macros
  179. //
  180. #define LOGLEVEL ig.IG_LogLevel
  181. #define LOGHANDLE ig.IG_LogHandle
  182. #define LOGERR RouterLogError
  183. #define LOGWARN RouterLogWarning
  184. #define LOGINFO RouterLogInformation
  185. #define LOGWARNDATA RouterLogWarningData
  186. // Error logging
  187. #define LOGERR0(msg,err) \
  188. if (LOGLEVEL >= IPRIP_LOGGING_ERROR) \
  189. LOGERR(LOGHANDLE,IPRIPLOG_ ## msg,0,NULL,(err))
  190. #define LOGERR1(msg,a,err) \
  191. if (LOGLEVEL >= IPRIP_LOGGING_ERROR) \
  192. LOGERR(LOGHANDLE,IPRIPLOG_ ## msg,1,&(a),(err))
  193. #define LOGERR2(msg,a,b,err) \
  194. if (LOGLEVEL >= IPRIP_LOGGING_ERROR) { \
  195. LPSTR _asz[2] = { (a), (b) }; \
  196. LOGERR(LOGHANDLE,IPRIPLOG_ ## msg,2,_asz,(err)); \
  197. }
  198. #define LOGERR3(msg,a,b,c,err) \
  199. if (LOGLEVEL >= IPRIP_LOGGING_ERROR) { \
  200. LPSTR _asz[3] = { (a), (b), (c) }; \
  201. LOGERR(LOGHANDLE,IPRIPLOG_ ## msg,3,_asz,(err)); \
  202. }
  203. #define LOGERR4(msg,a,b,c,d,err) \
  204. if (LOGLEVEL >= IPRIP_LOGGING_ERROR) { \
  205. LPSTR _asz[4] = { (a), (b), (c), (d) }; \
  206. LOGERR(LOGHANDLE,IPRIPLOG_ ## msg,4,_asz,(err)); \
  207. }
  208. // Warning logging
  209. #define LOGWARN0(msg,err) \
  210. if (LOGLEVEL >= IPRIP_LOGGING_WARN) \
  211. LOGWARN(LOGHANDLE,IPRIPLOG_ ## msg,0,NULL,(err))
  212. #define LOGWARN1(msg,a,err) \
  213. if (LOGLEVEL >= IPRIP_LOGGING_WARN) \
  214. LOGWARN(LOGHANDLE,IPRIPLOG_ ## msg,1,&(a),(err))
  215. #define LOGWARN2(msg,a,b,err) \
  216. if (LOGLEVEL >= IPRIP_LOGGING_WARN) { \
  217. LPSTR _asz[2] = { (a), (b) }; \
  218. LOGWARN(LOGHANDLE,IPRIPLOG_ ## msg,2,_asz,(err)); \
  219. }
  220. #define LOGWARN3(msg,a,b,c,err) \
  221. if (LOGLEVEL >= IPRIP_LOGGING_WARN) { \
  222. LPSTR _asz[3] = { (a), (b), (c) }; \
  223. LOGWARN(LOGHANDLE,IPRIPLOG_ ## msg,3,_asz,(err)); \
  224. }
  225. #define LOGWARN4(msg,a,b,c,d,err) \
  226. if (LOGLEVEL >= IPRIP_LOGGING_WARN) { \
  227. LPSTR _asz[4] = { (a), (b), (c), (d) }; \
  228. LOGWARN(LOGHANDLE,IPRIPLOG_ ## msg,4,_asz,(err)); \
  229. }
  230. #define LOGWARNDATA2(msg,a,b,dw,buf) \
  231. if (LOGLEVEL >= IPRIP_LOGGING_WARN) { \
  232. LPSTR _asz[2] = { (a), (b) }; \
  233. LOGWARNDATA(LOGHANDLE,IPRIPLOG_ ## msg,2,_asz,(dw),(buf)); \
  234. }
  235. // Information logging
  236. #define LOGINFO0(msg,err) \
  237. if (LOGLEVEL >= IPRIP_LOGGING_INFO) \
  238. LOGINFO(LOGHANDLE,IPRIPLOG_ ## msg,0,NULL,(err))
  239. #define LOGINFO1(msg,a,err) \
  240. if (LOGLEVEL >= IPRIP_LOGGING_INFO) \
  241. LOGINFO(LOGHANDLE,IPRIPLOG_ ## msg,1,&(a),(err))
  242. #define LOGINFO2(msg,a,b,err) \
  243. if (LOGLEVEL >= IPRIP_LOGGING_INFO) { \
  244. LPSTR _asz[2] = { (a), (b) }; \
  245. LOGINFO(LOGHANDLE,IPRIPLOG_ ## msg,2,_asz,(err)); \
  246. }
  247. #define LOGINFO3(msg,a,b,c,err) \
  248. if (LOGLEVEL >= IPRIP_LOGGING_INFO) { \
  249. LPSTR _asz[3] = { (a), (b), (c) }; \
  250. LOGINFO(LOGHANDLE,IPRIPLOG_ ## msg,3,_asz,(err)); \
  251. }
  252. #define LOGINFO4(msg,a,b,c,d,err) \
  253. if (LOGLEVEL >= IPRIP_LOGGING_INFO) { \
  254. LPSTR _asz[4] = { (a), (b), (c), (d) }; \
  255. LOGINFO(LOGHANDLE,IPRIPLOG_ ## msg,4,_asz,(err)); \
  256. }
  257. //
  258. // IP address conversion macro:
  259. // calls inet_ntoa directly on a DWORD, by casting it as an IN_ADDR.
  260. //
  261. #define INET_NTOA(dw) inet_ntoa( *(PIN_ADDR)&(dw) )
  262. //
  263. // external declaration of the main thread
  264. //
  265. DWORD
  266. IpripThread(
  267. PVOID pParam
  268. );
  269. //
  270. //
  271. //
  272. DWORD
  273. QueueRipWorker(
  274. WORKERFUNCTION pFunction,
  275. PVOID pContext
  276. );
  277. BOOL
  278. EnterRipAPI(
  279. );
  280. BOOL
  281. EnterRipWorker(
  282. );
  283. VOID
  284. LeaveRipWorker(
  285. );
  286. #endif // _IPRIP_H_