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.

356 lines
8.7 KiB

  1. //=============================================================================
  2. // Copyright (c) 1998 Microsoft Corporation
  3. // Module Name: main.c
  4. // Abstract:
  5. //
  6. // Author: K.S.Lokesh (lokeshs@) 1-1-98
  7. //=============================================================================
  8. //
  9. // forward declarations
  10. //
  11. struct _DVMRP_IF_TABLE;
  12. struct _ASYNC_SOCKET_DATA;
  13. //-----------------------------------------------------------------------------
  14. // globals structure
  15. //-----------------------------------------------------------------------------
  16. typedef struct _GLOBALS1 {
  17. ULONG RunningStatus;
  18. ULONG InitFlags;
  19. CRITICAL_SECTION WorkItemCS;
  20. HANDLE Heap;
  21. LOCKED_LIST RtmQueue;
  22. } GLOBALS1;
  23. typedef struct _GLOBALS {
  24. HANDLE LogHandle; //logging handle
  25. DWORD TraceId; //tracing handle
  26. DWORD ActivityCount; //count of pending work items
  27. HANDLE ActivityEvent; //signal it to notify 0 work items
  28. HANDLE RtmNotifyEvent; //signal it to notify Rtm
  29. DYNAMIC_LOCKS_STORE DynamicCSStore; //global store for dynamic CS
  30. DYNAMIC_LOCKS_STORE DynamicRWLStore; //global store for dynamic RWL
  31. struct _DVMRP_IF_TABLE *pIfTable; //interface table
  32. LARGE_INTEGER CurrentTime; //keeps current 64 bit tick time
  33. HANDLE MgmDvmrpHandle; //handle returned by MGM
  34. } GLOBALS;
  35. typedef DVMRP_GLOBAL_CONFIG GLOBAL_CONFIG;
  36. typedef PDVMRP_GLOBAL_CONFIG PGLOBAL_CONFIG;
  37. typedef DVMRP_IF_CONFIG IF_CONFIG;
  38. typedef PDVMRP_IF_CONFIG PIF_CONFIG;
  39. //-----------------------------------------------------------------------------
  40. // DVMRP_IF_TABLE
  41. //-----------------------------------------------------------------------------
  42. typedef struct _DVMRP_IF_TABLE {
  43. LIST_ENTRY IfList; // in order of increasing index
  44. CRITICAL_SECTION IfList_CS; // CS protecting IfList
  45. DWORD NumInterfaces;
  46. PLIST_ENTRY IfHashTable;
  47. PDYNAMIC_RW_LOCK *aIfDRWL;
  48. CRITICAL_SECTION PeerLists_CS; // common lock for add/remove peers
  49. DWORD NumActiveIfs;
  50. } DVMRP_IF_TABLE, *PDVMRP_IF_TABLE;
  51. #define IF_HASHTABLE_SIZE 50
  52. //-----------------------------------------------------------------------------
  53. // IF_TABLE_ENTRY
  54. //-----------------------------------------------------------------------------
  55. typedef struct _IF_TABLE_ENTRY {
  56. LIST_ENTRY Link;
  57. LIST_ENTRY HTLink;
  58. DWORD IfIndex;
  59. IPADDR IpAddr;
  60. DWORD Status;
  61. DWORD CreationFlags;
  62. DWORD RefCount;
  63. PIF_CONFIG pConfig;
  64. DWORD NumAddrBound;
  65. PDVMRP_ADDR_MASK pBinding;
  66. struct _IF_INFO *pInfo;
  67. DWORD NumPeers; // peers in PeerList
  68. LIST_ENTRY PeerList; // list of peers being created
  69. LIST_ENTRY DeletedPeerList; // list of peers being deleted
  70. SOCKET Socket;
  71. struct _ASYNC_SOCKET_DATA *pSocketData;
  72. RTM_ENTITY_HANDLE RtmHandle; // register with Rtm
  73. } IF_TABLE_ENTRY, *PIF_TABLE_ENTRY;
  74. #define IF_CREATED_FLAG 0x00000001
  75. #define IF_BOUND_FLAG 0x00000002
  76. #define IF_ENABLED_FLAG 0x00000004
  77. #define IF_ACTIVATED_FLAG 0x00000008
  78. #define IF_DELETED_FLAG 0x80000000
  79. #define IS_IF_BOUND(pite) \
  80. ((pite)->Status&IF_BOUND_FLAG)
  81. #define IS_IF_ENABLED_BY_RTRMGR(pite) \
  82. ((pite)->Status&IF_ENABLED_FLAG)
  83. #define IS_IF_ENABLED_IN_CONFIG(pite) \
  84. (IS_DVMRP_IF_ENABLED_FLAG_SET((pite)->pConfig->Flags))
  85. #define IS_IF_ENABLED(pite) \
  86. ( IS_IF_ENABLED_BY_RTRMGR(pite) && IS_IF_ENABLED_IN_CONFIG(pite) )
  87. #define IS_IF_ENABLED_BOUND(pite) \
  88. (IS_IF_ENABLED(pite)&&IS_IF_BOUND(pite))
  89. #define IS_IF_DELETED(pite) \
  90. ((pite)->Status&IF_DELETED_FLAG)
  91. #define IS_IF_ACTIVATED(pite) \
  92. ( !((pite)->Status&IF_DELETED_FLAG) \
  93. && ((pite)->Status & IF_ACTIVATED_FLAG) )
  94. #define IF_FLAGS_SOCKETS_CREATED 0x00000001
  95. #define IF_FLAGS_PROTO_REGISTERED_WITH_MGM 0x00000002
  96. #define IF_FLAGS_IF_REGISTERED_WITH_MGM 0x00000004
  97. //-----------------------------------------------------------------------------
  98. // IF_INFO
  99. //-----------------------------------------------------------------------------
  100. typedef struct _IF_INFO {
  101. LONGLONG TimeWhenActivated;
  102. } IF_INFO, *PIF_INFO;
  103. //-----------------------------------------------------------------------------
  104. // type definitions for event message queue
  105. //-----------------------------------------------------------------------------
  106. typedef struct _EVENT_QUEUE_ENTRY {
  107. ROUTING_PROTOCOL_EVENTS EventType;
  108. MESSAGE Msg;
  109. LIST_ENTRY Link;
  110. } EVENT_QUEUE_ENTRY, *PEVENT_QUEUE_ENTRY;
  111. //
  112. // extern variables
  113. //
  114. extern GLOBALS Globals;
  115. extern GLOBALS1 Globals1;
  116. extern GLOBAL_CONFIG GlobalConfig;
  117. #define G_pIfTable (Globals.pIfTable)
  118. //
  119. // defines
  120. //
  121. //-----------------------------------------------------------------------------
  122. // #defines for global structure
  123. //-----------------------------------------------------------------------------
  124. //
  125. // various codes describing states of dvmrp
  126. //
  127. typedef enum {
  128. DVMRP_STATUS_STARTING = 100,
  129. DVMRP_STATUS_RUNNING = 101,
  130. DVMRP_STATUS_STOPPING = 102,
  131. DVMRP_STATUS_STOPPED = 103
  132. } DVMRP_STATUS_CODE;
  133. //
  134. // WorkItemCS lock macros
  135. //
  136. #define ACQUIRE_WORKITEM_LOCK(proc) EnterCriticalSection(&Globals1.WorkItemCS)
  137. #define RELEASE_WORKITEM_LOCK(proc) LeaveCriticalSection(&Globals1.WorkItemCS)
  138. //-----------------------------------------------------------------------------
  139. // #defines for global config
  140. //-----------------------------------------------------------------------------
  141. //-----------------------------------------------------------------------------
  142. // macros for IfTable
  143. //-----------------------------------------------------------------------------
  144. #define IF_HASH_VALUE(_index) ((_index) % IF_HASHTABLE_SIZE)
  145. #define GET_IF_HASH_BUCKET(Index) \
  146. &G_pIfTable->IfHashTable[IF_HASH_VALUE(IfIndex)];
  147. // macros for If DRW lock
  148. #define ACQUIRE_IF_LOCK_EXCLUSIVE(_IfIndex, _proc) \
  149. AcquireDynamicRWLock( \
  150. &G_pIfTable->aIfDRWL[IF_HASH_VALUE(_IfIndex)], \
  151. LOCK_MODE_WRITE, &Globals.DynamicRWLStore)
  152. #define RELEASE_IF_LOCK_EXCLUSIVE(_IfIndex, _proc) \
  153. ReleaseDynamicRWLock( \
  154. &G_pIfTable->aIfDRWL[IF_HASH_VALUE(_IfIndex)],\
  155. LOCK_MODE_WRITE, &Globals.DynamicRWLStore)
  156. #define ACQUIRE_IF_LOCK_SHARED(_IfIndex, _proc) \
  157. AcquireDynamicRWLock( \
  158. &G_pIfTable->aIfDRWL[IF_HASH_VALUE(_IfIndex)],\
  159. LOCK_MODE_READ, &Globals.DynamicRWLStore)
  160. #define RELEASE_IF_LOCK_SHARED(_IfIndex, _proc) \
  161. ReleaseDynamicRWLock( \
  162. &G_pIfTable->aIfDRWL[IF_HASH_VALUE(_IfIndex)], \
  163. LOCK_MODE_READ, &Globals.DynamicRWLStore)
  164. // macros for IfList_CS lock
  165. #define ACQUIRE_IF_LIST_LOCK(_proc) \
  166. ENTER_CRITICAL_SECTION(&G_pIfTable->IfList_CS, "G_IfListCS", _proc);
  167. #define RELEASE_IF_LIST_LOCK(_proc) \
  168. LEAVE_CRITICAL_SECTION(&G_pIfTable->IfList_CS, "G_IfListCS", _proc);
  169. // macros for PeerLists_CS lock (see in peer.h)
  170. //
  171. // local prototypes
  172. //
  173. DWORD
  174. WINAPI
  175. StartProtocol(
  176. IN HANDLE hRtmNotifyEvent,
  177. IN PSUPPORT_FUNCTIONS pSupportFunctions,
  178. IN PVOID pGlobalConfig,
  179. IN ULONG ulStructureVersion,
  180. IN ULONG ulStructureSize,
  181. IN ULONG ulStructureCount
  182. );
  183. DWORD
  184. APIENTRY
  185. StartComplete(
  186. VOID
  187. );
  188. DWORD
  189. APIENTRY
  190. StopProtocol(
  191. VOID
  192. );
  193. DWORD
  194. WINAPI
  195. GetGlobalInfo(
  196. IN OUT PVOID pvConfig,
  197. IN OUT PDWORD pdwSize,
  198. IN OUT PULONG pulStructureVersion,
  199. IN OUT PULONG pulStructureSize,
  200. IN OUT PULONG pulStructureCount
  201. );
  202. DWORD
  203. WINAPI
  204. SetGlobalInfo(
  205. IN PVOID pvConfig,
  206. IN ULONG ulStructureVersion,
  207. IN ULONG ulStructureSize,
  208. IN ULONG ulStructureCount
  209. );
  210. DWORD
  211. APIENTRY
  212. GetEventMessage(
  213. OUT ROUTING_PROTOCOL_EVENTS *pEventType,
  214. OUT PMESSAGE pMessage
  215. );
  216. DWORD
  217. EnqueueEvent(
  218. PLOCKED_LIST pQueue,
  219. ROUTING_PROTOCOL_EVENTS EventType,
  220. MESSAGE Msg
  221. );
  222. DWORD
  223. DequeueEvent(
  224. PLOCKED_LIST pQueue,
  225. ROUTING_PROTOCOL_EVENTS *pEventType,
  226. PMESSAGE pResult
  227. );
  228. BOOL
  229. DllStartup(
  230. );
  231. BOOL
  232. DllCleanup(
  233. );
  234. VOID
  235. ProtocolCleanup(
  236. );
  237. DWORD
  238. ValidateGlobalConfig(
  239. PDVMRP_GLOBAL_CONFIG pGlobalConfig,
  240. DWORD StructureSize
  241. );