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.

166 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. NsProt.h
  5. Abstract:
  6. Protocol definitions for IpSec NAT shim
  7. Author:
  8. Jonathan Burstein (jonburs) 10-July-2001
  9. Environment:
  10. Kernel mode
  11. Revision History:
  12. --*/
  13. #pragma once
  14. //
  15. // IP Protocol Numbers
  16. //
  17. #define NS_PROTOCOL_ICMP 0x01
  18. #define NS_PROTOCOL_TCP 0x06
  19. #define NS_PROTOCOL_UDP 0x11
  20. //
  21. // ICMP message-type constants
  22. //
  23. #define ICMP_ECHO_REPLY 0
  24. #define ICMP_DEST_UNREACH 3
  25. #define ICMP_SOURCE_QUENCH 4
  26. #define ICMP_REDIRECT 5
  27. #define ICMP_ECHO_REQUEST 8
  28. #define ICMP_ROUTER_REPLY 9
  29. #define ICMP_ROUTER_REQUEST 10
  30. #define ICMP_TIME_EXCEED 11
  31. #define ICMP_PARAM_PROBLEM 12
  32. #define ICMP_TIMESTAMP_REQUEST 13
  33. #define ICMP_TIMESTAMP_REPLY 14
  34. #define ICMP_MASK_REQUEST 17
  35. #define ICMP_MASK_REPLY 18
  36. //
  37. // ICMP message-code constants
  38. //
  39. #define ICMP_CODE_NET_UNREACH 0
  40. #define ICMP_CODE_HOST_UNREACH 1
  41. #define ICMP_CODE_PROTOCOL_UNREACH 2
  42. #define ICMP_CODE_PORT_UNREACH 3
  43. #define ICMP_CODE_FRAG_NEEDED 4
  44. #define ICMP_SOURCE_ROUTE_FAILED 5
  45. //
  46. // Macro for extracting the data-offset from the field IPHeader.verlen
  47. //
  48. #define IP_DATA_OFFSET(h) \
  49. ((ULONG)((((IPHeader*)(h))->iph_verlen & 0x0F) << 2))
  50. //
  51. // Mask for extracting the fragment-offset from the IPHeader structure's
  52. // combined flags/fragment-offset field
  53. //
  54. #define IP_FRAGMENT_OFFSET_MASK ~0x00E0
  55. //
  56. // Macro for extracting the data-offset from the field TCP_HEADER.OffsetAndFlags
  57. // The offset is in 32-bit words, so shifting by 2 gives the value in bytes.
  58. //
  59. #define TCP_DATA_OFFSET(h) (((h)->OffsetAndFlags & 0x00F0) >> 2)
  60. //
  61. // Masks for extracting flags from the field TCP_HEADER.OffsetAndFlags
  62. //
  63. #define TCP_FLAG_FIN 0x0100
  64. #define TCP_FLAG_SYN 0x0200
  65. #define TCP_FLAG_RST 0x0400
  66. #define TCP_FLAG_PSH 0x0800
  67. #define TCP_FLAG_ACK 0x1000
  68. #define TCP_FLAG_URG 0x2000
  69. #define TCP_FLAG(h,f) ((h)->OffsetAndFlags & TCP_FLAG_ ## f)
  70. #define TCP_ALL_FLAGS(h) ((h)->OffsetAndFlags & 0x3f00)
  71. #define TCP_RESERVED_BITS(h) ((h)->OffsetAndFlags & 0xc00f)
  72. #include <packon.h>
  73. typedef struct _IP_HEADER {
  74. UCHAR VersionAndHeaderLength;
  75. UCHAR TypeOfService;
  76. USHORT TotalLength;
  77. USHORT Identification;
  78. USHORT OffsetAndFlags;
  79. UCHAR TimeToLive;
  80. UCHAR Protocol;
  81. USHORT Checksum;
  82. ULONG SourceAddress;
  83. ULONG DestinationAddress;
  84. } IP_HEADER, *PIP_HEADER;
  85. typedef struct _TCP_HEADER {
  86. USHORT SourcePort;
  87. USHORT DestinationPort;
  88. ULONG SequenceNumber;
  89. ULONG AckNumber;
  90. USHORT OffsetAndFlags;
  91. USHORT WindowSize;
  92. USHORT Checksum;
  93. USHORT UrgentPointer;
  94. } TCP_HEADER, *PTCP_HEADER;
  95. typedef struct _UDP_HEADER {
  96. USHORT SourcePort;
  97. USHORT DestinationPort;
  98. USHORT Length;
  99. USHORT Checksum;
  100. } UDP_HEADER, *PUDP_HEADER;
  101. typedef struct _ICMP_HEADER {
  102. UCHAR Type;
  103. UCHAR Code;
  104. USHORT Checksum;
  105. USHORT Identifier; // valid only for ICMP request/reply
  106. USHORT SequenceNumber; // valid only for ICMP request/reply
  107. IP_HEADER EncapsulatedIpHeader; // valid only for ICMP errors
  108. union {
  109. struct _ENCAPSULATED_TCP_HEADER {
  110. USHORT SourcePort;
  111. USHORT DestinationPort;
  112. ULONG SequenceNumber;
  113. } EncapsulatedTcpHeader;
  114. struct _ENCAPSULATED_UDP_HEADER {
  115. USHORT SourcePort;
  116. USHORT DestinationPort;
  117. USHORT Length;
  118. USHORT Checksum;
  119. } EncapsulatedUdpHeader;
  120. struct _ENCAPSULATED_ICMP_HEADER {
  121. UCHAR Type;
  122. UCHAR Code;
  123. USHORT Checksum;
  124. USHORT Identifier;
  125. USHORT SequenceNumber;
  126. } EncapsulatedIcmpHeader;
  127. };
  128. } ICMP_HEADER, *PICMP_HEADER;
  129. #include <packoff.h>