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.

423 lines
11 KiB

  1. // Copyright (c) 1997, Microsoft Corporation, all rights reserved
  2. //
  3. // tdix.h
  4. // RAS L2TP WAN mini-port/call-manager driver
  5. // TDI extensions header
  6. //
  7. // 01/07/97 Steve Cobb
  8. #ifndef _TDIX_H_
  9. #define _TDIX_H_
  10. //-----------------------------------------------------------------------------
  11. // Datatypes
  12. //-----------------------------------------------------------------------------
  13. // Forward declarations.
  14. //
  15. typedef struct _TDIXCONTEXT TDIXCONTEXT;
  16. typedef struct _TDIXROUTE TDIXROUTE;
  17. typedef enum _HOSTROUTEEXISTS HOSTROUTEEXISTS;
  18. // 'UDP' and 'RawIp' media type address descriptor.
  19. //
  20. typedef struct
  21. _TDIXIPADDRESS
  22. {
  23. // IP address in network byte order.
  24. //
  25. ULONG ulIpAddress;
  26. // UDP port in network byte order. Always 0 for 'RawIp' media.
  27. //
  28. SHORT sUdpPort;
  29. // interface index
  30. uint ifindex;
  31. }
  32. TDIXIPADDRESS;
  33. // Read datagram information context used to pass context information from the
  34. // ReadDatagram event handler to the RECEIVE_DATAGRAM completion routine.
  35. //
  36. typedef struct
  37. _TDIXRDGINFO
  38. {
  39. // The associated TDIX context;
  40. //
  41. TDIXCONTEXT* pTdix;
  42. // The source IP address of the received datagram in network byte order.
  43. //
  44. TDIXIPADDRESS source;
  45. // The buffer, allocated from caller's buffer pool, containing the
  46. // datagram information.
  47. //
  48. CHAR* pBuffer;
  49. // The length of the information copied to caller's buffer.
  50. //
  51. ULONG ulBufferLen;
  52. TDIXIPADDRESS dest;
  53. }
  54. TDIXRDGINFO;
  55. // TDIX client's send-complete handler prototype. 'PTdix' is the TDI
  56. // extension context. 'PContext1' and 'pContext2' are the contexts passed to
  57. // TdixSenddagram. 'PBuffer' is the buffer passed to TdiSendDatagram.
  58. //
  59. typedef
  60. VOID
  61. (*PTDIXSENDCOMPLETE)(
  62. IN TDIXCONTEXT* pTdix,
  63. IN VOID* pContext1,
  64. IN VOID* pContext2,
  65. IN CHAR* pBuffer );
  66. // Send datagram information context used to pass context information from
  67. // TdixSendDatagram to the send datagram completion handler.
  68. //
  69. typedef struct
  70. _TDIXSDGINFO
  71. {
  72. // The associated TDIX context;
  73. //
  74. TDIXCONTEXT* pTdix;
  75. // The buffer passed by caller to TdixSendDatagram.
  76. //
  77. CHAR* pBuffer;
  78. // Caller's send-complete handler.
  79. //
  80. PTDIXSENDCOMPLETE pSendCompleteHandler;
  81. // Caller's contexts to be returned to his send-complete handler.
  82. //
  83. VOID* pContext1;
  84. VOID* pContext2;
  85. // TDI request information.
  86. //
  87. TDI_CONNECTION_INFORMATION tdiconninfo;
  88. TA_IP_ADDRESS taip;
  89. }
  90. TDIXSDGINFO;
  91. #define ALLOC_TDIXRDGINFO( pTdix ) \
  92. NdisAllocateFromNPagedLookasideList( &(pTdix)->llistRdg )
  93. #define FREE_TDIXRDGINFO( pTdix, pRdg ) \
  94. NdisFreeToNPagedLookasideList( &(pTdix)->llistRdg, (pRdg) )
  95. #define ALLOC_TDIXSDGINFO( pTdix ) \
  96. NdisAllocateFromNPagedLookasideList( &(pTdix)->llistSdg )
  97. #define FREE_TDIXSDGINFO( pTdix, pSdg ) \
  98. NdisFreeToNPagedLookasideList( &(pTdix)->llistSdg, (pSdg) )
  99. #define ALLOC_TDIXROUTE( pTdix ) \
  100. ALLOC_NONPAGED( sizeof(TDIXROUTE), MTAG_TDIXROUTE )
  101. #define FREE_TDIXROUTE( pTdix, pR ) \
  102. FREE_NONPAGED( pR )
  103. // TDIX client's receive handler prototype. 'PTdix' is the TDI extension
  104. // context. 'PAddress' is the source address of the received datagram, which
  105. // for IP is a network byte-order IP address. 'PBuffer' is the receive buffer
  106. // of 'ulBytesLength' bytes where the first "real" data is at offset
  107. // 'ulOffset'. It is caller's responsibility to call FreeBufferToPool with
  108. // the same pool passed to TdixInitialize.
  109. //
  110. typedef
  111. VOID
  112. (*PTDIXRECEIVE)(
  113. IN TDIXCONTEXT* pTdix,
  114. IN TDIXRDGINFO* pRdg,
  115. IN CHAR* pBuffer,
  116. IN ULONG ulOffset,
  117. IN ULONG ulBufferLength );
  118. //
  119. //
  120. typedef
  121. NDIS_STATUS
  122. (*PTDIX_SEND_HANDLER)(
  123. IN TDIXCONTEXT* pTdix,
  124. IN FILE_OBJECT* FileObj,
  125. IN PTDIXSENDCOMPLETE pSendCompleteHandler,
  126. IN VOID* pContext1,
  127. IN VOID* pContext2,
  128. IN VOID* pAddress,
  129. IN CHAR* pBuffer,
  130. IN ULONG ulBufferLength,
  131. OUT IRP** ppIrp );
  132. // The TDI media types that L2TP can run on. The values are read from the
  133. // registry, so don't change randomly.
  134. //
  135. typedef enum
  136. _TDIXMEDIATYPE
  137. {
  138. TMT_RawIp = 1,
  139. TMT_Udp = 2
  140. }
  141. TDIXMEDIATYPE;
  142. // Context of a TDI extension session. Code outside the TdixXxx routines
  143. // should avoid referring to fields in this structure.
  144. //
  145. typedef struct
  146. _TDIXCONTEXT
  147. {
  148. // Reference count on this TDI session. The reference pairs are:
  149. //
  150. // (a) TdixOpen adds a reference that TdixClose removes.
  151. //
  152. // (b) TdixAddHostRoute adds a reference when it links a new route into
  153. // the TDIXCONTEXT.listRoutes and TdixDeleteHostRoute removes it.
  154. //
  155. // The field is accessed only by the ReferenceTdix and DereferenceTdix
  156. // routines which protect access via 'lock'.
  157. //
  158. LONG lRef;
  159. // Handle of the transport address object returned from ZwCreateFile, and
  160. // the object address of same.
  161. //
  162. HANDLE hAddress;
  163. FILE_OBJECT* pAddress;
  164. // The media type in use on this context.
  165. //
  166. TDIXMEDIATYPE mediatype;
  167. // Handle of the IP stack address object returned from ZwCreateFile, and
  168. // the object address of same. The IP stack address is needed to use the
  169. // referenced route IOCTLs supported in IP, but not in UDP, i.e. IP route
  170. // management calls are used in both UDP and raw IP modes.
  171. //
  172. HANDLE hIpStackAddress;
  173. FILE_OBJECT* pIpStackAddress;
  174. // TDIXF_* bit flags indicating various options and states. Access is via
  175. // the interlocked ReadFlags/SetFlags/ClearFlags routines only.
  176. //
  177. // TDIXF_Pending: Set when an open or close operation is pending, clear
  178. // otherwise. Access is protected by 'lock'.
  179. //
  180. // TDIXF_DisableUdpXsums: Set when UDP checksums should be disabled.
  181. //
  182. ULONG ulFlags;
  183. #define TDIXF_Pending 0x00000001
  184. #define TDIXF_DisableUdpXsums 0x00000002
  185. // The strategy employed when it is time to add a host route and that
  186. // route is found to already exists.
  187. //
  188. HOSTROUTEEXISTS hre;
  189. // The NDIS buffer pool from which buffers for received datagrams are
  190. // allocated.
  191. //
  192. BUFFERPOOL* pPoolNdisBuffers;
  193. // Client's receive handler called when packets are received.
  194. //
  195. PTDIXRECEIVE pReceiveHandler;
  196. // Double-linked list of TDIXROUTEs. Access is protected by 'lock'.
  197. //
  198. LIST_ENTRY listRoutes;
  199. // Lookaside list of TDIXRDGINFO blocks, used to pass context information
  200. // from the ReadDatagram event handler to the RECEIVE_DATAGRAM completion
  201. // routine.
  202. //
  203. NPAGED_LOOKASIDE_LIST llistRdg;
  204. // Lookaside list of TDIXSDGINFO blocks, used to pass context information
  205. // from TdixSendDatagram to the SEND_DATAGRAM completion routine.
  206. //
  207. NPAGED_LOOKASIDE_LIST llistSdg;
  208. // Spinlock protecting access to TDIXCONTENT fields as noted in the field
  209. // descriptions.
  210. //
  211. NDIS_SPIN_LOCK lock;
  212. }
  213. TDIXCONTEXT;
  214. typedef struct
  215. _TDIXUDPCONNECTCONTEXT
  216. {
  217. // Set if we are using different address objects for
  218. // control and payload packets.
  219. //
  220. BOOLEAN fUsePayloadAddr;
  221. // Handle and address of the transport address object returned from
  222. // ZwCreateFile for sending l2tp control messages on this route.
  223. //
  224. HANDLE hCtrlAddr;
  225. FILE_OBJECT* pCtrlAddr;
  226. // Handle and address of the transport address object returned from
  227. // ZwCreateFile for sending l2tp payloads on this route.
  228. //
  229. HANDLE hPayloadAddr;
  230. FILE_OBJECT* pPayloadAddr;
  231. }
  232. TDIXUDPCONNECTCONTEXT;
  233. // Context information for a single host route. The contexts are linked into
  234. // the TDIXCONTEXT's list of host routes. Access to all fields is protected
  235. // by 'TDIXCONTEXT.lockHostRoutes'.
  236. //
  237. typedef struct
  238. _TDIXROUTE
  239. {
  240. // Double-linked link of 'TDIXCONTEXT.listRoutes'. The block is linked
  241. // whenever there is an L2TP host route context for a given route.
  242. //
  243. LIST_ENTRY linkRoutes;
  244. // Host IP address of the route in network byte order.
  245. //
  246. ULONG ulIpAddress;
  247. // Host port in network byte order.
  248. //
  249. SHORT sPort;
  250. // Interface index of added route.
  251. //
  252. ULONG InterfaceIndex;
  253. // Number of references on the route. A block may be linked with the
  254. // reference count at zero during deletion but never without the pending
  255. // flag set.
  256. //
  257. LONG lRef;
  258. // Set when an add or delete of this route is pending. References should
  259. // not be taken when either operation is pending.
  260. //
  261. BOOLEAN fPending;
  262. // Set if the route was not actually added because it already exists, i.e.
  263. // we are in HRE_Use mode and someone besides L2TP added it.
  264. //
  265. BOOLEAN fUsedNonL2tpRoute;
  266. // Set if we are using different address objects for
  267. // control and payload packets.
  268. //
  269. BOOLEAN fUsePayloadAddr;
  270. // Handle and address of the transport address object returned from
  271. // ZwCreateFile for sending l2tp control messages on this route.
  272. //
  273. HANDLE hCtrlAddr;
  274. FILE_OBJECT* pCtrlAddr;
  275. // Handle and address of the transport address object returned from
  276. // ZwCreateFile for sending l2tp payloads on this route.
  277. //
  278. HANDLE hPayloadAddr;
  279. FILE_OBJECT* pPayloadAddr;
  280. }
  281. TDIXROUTE;
  282. //-----------------------------------------------------------------------------
  283. // Interface prototypes
  284. //-----------------------------------------------------------------------------
  285. VOID
  286. TdixInitialize(
  287. IN TDIXMEDIATYPE mediatype,
  288. IN HOSTROUTEEXISTS hre,
  289. IN ULONG ulFlags,
  290. IN PTDIXRECEIVE pReceiveHandler,
  291. IN BUFFERPOOL* pPoolNdisBuffers,
  292. IN OUT TDIXCONTEXT* pTdix );
  293. NDIS_STATUS
  294. TdixOpen(
  295. OUT TDIXCONTEXT* pTdix );
  296. VOID
  297. TdixClose(
  298. IN TDIXCONTEXT* pTdix );
  299. VOID
  300. TdixReference(
  301. IN TDIXCONTEXT* pTdix );
  302. NDIS_STATUS
  303. TdixSend(
  304. IN TDIXCONTEXT* pTdix,
  305. IN FILE_OBJECT* pFileObj,
  306. IN PTDIXSENDCOMPLETE pSendCompleteHandler,
  307. IN VOID* pContext1,
  308. IN VOID* pContext2,
  309. IN VOID* pAddress,
  310. IN CHAR* pBuffer,
  311. IN ULONG ulBufferLength,
  312. OUT IRP** ppIrp ) ;
  313. NDIS_STATUS
  314. TdixSendDatagram(
  315. IN TDIXCONTEXT* pTdix,
  316. IN FILE_OBJECT* pFileObj,
  317. IN PTDIXSENDCOMPLETE pSendCompleteHandler,
  318. IN VOID* pContext1,
  319. IN VOID* pContext2,
  320. IN VOID* pAddress,
  321. IN CHAR* pBuffer,
  322. IN ULONG ulBufferLength,
  323. OUT IRP** ppIrp );
  324. VOID
  325. TdixDestroyConnection(
  326. TDIXUDPCONNECTCONTEXT *pUdpContext);
  327. NDIS_STATUS
  328. TdixSetupConnection(
  329. IN TDIXCONTEXT* pTdix,
  330. IN ULONG ulIpAddress,
  331. IN SHORT sPort,
  332. IN TDIXROUTE *pTdixRoute,
  333. IN TDIXUDPCONNECTCONTEXT* pUdpContext);
  334. VOID*
  335. TdixAddHostRoute(
  336. IN TDIXCONTEXT* pTdix,
  337. IN ULONG ulIpAddress,
  338. IN SHORT sPort);
  339. VOID
  340. TdixDeleteHostRoute(
  341. IN TDIXCONTEXT* pTdix,
  342. IN ULONG ulIpAddress);
  343. NTSTATUS
  344. TdixGetInterfaceInfo(
  345. IN TDIXCONTEXT* pTdix,
  346. IN ULONG ulIpAddress,
  347. OUT PULONG pulSpeed);
  348. #endif // _TDIX_H_