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.

217 lines
5.1 KiB

  1. /*++
  2. Module Name:
  3. director.h
  4. Abstract:
  5. This module contains declarations for the NAT's director-handling.
  6. Directors are consulted about the routing of incoming sessions.
  7. Author:
  8. Abolade Gbadegesin (aboladeg) 16-Feb-1998
  9. Revision History:
  10. Abolade Gbadegesin (aboladeg) 19-Apr-1998
  11. Added support for wildcards in protocol/port of a director registration.
  12. --*/
  13. #ifndef _NAT_DIRECTOR_H_
  14. #define _NAT_DIRECTOR_H_
  15. //
  16. // Structure: NAT_DIRECTOR
  17. //
  18. // Holds information about a director
  19. //
  20. // Each director is on a global list ('DirectorList') which is protected
  21. // by a spin lock ('DirectorLock'). The list is sorted on a key composed of
  22. // the protocol of the sessions to be edited and the protocol port number.
  23. //
  24. // N.B. The list is sorted in **descending** order. We allow wildcard
  25. // registrations (e.g. port 0 means any port) so when searching for a director,
  26. // using descending order allows us to find more specific matches before
  27. // less-specific matches. The composition of the keys is critical in making
  28. // this work; the protocol is in the most-significant part of the key,
  29. // and the port is in the less-significant part.
  30. //
  31. // Access to directors is synchronized using the same reference-counting logic
  32. // used to synchronize access to interfaces. See 'IF.H' for more information.
  33. //
  34. // Each session being directed by a director is linked into the director's list
  35. // of mappings ('MappingList'). Access to this list of mappings must also
  36. // be synchronized. This is achieved using 'DirectorMappingLock', which
  37. // must be acquired before modifying any director's list of mappings.
  38. // See 'MAPPING.H' for further details.
  39. //
  40. // N.B. On the rare occasions when 'MappingLock' must be held at the same time
  41. // as one of 'InterfaceLock', 'EditorLock', and 'DirectorLock', 'MappingLock'
  42. // must always be acquired first. Again, see 'MAPPING.H' for further details.
  43. //
  44. typedef struct _NAT_DIRECTOR {
  45. LIST_ENTRY Link;
  46. ULONG Key;
  47. ULONG ReferenceCount;
  48. KSPIN_LOCK Lock;
  49. LIST_ENTRY MappingList;
  50. ULONG Flags;
  51. PVOID Context; // read-only
  52. PNAT_DIRECTOR_QUERY_SESSION QueryHandler; // read-only
  53. PNAT_DIRECTOR_CREATE_SESSION CreateHandler; // read-only
  54. PNAT_DIRECTOR_DELETE_SESSION DeleteHandler; // read-only
  55. PNAT_DIRECTOR_UNLOAD UnloadHandler; // read-only
  56. } NAT_DIRECTOR, *PNAT_DIRECTOR;
  57. //
  58. // Definitions of flags for the field NAT_DIRECTOR.Flags
  59. //
  60. #define NAT_DIRECTOR_FLAG_DELETED 0x80000000
  61. #define NAT_DIRECTOR_DELETED(Director) \
  62. ((Director)->Flags & NAT_DIRECTOR_FLAG_DELETED)
  63. //
  64. // Director key-manipulation macros
  65. //
  66. #define MAKE_DIRECTOR_KEY(Protocol,Port) \
  67. (((ULONG)((Protocol) & 0xFF) << 16) | \
  68. (ULONG)((Port) & 0xFFFF))
  69. #define DIRECTOR_KEY_PORT(Key) ((USHORT)((Key) & 0x0000FFFF))
  70. #define DIRECTOR_KEY_PROTOCOL(Key) ((UCHAR)((Key) >> 16))
  71. //
  72. // GLOBAL DATA DECLARATIONS
  73. //
  74. extern ULONG DirectorCount;
  75. extern LIST_ENTRY DirectorList;
  76. extern KSPIN_LOCK DirectorLock;
  77. extern KSPIN_LOCK DirectorMappingLock;
  78. //
  79. // DIRECTOR MANAGEMENT ROUTINES
  80. //
  81. VOID
  82. NatCleanupDirector(
  83. PNAT_DIRECTOR Director
  84. );
  85. NTSTATUS
  86. NatCreateDirector(
  87. PIP_NAT_REGISTER_DIRECTOR RegisterContext
  88. );
  89. NTSTATUS
  90. NatDeleteDirector(
  91. PNAT_DIRECTOR Director
  92. );
  93. //
  94. // BOOLEAN
  95. // NatDereferenceDirector(
  96. // PNAT_DIRECTOR Director
  97. // );
  98. //
  99. #define \
  100. NatDereferenceDirector( \
  101. _Director \
  102. ) \
  103. (InterlockedDecrement(&(_Director)->ReferenceCount) \
  104. ? TRUE \
  105. : NatCleanupDirector(_Director), FALSE)
  106. VOID
  107. NatInitializeDirectorManagement(
  108. VOID
  109. );
  110. PNAT_DIRECTOR
  111. NatLookupAndReferenceDirector(
  112. UCHAR Protocol,
  113. USHORT Port
  114. );
  115. PNAT_DIRECTOR
  116. NatLookupDirector(
  117. ULONG Key,
  118. PLIST_ENTRY* InsertionPoint
  119. );
  120. struct _NAT_DYNAMIC_MAPPING;
  121. VOID
  122. NatMappingAttachDirector(
  123. PNAT_DIRECTOR Director,
  124. PVOID DirectorSessionContext,
  125. struct _NAT_DYNAMIC_MAPPING* Mapping
  126. );
  127. VOID
  128. NatMappingDetachDirector(
  129. PNAT_DIRECTOR Director,
  130. PVOID DirectorSessionContext,
  131. struct _NAT_DYNAMIC_MAPPING* Mapping,
  132. IP_NAT_DELETE_REASON DeleteReason
  133. );
  134. NTSTATUS
  135. NatQueryDirectorTable(
  136. IN PIP_NAT_ENUMERATE_DIRECTORS InputBuffer,
  137. IN PIP_NAT_ENUMERATE_DIRECTORS OutputBuffer,
  138. IN PULONG OutputBufferLength
  139. );
  140. //
  141. // BOOLEAN
  142. // NatReferenceDirector(
  143. // PNAT_DIRECTOR Director
  144. // );
  145. //
  146. #define \
  147. NatReferenceDirector( \
  148. _Director \
  149. ) \
  150. (NAT_DIRECTOR_DELETED(_Director) \
  151. ? FALSE \
  152. : InterlockedIncrement(&(_Director)->ReferenceCount), TRUE)
  153. VOID
  154. NatShutdownDirectorManagement(
  155. VOID
  156. );
  157. //
  158. // HELPER ROUTINES
  159. //
  160. NTSTATUS
  161. NatDirectorDeregister(
  162. IN PVOID DirectorHandle
  163. );
  164. NTSTATUS
  165. NatDirectorDissociateSession(
  166. IN PVOID EditorHandle,
  167. IN PVOID SessionHandle
  168. );
  169. VOID
  170. NatDirectorQueryInfoSession(
  171. IN PVOID SessionHandle,
  172. OUT PIP_NAT_SESSION_MAPPING_STATISTICS Statistics OPTIONAL
  173. );
  174. #endif // _NAT_DIRECTOR_H_