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.

427 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. // Handle of the raw IP address object returned from ZwCreateFile, and
  165. // the object address of same.
  166. //
  167. HANDLE hRawAddress;
  168. FILE_OBJECT* pRawAddress;
  169. // The media type in use on this context.
  170. //
  171. TDIXMEDIATYPE mediatype;
  172. // Handle of the IP stack address object returned from ZwCreateFile, and
  173. // the object address of same. The IP stack address is needed to use the
  174. // referenced route IOCTLs supported in IP, but not in UDP, i.e. IP route
  175. // management calls are used in both UDP and raw IP modes.
  176. //
  177. HANDLE hIpStackAddress;
  178. FILE_OBJECT* pIpStackAddress;
  179. // TDIXF_* bit flags indicating various options and states. Access is via
  180. // the interlocked ReadFlags/SetFlags/ClearFlags routines only.
  181. //
  182. // TDIXF_Pending: Set when an open or close operation is pending, clear
  183. // otherwise. Access is protected by 'lock'.
  184. //
  185. // TDIXF_DisableUdpXsums: Set when UDP checksums should be disabled.
  186. //
  187. ULONG ulFlags;
  188. #define TDIXF_Pending 0x00000001
  189. #define TDIXF_DisableUdpXsums 0x00000002
  190. // The strategy employed when it is time to add a host route and that
  191. // route is found to already exists.
  192. //
  193. HOSTROUTEEXISTS hre;
  194. // The NDIS buffer pool from which buffers for received datagrams are
  195. // allocated.
  196. //
  197. BUFFERPOOL* pPoolNdisBuffers;
  198. // Client's receive handler called when packets are received.
  199. //
  200. PTDIXRECEIVE pReceiveHandler;
  201. // Double-linked list of TDIXROUTEs. Access is protected by 'lock'.
  202. //
  203. LIST_ENTRY listRoutes;
  204. // Lookaside list of TDIXRDGINFO blocks, used to pass context information
  205. // from the ReadDatagram event handler to the RECEIVE_DATAGRAM completion
  206. // routine.
  207. //
  208. NPAGED_LOOKASIDE_LIST llistRdg;
  209. // Lookaside list of TDIXSDGINFO blocks, used to pass context information
  210. // from TdixSendDatagram to the SEND_DATAGRAM completion routine.
  211. //
  212. NPAGED_LOOKASIDE_LIST llistSdg;
  213. // Spinlock protecting access to TDIXCONTENT fields as noted in the field
  214. // descriptions.
  215. //
  216. NDIS_SPIN_LOCK lock;
  217. }
  218. TDIXCONTEXT;
  219. typedef struct
  220. _TDIXUDPCONNECTCONTEXT
  221. {
  222. // Set if we are using different address objects for
  223. // control and payload packets.
  224. //
  225. BOOLEAN fUsePayloadAddr;
  226. // Handle and address of the transport address object returned from
  227. // ZwCreateFile for sending l2tp control messages on this route.
  228. //
  229. HANDLE hCtrlAddr;
  230. FILE_OBJECT* pCtrlAddr;
  231. // Handle and address of the transport address object returned from
  232. // ZwCreateFile for sending l2tp payloads on this route.
  233. //
  234. HANDLE hPayloadAddr;
  235. FILE_OBJECT* pPayloadAddr;
  236. }
  237. TDIXUDPCONNECTCONTEXT;
  238. // Context information for a single host route. The contexts are linked into
  239. // the TDIXCONTEXT's list of host routes. Access to all fields is protected
  240. // by 'TDIXCONTEXT.lockHostRoutes'.
  241. //
  242. typedef struct
  243. _TDIXROUTE
  244. {
  245. // Double-linked link of 'TDIXCONTEXT.listRoutes'. The block is linked
  246. // whenever there is an L2TP host route context for a given route.
  247. //
  248. LIST_ENTRY linkRoutes;
  249. // Host IP address of the route in network byte order.
  250. //
  251. ULONG ulIpAddress;
  252. // Host port in network byte order.
  253. //
  254. SHORT sPort;
  255. // Interface index of added route.
  256. //
  257. ULONG InterfaceIndex;
  258. // Number of references on the route. A block may be linked with the
  259. // reference count at zero during deletion but never without the pending
  260. // flag set.
  261. //
  262. LONG lRef;
  263. // Set when an add or delete of this route is pending. References should
  264. // not be taken when either operation is pending.
  265. //
  266. BOOLEAN fPending;
  267. // Set if the route was not actually added because it already exists, i.e.
  268. // we are in HRE_Use mode and someone besides L2TP added it.
  269. //
  270. BOOLEAN fUsedNonL2tpRoute;
  271. // Set if we are using different address objects for
  272. // control and payload packets.
  273. //
  274. BOOLEAN fUsePayloadAddr;
  275. // Handle and address of the transport address object returned from
  276. // ZwCreateFile for sending l2tp control messages on this route.
  277. //
  278. HANDLE hCtrlAddr;
  279. FILE_OBJECT* pCtrlAddr;
  280. // Handle and address of the transport address object returned from
  281. // ZwCreateFile for sending l2tp payloads on this route.
  282. //
  283. HANDLE hPayloadAddr;
  284. FILE_OBJECT* pPayloadAddr;
  285. }
  286. TDIXROUTE;
  287. //-----------------------------------------------------------------------------
  288. // Interface prototypes
  289. //-----------------------------------------------------------------------------
  290. VOID
  291. TdixInitialize(
  292. IN TDIXMEDIATYPE mediatype,
  293. IN HOSTROUTEEXISTS hre,
  294. IN ULONG ulFlags,
  295. IN PTDIXRECEIVE pReceiveHandler,
  296. IN BUFFERPOOL* pPoolNdisBuffers,
  297. IN OUT TDIXCONTEXT* pTdix );
  298. NDIS_STATUS
  299. TdixOpen(
  300. OUT TDIXCONTEXT* pTdix );
  301. VOID
  302. TdixClose(
  303. IN TDIXCONTEXT* pTdix );
  304. VOID
  305. TdixReference(
  306. IN TDIXCONTEXT* pTdix );
  307. NDIS_STATUS
  308. TdixSend(
  309. IN TDIXCONTEXT* pTdix,
  310. IN FILE_OBJECT* pFileObj,
  311. IN PTDIXSENDCOMPLETE pSendCompleteHandler,
  312. IN VOID* pContext1,
  313. IN VOID* pContext2,
  314. IN VOID* pAddress,
  315. IN CHAR* pBuffer,
  316. IN ULONG ulBufferLength,
  317. OUT IRP** ppIrp ) ;
  318. NDIS_STATUS
  319. TdixSendDatagram(
  320. IN TDIXCONTEXT* pTdix,
  321. IN FILE_OBJECT* pFileObj,
  322. IN PTDIXSENDCOMPLETE pSendCompleteHandler,
  323. IN VOID* pContext1,
  324. IN VOID* pContext2,
  325. IN VOID* pAddress,
  326. IN CHAR* pBuffer,
  327. IN ULONG ulBufferLength,
  328. OUT IRP** ppIrp );
  329. VOID
  330. TdixDestroyConnection(
  331. TDIXUDPCONNECTCONTEXT *pUdpContext);
  332. NDIS_STATUS
  333. TdixSetupConnection(
  334. IN TDIXCONTEXT* pTdix,
  335. IN TDIXROUTE *pTdixRoute,
  336. IN ULONG ulLocalIpAddress,
  337. IN TDIXUDPCONNECTCONTEXT* pUdpContext);
  338. VOID*
  339. TdixAddHostRoute(
  340. IN TDIXCONTEXT* pTdix,
  341. IN ULONG ulIpAddress,
  342. IN ULONG ulIfIndex);
  343. VOID
  344. TdixDeleteHostRoute(
  345. IN TDIXCONTEXT* pTdix,
  346. IN ULONG ulIpAddress);
  347. NTSTATUS
  348. TdixGetInterfaceInfo(
  349. IN TDIXCONTEXT* pTdix,
  350. IN ULONG ulIpAddress,
  351. OUT PULONG pulSpeed);
  352. #endif // _TDIX_H_