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.

290 lines
6.1 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. editor.h
  5. Abstract:
  6. This module contains declarations related to management of session-editors.
  7. Author:
  8. Abolade Gbadegesin (t-abolag) 14-July-1997
  9. Revision History:
  10. --*/
  11. #ifndef _NAT_EDITOR_H_
  12. #define _NAT_EDITOR_H_
  13. //
  14. // Structure: NAT_EDITOR
  15. //
  16. // Holds information about an editor
  17. //
  18. // Each editor is on a global list of editors ('EditorList') which is protected
  19. // by a spin lock ('EditorLock'). The list is sorted on a key composed of
  20. // the protocol of the sessions to be edited, the protocol port number, and
  21. // the flag indicating whether the defining port is the destination or source.
  22. //
  23. // Access to editors is synchronized using the same reference-counting logic
  24. // as access to interfaces. See 'IF.H' for more information.
  25. //
  26. // Each session being edited by an editor is linked into the editor's list
  27. // of mappings ('MappingList'). Access to this list of mappings must also
  28. // be synchronized. This is achieved using 'EditorMappingLock', which
  29. // must be acquired before modifying any editor's list of mappings.
  30. // See 'MAPPING.H' for further details.
  31. //
  32. // N.B. On the rare occasions when 'MappingLock' must be held at the same time
  33. // as one of 'InterfaceLock', 'EditorLock', and 'DirectorLock', 'MappingLock'
  34. // must always be acquired first.
  35. //
  36. typedef struct _NAT_EDITOR {
  37. LIST_ENTRY Link;
  38. ULONG Key;
  39. ULONG ReferenceCount;
  40. KSPIN_LOCK Lock;
  41. LIST_ENTRY MappingList;
  42. ULONG Flags;
  43. PVOID Context;
  44. PNAT_EDITOR_CREATE_HANDLER CreateHandler;
  45. PNAT_EDITOR_DELETE_HANDLER DeleteHandler;
  46. PNAT_EDITOR_DATA_HANDLER ForwardDataHandler;
  47. PNAT_EDITOR_DATA_HANDLER ReverseDataHandler;
  48. } NAT_EDITOR, *PNAT_EDITOR;
  49. //
  50. // Definitions of flags for the field NAT_EDITOR.Flags
  51. //
  52. #define NAT_EDITOR_FLAG_DELETED 0x80000000
  53. //
  54. // Macros used to test various flags
  55. //
  56. #define NAT_EDITOR_DELETED(Editor) \
  57. ((Editor)->Flags & NAT_EDITOR_FLAG_DELETED)
  58. #define NAT_EDITOR_RESIZE(Editor) \
  59. ((Editor)->Flags & IP_NAT_EDITOR_FLAGS_RESIZE)
  60. //
  61. // Editor key-manipulation macros
  62. //
  63. #define MAKE_EDITOR_KEY(Protocol,Port,Direction) \
  64. (((ULONG)((Protocol) & 0xFF) << 24) | \
  65. (ULONG)(((Direction) & 0xFF) << 16) | \
  66. (ULONG)((Port) & 0xFFFF))
  67. #define EDITOR_KEY_DIRECTION(Key) ((UCHAR)(((Key) & 0x00FF0000) >> 16))
  68. #define EDITOR_KEY_PORT(Key) ((USHORT)((Key) & 0x0000FFFF))
  69. #define EDITOR_KEY_PROTOCOL(Key) ((UCHAR)(((Key) & 0xFF000000) >> 24))
  70. //
  71. // GLOBAL DATA DECLARATIONS
  72. //
  73. extern LIST_ENTRY EditorList;
  74. extern KSPIN_LOCK EditorLock;
  75. extern KSPIN_LOCK EditorMappingLock;
  76. //
  77. // EDITOR MANAGEMENT ROUTINES
  78. //
  79. VOID
  80. NatCleanupEditor(
  81. PNAT_EDITOR Editor
  82. );
  83. NTSTATUS
  84. NatCreateEditor(
  85. PIP_NAT_REGISTER_EDITOR RegisterContext
  86. );
  87. NTSTATUS
  88. NatDeleteEditor(
  89. PNAT_EDITOR Editor
  90. );
  91. //
  92. // BOOLEAN
  93. // NatDereferenceEditor(
  94. // PNAT_EDITOR Editor
  95. // );
  96. //
  97. #define \
  98. NatDereferenceEditor( \
  99. _Editor \
  100. ) \
  101. (InterlockedDecrement(&(_Editor)->ReferenceCount) \
  102. ? TRUE \
  103. : NatCleanupEditor(_Editor), FALSE)
  104. VOID
  105. NatInitializeEditorManagement(
  106. VOID
  107. );
  108. PNAT_EDITOR
  109. NatLookupEditor(
  110. ULONG Key,
  111. PLIST_ENTRY* InsertionPoint
  112. );
  113. struct _NAT_DYNAMIC_MAPPING;
  114. VOID
  115. NatMappingAttachEditor(
  116. PNAT_EDITOR Editor,
  117. struct _NAT_DYNAMIC_MAPPING* Mapping
  118. );
  119. VOID
  120. NatMappingDetachEditor(
  121. PNAT_EDITOR Editor,
  122. struct _NAT_DYNAMIC_MAPPING* Mapping
  123. );
  124. NTSTATUS
  125. NatQueryEditorTable(
  126. IN PIP_NAT_ENUMERATE_EDITORS InputBuffer,
  127. IN PIP_NAT_ENUMERATE_EDITORS OutputBuffer,
  128. IN PULONG OutputBufferLength
  129. );
  130. //
  131. // BOOLEAN
  132. // NatReferenceEditor(
  133. // PNAT_DIRECTOR Editor
  134. // );
  135. //
  136. #define \
  137. NatReferenceEditor( \
  138. _Editor \
  139. ) \
  140. (NAT_EDITOR_DELETED(_Editor) \
  141. ? FALSE \
  142. : InterlockedIncrement(&(_Editor)->ReferenceCount), TRUE)
  143. VOID
  144. NatShutdownEditorManagement(
  145. VOID
  146. );
  147. //
  148. // HELPER ROUTINES
  149. //
  150. NTSTATUS
  151. NatEditorCreateTicket(
  152. IN PVOID InterfaceHandle,
  153. IN UCHAR Protocol,
  154. IN ULONG PrivateAddress,
  155. IN USHORT PrivatePort,
  156. IN ULONG RemoteAddress OPTIONAL,
  157. IN USHORT RemotePort OPTIONAL,
  158. OUT PULONG PublicAddress,
  159. OUT PUSHORT PublicPort
  160. );
  161. NTSTATUS
  162. NatEditorDeleteTicket(
  163. IN PVOID InterfaceHandle,
  164. IN ULONG PublicAddress,
  165. IN UCHAR Protocol,
  166. IN USHORT PublicPort,
  167. IN ULONG RemoteAddress OPTIONAL,
  168. IN USHORT RemotePort OPTIONAL
  169. );
  170. NTSTATUS
  171. NatEditorDeleteSession(
  172. IN PVOID EditorHandle,
  173. IN PVOID SessionHandle
  174. );
  175. NTSTATUS
  176. NatEditorDeregister(
  177. IN PVOID EditorHandle
  178. );
  179. NTSTATUS
  180. NatEditorDissociateSession(
  181. IN PVOID EditorHandle,
  182. IN PVOID SessionHandle
  183. );
  184. NTSTATUS
  185. NatEditorEditSession(
  186. IN PVOID DataHandle,
  187. IN PVOID RecvBuffer,
  188. IN ULONG OldDataOffset,
  189. IN ULONG OldDataLength,
  190. IN PUCHAR NewData,
  191. IN ULONG NewDataLength
  192. );
  193. VOID
  194. NatEditorQueryInfoSession(
  195. IN PVOID SessionHandle,
  196. OUT PULONG PrivateAddress OPTIONAL,
  197. OUT PUSHORT PrivatePort OPTIONAL,
  198. OUT PULONG RemoteAddress OPTIONAL,
  199. OUT PUSHORT RemotePort OPTIONAL,
  200. OUT PULONG PublicAddress OPTIONAL,
  201. OUT PUSHORT PublicPort OPTIONAL,
  202. OUT PIP_NAT_SESSION_MAPPING_STATISTICS Statistics OPTIONAL
  203. );
  204. VOID
  205. NatEditorTimeoutSession(
  206. IN PVOID EditorHandle,
  207. IN PVOID SessionHandle
  208. );
  209. __inline VOID
  210. NatEditorEditShortSession(
  211. IN PVOID DataHandle,
  212. IN PUSHORT Shortp,
  213. IN USHORT Value
  214. )
  215. {
  216. if (((PNAT_XLATE_CONTEXT)DataHandle)->ChecksumDelta) {
  217. *((PNAT_XLATE_CONTEXT)DataHandle)->ChecksumDelta += (USHORT)~(*Shortp);
  218. *((PNAT_XLATE_CONTEXT)DataHandle)->ChecksumDelta += (USHORT)Value;
  219. }
  220. *Shortp = Value;
  221. }
  222. __inline VOID
  223. NatEditorEditLongSession(
  224. IN PVOID DataHandle,
  225. IN PULONG Longp,
  226. IN ULONG Value
  227. )
  228. {
  229. if (((PNAT_XLATE_CONTEXT)DataHandle)->ChecksumDelta) {
  230. *((PNAT_XLATE_CONTEXT)DataHandle)->ChecksumDelta+=(USHORT)~(*Longp);
  231. *((PNAT_XLATE_CONTEXT)DataHandle)->ChecksumDelta+=(USHORT)~(*Longp>>16);
  232. *((PNAT_XLATE_CONTEXT)DataHandle)->ChecksumDelta+=(USHORT)Value;
  233. *((PNAT_XLATE_CONTEXT)DataHandle)->ChecksumDelta+=(USHORT)(Value>>16);
  234. }
  235. *Longp = Value;
  236. }
  237. #endif // _NAT_EDITOR_H_