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.

713 lines
28 KiB

  1. /*++
  2. Copyright (c) 1989-1999 Microsoft Corporation
  3. Module Name:
  4. afddata.c
  5. Abstract:
  6. This module contains global data for AFD.
  7. Author:
  8. David Treadwell (davidtr) 21-Feb-1992
  9. Revision History:
  10. Vadim Eydelman (vadime)
  11. 1998-1999 NT5.0 Optimization changes
  12. --*/
  13. #include "afdp.h"
  14. #ifdef ALLOC_PRAGMA
  15. #pragma alloc_text( INIT, AfdInitializeData )
  16. #endif
  17. PDEVICE_OBJECT AfdDeviceObject;
  18. LIST_ENTRY AfdEndpointListHead;
  19. LIST_ENTRY AfdConstrainedEndpointListHead;
  20. LIST_ENTRY AfdPollListHead;
  21. AFD_QSPIN_LOCK AfdPollListLock;
  22. LIST_ENTRY AfdTransportInfoListHead;
  23. KEVENT AfdContextWaitEvent;
  24. PKPROCESS AfdSystemProcess;
  25. //
  26. // Global data which must always be in nonpaged pool,
  27. // even when the driver is paged out (resource, lookaside lists).
  28. //
  29. PAFD_GLOBAL_DATA AfdGlobalData;
  30. //
  31. // Globals for dealing with AFD's executive worker thread.
  32. //
  33. LIST_ENTRY AfdWorkQueueListHead;
  34. BOOLEAN AfdWorkThreadRunning = FALSE;
  35. PIO_WORKITEM AfdWorkQueueItem;
  36. //
  37. // Globals to track the buffers used by AFD.
  38. //
  39. ULONG AfdLargeBufferListDepth;
  40. ULONG AfdMediumBufferListDepth;
  41. ULONG AfdSmallBufferListDepth;
  42. ULONG AfdBufferTagListDepth;
  43. ULONG AfdLargeBufferSize; // default == AfdBufferLengthForOnePage
  44. ULONG AfdMediumBufferSize = AFD_DEFAULT_MEDIUM_BUFFER_SIZE;
  45. ULONG AfdSmallBufferSize = AFD_DEFAULT_SMALL_BUFFER_SIZE;
  46. ULONG AfdBufferTagSize = AFD_DEFAULT_TAG_BUFFER_SIZE;
  47. ULONG AfdCacheLineSize;
  48. ULONG AfdBufferLengthForOnePage;
  49. ULONG AfdBufferOverhead;
  50. ULONG AfdBufferAlignment;
  51. ULONG AfdAlignmentTableSize;
  52. ULONG AfdAlignmentOverhead;
  53. //
  54. // Globals for tuning TransmitFile().
  55. //
  56. LIST_ENTRY AfdQueuedTransmitFileListHead;
  57. AFD_QSPIN_LOCK AfdQueuedTransmitFileSpinLock;
  58. ULONG AfdActiveTransmitFileCount;
  59. ULONG AfdMaxActiveTransmitFileCount;
  60. ULONG AfdDefaultTransmitWorker = AFD_DEFAULT_TRANSMIT_WORKER;
  61. //
  62. // Various pieces of configuration information, with default values.
  63. //
  64. ULONG AfdReceiveWindowSize;
  65. ULONG AfdSendWindowSize;
  66. ULONG AfdStandardAddressLength = AFD_DEFAULT_STD_ADDRESS_LENGTH;
  67. CCHAR AfdIrpStackSize = AFD_DEFAULT_IRP_STACK_SIZE;
  68. CCHAR AfdTdiStackSize = AFD_DEFAULT_IRP_STACK_SIZE-1;
  69. #ifdef _AFD_VARIABLE_STACK_
  70. CCHAR AfdMaxStackSize = AFD_DEFAULT_IRP_STACK_SIZE-1;
  71. #endif // _AFD_VARIABLE_STACK_
  72. CCHAR AfdPriorityBoost = AFD_DEFAULT_PRIORITY_BOOST;
  73. ULONG AfdBlockingSendCopyThreshold = AFD_BLOCKING_SEND_COPY_THRESHOLD;
  74. ULONG AfdFastSendDatagramThreshold = AFD_FAST_SEND_DATAGRAM_THRESHOLD;
  75. ULONG AfdTPacketsCopyThreshold = AFD_TPACKETS_COPY_THRESHOLD;
  76. ULONG AfdTransmitIoLength;
  77. ULONG AfdMaxFastTransmit = AFD_DEFAULT_MAX_FAST_TRANSMIT;
  78. ULONG AfdMaxFastCopyTransmit = AFD_DEFAULT_MAX_FAST_COPY_TRANSMIT;
  79. LONG AfdEndpointsOpened = 0;
  80. LONG AfdEndpointsCleanedUp = 0;
  81. LONG AfdEndpointsClosed = 0;
  82. LONG AfdEndpointsFreeing = 0;
  83. LONG AfdConnectionsFreeing = 0;
  84. BOOLEAN AfdIgnorePushBitOnReceives = FALSE;
  85. BOOLEAN AfdEnableDynamicBacklog = AFD_DEFAULT_ENABLE_DYNAMIC_BACKLOG;
  86. LONG AfdMinimumDynamicBacklog = AFD_DEFAULT_MINIMUM_DYNAMIC_BACKLOG;
  87. LONG AfdMaximumDynamicBacklog = AFD_DEFAULT_MAXIMUM_DYNAMIC_BACKLOG;
  88. LONG AfdDynamicBacklogGrowthDelta = AFD_DEFAULT_DYNAMIC_BACKLOG_GROWTH_DELTA;
  89. PSECURITY_DESCRIPTOR AfdAdminSecurityDescriptor = NULL;
  90. SECURITY_DESCRIPTOR AfdEmptySd;
  91. BOOLEAN AfdDisableRawSecurity = FALSE;
  92. BOOLEAN AfdDisableDirectSuperAccept = FALSE;
  93. BOOLEAN AfdDisableChainedReceive = FALSE;
  94. #ifdef TDI_SERVICE_SEND_AND_DISCONNECT
  95. BOOLEAN AfdUseTdiSendAndDisconnect = TRUE;
  96. #endif //TDI_SERVICE_SEND_AND_DISCONNECT
  97. ULONG AfdDefaultTpInfoElementCount = 3;
  98. //
  99. // Data for transport address lists and queued change queries
  100. //
  101. HANDLE AfdBindingHandle = NULL;
  102. LIST_ENTRY AfdAddressEntryList;
  103. LIST_ENTRY AfdAddressChangeList;
  104. PERESOURCE AfdAddressListLock = NULL;
  105. AFD_QSPIN_LOCK AfdAddressChangeLock;
  106. PERESOURCE AfdTdiPnPHandlerLock = NULL;
  107. AFD_WORK_ITEM AfdPnPDeregisterWorker;
  108. IO_STATUS_BLOCK AfdDontCareIoStatus;
  109. // Holds TDI connect timeout (-1).
  110. const LARGE_INTEGER AfdInfiniteTimeout = {(ULONG)-1,-1};
  111. SLIST_HEADER AfdLRList;
  112. KDPC AfdLRListDpc;
  113. KTIMER AfdLRListTimer;
  114. AFD_WORK_ITEM AfdLRListWorker;
  115. LONG AfdLRListCount;
  116. SLIST_HEADER AfdLRFileMdlList;
  117. AFD_LR_LIST_ITEM AfdLRFileMdlListItem;
  118. //
  119. // Global which holds AFD's discardable code handle, and a BOOLEAN
  120. // that tells whether AFD is loaded.
  121. //
  122. PVOID AfdDiscardableCodeHandle;
  123. PKEVENT AfdLoaded = NULL;
  124. AFD_WORK_ITEM AfdUnloadWorker;
  125. BOOLEAN AfdVolatileConfig=0;
  126. HANDLE AfdParametersNotifyHandle;
  127. WORK_QUEUE_ITEM AfdParametersNotifyWorker;
  128. PKEVENT AfdParametersUnloadEvent = NULL;
  129. // SAN code segment handle, loaded only when SAN support is needed by the app.
  130. HANDLE AfdSanCodeHandle = NULL;
  131. // List of SAN helper endpoints
  132. LIST_ENTRY AfdSanHelperList;
  133. // San helper endpoint for special service process used for socket handle
  134. // duplication and provider change notifications.
  135. PAFD_ENDPOINT AfdSanServiceHelper = NULL;
  136. // PID of service process.
  137. HANDLE AfdSanServicePid = NULL;
  138. // Completion object type (kernel does not export this constant)
  139. POBJECT_TYPE IoCompletionObjectType = NULL;
  140. // Provider list sequence number.
  141. LONG AfdSanProviderListSeqNum = 0;
  142. FAST_IO_DISPATCH AfdFastIoDispatch =
  143. {
  144. sizeof (FAST_IO_DISPATCH), // SizeOfFastIoDispatch
  145. NULL, // FastIoCheckIfPossible
  146. AfdFastIoRead, // FastIoRead
  147. AfdFastIoWrite, // FastIoWrite
  148. NULL, // FastIoQueryBasicInfo
  149. NULL, // FastIoQueryStandardInfo
  150. NULL, // FastIoLock
  151. NULL, // FastIoUnlockSingle
  152. AfdSanFastUnlockAll, // FastIoUnlockAll
  153. NULL, // FastIoUnlockAllByKey
  154. AfdFastIoDeviceControl // FastIoDeviceControl
  155. };
  156. //
  157. // Lookup table to verify incoming IOCTL codes.
  158. //
  159. ULONG AfdIoctlTable[AFD_NUM_IOCTLS] =
  160. {
  161. IOCTL_AFD_BIND,
  162. IOCTL_AFD_CONNECT,
  163. IOCTL_AFD_START_LISTEN,
  164. IOCTL_AFD_WAIT_FOR_LISTEN,
  165. IOCTL_AFD_ACCEPT,
  166. IOCTL_AFD_RECEIVE,
  167. IOCTL_AFD_RECEIVE_DATAGRAM,
  168. IOCTL_AFD_SEND,
  169. IOCTL_AFD_SEND_DATAGRAM,
  170. IOCTL_AFD_POLL,
  171. IOCTL_AFD_PARTIAL_DISCONNECT,
  172. IOCTL_AFD_GET_ADDRESS,
  173. IOCTL_AFD_QUERY_RECEIVE_INFO,
  174. IOCTL_AFD_QUERY_HANDLES,
  175. IOCTL_AFD_SET_INFORMATION,
  176. IOCTL_AFD_GET_REMOTE_ADDRESS,
  177. IOCTL_AFD_GET_CONTEXT,
  178. IOCTL_AFD_SET_CONTEXT,
  179. IOCTL_AFD_SET_CONNECT_DATA,
  180. IOCTL_AFD_SET_CONNECT_OPTIONS,
  181. IOCTL_AFD_SET_DISCONNECT_DATA,
  182. IOCTL_AFD_SET_DISCONNECT_OPTIONS,
  183. IOCTL_AFD_GET_CONNECT_DATA,
  184. IOCTL_AFD_GET_CONNECT_OPTIONS,
  185. IOCTL_AFD_GET_DISCONNECT_DATA,
  186. IOCTL_AFD_GET_DISCONNECT_OPTIONS,
  187. IOCTL_AFD_SIZE_CONNECT_DATA,
  188. IOCTL_AFD_SIZE_CONNECT_OPTIONS,
  189. IOCTL_AFD_SIZE_DISCONNECT_DATA,
  190. IOCTL_AFD_SIZE_DISCONNECT_OPTIONS,
  191. IOCTL_AFD_GET_INFORMATION,
  192. IOCTL_AFD_TRANSMIT_FILE,
  193. IOCTL_AFD_SUPER_ACCEPT,
  194. IOCTL_AFD_EVENT_SELECT,
  195. IOCTL_AFD_ENUM_NETWORK_EVENTS,
  196. IOCTL_AFD_DEFER_ACCEPT,
  197. IOCTL_AFD_WAIT_FOR_LISTEN_LIFO,
  198. IOCTL_AFD_SET_QOS,
  199. IOCTL_AFD_GET_QOS,
  200. IOCTL_AFD_NO_OPERATION,
  201. IOCTL_AFD_VALIDATE_GROUP,
  202. IOCTL_AFD_GET_UNACCEPTED_CONNECT_DATA,
  203. IOCTL_AFD_ROUTING_INTERFACE_QUERY,
  204. IOCTL_AFD_ROUTING_INTERFACE_CHANGE,
  205. IOCTL_AFD_ADDRESS_LIST_QUERY,
  206. IOCTL_AFD_ADDRESS_LIST_CHANGE,
  207. IOCTL_AFD_JOIN_LEAF,
  208. 0, // AFD_TRANSPORT_IOCTL
  209. IOCTL_AFD_TRANSMIT_PACKETS,
  210. IOCTL_AFD_SUPER_CONNECT,
  211. IOCTL_AFD_SUPER_DISCONNECT,
  212. IOCTL_AFD_RECEIVE_MESSAGE,
  213. //
  214. // SAN Ioctls
  215. //
  216. IOCTL_AFD_SWITCH_CEMENT_SAN,
  217. IOCTL_AFD_SWITCH_SET_EVENTS,
  218. IOCTL_AFD_SWITCH_RESET_EVENTS,
  219. IOCTL_AFD_SWITCH_CONNECT_IND,
  220. IOCTL_AFD_SWITCH_CMPL_ACCEPT,
  221. IOCTL_AFD_SWITCH_CMPL_REQUEST,
  222. IOCTL_AFD_SWITCH_CMPL_IO,
  223. IOCTL_AFD_SWITCH_REFRESH_ENDP,
  224. IOCTL_AFD_SWITCH_GET_PHYSICAL_ADDR,
  225. IOCTL_AFD_SWITCH_ACQUIRE_CTX,
  226. IOCTL_AFD_SWITCH_TRANSFER_CTX,
  227. IOCTL_AFD_SWITCH_GET_SERVICE_PID,
  228. IOCTL_AFD_SWITCH_SET_SERVICE_PROCESS,
  229. IOCTL_AFD_SWITCH_PROVIDER_CHANGE,
  230. IOCTL_AFD_SWITCH_ADDRLIST_CHANGE
  231. };
  232. //
  233. // Table of IRP based IOCTLS.
  234. //
  235. PAFD_IRP_CALL AfdIrpCallDispatch[AFD_NUM_IOCTLS]= {
  236. AfdBind, // IOCTL_AFD_BIND
  237. AfdConnect, // IOCTL_AFD_CONNECT,
  238. AfdDispatchImmediateIrp, // IOCTL_AFD_START_LISTEN,
  239. AfdWaitForListen, // IOCTL_AFD_WAIT_FOR_LISTEN,
  240. AfdAccept, // IOCTL_AFD_ACCEPT,
  241. AfdReceive, // IOCTL_AFD_RECEIVE,
  242. AfdReceiveDatagram, // IOCTL_AFD_RECEIVE_DATAGRAM,
  243. AfdSend, // IOCTL_AFD_SEND,
  244. AfdSendDatagram, // IOCTL_AFD_SEND_DATAGRAM,
  245. AfdPoll, // IOCTL_AFD_POLL,
  246. AfdDispatchImmediateIrp, // IOCTL_AFD_PARTIAL_DISCONNECT,
  247. AfdGetAddress, // IOCTL_AFD_GET_ADDRESS,
  248. AfdDispatchImmediateIrp, // IOCTL_AFD_QUERY_RECEIVE_INFO,
  249. AfdDispatchImmediateIrp, // IOCTL_AFD_QUERY_HANDLES,
  250. AfdDispatchImmediateIrp, // IOCTL_AFD_SET_INFORMATION,
  251. AfdDispatchImmediateIrp, // IOCTL_AFD_GET_REMOTE_ADDRESS,
  252. AfdDispatchImmediateIrp, // IOCTL_AFD_GET_CONTEXT,
  253. AfdDispatchImmediateIrp, // IOCTL_AFD_SET_CONTEXT,
  254. AfdDispatchImmediateIrp, // IOCTL_AFD_SET_CONNECT_DATA,
  255. AfdDispatchImmediateIrp, // IOCTL_AFD_SET_CONNECT_OPTIONS,
  256. AfdDispatchImmediateIrp, // IOCTL_AFD_SET_DISCONNECT_DATA,
  257. AfdDispatchImmediateIrp, // IOCTL_AFD_SET_DISCONNECT_OPTIONS,
  258. AfdDispatchImmediateIrp, // IOCTL_AFD_GET_CONNECT_DATA,
  259. AfdDispatchImmediateIrp, // IOCTL_AFD_GET_CONNECT_OPTIONS,
  260. AfdDispatchImmediateIrp, // IOCTL_AFD_GET_DISCONNECT_DATA,
  261. AfdDispatchImmediateIrp, // IOCTL_AFD_GET_DISCONNECT_OPTIONS,
  262. AfdDispatchImmediateIrp, // IOCTL_AFD_SIZE_CONNECT_DATA,
  263. AfdDispatchImmediateIrp, // IOCTL_AFD_SIZE_CONNECT_OPTIONS,
  264. AfdDispatchImmediateIrp, // IOCTL_AFD_SIZE_DISCONNECT_DATA,
  265. AfdDispatchImmediateIrp, // IOCTL_AFD_SIZE_DISCONNECT_OPTIONS,
  266. AfdDispatchImmediateIrp, // IOCTL_AFD_GET_INFORMATION,
  267. AfdTransmitFile, // IOCTL_AFD_TRANSMIT_FILE,
  268. AfdSuperAccept, // IOCTL_AFD_SUPER_ACCEPT,
  269. AfdDispatchImmediateIrp, // IOCTL_AFD_EVENT_SELECT,
  270. AfdDispatchImmediateIrp, // IOCTL_AFD_ENUM_NETWORK_EVENTS,
  271. AfdDeferAccept, // IOCTL_AFD_DEFER_ACCEPT,
  272. AfdWaitForListen, // IOCTL_AFD_WAIT_FOR_LISTEN_LIFO,
  273. AfdSetQos, // IOCTL_AFD_SET_QOS,
  274. AfdGetQos, // IOCTL_AFD_GET_QOS,
  275. AfdNoOperation, // IOCTL_AFD_NO_OPERATION,
  276. AfdValidateGroup, // IOCTL_AFD_VALIDATE_GROUP,
  277. AfdDispatchImmediateIrp, // IOCTL_AFD_GET_UNACCEPTED_CONNECT_DATA
  278. AfdDispatchImmediateIrp, // IOCTL_AFD_ROUTING_INTERFACE_QUERY,
  279. AfdRoutingInterfaceChange,// IOCTL_AFD_ROUTING_INTERFACE_CHANGE,
  280. AfdDispatchImmediateIrp, // IOCTL_AFD_ADDRESS_LIST_QUERY,
  281. AfdAddressListChange, // IOCTL_AFD_ADDRESS_LIST_CHANGE,
  282. AfdJoinLeaf, // IOCTL_AFD_JOIN_LEAF,
  283. NULL, // IOCTL_AFD_TRANSPORT_IOCTL,
  284. AfdTransmitPackets, // IOCTL_AFD_TRANSMIT_PACKETS
  285. AfdSuperConnect, // IOCTL_AFD_SUPER_CONNECT
  286. AfdSuperDisconnect, // IOCTL_AFD_SUPER_DISCONNECT
  287. AfdReceiveDatagram, // IOCTL_AFD_RECEIVE_MESSAGE
  288. AfdDispatchImmediateIrp, // IOCTL_AFD_SWITCH_CEMENT_SAN
  289. AfdDispatchImmediateIrp, // IOCTL_AFD_SWITCH_SET_EVENTS
  290. AfdDispatchImmediateIrp, // IOCTL_AFD_SWITCH_RESET_EVENTS
  291. AfdSanConnectHandler, // IOCTL_AFD_SWITCH_CONNECT_IND
  292. AfdDispatchImmediateIrp, // IOCTL_AFD_SWITCH_CMPL_ACCEPT
  293. AfdDispatchImmediateIrp, // IOCTL_AFD_SWITCH_CMPL_REQUEST
  294. AfdDispatchImmediateIrp, // IOCTL_AFD_SWITCH_CMPL_IO
  295. AfdDispatchImmediateIrp, // IOCTL_AFD_SWITCH_REFRESH_ENDP
  296. AfdDispatchImmediateIrp, // IOCTL_AFD_SWITCH_GET_PHYSICAL_ADDR
  297. AfdSanAcquireContext, // IOCTL_AFD_SWITCH_ACQUIRE_CTX
  298. AfdDispatchImmediateIrp, // IOCTL_AFD_SWITCH_TRANSFER_CTX
  299. AfdDispatchImmediateIrp, // IOCTL_AFD_SWITCH_GET_SERVICE_PID
  300. AfdDispatchImmediateIrp, // IOCTL_AFD_SWITCH_SET_SERVICE_PROCESS
  301. AfdDispatchImmediateIrp, // IOCTL_AFD_SWITCH_PROVIDER_CHANGE
  302. AfdSanAddrListChange // IOCTL_AFD_SWITCH_ADDRLIST_CHANGE
  303. };
  304. //
  305. // Table of immediate IOCTLS (can never be pended).
  306. //
  307. PAFD_IMMEDIATE_CALL AfdImmediateCallDispatch[AFD_NUM_IOCTLS]= {
  308. NULL, // IOCTL_AFD_BIND
  309. NULL, // IOCTL_AFD_CONNECT,
  310. AfdStartListen, // IOCTL_AFD_START_LISTEN,
  311. NULL, // IOCTL_AFD_WAIT_FOR_LISTEN,
  312. NULL, // IOCTL_AFD_ACCEPT,
  313. NULL, // IOCTL_AFD_RECEIVE,
  314. NULL, // IOCTL_AFD_RECEIVE_DATAGRAM,
  315. NULL, // IOCTL_AFD_SEND,
  316. NULL, // IOCTL_AFD_SEND_DATAGRAM,
  317. NULL, // IOCTL_AFD_POLL,
  318. AfdPartialDisconnect, // IOCTL_AFD_PARTIAL_DISCONNECT,
  319. NULL, // IOCTL_AFD_GET_ADDRESS,
  320. AfdQueryReceiveInformation,// IOCTL_AFD_QUERY_RECEIVE_INFO,
  321. AfdQueryHandles, // IOCTL_AFD_QUERY_HANDLES,
  322. AfdSetInformation, // IOCTL_AFD_SET_INFORMATION,
  323. AfdGetRemoteAddress, // IOCTL_AFD_GET_REMOTE_ADDRESS,
  324. AfdGetContext, // IOCTL_AFD_GET_CONTEXT,
  325. AfdSetContext, // IOCTL_AFD_SET_CONTEXT,
  326. AfdSetConnectData, // IOCTL_AFD_SET_CONNECT_DATA,
  327. AfdSetConnectData, // IOCTL_AFD_SET_CONNECT_OPTIONS,
  328. AfdSetConnectData, // IOCTL_AFD_SET_DISCONNECT_DATA,
  329. AfdSetConnectData, // IOCTL_AFD_SET_DISCONNECT_OPTIONS,
  330. AfdGetConnectData, // IOCTL_AFD_GET_CONNECT_DATA,
  331. AfdGetConnectData, // IOCTL_AFD_GET_CONNECT_OPTIONS,
  332. AfdGetConnectData, // IOCTL_AFD_GET_DISCONNECT_DATA,
  333. AfdGetConnectData, // IOCTL_AFD_GET_DISCONNECT_OPTIONS,
  334. AfdSetConnectData, // IOCTL_AFD_SIZE_CONNECT_DATA,
  335. AfdSetConnectData, // IOCTL_AFD_SIZE_CONNECT_OPTIONS,
  336. AfdSetConnectData, // IOCTL_AFD_SIZE_DISCONNECT_DATA,
  337. AfdSetConnectData, // IOCTL_AFD_SIZE_DISCONNECT_OPTIONS,
  338. AfdGetInformation, // IOCTL_AFD_GET_INFORMATION,
  339. NULL, // IOCTL_AFD_TRANSMIT_FILE,
  340. NULL, // IOCTL_AFD_SUPER_ACCEPT,
  341. AfdEventSelect, // IOCTL_AFD_EVENT_SELECT,
  342. AfdEnumNetworkEvents, // IOCTL_AFD_ENUM_NETWORK_EVENTS,
  343. NULL, // IOCTL_AFD_DEFER_ACCEPT,
  344. NULL, // IOCTL_AFD_WAIT_FOR_LISTEN_LIFO,
  345. NULL, // IOCTL_AFD_SET_QOS,
  346. NULL, // IOCTL_AFD_GET_QOS,
  347. NULL, // IOCTL_AFD_NO_OPERATION,
  348. NULL, // IOCTL_AFD_VALIDATE_GROUP,
  349. AfdGetUnacceptedConnectData,// IOCTL_AFD_GET_UNACCEPTED_CONNECT_DATA
  350. AfdRoutingInterfaceQuery, // IOCTL_AFD_ROUTING_INTERFACE_QUERY,
  351. NULL, // IOCTL_AFD_ROUTING_INTERFACE_CHANGE,
  352. AfdAddressListQuery, // IOCTL_AFD_ADDRESS_LIST_QUERY,
  353. NULL, // IOCTL_AFD_ADDRESS_LIST_CHANGE,
  354. NULL, // IOCTL_AFD_JOIN_LEAF,
  355. NULL, // IOCTL_AFD_TRANSPORT_IOCTL,
  356. NULL, // IOCTL_AFD_TRANSMIT_PACKETS
  357. NULL, // IOCTL_AFD_SUPER_CONNECT
  358. NULL, // IOCTL_AFD_SUPER_DISCONNECT
  359. NULL, // IOCTL_AFD_RECEIVE_MESSAGE
  360. AfdSanFastCementEndpoint, // IOCTL_AFD_SWITCH_CEMENT_SAN
  361. AfdSanFastSetEvents, // IOCTL_AFD_SWITCH_SET_EVENTS
  362. AfdSanFastResetEvents, // IOCTL_AFD_SWITCH_RESET_EVENTS
  363. NULL, // IOCTL_AFD_SWITCH_CONNECT_IND
  364. AfdSanFastCompleteAccept, // IOCTL_AFD_SWITCH_CMPL_ACCEPT
  365. AfdSanFastCompleteRequest,// IOCTL_AFD_SWITCH_CMPL_REQUEST
  366. AfdSanFastCompleteIo, // IOCTL_AFD_SWITCH_CMPL_IO
  367. AfdSanFastRefreshEndpoint,// IOCTL_AFD_SWITCH_REFRESH_ENDP
  368. AfdSanFastGetPhysicalAddr,// IOCTL_AFD_SWITCH_GET_PHYSICAL_ADDR
  369. NULL, // IOCTL_AFD_SWITCH_ACQUIRE_CTX
  370. AfdSanFastTransferCtx, // IOCTL_AFD_SWITCH_TRANSFER_CTX
  371. AfdSanFastGetServicePid, // IOCTL_AFD_SWITCH_GET_SERVICE_PID
  372. AfdSanFastSetServiceProcess,// IOCTL_AFD_SWITCH_SET_SERVICE_PROCESS
  373. AfdSanFastProviderChange, // IOCTL_AFD_SWITCH_PROVIDER_CHANGE
  374. NULL // IOCTL_AFD_SWITCH_ADDRLIST_CHANGE
  375. };
  376. //
  377. // Make sure the above IOCTLs have method neither.
  378. //
  379. C_ASSERT ((IOCTL_AFD_START_LISTEN & 3) == METHOD_NEITHER);
  380. C_ASSERT ((IOCTL_AFD_PARTIAL_DISCONNECT & 3) == METHOD_NEITHER);
  381. C_ASSERT ((IOCTL_AFD_QUERY_RECEIVE_INFO & 3) == METHOD_NEITHER);
  382. C_ASSERT ((IOCTL_AFD_QUERY_HANDLES & 3) == METHOD_NEITHER);
  383. C_ASSERT ((IOCTL_AFD_SET_INFORMATION & 3) == METHOD_NEITHER);
  384. C_ASSERT ((IOCTL_AFD_GET_REMOTE_ADDRESS & 3) == METHOD_NEITHER);
  385. C_ASSERT ((IOCTL_AFD_GET_CONTEXT & 3) == METHOD_NEITHER);
  386. C_ASSERT ((IOCTL_AFD_SET_CONTEXT & 3) == METHOD_NEITHER);
  387. C_ASSERT ((IOCTL_AFD_SET_CONNECT_DATA & 3) == METHOD_NEITHER);
  388. C_ASSERT ((IOCTL_AFD_SET_CONNECT_OPTIONS & 3) == METHOD_NEITHER);
  389. C_ASSERT ((IOCTL_AFD_SET_DISCONNECT_DATA & 3) == METHOD_NEITHER);
  390. C_ASSERT ((IOCTL_AFD_SET_DISCONNECT_OPTIONS & 3) == METHOD_NEITHER);
  391. C_ASSERT ((IOCTL_AFD_GET_CONNECT_DATA & 3) == METHOD_NEITHER);
  392. C_ASSERT ((IOCTL_AFD_GET_CONNECT_OPTIONS & 3) == METHOD_NEITHER);
  393. C_ASSERT ((IOCTL_AFD_GET_DISCONNECT_DATA & 3) == METHOD_NEITHER);
  394. C_ASSERT ((IOCTL_AFD_GET_DISCONNECT_OPTIONS & 3) == METHOD_NEITHER);
  395. C_ASSERT ((IOCTL_AFD_SIZE_CONNECT_DATA & 3) == METHOD_NEITHER);
  396. C_ASSERT ((IOCTL_AFD_SIZE_CONNECT_OPTIONS & 3) == METHOD_NEITHER);
  397. C_ASSERT ((IOCTL_AFD_SIZE_DISCONNECT_DATA & 3) == METHOD_NEITHER);
  398. C_ASSERT ((IOCTL_AFD_SIZE_DISCONNECT_OPTIONS & 3) == METHOD_NEITHER);
  399. C_ASSERT ((IOCTL_AFD_GET_INFORMATION & 3) == METHOD_NEITHER);
  400. C_ASSERT ((IOCTL_AFD_EVENT_SELECT & 3) == METHOD_NEITHER);
  401. C_ASSERT ((IOCTL_AFD_ENUM_NETWORK_EVENTS & 3) == METHOD_NEITHER);
  402. C_ASSERT ((IOCTL_AFD_GET_UNACCEPTED_CONNECT_DATA & 3) == METHOD_NEITHER);
  403. C_ASSERT ((IOCTL_AFD_ADDRESS_LIST_QUERY & 3) == METHOD_NEITHER);
  404. C_ASSERT ((IOCTL_AFD_ROUTING_INTERFACE_QUERY & 3) == METHOD_NEITHER);
  405. C_ASSERT ((IOCTL_AFD_SWITCH_CEMENT_SAN & 3) == METHOD_NEITHER);
  406. C_ASSERT ((IOCTL_AFD_SWITCH_SET_EVENTS & 3) == METHOD_NEITHER);
  407. C_ASSERT ((IOCTL_AFD_SWITCH_RESET_EVENTS & 3) == METHOD_NEITHER);
  408. C_ASSERT ((IOCTL_AFD_SWITCH_CMPL_ACCEPT & 3) == METHOD_NEITHER);
  409. C_ASSERT ((IOCTL_AFD_SWITCH_CMPL_REQUEST & 3) == METHOD_NEITHER);
  410. C_ASSERT ((IOCTL_AFD_SWITCH_CMPL_IO & 3) == METHOD_NEITHER);
  411. C_ASSERT ((IOCTL_AFD_SWITCH_REFRESH_ENDP & 3) == METHOD_NEITHER);
  412. C_ASSERT ((IOCTL_AFD_SWITCH_GET_PHYSICAL_ADDR & 3) == METHOD_NEITHER);
  413. C_ASSERT ((IOCTL_AFD_SWITCH_TRANSFER_CTX & 3) == METHOD_NEITHER);
  414. C_ASSERT ((IOCTL_AFD_SWITCH_GET_SERVICE_PID & 3) == METHOD_NEITHER);
  415. C_ASSERT ((IOCTL_AFD_SWITCH_SET_SERVICE_PROCESS & 3) == METHOD_NEITHER);
  416. C_ASSERT ((IOCTL_AFD_SWITCH_PROVIDER_CHANGE & 3) == METHOD_NEITHER);
  417. #if DBG
  418. ULONG AfdDebug = 0;
  419. ULONG AfdLocksAcquired = 0;
  420. BOOLEAN AfdUsePrivateAssert = TRUE;
  421. #endif
  422. //
  423. // Some counters used for monitoring performance. These are not enabled
  424. // in the normal build.
  425. //
  426. #if AFD_PERF_DBG
  427. LONG AfdFullReceiveIndications = 0;
  428. LONG AfdPartialReceiveIndications = 0;
  429. LONG AfdFullReceiveDatagramIndications = 0;
  430. LONG AfdPartialReceiveDatagramIndications = 0;
  431. LONG AfdFastSendsSucceeded = 0;
  432. LONG AfdFastSendsFailed = 0;
  433. LONG AfdFastReceivesSucceeded = 0;
  434. LONG AfdFastReceivesFailed = 0;
  435. LONG AfdFastSendDatagramsSucceeded = 0;
  436. LONG AfdFastSendDatagramsFailed = 0;
  437. LONG AfdFastReceiveDatagramsSucceeded = 0;
  438. LONG AfdFastReceiveDatagramsFailed = 0;
  439. LONG AfdFastReadsSucceeded = 0;
  440. LONG AfdFastReadsFailed = 0;
  441. LONG AfdFastWritesSucceeded = 0;
  442. LONG AfdFastWritesFailed = 0;
  443. LONG AfdFastTfSucceeded=0;
  444. LONG AfdFastTfFailed=0;
  445. LONG AfdFastTfReadFailed=0;
  446. LONG AfdTPWorkersExecuted=0;
  447. LONG AfdTPRequests=0;
  448. BOOLEAN AfdDisableFastIo = FALSE;
  449. BOOLEAN AfdDisableConnectionReuse = FALSE;
  450. #endif // AFD_PERF_DBG
  451. #if AFD_KEEP_STATS
  452. AFD_QUOTA_STATS AfdQuotaStats;
  453. AFD_HANDLE_STATS AfdHandleStats;
  454. AFD_QUEUE_STATS AfdQueueStats;
  455. AFD_CONNECTION_STATS AfdConnectionStats;
  456. #endif // AFD_KEEP_STATS
  457. #ifdef _WIN64
  458. QOS32 AfdDefaultQos32 =
  459. {
  460. { // SendingFlowspec
  461. (ULONG)-1, // TokenRate
  462. (ULONG)-1, // TokenBucketSize
  463. (ULONG)-1, // PeakBandwidth
  464. (ULONG)-1, // Latency
  465. (ULONG)-1, // DelayVariation
  466. SERVICETYPE_BESTEFFORT, // ServiceType
  467. (ULONG)-1, // MaxSduSize
  468. (ULONG)-1 // MinimumPolicedSize
  469. },
  470. { // SendingFlowspec
  471. (ULONG)-1, // TokenRate
  472. (ULONG)-1, // TokenBucketSize
  473. (ULONG)-1, // PeakBandwidth
  474. (ULONG)-1, // Latency
  475. (ULONG)-1, // DelayVariation
  476. SERVICETYPE_BESTEFFORT, // ServiceType
  477. (ULONG)-1, // MaxSduSize
  478. (ULONG)-1 // MinimumPolicedSize
  479. },
  480. };
  481. #endif
  482. QOS AfdDefaultQos =
  483. {
  484. { // SendingFlowspec
  485. (ULONG)-1, // TokenRate
  486. (ULONG)-1, // TokenBucketSize
  487. (ULONG)-1, // PeakBandwidth
  488. (ULONG)-1, // Latency
  489. (ULONG)-1, // DelayVariation
  490. SERVICETYPE_BESTEFFORT, // ServiceType
  491. (ULONG)-1, // MaxSduSize
  492. (ULONG)-1 // MinimumPolicedSize
  493. },
  494. { // SendingFlowspec
  495. (ULONG)-1, // TokenRate
  496. (ULONG)-1, // TokenBucketSize
  497. (ULONG)-1, // PeakBandwidth
  498. (ULONG)-1, // Latency
  499. (ULONG)-1, // DelayVariation
  500. SERVICETYPE_BESTEFFORT, // ServiceType
  501. (ULONG)-1, // MaxSduSize
  502. (ULONG)-1 // MinimumPolicedSize
  503. },
  504. };
  505. VOID
  506. AfdInitializeData (
  507. VOID
  508. )
  509. {
  510. PAGED_CODE( );
  511. #if DBG || REFERENCE_DEBUG
  512. AfdInitializeDebugData( );
  513. #endif
  514. //
  515. // Initialize global spin locks and lists.
  516. //
  517. AfdInitializeSpinLock( &AfdPollListLock );
  518. //
  519. // Initialize global lists.
  520. //
  521. InitializeListHead( &AfdEndpointListHead );
  522. InitializeListHead( &AfdPollListHead );
  523. InitializeListHead( &AfdTransportInfoListHead );
  524. InitializeListHead( &AfdWorkQueueListHead );
  525. InitializeListHead( &AfdConstrainedEndpointListHead );
  526. InitializeListHead( &AfdQueuedTransmitFileListHead );
  527. AfdInitializeSpinLock( &AfdQueuedTransmitFileSpinLock );
  528. InitializeListHead( &AfdAddressEntryList );
  529. InitializeListHead( &AfdAddressChangeList );
  530. ExInitializeSListHead( &AfdLRList);
  531. ExInitializeSListHead( &AfdLRFileMdlList);
  532. AfdBufferAlignment = KeGetRecommendedSharedDataAlignment( );
  533. if (AfdBufferAlignment < AFD_MINIMUM_BUFFER_ALIGNMENT) {
  534. AfdBufferAlignment = AFD_MINIMUM_BUFFER_ALIGNMENT;
  535. }
  536. AfdAlignmentTableSize = AfdBufferAlignment/AFD_MINIMUM_BUFFER_ALIGNMENT;
  537. AfdBufferOverhead = AfdCalculateBufferSize(
  538. PAGE_SIZE,
  539. AfdStandardAddressLength,
  540. AfdTdiStackSize) - PAGE_SIZE;
  541. AfdBufferLengthForOnePage = ALIGN_DOWN_A(
  542. PAGE_SIZE-AfdBufferOverhead,
  543. AFD_MINIMUM_BUFFER_ALIGNMENT);
  544. AfdLargeBufferSize = AfdBufferLengthForOnePage;
  545. //
  546. // Set up buffer counts based on machine size. For smaller
  547. // machines, it is OK to take the perf hit of the additional
  548. // allocations in order to save the nonpaged pool overhead.
  549. //
  550. switch ( MmQuerySystemSize( ) ) {
  551. case MmSmallSystem:
  552. AfdReceiveWindowSize = AFD_SM_DEFAULT_RECEIVE_WINDOW;
  553. AfdSendWindowSize = AFD_SM_DEFAULT_SEND_WINDOW;
  554. AfdTransmitIoLength = AFD_SM_DEFAULT_TRANSMIT_IO_LENGTH;
  555. AfdLargeBufferListDepth = AFD_SM_DEFAULT_LARGE_LIST_DEPTH;
  556. AfdMediumBufferListDepth = AFD_SM_DEFAULT_MEDIUM_LIST_DEPTH;
  557. AfdSmallBufferListDepth = AFD_SM_DEFAULT_SMALL_LIST_DEPTH;
  558. AfdBufferTagListDepth = AFD_SM_DEFAULT_TAG_LIST_DEPTH;
  559. break;
  560. case MmMediumSystem:
  561. AfdReceiveWindowSize = AFD_MM_DEFAULT_RECEIVE_WINDOW;
  562. AfdSendWindowSize = AFD_MM_DEFAULT_SEND_WINDOW;
  563. AfdTransmitIoLength = AFD_MM_DEFAULT_TRANSMIT_IO_LENGTH;
  564. AfdLargeBufferListDepth = AFD_MM_DEFAULT_LARGE_LIST_DEPTH;
  565. AfdMediumBufferListDepth = AFD_MM_DEFAULT_MEDIUM_LIST_DEPTH;
  566. AfdSmallBufferListDepth = AFD_MM_DEFAULT_SMALL_LIST_DEPTH;
  567. AfdBufferTagListDepth = AFD_MM_DEFAULT_TAG_LIST_DEPTH;
  568. break;
  569. default:
  570. ASSERT(!"Unknown system size" );
  571. case MmLargeSystem:
  572. AfdReceiveWindowSize = AFD_LM_DEFAULT_RECEIVE_WINDOW;
  573. AfdSendWindowSize = AFD_LM_DEFAULT_SEND_WINDOW;
  574. AfdTransmitIoLength = AFD_LM_DEFAULT_TRANSMIT_IO_LENGTH;
  575. AfdLargeBufferListDepth = AFD_LM_DEFAULT_LARGE_LIST_DEPTH;
  576. AfdMediumBufferListDepth = AFD_LM_DEFAULT_MEDIUM_LIST_DEPTH;
  577. AfdSmallBufferListDepth = AFD_LM_DEFAULT_SMALL_LIST_DEPTH;
  578. AfdBufferTagListDepth = AFD_LM_DEFAULT_TAG_LIST_DEPTH;
  579. break;
  580. }
  581. if( MmIsThisAnNtAsSystem() ) {
  582. //
  583. // On the NT Server product, there is no maximum active TransmitFile
  584. // count. Setting this counter to zero short-circuits a number of
  585. // tests for queueing TransmitFile IRPs.
  586. //
  587. AfdMaxActiveTransmitFileCount = 0;
  588. } else {
  589. //
  590. // On the workstation product, the TransmitFile default I/O length
  591. // is always a page size. This conserves memory on workstatioons
  592. // and keeps the server product's performance high.
  593. //
  594. AfdTransmitIoLength = PAGE_SIZE;
  595. //
  596. // Enforce a maximum active TransmitFile count.
  597. //
  598. AfdMaxActiveTransmitFileCount =
  599. AFD_DEFAULT_MAX_ACTIVE_TRANSMIT_FILE_COUNT;
  600. }
  601. RtlCreateSecurityDescriptor (&AfdEmptySd,
  602. SECURITY_DESCRIPTOR_REVISION);
  603. } // AfdInitializeData