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.

134 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. icmp.h
  5. Abstract:
  6. Contains declarations for the NAT's ICMP-message manipulation.
  7. Author:
  8. Abolade Gbadegesin (t-abolag) 30-July-1997
  9. Revision History:
  10. --*/
  11. #ifndef _NAT_ICMP_H_
  12. #define _NAT_ICMP_H_
  13. //
  14. // Structure: NAT_ICMP_MAPPING
  15. //
  16. // This structure stores a mapping created for an ICMP-request message.
  17. //
  18. // In order to allow ICMP requests to be associated with replies,
  19. // we translate the 'Identification' field, which operates in a manner
  20. // similar to the TCP/UDP port field; the 'Identification' field is the same
  21. // for a 'session' (e.g. a series of echo-request messages).
  22. //
  23. // This means that when an internal machine 'pings' an external machine,
  24. // we choose a unique 'PublicId' for the 'session' from the point of view
  25. // of the external machine. Likewise, when an external machine 'pings'
  26. // an internal machine, we choose a unique 'PrivateId' for the session.
  27. //
  28. // Hence, on the outbound path we identify ICMP messages using the tuple
  29. //
  30. // <RemoteAddress # PrivateAddress, PrivateId>
  31. //
  32. // and on the inbound path we identify using the tuple
  33. //
  34. // <RemoteAddress # PublicAddress, PublicId>
  35. //
  36. // and these tuples are the composite search keys for the outbound and inbound
  37. // list of mappings, respectively, for each interface.
  38. //
  39. typedef struct _NAT_ICMP_MAPPING {
  40. LIST_ENTRY Link[NatMaximumDirection];
  41. ULONG64 PrivateKey;
  42. ULONG64 PublicKey;
  43. USHORT PrivateId;
  44. USHORT PublicId;
  45. LONG64 LastAccessTime;
  46. } NAT_ICMP_MAPPING, *PNAT_ICMP_MAPPING;
  47. //
  48. // ICMP mapping-key manipulation macros
  49. //
  50. #define MAKE_ICMP_KEY(RemoteAddress,OtherAddress) \
  51. ((ULONG)(RemoteAddress) | ((ULONG64)((ULONG)(OtherAddress)) << 32))
  52. #define ICMP_KEY_REMOTE(Key) ((ULONG)(Key))
  53. #define ICMP_KEY_PRIVATE(Key) ((ULONG)((Key) >> 32))
  54. #define ICMP_KEY_PUBLIC(Key) ((ULONG)((Key) >> 32))
  55. //
  56. // ICMP mapping allocation macros
  57. //
  58. #define ALLOCATE_ICMP_BLOCK() \
  59. ExAllocateFromNPagedLookasideList(&IcmpLookasideList)
  60. #define FREE_ICMP_BLOCK(Block) \
  61. ExFreeToNPagedLookasideList(&IcmpLookasideList,(Block))
  62. extern NPAGED_LOOKASIDE_LIST IcmpLookasideList;
  63. extern LIST_ENTRY IcmpMappingList[NatMaximumDirection];
  64. extern KSPIN_LOCK IcmpMappingLock;
  65. //
  66. // ICMP MAPPING MANAGEMENT ROUTINES
  67. //
  68. NTSTATUS
  69. NatCreateIcmpMapping(
  70. PNAT_INTERFACE Interfacep,
  71. ULONG RemoteAddress,
  72. ULONG PrivateAddress,
  73. ULONG PublicAddress,
  74. PUSHORT PrivateId,
  75. PUSHORT PublicId,
  76. PLIST_ENTRY InboundInsertionPoint,
  77. PLIST_ENTRY OutboundInsertionPoint,
  78. PNAT_ICMP_MAPPING* MappingCreated
  79. );
  80. VOID
  81. NatInitializeIcmpManagement(
  82. VOID
  83. );
  84. PNAT_ICMP_MAPPING
  85. NatLookupInboundIcmpMapping(
  86. ULONG64 PublicKey,
  87. USHORT PublicId,
  88. PLIST_ENTRY* InsertionPoint
  89. );
  90. PNAT_ICMP_MAPPING
  91. NatLookupOutboundIcmpMapping(
  92. ULONG64 PrivateKey,
  93. USHORT PrivateId,
  94. PLIST_ENTRY* InsertionPoint
  95. );
  96. VOID
  97. NatShutdownIcmpManagement(
  98. VOID
  99. );
  100. XLATE_IP_ROUTINE(NatTranslateIcmp)
  101. #endif // _NAT_ICMP_H_