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.

417 lines
7.8 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. cxinit.c
  5. Abstract:
  6. Initialization code for the Cluster Network Driver.
  7. Author:
  8. Mike Massa (mikemas) January 3, 1997
  9. Revision History:
  10. Who When What
  11. -------- -------- ----------------------------------------------
  12. mikemas 01-03-97 created
  13. Notes:
  14. --*/
  15. #include "precomp.h"
  16. #pragma hdrstop
  17. #include "cxinit.tmh"
  18. //
  19. // Tdi Data
  20. //
  21. HANDLE CxTdiRegistrationHandle = NULL;
  22. HANDLE CxTdiPnpBindingHandle = NULL;
  23. //
  24. // FIPS function table
  25. //
  26. HANDLE CxFipsDriverHandle = NULL;
  27. FIPS_FUNCTION_TABLE CxFipsFunctionTable;
  28. #ifdef ALLOC_PRAGMA
  29. #pragma alloc_text(INIT, CxLoad)
  30. #pragma alloc_text(PAGE, CxUnload)
  31. #pragma alloc_text(PAGE, CxInitialize)
  32. #pragma alloc_text(PAGE, CxShutdown)
  33. #endif // ALLOC_PRAGMA
  34. //
  35. // Routines
  36. //
  37. NTSTATUS
  38. CxLoad(
  39. IN PUNICODE_STRING RegistryPath
  40. )
  41. /*++
  42. Routine Description:
  43. Driver load routine for the cluster transport. Initializes all
  44. transport data structures.
  45. Arguments:
  46. RegistryPath - The driver's registry key.
  47. Return Value:
  48. An NT status code.
  49. --*/
  50. {
  51. NTSTATUS status;
  52. UNICODE_STRING deviceName;
  53. TDI_CLIENT_INTERFACE_INFO info;
  54. IF_CNDBG(CN_DEBUG_INIT) {
  55. CNPRINT(("[CX] Loading...\n"));
  56. }
  57. TdiInitialize();
  58. //
  59. // Register our device object with TDI.
  60. //
  61. RtlInitUnicodeString(&deviceName, DD_CDP_DEVICE_NAME);
  62. status = TdiRegisterDeviceObject(&deviceName, &CxTdiRegistrationHandle);
  63. if (!NT_SUCCESS(status)) {
  64. CNPRINT((
  65. "[CX] Unable to register device %ws with TDI, status %lx\n",
  66. deviceName.Buffer,
  67. status
  68. ));
  69. return(status);
  70. }
  71. //
  72. // Register for PnP events.
  73. //
  74. RtlZeroMemory(&info, sizeof(info));
  75. info.MajorTdiVersion = 2;
  76. info.MinorTdiVersion = 0;
  77. info.ClientName = &deviceName;
  78. info.AddAddressHandlerV2 = CxTdiAddAddressHandler;
  79. info.DelAddressHandlerV2 = CxTdiDelAddressHandler;
  80. status = TdiRegisterPnPHandlers(
  81. &info,
  82. sizeof(info),
  83. &CxTdiPnpBindingHandle
  84. );
  85. if (!NT_SUCCESS(status)) {
  86. CNPRINT((
  87. "[CX] Unable to register for TDI PnP events, status %lx\n",
  88. status
  89. ));
  90. return(status);
  91. }
  92. //
  93. // Register for WMI NDIS media status events.
  94. //
  95. status = CxWmiPnpLoad();
  96. if (!NT_SUCCESS(status)) {
  97. CNPRINT((
  98. "[CX] Failed to initialize WMI PnP event handlers, "
  99. "status %lx\n",
  100. status
  101. ));
  102. }
  103. //
  104. // Get the FIPS function table. Hold onto the FIPS driver
  105. // handle so that the FIPS driver cannot unload.
  106. //
  107. status = CnpOpenDevice(FIPS_DEVICE_NAME, &CxFipsDriverHandle);
  108. if (NT_SUCCESS(status)) {
  109. status = CnpZwDeviceControl(
  110. CxFipsDriverHandle,
  111. IOCTL_FIPS_GET_FUNCTION_TABLE,
  112. NULL,
  113. 0,
  114. &CxFipsFunctionTable,
  115. sizeof(CxFipsFunctionTable)
  116. );
  117. if (!NT_SUCCESS(status)) {
  118. IF_CNDBG(CN_DEBUG_INIT) {
  119. CNPRINT(("[CNP] Failed to fill FIPS function "
  120. "table, status %x.\n", status));
  121. }
  122. }
  123. } else {
  124. CxFipsDriverHandle = NULL;
  125. IF_CNDBG(CN_DEBUG_INIT) {
  126. CNPRINT(("[CNP] Failed to open FIPS device, "
  127. "status %x.\n", status));
  128. }
  129. }
  130. if (status != STATUS_SUCCESS) {
  131. return(status);
  132. }
  133. status = CnpLoadNodes();
  134. if (status != STATUS_SUCCESS) {
  135. return(status);
  136. }
  137. status = CnpLoadNetworks();
  138. if (status != STATUS_SUCCESS) {
  139. return(status);
  140. }
  141. status = CnpLoad();
  142. if (status != STATUS_SUCCESS) {
  143. return(status);
  144. }
  145. status = CcmpLoad();
  146. if (status != STATUS_SUCCESS) {
  147. return(status);
  148. }
  149. status = CxInitializeHeartBeat();
  150. if (status != STATUS_SUCCESS) {
  151. return(status);
  152. }
  153. status = CdpLoad();
  154. if (status != STATUS_SUCCESS) {
  155. return(status);
  156. }
  157. IF_CNDBG(CN_DEBUG_INIT) {
  158. CNPRINT(("[CX] Loaded.\n"));
  159. }
  160. return(STATUS_SUCCESS);
  161. } // CxLoad
  162. VOID
  163. CxUnload(
  164. VOID
  165. )
  166. /*++
  167. Routine Description:
  168. Called when the Cluster Network driver is unloading. Frees all resources
  169. allocated by the Cluster Transport.
  170. The Transport is guaranteed not to receive any more user-mode requests,
  171. membership send requests, or membership events at the time
  172. this routine is called.
  173. A shutdown of the Cluster Network driver has already occured when this
  174. routine is called.
  175. Arguments:
  176. None.
  177. Return Value:
  178. None
  179. Notes:
  180. This routine MUST be callable even if CxLoad() has not yet been
  181. called.
  182. --*/
  183. {
  184. PAGED_CODE();
  185. IF_CNDBG(CN_DEBUG_INIT) {
  186. CNPRINT(("[CX] Unloading...\n"));
  187. }
  188. CxUnreserveClusnetEndpoint();
  189. CdpUnload();
  190. CxUnloadHeartBeat();
  191. CcmpUnload();
  192. CnpUnload();
  193. CxWmiPnpUnload();
  194. if (CxFipsDriverHandle != NULL) {
  195. ZwClose(CxFipsDriverHandle);
  196. CxFipsDriverHandle = NULL;
  197. }
  198. if (CxTdiPnpBindingHandle != NULL) {
  199. TdiDeregisterPnPHandlers(CxTdiPnpBindingHandle);
  200. CxTdiPnpBindingHandle = NULL;
  201. }
  202. if (CxTdiRegistrationHandle != NULL) {
  203. TdiDeregisterDeviceObject(CxTdiRegistrationHandle);
  204. CxTdiRegistrationHandle = NULL;
  205. }
  206. IF_CNDBG(CN_DEBUG_INIT) {
  207. CNPRINT(("[CX] Unloaded.\n"));
  208. }
  209. return;
  210. } // CxUnload
  211. NTSTATUS
  212. CxInitialize(
  213. VOID
  214. )
  215. /*++
  216. Routine Description:
  217. Initialization routine for the Cluster Transport.
  218. Called when the Membership Manager is starting up.
  219. Enables operation of the transport.
  220. Arguments:
  221. None.
  222. Return Value:
  223. An NT status code.
  224. --*/
  225. {
  226. NTSTATUS status;
  227. IF_CNDBG(CN_DEBUG_INIT) {
  228. CNPRINT(("[CX] Initializing...\n"));
  229. }
  230. EventEpoch = 0;
  231. CxMulticastEpoch = 0;
  232. //
  233. // Initialize our FIPS-seeded salt generator.
  234. //
  235. status = CnpInitializeSaltGenerator();
  236. if (status != STATUS_SUCCESS) {
  237. IF_CNDBG(CN_DEBUG_INIT) {
  238. CNPRINT(("[CNP] Failed to initialize FIPS-seeded "
  239. "random number generator, status %x.\n",
  240. status));
  241. }
  242. return(status);
  243. }
  244. status = CnpInitializeNodes();
  245. if (!NT_SUCCESS(status)) {
  246. return(status);
  247. }
  248. status = CnpInitializeNetworks();
  249. if (!NT_SUCCESS(status)) {
  250. return(status);
  251. }
  252. status = CxWmiPnpInitialize();
  253. if (!NT_SUCCESS(status)) {
  254. return(status);
  255. }
  256. IF_CNDBG(CN_DEBUG_INIT) {
  257. CNPRINT(("[CX] Initialized...\n"));
  258. }
  259. return(STATUS_SUCCESS);
  260. } // CxInitialize
  261. VOID
  262. CxShutdown(
  263. VOID
  264. )
  265. /*++
  266. Routine Description:
  267. Terminates operation of the Cluster Transport.
  268. Called when the Membership Manager is shutting down.
  269. Arguments:
  270. None.
  271. Return Value:
  272. None.
  273. --*/
  274. {
  275. IF_CNDBG(CN_DEBUG_INIT) {
  276. CNPRINT(("[CX] Shutting down...\n"));
  277. }
  278. CnpStopHeartBeats();
  279. CxWmiPnpShutdown();
  280. CnpShutdownNetworks();
  281. CnpShutdownNodes();
  282. IF_CNDBG(CN_DEBUG_INIT) {
  283. CNPRINT(("[CX] Shutdown complete...\n"));
  284. }
  285. return;
  286. } // CxShutdown