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.

426 lines
10 KiB

  1. /*++
  2. Copyright (c) 1989-1993 Microsoft Corporation
  3. Module Name:
  4. spxaddr.h
  5. Abstract:
  6. Author:
  7. Adam Barr (adamba ) Original Version
  8. Nikhil Kamkolkar (nikhilk) 11-November-1993
  9. Environment:
  10. Kernel mode
  11. Revision History:
  12. --*/
  13. #define DYNSKT_RANGE_START 0x4000
  14. #define DYNSKT_RANGE_END 0x7FFF
  15. #define SOCKET_UNIQUENESS 1
  16. // This structure is pointed to by the FsContext field in the FILE_OBJECT
  17. // for this Address. This structure is the base for all activities on
  18. // the open file object within the transport provider. All active connections
  19. // on the address point to this structure, although no queues exist here to do
  20. // work from. This structure also maintains a reference to an ADDRESS
  21. // structure, which describes the address that it is bound to.
  22. #define AFREF_CREATE 0
  23. #define AFREF_VERIFY 1
  24. #define AFREF_INDICATION 2
  25. #define AFREF_CONN_ASSOC 3
  26. #define AFREF_TOTAL 4
  27. typedef struct _SPX_ADDR_FILE {
  28. #if DBG
  29. ULONG saf_RefTypes[AFREF_TOTAL];
  30. #endif
  31. CSHORT saf_Type;
  32. CSHORT saf_Size;
  33. // number of references to this object.
  34. ULONG saf_RefCount;
  35. // Linkage in address list.
  36. struct _SPX_ADDR_FILE * saf_Next;
  37. struct _SPX_ADDR_FILE * saf_GlobalNext;
  38. // List of associated connection/active or otherwise
  39. struct _SPX_CONN_FILE * saf_AssocConnList;
  40. // the current state of the address file structure; this is either open or
  41. // closing
  42. USHORT saf_Flags;
  43. // address to which we are bound, pointer to its lock.
  44. struct _SPX_ADDR * saf_Addr;
  45. CTELock * saf_AddrLock;
  46. #ifdef ISN_NT
  47. // easy backlink to file object.
  48. PFILE_OBJECT saf_FileObject;
  49. #endif
  50. // device to which we are attached.
  51. struct _DEVICE * saf_Device;
  52. // This holds the request used to close this address file,
  53. // for pended completion.
  54. PREQUEST saf_CloseReq;
  55. // This function pointer points to a connection indication handler for this
  56. // Address. Any time a connect request is received on the address, this
  57. // routine is invoked.
  58. PTDI_IND_CONNECT saf_ConnHandler;
  59. PVOID saf_ConnHandlerCtx;
  60. // The following function pointer always points to a TDI_IND_DISCONNECT
  61. // handler for the address.
  62. PTDI_IND_DISCONNECT saf_DiscHandler;
  63. PVOID saf_DiscHandlerCtx;
  64. // The following function pointer always points to a TDI_IND_RECEIVE
  65. // event handler for connections on this address.
  66. PTDI_IND_RECEIVE saf_RecvHandler;
  67. PVOID saf_RecvHandlerCtx;
  68. // Send possible handler
  69. PTDI_IND_SEND_POSSIBLE saf_SendPossibleHandler;
  70. PVOID saf_SendPossibleHandlerCtx;
  71. // !!!We do not do datagrams or expedited data!!!
  72. // The following function pointer always points to a TDI_IND_ERROR
  73. // handler for the address.
  74. PTDI_IND_ERROR saf_ErrHandler;
  75. PVOID saf_ErrHandlerCtx;
  76. PVOID saf_ErrHandlerOwner;
  77. } SPX_ADDR_FILE, *PSPX_ADDR_FILE;
  78. #define SPX_ADDRFILE_OPENING 0x0000 // not yet open for business
  79. #define SPX_ADDRFILE_OPEN 0x0001 // open for business
  80. #define SPX_ADDRFILE_CLOSING 0x0002 // closing
  81. #define SPX_ADDRFILE_STREAM 0x0004 // Opened for stream mode operation
  82. #define SPX_ADDRFILE_CONNIND 0x0008 // Connect ind in progress
  83. #define SPX_ADDRFILE_SPX2 0x0010 // Attempt SPX2 address file
  84. #define SPX_ADDRFILE_NOACKWAIT 0x0020 // Dont delay acks on assoc connections
  85. #define SPX_ADDRFILE_IPXHDR 0x0040 // Pass ipx hdr on all assoc connections
  86. // ***STOP*** ***STOP*** ***STOP*** ***STOP*** ***STOP*** ***STOP*** ***STOP***
  87. // If you are adding any more states to this beyond 0x0080, MAKE SURE to go
  88. // in code and change statements like (Flags & SPX_***) to
  89. // ((Flags & SPX_**) != 0)!!! I dont want to make that change that at this stage.
  90. // ***STOP*** ***STOP*** ***STOP*** ***STOP*** ***STOP*** ***STOP*** ***STOP***
  91. // This structure defines an ADDRESS, or active transport address,
  92. // maintained by the transport provider. It contains all the visible
  93. // components of the address (such as the TSAP and network name components),
  94. // and it also contains other maintenance parts, such as a reference count,
  95. // ACL, and so on.
  96. #define AREF_ADDR_FILE 0
  97. #define AREF_LOOKUP 1
  98. #define AREF_RECEIVE 2
  99. #define AREF_TOTAL 4
  100. typedef struct _SPX_ADDR {
  101. #if DBG
  102. ULONG sa_RefTypes[AREF_TOTAL];
  103. #endif
  104. USHORT sa_Size;
  105. CSHORT sa_Type;
  106. // number of references to this object.
  107. ULONG sa_RefCount;
  108. // next address/this device object.
  109. struct _SPX_ADDR * sa_Next;
  110. // The following fields are used to maintain state about this address.
  111. // attributes of the address.
  112. ULONG sa_Flags;
  113. // Next addressfile for this address
  114. struct _SPX_ADDR_FILE * sa_AddrFileList;
  115. // List of inactive connections and active connections on this address file.
  116. struct _SPX_CONN_FILE * sa_InactiveConnList;
  117. struct _SPX_CONN_FILE * sa_ActiveConnList;
  118. // This is the list of connections which have a POST_LISTEN on them. They
  119. // do not have a local connection id at this point. But will, when they move
  120. // from here to the ActiveConnList, when the listen is satisfied (no matter
  121. // if the accept has not been posted yet, in the case of non-autoaccept listens)
  122. struct _SPX_CONN_FILE * sa_ListenConnList;
  123. CTELock sa_Lock;
  124. // the socket this address corresponds to.
  125. USHORT sa_Socket;
  126. // device context to which we are attached.
  127. struct _DEVICE * sa_Device;
  128. CTELock * sa_DeviceLock;
  129. #ifdef ISN_NT
  130. // These two can be a union because they are not used
  131. // concurrently.
  132. union {
  133. // This structure is used for checking share access.
  134. SHARE_ACCESS sa_ShareAccess;
  135. // Used for delaying NbfDestroyAddress to a thread so
  136. // we can access the security descriptor.
  137. WORK_QUEUE_ITEM sa_DestroyAddrQueueItem;
  138. } u;
  139. // This structure is used to hold ACLs on the address.
  140. PSECURITY_DESCRIPTOR sa_SecurityDescriptor;
  141. #endif
  142. } SPX_ADDR, *PSPX_ADDR;
  143. #define SPX_ADDR_CLOSING 0x00000001
  144. // ROUTINE PROTOTYPES
  145. VOID
  146. SpxAddrRef(
  147. IN PSPX_ADDR Address);
  148. VOID
  149. SpxAddrLockRef(
  150. IN PSPX_ADDR Address);
  151. VOID
  152. SpxAddrDeref(
  153. IN PSPX_ADDR Address);
  154. VOID
  155. SpxAddrFileRef(
  156. IN PSPX_ADDR_FILE pAddrFile);
  157. VOID
  158. SpxAddrFileLockRef(
  159. IN PSPX_ADDR_FILE pAddrFile);
  160. VOID
  161. SpxAddrFileDeref(
  162. IN PSPX_ADDR_FILE pAddrFile);
  163. PSPX_ADDR
  164. SpxAddrCreate(
  165. IN PDEVICE Device,
  166. IN USHORT Socket);
  167. NTSTATUS
  168. SpxAddrFileCreate(
  169. IN PDEVICE Device,
  170. IN PREQUEST Request,
  171. OUT PSPX_ADDR_FILE * ppAddrFile);
  172. NTSTATUS
  173. SpxAddrOpen(
  174. IN PDEVICE Device,
  175. IN PREQUEST Request);
  176. NTSTATUS
  177. SpxAddrSetEventHandler(
  178. IN PDEVICE Device,
  179. IN PREQUEST pRequest);
  180. NTSTATUS
  181. SpxAddrFileVerify(
  182. IN PSPX_ADDR_FILE pAddrFile);
  183. NTSTATUS
  184. SpxAddrFileStop(
  185. IN PSPX_ADDR_FILE pAddrFile,
  186. IN PSPX_ADDR Address);
  187. NTSTATUS
  188. SpxAddrFileCleanup(
  189. IN PDEVICE Device,
  190. IN PREQUEST Request);
  191. NTSTATUS
  192. SpxAddrFileClose(
  193. IN PDEVICE Device,
  194. IN PREQUEST Request);
  195. PSPX_ADDR
  196. SpxAddrLookup(
  197. IN PDEVICE Device,
  198. IN USHORT Socket);
  199. NTSTATUS
  200. SpxAddrConnByRemoteIdAddrLock(
  201. IN PSPX_ADDR pSpxAddr,
  202. IN USHORT SrcConnId,
  203. IN PBYTE SrcIpxAddr,
  204. OUT struct _SPX_CONN_FILE **ppSpxConnFile);
  205. NTSTATUS
  206. SpxAddrFileDestroy(
  207. IN PSPX_ADDR_FILE pAddrFile);
  208. VOID
  209. SpxAddrDestroy(
  210. IN PVOID Parameter);
  211. USHORT
  212. SpxAddrAssignSocket(
  213. IN PDEVICE Device);
  214. BOOLEAN
  215. SpxAddrExists(
  216. IN PDEVICE Device,
  217. IN USHORT Socket);
  218. NTSTATUS
  219. spxAddrRemoveFromGlobalList(
  220. IN PSPX_ADDR_FILE pSpxAddrFile);
  221. VOID
  222. spxAddrInsertIntoGlobalList(
  223. IN PSPX_ADDR_FILE pSpxAddrFile);
  224. #if DBG
  225. #define SpxAddrReference(_Address, _Type) \
  226. { \
  227. (VOID)SPX_ADD_ULONG ( \
  228. &(_Address)->sa_RefTypes[_Type],\
  229. 1, \
  230. &SpxGlobalInterlock); \
  231. SpxAddrRef (_Address); \
  232. }
  233. #define SpxAddrLockReference(_Address, _Type) \
  234. { \
  235. (VOID)SPX_ADD_ULONG ( \
  236. &(_Address)->sa_RefTypes[_Type], \
  237. 1, \
  238. &SpxGlobalInterlock); \
  239. SpxAddrLockRef (_Address); \
  240. }
  241. #define SpxAddrDereference(_Address, _Type) \
  242. { \
  243. (VOID)SPX_ADD_ULONG ( \
  244. &(_Address)->sa_RefTypes[_Type], \
  245. (ULONG)-1, \
  246. &SpxGlobalInterlock); \
  247. if (SPX_ADD_ULONG( \
  248. &(_Address)->sa_RefCount, \
  249. (ULONG)-1, \
  250. &(_Address)->sa_Lock) == 1) { \
  251. SpxAddrDestroy (_Address); \
  252. }\
  253. }
  254. #define SpxAddrFileReference(_AddressFile, _Type) \
  255. { \
  256. (VOID)SPX_ADD_ULONG ( \
  257. &(_AddressFile)->saf_RefTypes[_Type], \
  258. 1, \
  259. &SpxGlobalInterlock); \
  260. SpxAddrFileRef (_AddressFile); \
  261. }
  262. #define SpxAddrFileLockReference(_AddressFile, _Type) \
  263. { \
  264. (VOID)SPX_ADD_ULONG ( \
  265. &(_AddressFile)->saf_RefTypes[_Type], \
  266. 1, \
  267. &SpxGlobalInterlock); \
  268. SpxAddrFileLockRef (_AddressFile); \
  269. }
  270. #define SpxAddrFileDereference(_AddressFile, _Type) \
  271. { \
  272. (VOID)SPX_ADD_ULONG ( \
  273. &(_AddressFile)->saf_RefTypes[_Type], \
  274. (ULONG)-1, \
  275. &SpxGlobalInterlock); \
  276. SpxAddrFileDeref (_AddressFile); \
  277. }
  278. #define SpxAddrFileTransferReference(_AddressFile, _OldType, _NewType) \
  279. { \
  280. (VOID)SPX_ADD_ULONG ( \
  281. &(_AddressFile)->saf_RefTypes[_NewType], \
  282. 1, \
  283. &SpxGlobalInterlock); \
  284. (VOID)SPX_ADD_ULONG ( \
  285. &(_AddressFile)->saf_RefTypes[_OldType], \
  286. (ULONG)-1, \
  287. &SpxGlobalInterlock); \
  288. }
  289. #else // DBG
  290. #define SpxAddrReference(_Address, _Type) \
  291. SPX_ADD_ULONG( \
  292. &(_Address)->sa_RefCount, \
  293. 1, \
  294. (_Address)->sa_DeviceLock)
  295. #define SpxAddrLockReference(_Address, _Type) \
  296. SPX_ADD_ULONG( \
  297. &(_Address)->sa_RefCount, \
  298. 1, \
  299. (_Address)->sa_DeviceLock);
  300. #define SpxAddrDereference(_Address, _Type) \
  301. if (SPX_ADD_ULONG( \
  302. &(_Address)->sa_RefCount, \
  303. (ULONG)-1, \
  304. &(_Address)->sa_Lock) == 1) { \
  305. SpxAddrDestroy (_Address); \
  306. }
  307. #define SpxAddrFileReference(_AddressFile, _Type) \
  308. SPX_ADD_ULONG( \
  309. &(_AddressFile)->saf_RefCount, \
  310. 1, \
  311. (_AddressFile)->saf_AddrLock)
  312. #define SpxAddrFileLockReference(_AddressFile, _Type) \
  313. SPX_ADD_ULONG( \
  314. &(_AddressFile)->saf_RefCount, \
  315. 1, \
  316. (_AddressFile)->saf_AddrLock);
  317. #define SpxAddrFileDereference(_AddressFile, _Type) \
  318. if (SPX_ADD_ULONG( \
  319. &(_AddressFile)->saf_RefCount, \
  320. (ULONG)-1, \
  321. (_AddressFile)->saf_AddrLock) == 1) { \
  322. SpxAddrFileDestroy (_AddressFile); \
  323. }
  324. #define SpxAddrFileTransferReference(_AddressFile, _OldType, _NewType)
  325. #endif // DBG
  326.