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.

801 lines
18 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. clusnet.h
  5. Abstract:
  6. Top-level, common header file for the Cluster Network Driver.
  7. Defines common driver structures.
  8. Author:
  9. Mike Massa (mikemas) January 3, 1997
  10. Revision History:
  11. Who When What
  12. -------- -------- ----------------------------------------------
  13. mikemas 01-03-97 created
  14. Notes:
  15. --*/
  16. #ifndef _CLUSNET_INCLUDED_
  17. #define _CLUSNET_INCLUDED_
  18. #define _NTDDK_ // [HACKHACK] to make ProbeForRead work. Better to include ntddk instead of ntos //
  19. #define WMI_TRACING 1
  20. #include <ntos.h>
  21. #include <zwapi.h>
  22. #include <clusdef.h>
  23. #include <ntddcnet.h>
  24. #include <cnettest.h>
  25. #include <ntemgmt.h>
  26. #include <nbtmgmt.h>
  27. #include <memlog.h>
  28. #if defined(WMI_TRACING)
  29. # include "cnwmi.h"
  30. #endif
  31. //
  32. // Constants
  33. //
  34. #define CN_POOL_TAG 'tnSC'
  35. #define CDP_DEFAULT_IRP_STACK_SIZE 4
  36. #define CN_DEFAULT_IRP_STACK_SIZE 4
  37. //
  38. // Pool Macros
  39. //
  40. #define CnAllocatePool(_bufsize) \
  41. ExAllocatePoolWithTag(NonPagedPool, (_bufsize), CN_POOL_TAG);
  42. #define CnAllocatePoolWithQuota(_bufsize) \
  43. ExAllocatePoolWithQuotaTag(NonPagedPool, (_bufsize), CN_POOL_TAG);
  44. #define CnFreePool(_ptr) \
  45. ExFreePool((_ptr))
  46. #define ROUND32(_value) ( ((_value) + 3) & ~(0x3) )
  47. //
  48. // Init/Cleanup synchronization
  49. //
  50. typedef enum {
  51. CnStateShutdown = 0,
  52. CnStateShutdownPending = 1,
  53. CnStateInitializePending = 2,
  54. CnStateInitialized = 3
  55. } CN_STATE;
  56. // Clusnet Heart Beat Period definintion Removed from clusnet\xport\Chbeat.c
  57. // This is it's proper place.
  58. //
  59. // heart beat period in millisecs
  60. //
  61. #define HEART_BEAT_PERIOD 600
  62. //
  63. // Node ID validation macro
  64. //
  65. #define CnIsValidNodeId(_id) ( ((_id) >= CnMinValidNodeId) && \
  66. ((_id) <= CnMaxValidNodeId) )
  67. //
  68. // Lock acquisition ranking. Locks must be acquired in this order to
  69. // prevent deadlocks. Components really should avoid calling outside
  70. // of themselves while holding locks.
  71. //
  72. #define CN_IOCANCEL_LOCK 0x00000001
  73. #define CN_IOCANCEL_LOCK_MAX 0x00000001
  74. // MM locks
  75. #define MM_RGP_LOCK 0x00000010
  76. #define MM_CALLBACK_LOCK 0x00000020
  77. // CX Locks
  78. #define CX_PRECEEDING_LOCK_RANGE 0x0000FFFF
  79. #define CX_LOCK_RANGE 0xFFFF0000
  80. #define CX_ADDROBJ_TABLE_LOCK 0x00010000
  81. #define CX_ADDROBJ_TABLE_LOCK_MAX 0x0001FFFF
  82. #define CX_ADDROBJ_LOCK 0x00020000
  83. #define CX_ADDROBJ_LOCK_MAX 0x0003FFFF
  84. #define CNP_PRECEEDING_LOCK_RANGE 0x00FFFFFF
  85. #define CNP_LOCK_RANGE 0xFF000000
  86. #define CNP_NODE_TABLE_LOCK 0x01000000
  87. #define CNP_NODE_TABLE_LOCK_MAX 0x01FFFFFF
  88. #define CNP_NODE_OBJECT_LOCK 0x02000000
  89. #define CNP_NODE_OBJECT_LOCK_MAX 0x03FFFFFF
  90. #define CNP_NETWORK_LIST_LOCK 0x04000000
  91. #define CNP_NETWORK_LIST_LOCK_MAX 0x07FFFFFF
  92. #define CNP_NETWORK_OBJECT_LOCK 0x08000000
  93. #define CNP_NETWORK_OBJECT_LOCK_MAX 0x0FFFFFFF
  94. #define CNP_HBEAT_LOCK 0x10000000
  95. #define CNP_EVENT_LOCK_PRECEEDING 0x1FFFFFFF
  96. #define CNP_EVENT_LOCK 0x20000000
  97. #define CNP_EVENT_LOCK_MAX 0x3FFFFFFF
  98. #define CNP_SEC_CTXT_LOCK 0x20000000
  99. //
  100. // Debugging Definitions
  101. //
  102. #if DBG
  103. #define CNPRINT(many_args) DbgPrint many_args
  104. extern ULONG CnDebug;
  105. #define CN_DEBUG_INIT 0x00000001
  106. #define CN_DEBUG_OPEN 0x00000002
  107. #define CN_DEBUG_CLEANUP 0x00000004
  108. #define CN_DEBUG_CLOSE 0x00000008
  109. #define CN_DEBUG_IRP 0x00000010
  110. #define CN_DEBUG_NODEOBJ 0x00000020
  111. #define CN_DEBUG_NETOBJ 0x00000040
  112. #define CN_DEBUG_IFOBJ 0x00000080
  113. #define CN_DEBUG_CONFIG 0x00000100
  114. #define CN_DEBUG_CNPSEND 0x00000200
  115. #define CN_DEBUG_CNPRECV 0x00000400
  116. #define CN_DEBUG_CNPREF 0x00000800
  117. #define CN_DEBUG_EVENT 0x00001000
  118. #define CN_DEBUG_MMSTATE 0x00002000
  119. #define CN_DEBUG_HBEATS 0x00004000
  120. #define CN_DEBUG_POISON 0x00008000
  121. #define CN_DEBUG_CDPSEND 0x00010000
  122. #define CN_DEBUG_CDPRECV 0x00020000
  123. #define CN_DEBUG_CCMPSEND 0x00040000
  124. #define CN_DEBUG_CCMPRECV 0x00080000
  125. #define CN_DEBUG_ADDROBJ 0x00100000
  126. #define CN_DEBUG_INFO 0x00200000
  127. #define CN_DEBUG_NTE 0x00400000
  128. #define CN_DEBUG_NDIS 0x00800000
  129. #define CN_DEBUG_RGP 0x10000000
  130. #define CN_DEBUG_CMM 0x20000000
  131. #define CN_DEBUG_CMMMSG 0x40000000
  132. #define CN_DEBUG_CMMTIMERQ 0x80000000
  133. #define IF_CNDBG(flag) if (CnDebug & flag)
  134. VOID
  135. CnAssertBreak(
  136. PCHAR FailedStatement,
  137. PCHAR FileName,
  138. ULONG LineNumber
  139. );
  140. #define CnAssert(_statement) \
  141. if (!(_statement)) CnAssertBreak(#_statement, __FILE__, __LINE__)
  142. #define CN_SIGNATURE_FIELD ULONG Signature;
  143. #define CN_INIT_SIGNATURE(pstruct, sig) ((pstruct)->Signature = (sig))
  144. #define CN_ASSERT_SIGNATURE(pstruct, sig) CnAssert( (pstruct)->Signature == \
  145. (sig) )
  146. #define CN_DBGCHECK DbgBreakPoint()
  147. typedef struct {
  148. KSPIN_LOCK SpinLock;
  149. ULONG Rank;
  150. } CN_LOCK, *PCN_LOCK;
  151. typedef KIRQL CN_IRQL, *PCN_IRQL;
  152. ULONG
  153. CnGetCpuLockMask(
  154. VOID
  155. );
  156. VOID
  157. CnVerifyCpuLockMask(
  158. IN ULONG RequiredLockMask,
  159. IN ULONG ForbiddenLockMask,
  160. IN ULONG MaximumLockMask
  161. );
  162. VOID
  163. CnInitializeLock(
  164. PCN_LOCK Lock,
  165. ULONG Rank
  166. );
  167. VOID
  168. CnAcquireLock(
  169. IN PCN_LOCK Lock,
  170. OUT PCN_IRQL Irql
  171. );
  172. VOID
  173. CnReleaseLock(
  174. IN PCN_LOCK Lock,
  175. IN CN_IRQL Irql
  176. );
  177. VOID
  178. CnAcquireLockAtDpc(
  179. IN PCN_LOCK Lock
  180. );
  181. VOID
  182. CnReleaseLockFromDpc(
  183. IN PCN_LOCK Lock
  184. );
  185. VOID
  186. CnMarkIoCancelLockAcquired(
  187. VOID
  188. );
  189. VOID
  190. CnAcquireCancelSpinLock(
  191. OUT PCN_IRQL Irql
  192. );
  193. VOID
  194. CnReleaseCancelSpinLock(
  195. IN CN_IRQL Irql
  196. );
  197. #else // DBG
  198. #define CNPRINT(many_args)
  199. #define IF_CNDBG(flag) if (0)
  200. #define CnAssert(_statement)
  201. #define CN_SIGNATURE_FIELD
  202. #define CN_INIT_SIGNATURE(pstruct, sig)
  203. #define CN_ASSERT_SIGNATURE(pstruct, sig)
  204. #define CN_DBGCHECK
  205. typedef KSPIN_LOCK CN_LOCK, *PCN_LOCK;
  206. typedef KIRQL CN_IRQL, *PCN_IRQL;
  207. #define CnVerifyCpuLockMask(p1, p2, p3)
  208. #define CnInitializeLock(_plock, _rank) KeInitializeSpinLock((_plock))
  209. #define CnAcquireLock(_plock, _pirql) KeAcquireSpinLock((_plock), (_pirql))
  210. #define CnReleaseLock(_plock, _irql) KeReleaseSpinLock((_plock), (_irql))
  211. #define CnAcquireLockAtDpc(_plock) KeAcquireSpinLockAtDpcLevel((_plock))
  212. #define CnReleaseLockFromDpc(_plock) KeReleaseSpinLockFromDpcLevel((_plock))
  213. #define CnMarkIoCancelLockAcquired()
  214. #define CnAcquireCancelSpinLock(_pirql) IoAcquireCancelSpinLock((_pirql))
  215. #define CnReleaseCancelSpinLock(_irql) IoReleaseCancelSpinLock((_irql))
  216. #endif // DBG
  217. //
  218. // File Object Context Structure
  219. //
  220. // A pointer to this structure is stored in FileObject->FsContext.
  221. // It maintains context information about open file objects.
  222. //
  223. typedef struct {
  224. //
  225. // used by event mechanism to find interested consumers when a new event
  226. // is posted.
  227. //
  228. LIST_ENTRY Linkage;
  229. CN_SIGNATURE_FIELD
  230. PFILE_OBJECT FileObject;
  231. LONG ReferenceCount;
  232. UCHAR CancelIrps;
  233. UCHAR ShutdownOnClose;
  234. UCHAR Pad[2];
  235. KEVENT CleanupEvent;
  236. //
  237. // list of event context blocks representing events to be delivered to
  238. // consumer
  239. //
  240. LIST_ENTRY EventList;
  241. //
  242. // pending IRP that is completed when a new event is issued
  243. //
  244. PIRP EventIrp;
  245. //
  246. // event types in which this consumer is interested
  247. //
  248. ULONG EventMask;
  249. //
  250. // routine used to notify kernel consumers of new events
  251. //
  252. CLUSNET_EVENT_CALLBACK_ROUTINE KmodeEventCallback;
  253. } CN_FSCONTEXT, *PCN_FSCONTEXT;
  254. #define CN_CONTROL_CHANNEL_SIG 'lrtc'
  255. //
  256. // Generic Resource Management Package
  257. //
  258. //
  259. // Forward Declarations
  260. //
  261. typedef struct _CN_RESOURCE *PCN_RESOURCE;
  262. typedef struct _CN_RESOURCE_POOL *PCN_RESOURCE_POOL;
  263. /*++
  264. PCN_RESOURCE
  265. CnCreateResourceRoutine(
  266. IN PVOID Context
  267. );
  268. Routine Description:
  269. Creates a new instance of a resource to be managed by a resource pool.
  270. Arguments:
  271. Context - The context value specified when the pool was initialized.
  272. Return Value:
  273. A pointer to the newly created resource if successful.
  274. NULL if unsuccessful.
  275. --*/
  276. typedef
  277. PCN_RESOURCE
  278. (*PCN_CREATE_RESOURCE_ROUTINE)(
  279. IN PVOID PoolContext
  280. );
  281. /*++
  282. PCN_RESOURCE
  283. CnDeleteResourceRoutine(
  284. IN PCN_RESOURCE Resource
  285. );
  286. Routine Description:
  287. Destroys an instance of a resource allocated by
  288. CnCreateResourceRoutine().
  289. Arguments:
  290. Resource - A pointer to the resource to destroy.
  291. Return Value:
  292. None.
  293. --*/
  294. typedef
  295. VOID
  296. (*PCN_DELETE_RESOURCE_ROUTINE) (
  297. IN PCN_RESOURCE Resource
  298. );
  299. //
  300. // Resource Pool Structure
  301. //
  302. typedef struct _CN_RESOURCE_POOL {
  303. CN_SIGNATURE_FIELD
  304. SLIST_HEADER ResourceList;
  305. KSPIN_LOCK ResourceListLock;
  306. USHORT Depth;
  307. USHORT Pad;
  308. PCN_CREATE_RESOURCE_ROUTINE CreateRoutine;
  309. PVOID CreateContext;
  310. PCN_DELETE_RESOURCE_ROUTINE DeleteRoutine;
  311. } CN_RESOURCE_POOL;
  312. #define CN_RESOURCE_POOL_SIG 'lpnc'
  313. //
  314. // Resource Structure
  315. //
  316. typedef struct _CN_RESOURCE {
  317. SLIST_ENTRY Linkage;
  318. CN_SIGNATURE_FIELD
  319. PCN_RESOURCE_POOL Pool;
  320. PVOID Context;
  321. } CN_RESOURCE;
  322. #define CN_RESOURCE_SIG 'ernc'
  323. //
  324. // Routines for operating on Resource Pools
  325. //
  326. /*++
  327. VOID
  328. CnInitializeResourcePool(
  329. IN PCN_RESOURCE_POOL Pool,
  330. IN USHORT Depth,
  331. IN PCN_CREATE_RESOURCE_ROUTINE CreateRoutine,
  332. IN PVOID CreateContext,
  333. IN PCN_DELETE_RESOURCE_ROUTINE DeleteRoutine,
  334. );
  335. Routine Description:
  336. Initializes a resource pool structure.
  337. Arguments:
  338. Pool - A pointer to the pool structure to initialize.
  339. Depth - The maximum number of items to cache in the pool.
  340. CreateRoutine - A pointer to the routine to call to create a new
  341. instance of a resource.
  342. CreateContext - A context value to pass as an argument to
  343. the CreateRoutine.
  344. DeleteRoutine - A pointer to the routine to call to destroy an instance
  345. of a resource created by CreateRoutine.
  346. Return Value
  347. None.
  348. --*/
  349. #define CnInitializeResourcePool(_pool, _depth, _creatertn, _createctx, _deletertn) \
  350. { \
  351. CN_INIT_SIGNATURE(_pool, CN_RESOURCE_POOL_SIG); \
  352. ExInitializeSListHead(&((_pool)->ResourceList)); \
  353. KeInitializeSpinLock(&((_pool)->ResourceListLock)); \
  354. (_pool)->Depth = _depth; \
  355. (_pool)->CreateRoutine = _creatertn; \
  356. (_pool)->CreateContext = _createctx; \
  357. (_pool)->DeleteRoutine = _deletertn; \
  358. }
  359. VOID
  360. CnDrainResourcePool(
  361. IN PCN_RESOURCE_POOL Pool
  362. );
  363. PCN_RESOURCE
  364. CnAllocateResource(
  365. IN PCN_RESOURCE_POOL Pool
  366. );
  367. VOID
  368. CnFreeResource(
  369. PCN_RESOURCE Resource
  370. );
  371. /*++
  372. VOID
  373. CnSetResourceContext(
  374. IN PCN_RESOURCE Resource,
  375. IN PVOID ContextValue
  376. );
  377. Routine Description:
  378. Sets the context value for a Resource.
  379. Arguments:
  380. Resource - A pointer to the resource on which to operate.
  381. Return Value:
  382. A pointer to the context value associated with the resource.
  383. --*/
  384. #define CnSetResourceContext(_res, _value) ((_res)->Context = (_value))
  385. /*++
  386. PVOID
  387. CnGetResourceContext(
  388. IN PCN_RESOURCE Resource
  389. );
  390. Routine Description:
  391. Retrieves the context value from a Resource.
  392. Arguments:
  393. Resource - A pointer to the resource on which to operate.
  394. Return Value:
  395. A pointer to the context value associated with the resource.
  396. --*/
  397. #define CnGetResourceContext(_res) ((_res)->Context)
  398. //
  399. // Init/Cleanup Function Prototypes
  400. //
  401. NTSTATUS
  402. CnInitialize(
  403. IN CL_NODE_ID LocalNodeId,
  404. IN ULONG MaxNodes
  405. );
  406. NTSTATUS
  407. CnShutdown(
  408. VOID
  409. );
  410. BOOLEAN
  411. CnHaltOperation(
  412. IN PKEVENT ShutdownEvent OPTIONAL
  413. );
  414. NTSTATUS
  415. CnCloseProcessHandle(
  416. HANDLE Handle
  417. );
  418. VOID
  419. CnEnableHaltProcessing(
  420. VOID
  421. );
  422. //
  423. // Irp Handling Routines
  424. //
  425. NTSTATUS
  426. CnDispatch(
  427. IN PDEVICE_OBJECT DeviceObject,
  428. IN PIRP Irp
  429. );
  430. NTSTATUS
  431. CnDispatchInternalDeviceControl(
  432. IN PDEVICE_OBJECT DeviceObject,
  433. IN PIRP Irp
  434. );
  435. NTSTATUS
  436. CnDispatchDeviceControl(
  437. IN PDEVICE_OBJECT DeviceObject,
  438. IN PIRP Irp
  439. );
  440. #if DBG
  441. #define CnReferenceFsContext(_fsc) \
  442. { \
  443. LONG newValue = InterlockedIncrement(&((_fsc)->ReferenceCount)); \
  444. CnAssert(newValue > 1); \
  445. }
  446. #else // DBG
  447. #define CnReferenceFsContext(_fsc) \
  448. (VOID) InterlockedIncrement( &((_fsc)->ReferenceCount) )
  449. #endif // DBG
  450. VOID
  451. CnDereferenceFsContext(
  452. PCN_FSCONTEXT FsContext
  453. );
  454. NTSTATUS
  455. CnMarkRequestPending(
  456. PIRP Irp,
  457. PIO_STACK_LOCATION IrpSp,
  458. PDRIVER_CANCEL CancelRoutine
  459. );
  460. VOID
  461. CnCompletePendingRequest(
  462. IN PIRP Irp,
  463. IN NTSTATUS Status,
  464. IN ULONG BytesReturned
  465. );
  466. PFILE_OBJECT
  467. CnBeginCancelRoutine(
  468. IN PIRP Irp
  469. );
  470. VOID
  471. CnEndCancelRoutine(
  472. PFILE_OBJECT FileObject
  473. );
  474. VOID
  475. CnAdjustDeviceObjectStackSize(
  476. PDEVICE_OBJECT ClusnetDeviceObject,
  477. PDEVICE_OBJECT TargetDeviceObject
  478. );
  479. //
  480. // ExResource wrappers
  481. //
  482. BOOLEAN
  483. CnAcquireResourceExclusive(
  484. IN PERESOURCE Resource,
  485. IN BOOLEAN Wait
  486. );
  487. BOOLEAN
  488. CnAcquireResourceShared(
  489. IN PERESOURCE Resource,
  490. IN BOOLEAN Wait
  491. );
  492. VOID
  493. CnReleaseResourceForThread(
  494. IN PERESOURCE Resource,
  495. IN ERESOURCE_THREAD ResourceThreadId
  496. );
  497. //
  498. // routines for in-memory logging facility
  499. //
  500. #ifdef MEMLOGGING
  501. VOID
  502. CnInitializeMemoryLog(
  503. VOID
  504. );
  505. VOID
  506. CnFreeMemoryLog(
  507. VOID
  508. );
  509. #endif // MEMLOGGING
  510. NTSTATUS
  511. CnSetMemLogging(
  512. PCLUSNET_SET_MEM_LOGGING_REQUEST request
  513. );
  514. #if 0
  515. //
  516. // NDIS related stuff
  517. //
  518. NDIS_STATUS
  519. CnRegisterNDISProtocolHandlers(
  520. VOID
  521. );
  522. NDIS_STATUS
  523. CnDeregisterNDISProtocolHandlers(
  524. VOID
  525. );
  526. VOID
  527. CnOpenAdapterComplete(
  528. IN NDIS_HANDLE ProtocolBindingContext,
  529. IN NDIS_STATUS Status,
  530. IN NDIS_STATUS OpenErrorStatus
  531. );
  532. VOID
  533. CnCloseAdapterComplete(
  534. IN NDIS_HANDLE ProtocolBindingContext,
  535. IN NDIS_STATUS Status
  536. );
  537. VOID
  538. CnStatusIndication(
  539. IN NDIS_HANDLE ProtocolBindingContext,
  540. IN NDIS_STATUS GeneralStatus,
  541. IN PVOID StatusBuffer,
  542. IN UINT StatusBufferSize
  543. );
  544. VOID
  545. CnStatusIndicationComplete(
  546. IN NDIS_HANDLE ProtocolBindingContext
  547. );
  548. #endif
  549. //
  550. // error logging support
  551. //
  552. VOID _cdecl
  553. CnWriteErrorLogEntry(
  554. IN ULONG UniqueErrorCode,
  555. IN NTSTATUS NtStatusCode,
  556. IN PVOID ExtraInformationBuffer,
  557. IN USHORT ExtraInformationLength,
  558. IN USHORT NumberOfInsertionStrings,
  559. ...
  560. );
  561. //
  562. // Global Data
  563. //
  564. extern PDRIVER_OBJECT CnDriverObject;
  565. extern PDEVICE_OBJECT CnDeviceObject;;
  566. extern PDEVICE_OBJECT CdpDeviceObject;
  567. extern PKPROCESS CnSystemProcess;
  568. extern CN_STATE CnState;
  569. extern PERESOURCE CnResource;
  570. extern CL_NODE_ID CnMinValidNodeId;
  571. extern CL_NODE_ID CnMaxValidNodeId;
  572. extern CL_NODE_ID CnLocalNodeId;
  573. extern HANDLE ClussvcProcessHandle;
  574. //
  575. // vars for managing Events. The lookaside list generates Event data structs
  576. // that are used to carry the event data back to user mode. EventLock is
  577. // acquired when ANY Event operation takes place. Events are not generated
  578. // at a high rate, hence the gross level of locking. EventFileHandles is a list
  579. // of CN_FSCONTEXT blocks. These contain the acutal list of Events to be delivered
  580. // to that file handle when clussvc makes an IRP available.
  581. //
  582. extern PNPAGED_LOOKASIDE_LIST EventLookasideList;
  583. extern CN_LOCK EventLock;
  584. extern LIST_ENTRY EventFileHandles;
  585. extern ULONG EventEpoch;
  586. extern LONG EventDeliveryInProgress;
  587. extern KEVENT EventDeliveryComplete;
  588. extern BOOLEAN EventRevisitRequired;
  589. //
  590. // Exports for Clussvc to Clusnet Heartbeating.
  591. //
  592. extern ULONG ClussvcClusnetHbTimeoutTicks;
  593. extern ClussvcHangAction ClussvcClusnetHbTimeoutAction;
  594. extern ULONG ClussvcClusnetHbTickCount;
  595. extern PEPROCESS ClussvcProcessObject;
  596. extern ULONG ClussvcClusnetHbTimeoutSeconds;
  597. //
  598. // ClusNet security descriptor
  599. //
  600. extern PSECURITY_DESCRIPTOR CdpAdminSecurityDescriptor;
  601. #include <cluxport.h>
  602. #include <event.h>
  603. #ifdef MM_IN_CLUSNET
  604. #include <clusmem.h>
  605. #endif // MM_IN_CLUSNET
  606. #endif // ifndef _CLUSNET_INCLUDED_