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.

386 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. DWORD IG_MaxProcessInputWorkItems;
  82. LONG IG_NumProcessInputWorkItems;
  83. HANDLE IG_DllHandle;
  84. SUPPORT_FUNCTIONS IG_SupportFunctions;
  85. } IPRIP_GLOBALS, *PIPRIP_GLOBALS;
  86. //
  87. // external declaration of the global IPRIP struct
  88. //
  89. extern IPRIP_GLOBALS ig;
  90. //
  91. // memory-allocation constants and macros
  92. //
  93. #define GLOBAL_HEAP ig.IG_IpripGlobalHeap
  94. #define RIP_ALLOC(size) HeapAlloc(GLOBAL_HEAP, 0, size)
  95. #define RIP_FREE(ptr) HeapFree(GLOBAL_HEAP, 0, ptr)
  96. //
  97. // macros invoked when entering API or worker functions
  98. //
  99. #define ENTER_RIP_API() EnterRipAPI()
  100. #define ENTER_RIP_WORKER() EnterRipWorker()
  101. //
  102. // macro invoked when leaving API or worker functions
  103. //
  104. #define LEAVE_RIP_API() LeaveRipWorker()
  105. #define LEAVE_RIP_WORKER() LeaveRipWorker()
  106. //
  107. // macros used for locking and unlocking protected structures
  108. //
  109. #define ACQUIRE_GLOBAL_LOCK_EXCLUSIVE() \
  110. AcquireWriteLock(&ig.IG_RWL)
  111. #define RELEASE_GLOBAL_LOCK_EXCLUSIVE() \
  112. ReleaseWriteLock(&ig.IG_RWL)
  113. #define ACQUIRE_GLOBAL_LOCK_SHARED() \
  114. AcquireReadLock(&ig.IG_RWL)
  115. #define RELEASE_GLOBAL_LOCK_SHARED() \
  116. ReleaseReadLock(&ig.IG_RWL)
  117. #define ENTER_GLOBAL_SECTION() \
  118. EnterCriticalSection(&ig.IG_CS)
  119. #define LEAVE_GLOBAL_SECTION() \
  120. LeaveCriticalSection(&ig.IG_CS)
  121. #define ACQUIRE_IF_LOCK_EXCLUSIVE() \
  122. AcquireWriteLock(&ig.IG_IfTable->IT_RWL)
  123. #define RELEASE_IF_LOCK_EXCLUSIVE() \
  124. ReleaseWriteLock(&ig.IG_IfTable->IT_RWL)
  125. #define ACQUIRE_IF_LOCK_SHARED() \
  126. AcquireReadLock(&ig.IG_IfTable->IT_RWL)
  127. #define RELEASE_IF_LOCK_SHARED() \
  128. ReleaseReadLock(&ig.IG_IfTable->IT_RWL)
  129. #define ENTER_IF_SECTION() \
  130. EnterCriticalSection(&ig.IG_IfTable->IT_CS)
  131. #define LEAVE_IF_SECTION() \
  132. LeaveCriticalSection(&ig.IG_IfTable->IT_CS)
  133. #define ACQUIRE_PEER_LOCK_EXCLUSIVE() \
  134. AcquireWriteLock(&ig.IG_PeerTable->PT_RWL)
  135. #define RELEASE_PEER_LOCK_EXCLUSIVE() \
  136. ReleaseWriteLock(&ig.IG_PeerTable->PT_RWL)
  137. #define ACQUIRE_PEER_LOCK_SHARED() \
  138. AcquireReadLock(&ig.IG_PeerTable->PT_RWL)
  139. #define RELEASE_PEER_LOCK_SHARED() \
  140. ReleaseReadLock(&ig.IG_PeerTable->PT_RWL)
  141. #define ACQUIRE_BINDING_LOCK_EXCLUSIVE() \
  142. AcquireWriteLock(&ig.IG_BindingTable->BT_RWL)
  143. #define RELEASE_BINDING_LOCK_EXCLUSIVE() \
  144. ReleaseWriteLock(&ig.IG_BindingTable->BT_RWL)
  145. #define ACQUIRE_BINDING_LOCK_SHARED() \
  146. AcquireReadLock(&ig.IG_BindingTable->BT_RWL)
  147. #define RELEASE_BINDING_LOCK_SHARED() \
  148. ReleaseReadLock(&ig.IG_BindingTable->BT_RWL)
  149. //
  150. // constants and macros used for tracing
  151. //
  152. #define IPRIP_TRACE_ANY ((DWORD)0xFFFF0000 | TRACE_USE_MASK)
  153. #define IPRIP_TRACE_ENTER ((DWORD)0x00010000 | TRACE_USE_MASK)
  154. #define IPRIP_TRACE_LEAVE ((DWORD)0x00020000 | TRACE_USE_MASK)
  155. #define IPRIP_TRACE_TIMER ((DWORD)0x00040000 | TRACE_USE_MASK)
  156. #define IPRIP_TRACE_IF ((DWORD)0x00080000 | TRACE_USE_MASK)
  157. #define IPRIP_TRACE_ROUTE ((DWORD)0x00100000 | TRACE_USE_MASK)
  158. #define IPRIP_TRACE_SEND ((DWORD)0x00200000 | TRACE_USE_MASK)
  159. #define IPRIP_TRACE_RECEIVE ((DWORD)0x00400000 | TRACE_USE_MASK)
  160. #define IPRIP_TRACE_CONFIG ((DWORD)0x00800000 | TRACE_USE_MASK)
  161. #define IPRIP_TRACE_START ((DWORD)0x01000000 | TRACE_USE_MASK)
  162. #define IPRIP_TRACE_STOP ((DWORD)0x02000000 | TRACE_USE_MASK)
  163. #define IPRIP_TRACE_REQUEST ((DWORD)0x04000000 | TRACE_USE_MASK)
  164. #define IPRIP_TRACE_RESPONSE ((DWORD)0x08000000 | TRACE_USE_MASK)
  165. #define TRACEID ig.IG_TraceID
  166. #define TRACE0(l,a) \
  167. if (TRACEID != INVALID_TRACEID) TracePrintfEx(TRACEID, IPRIP_TRACE_ ## l, a)
  168. #define TRACE1(l,a,b) \
  169. if (TRACEID != INVALID_TRACEID) TracePrintfEx(TRACEID, IPRIP_TRACE_ ## l, a, b)
  170. #define TRACE2(l,a,b,c) \
  171. if (TRACEID != INVALID_TRACEID) TracePrintfEx(TRACEID, IPRIP_TRACE_ ## l, a, b, c)
  172. #define TRACE3(l,a,b,c,d) \
  173. if (TRACEID != INVALID_TRACEID) TracePrintfEx(TRACEID, IPRIP_TRACE_ ## l, a, b, c, d)
  174. #define TRACE4(l,a,b,c,d,e) \
  175. if (TRACEID != INVALID_TRACEID) TracePrintfEx(TRACEID, IPRIP_TRACE_ ## l, a, b, c, d, e)
  176. #define TRACE5(l,a,b,c,d,e,f) \
  177. if (TRACEID != INVALID_TRACEID) TracePrintfEx(TRACEID, IPRIP_TRACE_ ## l, a, b, c, d, e, f)
  178. #define TRACEDUMP(l,a,b,c) \
  179. TraceDumpEx(TRACEID,l,a,b,c,TRUE)
  180. //
  181. // Event logging macros
  182. //
  183. #define LOGLEVEL ig.IG_LogLevel
  184. #define LOGHANDLE ig.IG_LogHandle
  185. #define LOGERR RouterLogError
  186. #define LOGWARN RouterLogWarning
  187. #define LOGINFO RouterLogInformation
  188. #define LOGWARNDATA RouterLogWarningData
  189. // Error logging
  190. #define LOGERR0(msg,err) \
  191. if (LOGLEVEL >= IPRIP_LOGGING_ERROR) \
  192. LOGERR(LOGHANDLE,IPRIPLOG_ ## msg,0,NULL,(err))
  193. #define LOGERR1(msg,a,err) \
  194. if (LOGLEVEL >= IPRIP_LOGGING_ERROR) { \
  195. LPSTR _asz[1] = { (a) }; \
  196. LOGERR(LOGHANDLE,IPRIPLOG_ ## msg,1,_asz,(err)); \
  197. }
  198. #define LOGERR2(msg,a,b,err) \
  199. if (LOGLEVEL >= IPRIP_LOGGING_ERROR) { \
  200. LPSTR _asz[2] = { (a), (b) }; \
  201. LOGERR(LOGHANDLE,IPRIPLOG_ ## msg,2,_asz,(err)); \
  202. }
  203. #define LOGERR3(msg,a,b,c,err) \
  204. if (LOGLEVEL >= IPRIP_LOGGING_ERROR) { \
  205. LPSTR _asz[3] = { (a), (b), (c) }; \
  206. LOGERR(LOGHANDLE,IPRIPLOG_ ## msg,3,_asz,(err)); \
  207. }
  208. #define LOGERR4(msg,a,b,c,d,err) \
  209. if (LOGLEVEL >= IPRIP_LOGGING_ERROR) { \
  210. LPSTR _asz[4] = { (a), (b), (c), (d) }; \
  211. LOGERR(LOGHANDLE,IPRIPLOG_ ## msg,4,_asz,(err)); \
  212. }
  213. // Warning logging
  214. #define LOGWARN0(msg,err) \
  215. if (LOGLEVEL >= IPRIP_LOGGING_WARN) \
  216. LOGWARN(LOGHANDLE,IPRIPLOG_ ## msg,0,NULL,(err))
  217. #define LOGWARN1(msg,a,err) \
  218. if (LOGLEVEL >= IPRIP_LOGGING_WARN) { \
  219. LPSTR _asz[1] = { (a) }; \
  220. LOGWARN(LOGHANDLE,IPRIPLOG_ ## msg,1,_asz,(err)); \
  221. }
  222. #define LOGWARN2(msg,a,b,err) \
  223. if (LOGLEVEL >= IPRIP_LOGGING_WARN) { \
  224. LPSTR _asz[2] = { (a), (b) }; \
  225. LOGWARN(LOGHANDLE,IPRIPLOG_ ## msg,2,_asz,(err)); \
  226. }
  227. #define LOGWARN3(msg,a,b,c,err) \
  228. if (LOGLEVEL >= IPRIP_LOGGING_WARN) { \
  229. LPSTR _asz[3] = { (a), (b), (c) }; \
  230. LOGWARN(LOGHANDLE,IPRIPLOG_ ## msg,3,_asz,(err)); \
  231. }
  232. #define LOGWARN4(msg,a,b,c,d,err) \
  233. if (LOGLEVEL >= IPRIP_LOGGING_WARN) { \
  234. LPSTR _asz[4] = { (a), (b), (c), (d) }; \
  235. LOGWARN(LOGHANDLE,IPRIPLOG_ ## msg,4,_asz,(err)); \
  236. }
  237. #define LOGWARNDATA2(msg,a,b,dw,buf) \
  238. if (LOGLEVEL >= IPRIP_LOGGING_WARN) { \
  239. LPSTR _asz[2] = { (a), (b) }; \
  240. LOGWARNDATA(LOGHANDLE,IPRIPLOG_ ## msg,2,_asz,(dw),(buf)); \
  241. }
  242. // Information logging
  243. #define LOGINFO0(msg,err) \
  244. if (LOGLEVEL >= IPRIP_LOGGING_INFO) \
  245. LOGINFO(LOGHANDLE,IPRIPLOG_ ## msg,0,NULL,(err))
  246. #define LOGINFO1(msg,a,err) \
  247. if (LOGLEVEL >= IPRIP_LOGGING_INFO) { \
  248. LPSTR _asz[1] = { (a) }; \
  249. LOGINFO(LOGHANDLE,IPRIPLOG_ ## msg,1,_asz,(err)); \
  250. }
  251. #define LOGINFO2(msg,a,b,err) \
  252. if (LOGLEVEL >= IPRIP_LOGGING_INFO) { \
  253. LPSTR _asz[2] = { (a), (b) }; \
  254. LOGINFO(LOGHANDLE,IPRIPLOG_ ## msg,2,_asz,(err)); \
  255. }
  256. #define LOGINFO3(msg,a,b,c,err) \
  257. if (LOGLEVEL >= IPRIP_LOGGING_INFO) { \
  258. LPSTR _asz[3] = { (a), (b), (c) }; \
  259. LOGINFO(LOGHANDLE,IPRIPLOG_ ## msg,3,_asz,(err)); \
  260. }
  261. #define LOGINFO4(msg,a,b,c,d,err) \
  262. if (LOGLEVEL >= IPRIP_LOGGING_INFO) { \
  263. LPSTR _asz[4] = { (a), (b), (c), (d) }; \
  264. LOGINFO(LOGHANDLE,IPRIPLOG_ ## msg,4,_asz,(err)); \
  265. }
  266. //
  267. // IP address conversion macro:
  268. // calls inet_ntoa directly on a DWORD, by casting it as an IN_ADDR.
  269. //
  270. #define INET_NTOA(dw) inet_ntoa( *(PIN_ADDR)&(dw) )
  271. //
  272. // external declaration of the main thread
  273. //
  274. DWORD
  275. IpripThread(
  276. PVOID pParam
  277. );
  278. //
  279. //
  280. //
  281. DWORD
  282. QueueRipWorker(
  283. WORKERFUNCTION pFunction,
  284. PVOID pContext
  285. );
  286. BOOL
  287. EnterRipAPI(
  288. );
  289. BOOL
  290. EnterRipWorker(
  291. );
  292. VOID
  293. LeaveRipWorker(
  294. );
  295. #endif // _IPRIP_H_