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.

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