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.

261 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 1997, Microsoft Corporation
  3. Module Name:
  4. ticket.h
  5. Abstract:
  6. This module contains declarations for the NAT's ticket-management.
  7. A NAT ticket is a dynamically-created token which allows any external
  8. endpoint to establish a session to an internal endpoint using an allocated
  9. public address/port pair. For instance, a streaming protocol might create
  10. a ticket for a dynamically-negotiated secondary session to be established.
  11. Author:
  12. Abolade Gbadegesin (t-abolag) 21-Aug-1997
  13. Revision History:
  14. Abolade Gbadegesin (aboladeg) 16-Apr-1998
  15. Allow wildcard tickets to be created by specifying zero for a field.
  16. 'NatLookupAndRemoveTicket' may be used to retrieve such tickets.
  17. Abolade Gbadegesin (aboladeg) 17-Oct-1998
  18. Eliminated wildcard ticket support. Created dynamic ticket support.
  19. (See 'NAT_DYNAMIC_TICKET' below.)
  20. --*/
  21. #ifndef _NAT_TICKET_H_
  22. #define _NAT_TICKET_H_
  23. //
  24. // Structure: NAT_TICKET
  25. //
  26. // This structure holds all the information we need about a ticket.
  27. // Each instance is linked into a sorted per-interface list of tickets
  28. // which is protected by the interface's lock.
  29. //
  30. typedef struct _NAT_TICKET {
  31. LIST_ENTRY Link;
  32. ULONG64 Key;
  33. ULONG64 RemoteKey;
  34. PNAT_USED_ADDRESS UsedAddress;
  35. ULONG PrivateAddress;
  36. USHORT PrivateOrHostOrderEndPort;
  37. ULONG Flags;
  38. LONG64 LastAccessTime;
  39. } NAT_TICKET, *PNAT_TICKET;
  40. //
  41. // Structure: NAT_DYNAMIC_TICKET
  42. //
  43. // This structure holds the description of a dynamic ticket.
  44. // Such a ticket is created so that when an outbound session is translated
  45. // with a given destination port, a ticket can be created for a corresponding
  46. // inbound session to a predetermined port, or to one of a range of ports.
  47. //
  48. typedef struct _NAT_DYNAMIC_TICKET {
  49. LIST_ENTRY Link;
  50. ULONG Key;
  51. ULONG ResponseCount;
  52. struct {
  53. UCHAR Protocol;
  54. USHORT StartPort;
  55. USHORT EndPort;
  56. }* ResponseArray;
  57. PFILE_OBJECT FileObject;
  58. } NAT_DYNAMIC_TICKET, *PNAT_DYNAMIC_TICKET;
  59. //
  60. // Ticket flags
  61. //
  62. #define NAT_TICKET_FLAG_PERSISTENT 0x00000001
  63. #define NAT_TICKET_PERSISTENT(t) \
  64. ((t)->Flags & NAT_TICKET_FLAG_PERSISTENT)
  65. #define NAT_TICKET_FLAG_PORT_MAPPING 0x00000002
  66. #define NAT_TICKET_PORT_MAPPING(t) \
  67. ((t)->Flags & NAT_TICKET_FLAG_PORT_MAPPING)
  68. #define NAT_TICKET_FLAG_IS_RANGE 0x00000004
  69. #define NAT_TICKET_IS_RANGE(t) \
  70. ((t)->Flags & NAT_TICKET_FLAG_IS_RANGE)
  71. //
  72. // Ticket-key manipulation macros
  73. //
  74. #define MAKE_TICKET_KEY(Protocol,Address,Port) \
  75. ((Address) | \
  76. ((ULONG64)((Port) & 0xFFFF) << 32) | \
  77. ((ULONG64)((Protocol) & 0xFF) << 48))
  78. #define TICKET_PROTOCOL(Key) ((UCHAR)(((Key) >> 48) & 0xFF))
  79. #define TICKET_PORT(Key) ((USHORT)(((Key) >> 32) & 0xFFFF))
  80. #define TICKET_ADDRESS(Key) ((ULONG)(Key))
  81. #define MAKE_DYNAMIC_TICKET_KEY(Protocol, Port) \
  82. ((ULONG)((Port) & 0xFFFF) | ((ULONG)((Protocol) & 0xFF) << 16))
  83. #define DYNAMIC_TICKET_PROTOCOL(Key) ((UCHAR)(((Key) >> 16) & 0xFF))
  84. #define DYNAMIC_TICKET_PORT(Key) ((USHORT)((Key) & 0xFFFF))
  85. //
  86. // Ticket allocation macros
  87. //
  88. #define ALLOCATE_TICKET_BLOCK() \
  89. (PNAT_TICKET)ExAllocatePoolWithTag( \
  90. NonPagedPool,sizeof(NAT_TICKET), NAT_TAG_TICKET \
  91. )
  92. #define FREE_TICKET_BLOCK(Block) \
  93. ExFreePool(Block)
  94. //
  95. // GLOBAL DATA DECLARATIONS
  96. //
  97. ULONG DynamicTicketCount;
  98. ULONG TicketCount;
  99. //
  100. // TICKET MANAGEMENT ROUTINES
  101. //
  102. NTSTATUS
  103. NatCreateDynamicTicket(
  104. PIP_NAT_CREATE_DYNAMIC_TICKET CreateTicket,
  105. ULONG InputBufferLength,
  106. PFILE_OBJECT FileObject
  107. );
  108. NTSTATUS
  109. NatCreateTicket(
  110. PNAT_INTERFACE Interfacep,
  111. UCHAR Protocol,
  112. ULONG PrivateAddress,
  113. USHORT PrivatePort,
  114. ULONG RemoteAddress OPTIONAL,
  115. ULONG RemotePort OPTIONAL,
  116. ULONG Flags,
  117. PNAT_USED_ADDRESS AddressToUse OPTIONAL,
  118. USHORT PortToUse OPTIONAL,
  119. PULONG PublicAddress,
  120. PUSHORT PublicPort
  121. );
  122. VOID
  123. NatDeleteAnyAssociatedDynamicTicket(
  124. PFILE_OBJECT FileObject
  125. );
  126. NTSTATUS
  127. NatDeleteDynamicTicket(
  128. PIP_NAT_DELETE_DYNAMIC_TICKET DeleteTicket,
  129. PFILE_OBJECT FileObject
  130. );
  131. VOID
  132. NatDeleteTicket(
  133. PNAT_INTERFACE Interfacep,
  134. PNAT_TICKET Ticketp
  135. );
  136. VOID
  137. NatInitializeDynamicTicketManagement(
  138. VOID
  139. );
  140. BOOLEAN
  141. NatIsPortUsedByTicket(
  142. PNAT_INTERFACE Interfacep,
  143. UCHAR Protocol,
  144. USHORT PublicPort
  145. );
  146. VOID
  147. NatLookupAndApplyDynamicTicket(
  148. UCHAR Protocol,
  149. USHORT DestinationPort,
  150. PNAT_INTERFACE Interfacep,
  151. ULONG PublicAddress,
  152. ULONG PrivateAddress
  153. );
  154. NTSTATUS
  155. NatLookupAndDeleteTicket(
  156. PNAT_INTERFACE Interfacep,
  157. ULONG64 Key,
  158. ULONG64 RemoteKey
  159. );
  160. NTSTATUS
  161. NatLookupAndRemoveTicket(
  162. PNAT_INTERFACE Interfacep,
  163. ULONG64 Key,
  164. ULONG64 RemoteKey,
  165. PNAT_USED_ADDRESS* UsedAddress,
  166. PULONG PrivateAddress,
  167. PUSHORT PrivatePort
  168. );
  169. PNAT_TICKET
  170. NatLookupFirewallTicket(
  171. PNAT_INTERFACE Interfacep,
  172. UCHAR Protocol,
  173. USHORT Port
  174. );
  175. PNAT_TICKET
  176. NatLookupTicket(
  177. PNAT_INTERFACE Interfacep,
  178. ULONG64 Key,
  179. ULONG64 RemoteKey,
  180. PLIST_ENTRY* InsertionPoint
  181. );
  182. PNAT_DYNAMIC_TICKET
  183. NatLookupDynamicTicket(
  184. ULONG Key,
  185. PLIST_ENTRY* InsertionPoint
  186. );
  187. NTSTATUS
  188. NatProcessCreateTicket(
  189. PIP_NAT_CREATE_TICKET CreateTicket,
  190. PFILE_OBJECT FileObject
  191. );
  192. NTSTATUS
  193. NatProcessDeleteTicket(
  194. PIP_NAT_CREATE_TICKET DeleteTicket,
  195. PFILE_OBJECT FileObject
  196. );
  197. NTSTATUS
  198. NatProcessLookupTicket(
  199. PIP_NAT_CREATE_TICKET LookupTicket,
  200. PIP_NAT_PORT_MAPPING Ticket,
  201. PFILE_OBJECT FileObject
  202. );
  203. VOID
  204. NatShutdownDynamicTicketManagement(
  205. VOID
  206. );
  207. #endif // _NAT_TICKET_H_