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.

254 lines
5.7 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. USHORT PrivateCallId;
  54. USHORT PublicCallId;
  55. USHORT RemoteCallId;
  56. ULONG Flags;
  57. LONG64 LastAccessTime;
  58. } NAT_PPTP_MAPPING, *PNAT_PPTP_MAPPING;
  59. //
  60. // PPTP mapping flags
  61. //
  62. #define NAT_PPTP_FLAG_HALF_OPEN 0x00000001
  63. #define NAT_PPTP_FLAG_DISCONNECTED 0x00000002
  64. #define NAT_PPTP_HALF_OPEN(m) \
  65. ((m)->Flags & NAT_PPTP_FLAG_HALF_OPEN)
  66. #define NAT_PPTP_DISCONNECTED(m) \
  67. ((m)->Flags & NAT_PPTP_FLAG_DISCONNECTED)
  68. //
  69. // PPTP key-manipulation macros
  70. //
  71. #define MAKE_PPTP_KEY(RemoteAddress,OtherAddress) \
  72. ((ULONG)(RemoteAddress) | ((ULONG64)((ULONG)(OtherAddress)) << 32))
  73. #define PPTP_KEY_REMOTE(Key) ((ULONG)(Key))
  74. #define PPTP_KEY_PRIVATE(Key) ((ULONG)((Key) >> 32))
  75. #define PPTP_KEY_PUBLIC(Key) ((ULONG)((Key) >> 32))
  76. //
  77. // PPTP mapping allocation macros
  78. //
  79. #define ALLOCATE_PPTP_BLOCK() \
  80. ExAllocateFromNPagedLookasideList(&PptpLookasideList)
  81. #define FREE_PPTP_BLOCK(Block) \
  82. ExFreeToNPagedLookasideList(&PptpLookasideList,(Block))
  83. //
  84. // Define the depth of the lookaside list for allocating PPTP mappings
  85. //
  86. #define PPTP_LOOKASIDE_DEPTH 10
  87. //
  88. // Global data declarations
  89. //
  90. extern NPAGED_LOOKASIDE_LIST PptpLookasideList;
  91. extern LIST_ENTRY PptpMappingList[NatMaximumDirection];
  92. extern KSPIN_LOCK PptpMappingLock;
  93. extern IP_NAT_REGISTER_EDITOR PptpRegisterEditorClient;
  94. extern IP_NAT_REGISTER_EDITOR PptpRegisterEditorServer;
  95. //
  96. // PPTP mapping management routines
  97. //
  98. NTSTATUS
  99. NatAllocatePublicPptpCallId(
  100. ULONG64 PublicKey,
  101. PUSHORT CallIdp,
  102. PLIST_ENTRY *InsertionPoint OPTIONAL
  103. );
  104. NTSTATUS
  105. NatCreatePptpMapping(
  106. ULONG RemoteAddress,
  107. ULONG PrivateAddress,
  108. USHORT PrivateCallId,
  109. ULONG PublicAddress,
  110. PUSHORT CallIdp,
  111. IP_NAT_DIRECTION Direction,
  112. PNAT_PPTP_MAPPING* MappingCreated
  113. );
  114. NTSTATUS
  115. NatInitializePptpManagement(
  116. VOID
  117. );
  118. PNAT_PPTP_MAPPING
  119. NatLookupInboundPptpMapping(
  120. ULONG64 PublicKey,
  121. USHORT PrivateCallId,
  122. PLIST_ENTRY* InsertionPoint
  123. );
  124. PNAT_PPTP_MAPPING
  125. NatLookupOutboundPptpMapping(
  126. ULONG64 PrivateKey,
  127. USHORT RemoteCallId,
  128. PLIST_ENTRY* InsertionPoint
  129. );
  130. VOID
  131. NatShutdownPptpManagement(
  132. VOID
  133. );
  134. //
  135. // PPTP control-connection editor routines
  136. //
  137. NTSTATUS
  138. NatClientToServerDataHandlerPptp(
  139. IN PVOID InterfaceHandle,
  140. IN PVOID SessionHandle,
  141. IN PVOID DataHandle,
  142. IN PVOID EditorContext,
  143. IN PVOID EditorSessionContext,
  144. IN PVOID ReceiveBuffer,
  145. IN ULONG DataOffset,
  146. IN IP_NAT_DIRECTION Direction
  147. );
  148. NTSTATUS
  149. NatDeleteHandlerPptp(
  150. IN PVOID InterfaceHandle,
  151. IN PVOID SessionHandle,
  152. IN PVOID EditorContext,
  153. IN PVOID EditorSessionContext
  154. );
  155. NTSTATUS
  156. NatInboundDataHandlerPptpClient(
  157. IN PVOID InterfaceHandle,
  158. IN PVOID SessionHandle,
  159. IN PVOID DataHandle,
  160. IN PVOID EditorContext,
  161. IN PVOID EditorSessionContext,
  162. IN PVOID RecvBuffer,
  163. IN ULONG DataOffset
  164. );
  165. NTSTATUS
  166. NatInboundDataHandlerPptpServer(
  167. IN PVOID InterfaceHandle,
  168. IN PVOID SessionHandle,
  169. IN PVOID DataHandle,
  170. IN PVOID EditorContext,
  171. IN PVOID EditorSessionContext,
  172. IN PVOID RecvBuffer,
  173. IN ULONG DataOffset
  174. );
  175. NTSTATUS
  176. NatOutboundDataHandlerPptpClient(
  177. IN PVOID InterfaceHandle,
  178. IN PVOID SessionHandle,
  179. IN PVOID DataHandle,
  180. IN PVOID EditorContext,
  181. IN PVOID EditorSessionContext,
  182. IN PVOID RecvBuffer,
  183. IN ULONG DataOffset
  184. );
  185. NTSTATUS
  186. NatOutboundDataHandlerPptpServer(
  187. IN PVOID InterfaceHandle,
  188. IN PVOID SessionHandle,
  189. IN PVOID DataHandle,
  190. IN PVOID EditorContext,
  191. IN PVOID EditorSessionContext,
  192. IN PVOID RecvBuffer,
  193. IN ULONG DataOffset
  194. );
  195. NTSTATUS
  196. NatServerToClientDataHandlerPptp(
  197. IN PVOID InterfaceHandle,
  198. IN PVOID SessionHandle,
  199. IN PVOID DataHandle,
  200. IN PVOID EditorContext,
  201. IN PVOID EditorSessionContext,
  202. IN PVOID ReceiveBuffer,
  203. IN ULONG DataOffset,
  204. IN IP_NAT_DIRECTION Direction
  205. );
  206. XLATE_IP_ROUTINE(NatTranslatePptp)
  207. #endif // _NAT_PPTP_H_