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.

267 lines
6.4 KiB

  1. /*++
  2. Copyright (c) 1997, Microsoft Corporation
  3. Module Name:
  4. pptp.h
  5. Abstract:
  6. This module contains declarations for the NAT's PPTP-support routines.
  7. Author:
  8. Abolade Gbadegesin (t-abolag) 18-Aug-1997
  9. Revision History:
  10. --*/
  11. #ifndef _NAT_PPTP_H_
  12. #define _NAT_PPTP_H_
  13. //
  14. // Structure: NAT_PPTP_MAPPING
  15. //
  16. // This structure stores a mapping created for a PPTP tunnel.
  17. //
  18. // Any PPTP tunnel is uniquely identified by the quadruple
  19. //
  20. // <PrivateAddress, RemoteAddress, PrivateCallID, RemoteCallID>
  21. //
  22. // We need to ensure that the 'PrivateCallID's are unique for all the machines
  23. // behind the NAT.
  24. //
  25. // Hence, the NAT watches all PPTP control sessions (TCP port 1723), and for
  26. // any PPTP call detected, allocates a call ID to replace the ID chosen by
  27. // the private-network PPTP endpoint.
  28. //
  29. // The allocation is recorded by creating an entry in a list of PPTP mappings,
  30. // which is sorted for outbound-tunnel-message searching on
  31. //
  32. // <RemoteAddress # PrivateAddress, RemoteCallId>
  33. //
  34. // and sorted for inbound-tunnel-message searching on
  35. //
  36. // <RemoteAddress # PublicAddress, PublicCallId>.
  37. //
  38. // When a mapping is first created, it is marked half-open and is inserted
  39. // only in the inbound-list, since no remote-call-ID is available to serve
  40. // as the secondary key in the outbound list. Later, when the call-reply
  41. // is received, the mapping is also placed on the outbound list.
  42. //
  43. // Access to the list of PPTP mappings is granted by 'PptpMappingLock'.
  44. //
  45. // N.B. On the rare occasions when 'MappingLock' must be held at the same time
  46. // as one of 'InterfaceLock', 'EditorLock', and 'DirectorLock', 'MappingLock'
  47. // must always be acquired first.
  48. //
  49. typedef struct _NAT_PPTP_MAPPING {
  50. LIST_ENTRY Link[NatMaximumDirection];
  51. ULONG64 PrivateKey;
  52. ULONG64 PublicKey;
  53. ULONG64 PortKey;
  54. USHORT PrivateCallId;
  55. USHORT PublicCallId;
  56. USHORT RemoteCallId;
  57. ULONG Flags;
  58. LONG64 LastAccessTime;
  59. } NAT_PPTP_MAPPING, *PNAT_PPTP_MAPPING;
  60. //
  61. // PPTP mapping flags
  62. //
  63. #define NAT_PPTP_FLAG_HALF_OPEN 0x00000001
  64. #define NAT_PPTP_FLAG_DISCONNECTED 0x00000002
  65. #define NAT_PPTP_HALF_OPEN(m) \
  66. ((m)->Flags & NAT_PPTP_FLAG_HALF_OPEN)
  67. #define NAT_PPTP_DISCONNECTED(m) \
  68. ((m)->Flags & NAT_PPTP_FLAG_DISCONNECTED)
  69. //
  70. // PPTP key-manipulation macros
  71. //
  72. #define MAKE_PPTP_KEY(RemoteAddress,OtherAddress) \
  73. ((ULONG)(RemoteAddress) | ((ULONG64)((ULONG)(OtherAddress)) << 32))
  74. #define PPTP_KEY_REMOTE(Key) ((ULONG)(Key))
  75. #define PPTP_KEY_PRIVATE(Key) ((ULONG)((Key) >> 32))
  76. #define PPTP_KEY_PUBLIC(Key) ((ULONG)((Key) >> 32))
  77. #define MAKE_PPTP_PORT_KEY(PrivatePort,PublicPort,RemotePort) \
  78. ((PrivatePort) | \
  79. ((ULONG64)((PublicPort) & 0xFFFF) << 16) | \
  80. ((ULONG64)((RemotePort) & 0xFFFF) << 32))
  81. #define PPTP_PORT_KEY_REMOTE(Key) ((USHORT)(((Key) >> 32) & 0xFFFF))
  82. #define PPTP_PORT_KEY_PUBLIC(Key) ((USHORT)(((Key) >> 16) & 0xFFFF))
  83. #define PPTP_PORT_KEY_PRIVATE(Key) ((USHORT)(Key))
  84. //
  85. // PPTP mapping allocation macros
  86. //
  87. #define ALLOCATE_PPTP_BLOCK() \
  88. ExAllocateFromNPagedLookasideList(&PptpLookasideList)
  89. #define FREE_PPTP_BLOCK(Block) \
  90. ExFreeToNPagedLookasideList(&PptpLookasideList,(Block))
  91. //
  92. // Define the depth of the lookaside list for allocating PPTP mappings
  93. //
  94. #define PPTP_LOOKASIDE_DEPTH 10
  95. //
  96. // Global data declarations
  97. //
  98. extern NPAGED_LOOKASIDE_LIST PptpLookasideList;
  99. extern LIST_ENTRY PptpMappingList[NatMaximumDirection];
  100. extern KSPIN_LOCK PptpMappingLock;
  101. extern IP_NAT_REGISTER_EDITOR PptpRegisterEditorClient;
  102. extern IP_NAT_REGISTER_EDITOR PptpRegisterEditorServer;
  103. //
  104. // PPTP mapping management routines
  105. //
  106. NTSTATUS
  107. NatAllocatePublicPptpCallId(
  108. ULONG64 PublicKey,
  109. PUSHORT CallIdp,
  110. PLIST_ENTRY *InsertionPoint OPTIONAL
  111. );
  112. NTSTATUS
  113. NatCreatePptpMapping(
  114. ULONG RemoteAddress,
  115. ULONG PrivateAddress,
  116. USHORT PrivateCallId,
  117. ULONG PublicAddress,
  118. PUSHORT CallIdp,
  119. IP_NAT_DIRECTION Direction,
  120. USHORT PrivatePort,
  121. USHORT PublicPort,
  122. USHORT RemotePort,
  123. PNAT_PPTP_MAPPING* MappingCreated
  124. );
  125. NTSTATUS
  126. NatInitializePptpManagement(
  127. VOID
  128. );
  129. PNAT_PPTP_MAPPING
  130. NatLookupInboundPptpMapping(
  131. ULONG64 PublicKey,
  132. USHORT PrivateCallId,
  133. PLIST_ENTRY* InsertionPoint
  134. );
  135. PNAT_PPTP_MAPPING
  136. NatLookupOutboundPptpMapping(
  137. ULONG64 PrivateKey,
  138. USHORT RemoteCallId,
  139. PLIST_ENTRY* InsertionPoint
  140. );
  141. VOID
  142. NatShutdownPptpManagement(
  143. VOID
  144. );
  145. //
  146. // PPTP control-connection editor routines
  147. //
  148. NTSTATUS
  149. NatClientToServerDataHandlerPptp(
  150. IN PVOID InterfaceHandle,
  151. IN PVOID SessionHandle,
  152. IN PVOID DataHandle,
  153. IN PVOID EditorContext,
  154. IN PVOID EditorSessionContext,
  155. IN PVOID ReceiveBuffer,
  156. IN ULONG DataOffset,
  157. IN IP_NAT_DIRECTION Direction
  158. );
  159. NTSTATUS
  160. NatDeleteHandlerPptp(
  161. IN PVOID InterfaceHandle,
  162. IN PVOID SessionHandle,
  163. IN PVOID EditorContext,
  164. IN PVOID EditorSessionContext
  165. );
  166. NTSTATUS
  167. NatInboundDataHandlerPptpClient(
  168. IN PVOID InterfaceHandle,
  169. IN PVOID SessionHandle,
  170. IN PVOID DataHandle,
  171. IN PVOID EditorContext,
  172. IN PVOID EditorSessionContext,
  173. IN PVOID RecvBuffer,
  174. IN ULONG DataOffset
  175. );
  176. NTSTATUS
  177. NatInboundDataHandlerPptpServer(
  178. IN PVOID InterfaceHandle,
  179. IN PVOID SessionHandle,
  180. IN PVOID DataHandle,
  181. IN PVOID EditorContext,
  182. IN PVOID EditorSessionContext,
  183. IN PVOID RecvBuffer,
  184. IN ULONG DataOffset
  185. );
  186. NTSTATUS
  187. NatOutboundDataHandlerPptpClient(
  188. IN PVOID InterfaceHandle,
  189. IN PVOID SessionHandle,
  190. IN PVOID DataHandle,
  191. IN PVOID EditorContext,
  192. IN PVOID EditorSessionContext,
  193. IN PVOID RecvBuffer,
  194. IN ULONG DataOffset
  195. );
  196. NTSTATUS
  197. NatOutboundDataHandlerPptpServer(
  198. IN PVOID InterfaceHandle,
  199. IN PVOID SessionHandle,
  200. IN PVOID DataHandle,
  201. IN PVOID EditorContext,
  202. IN PVOID EditorSessionContext,
  203. IN PVOID RecvBuffer,
  204. IN ULONG DataOffset
  205. );
  206. NTSTATUS
  207. NatServerToClientDataHandlerPptp(
  208. IN PVOID InterfaceHandle,
  209. IN PVOID SessionHandle,
  210. IN PVOID DataHandle,
  211. IN PVOID EditorContext,
  212. IN PVOID EditorSessionContext,
  213. IN PVOID ReceiveBuffer,
  214. IN ULONG DataOffset,
  215. IN IP_NAT_DIRECTION Direction
  216. );
  217. XLATE_IP_ROUTINE(NatTranslatePptp)
  218. #endif // _NAT_PPTP_H_