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.

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