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.

328 lines
11 KiB

  1. // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil -*- (for GNU Emacs)
  2. //
  3. // Copyright (c) 1985-2000 Microsoft Corporation
  4. //
  5. // This file is part of the Microsoft Research IPv6 Network Protocol Stack.
  6. // You should have received a copy of the Microsoft End-User License Agreement
  7. // for this software along with this release; see the file "license.txt".
  8. // If not, please see http://www.research.microsoft.com/msripv6/license.htm,
  9. // or write to Microsoft Research, One Microsoft Way, Redmond, WA 98052-6399.
  10. //
  11. // Abstract:
  12. //
  13. // Definitions derived from the IPv6 protocol specifications.
  14. //
  15. #ifndef IP6_INCLUDED
  16. #define IP6_INCLUDED 1
  17. #define IPV6_ADDRESS_LENGTH 128 // Bits in an address.
  18. #define IPV6_ID_LENGTH 64 // Bits in an interface identifier.
  19. //
  20. // IPv6 Header Format.
  21. // See RFC 1883, page 5 (and subsequent draft updates to same).
  22. //
  23. typedef struct IPv6Header {
  24. u_long VersClassFlow; // 4 bits Version, 8 Traffic Class, 20 Flow Label.
  25. u_short PayloadLength; // Zero indicates Jumbo Payload hop-by-hop option.
  26. u_char NextHeader; // Values are superset of IPv4's Protocol field.
  27. u_char HopLimit;
  28. struct in6_addr Source;
  29. struct in6_addr Dest;
  30. } IPv6Header;
  31. //
  32. // Maximum value for the PayloadLength field.
  33. // Note that the 40-byte IPv6 header is NOT included.
  34. //
  35. #define MAX_IPv6_PAYLOAD 65535
  36. //
  37. // Minimum size of an IPv6 link's MTU.
  38. // Note that the 40-byte IPv6 header IS included,
  39. // but any link-layer header is not.
  40. //
  41. #define IPv6_MINIMUM_MTU 1280
  42. //
  43. // Useful constants for working with various fields in the IPv6 header.
  44. //
  45. // NOTE: We keep the Version, Traffic Class and Flow Label fields as a single
  46. // NOTE: 32 bit value (VersClassFlow) in network byte order (big-endian).
  47. // NOTE: Since NT is little-endian, this means all loads/stores to/from this
  48. // NOTE: field need to be byte swapped.
  49. //
  50. #define IP_VER_MASK 0x000000F0 // Version is high 4 bits of VersClassFlow.
  51. #define IP_VERSION 0x00000060 // This is 6 << 28 (after byte swap).
  52. #define IP_TRAFFIC_CLASS_MASK 0x0000F00F // 0x0FF00000 (after byte swap).
  53. #define MAX_IP_PROTOCOL 255
  54. //
  55. // Protocol (i.e. "Next Header" field) values for included protocols.
  56. //
  57. #define IP_PROTOCOL_HOP_BY_HOP 0 // IPv6 Hop-by-Hop Options Header.
  58. #define IP_PROTOCOL_ICMPv4 1 // IPv4 Internet Control Message Protocol.
  59. #define IP_PROTOCOL_V6 41 // IPv6 Header.
  60. #define IP_PROTOCOL_ROUTING 43 // IPv6 Routing Header.
  61. #define IP_PROTOCOL_FRAGMENT 44 // IPv6 Fragment Header.
  62. #define IP_PROTOCOL_ESP 50 // IPSec Encapsulating Security Payload Hdr.
  63. #define IP_PROTOCOL_AH 51 // IPSec Authentication Hdr.
  64. #define IP_PROTOCOL_ICMPv6 58 // IPv6 Internet Control Message Protocol.
  65. #define IP_PROTOCOL_NONE 59 // No next header - ignore packet remainder.
  66. #define IP_PROTOCOL_DEST_OPTS 60 // IPv6 Destination Options Header.
  67. __inline int
  68. IsExtensionHeader(u_char Prot)
  69. {
  70. if ((Prot == IP_PROTOCOL_HOP_BY_HOP) || (Prot == IP_PROTOCOL_ROUTING) ||
  71. (Prot == IP_PROTOCOL_FRAGMENT) || (Prot == IP_PROTOCOL_DEST_OPTS) ||
  72. (Prot == IP_PROTOCOL_ESP) || (Prot == IP_PROTOCOL_AH))
  73. return TRUE;
  74. return FALSE;
  75. }
  76. //
  77. // IPv6 type-length-value (TLV) encoded option types found in some
  78. // extension headers. The upper two bits of each type are encoded
  79. // so as to specify what action the node should take if it doesn't
  80. // grok the option type. The third-highest-order bit specifies if
  81. // the option data can change en-route to the final destination.
  82. // See RFC 1883, section 4.2 (pages 9-10) for more information.
  83. //
  84. #define IPv6_OPT_ACTION_MASK 0xc0 // High two bits.
  85. #define IPv6_OPT_DYNDATA_MASK 0x20 // Third-highest bit.
  86. //
  87. // Hop-by-Hop and Destination Options Headers.
  88. // We use a single structure for both.
  89. //
  90. typedef struct IPv6OptionsHeader {
  91. u_char NextHeader;
  92. u_char HeaderExtLength; // In 8-byte units, not counting first 8.
  93. } IPv6OptionsHeader;
  94. //
  95. // Routing Header.
  96. //
  97. typedef struct IPv6RoutingHeader {
  98. u_char NextHeader;
  99. u_char HeaderExtLength; // In 8-byte units, not counting first 8.
  100. u_char RoutingType;
  101. u_char SegmentsLeft; // Number of nodes still left to be visited.
  102. u_char Reserved[4]; // Not a u_int to avoid alignment.
  103. } IPv6RoutingHeader;
  104. //
  105. // Fragment Header.
  106. //
  107. typedef struct FragmentHeader {
  108. u_char NextHeader;
  109. u_char Reserved;
  110. u_short OffsetFlag; // Offset is upper 13 bits, flag is lowest bit.
  111. u_long Id;
  112. } FragmentHeader;
  113. #define FRAGMENT_OFFSET_MASK 0xfff8
  114. #define FRAGMENT_FLAG_MASK 0x0001
  115. //
  116. // Generic Extension Header.
  117. //
  118. typedef struct ExtensionHeader {
  119. u_char NextHeader;
  120. u_char HeaderExtLength; // In 8-byte units, not counting first 8.
  121. } ExtensionHeader;
  122. #define EXT_LEN_UNIT 8 // 8-byte units used for extension hdr length.
  123. //
  124. // Generic Options Header.
  125. //
  126. typedef struct OptionHeader {
  127. u_char Type;
  128. u_char DataLength; // In bytes, not counting two for the header.
  129. } OptionHeader;
  130. //
  131. // Format of the router alert within the Hop-by-Hop Option header.
  132. //
  133. typedef struct IPv6RouterAlertOption {
  134. u_char Type;
  135. u_char Length;
  136. u_short Value;
  137. } IPv6RouterAlertOption;
  138. //
  139. // Mobile IPv6 destination option formats.
  140. //
  141. #pragma pack(1)
  142. typedef struct IPv6BindingUpdateOption {
  143. u_char Type;
  144. u_char Length;
  145. u_char Flags; // See mask values below.
  146. u_char PrefixLength; // Only used for "home registration" updates.
  147. u_short SeqNumber;
  148. u_int Lifetime; // Number of seconds before binding expires.
  149. } IPv6BindingUpdateOption;
  150. #pragma pack()
  151. // Masks for the Flags field.
  152. #define IPV6_BINDING_ACK 0x80 // Request a binding acknowledgement.
  153. #define IPV6_BINDING_HOME_REG 0x40 // Request host to act as home agent.
  154. #define IPV6_BINDING_ROUTER 0x20 // Sender is a router (valid w/ HOME_REG).
  155. #define IPV6_BINDING_DAD 0x10 // Request HA perform DAD on home link.
  156. typedef u_char BindingUpdateDisposition;
  157. #pragma pack(1)
  158. typedef struct IPv6BindingAcknowledgementOption {
  159. u_char Type;
  160. u_char Length;
  161. BindingUpdateDisposition Status; // Disposition of the MN's binding update.
  162. u_short SeqNumber;
  163. u_int Lifetime; // Granted lifetime if binding accepted.
  164. u_int Refresh; // Interval recommended to send new binging update.
  165. } IPv6BindingAcknowledgementOption;
  166. #pragma pack()
  167. // Disposition status values.
  168. #define IPV6_BINDING_ACCEPTED 0
  169. #define IPV6_BINDING_REJECTED 128 // Rejected for unspecified reason.
  170. // was IPV6_BINDING_POORLY_FORMED 129 // Poorly formed binding update.
  171. #define IPV6_BINDING_PROHIBITED 130 // Administratively prohibited.
  172. #define IPV6_BINDING_NO_RESOURCES 131
  173. #define IPV6_BINDING_HOME_REG_NOT_SUPPORTED 132 // Registration not supported.
  174. #define IPV6_BINDING_NOT_HOME_SUBNET 133
  175. #define IPV6_BINDING_SEQ_NO_TOO_SMALL 134 // Internal only - never on wire.
  176. // was IPV6_BINDING_DYNAMIC_RESPONSE 135 // Dynamic HA discovery response.
  177. #define IPV6_BINDING_BAD_IF_LENGTH 136 // Incorrect interface id length.
  178. #define IPV6_BINDING_NOT_HOME_AGENT 137 // Not the HA for this mobile node.
  179. #define IPV6_BINDING_DAD_FAILED 138 // DAD failed.
  180. typedef struct IPv6BindingRequestOption {
  181. u_char Type;
  182. u_char Length;
  183. } IPv6BindingRequstOption;
  184. #pragma pack(1)
  185. typedef struct IPv6HomeAddressOption {
  186. u_char Type;
  187. u_char Length;
  188. struct in6_addr HomeAddress;
  189. } IPv6HomeAddressOption;
  190. #pragma pack()
  191. typedef struct SubOptionHeader {
  192. u_char Type;
  193. u_char DataLength; // In bytes, not counting two for the header.
  194. } SubOptionHeader;
  195. #define SUBOPT6_UNIQUE_ID 1
  196. #define SUBOPT6_HOME_AGENTS_LIST 2
  197. #define SUBOPT6_CARE_OF_ADDRESS 4
  198. #pragma pack(1)
  199. typedef struct IPv6UniqueIdSubOption {
  200. u_char Type;
  201. u_char Length;
  202. u_short UniqueId;
  203. } IPv6UniqueIdSubOption;
  204. #pragma pack()
  205. #pragma pack(1)
  206. typedef struct IPv6HomeAgentsListSubOption {
  207. u_char Type;
  208. u_char Length;
  209. // The list of home agents follows at this point.
  210. } IPv6HomeAgentsListSubOption;
  211. #pragma pack()
  212. #pragma pack(1)
  213. typedef struct IPv6CareOfAddrSubOption {
  214. u_char Type;
  215. u_char Length;
  216. struct in6_addr CareOfAddr;
  217. } IPv6CareOfAddrSubOption;
  218. #pragma pack()
  219. // Option Header Values.
  220. #define OPT6_PAD_1 0 // Single byte pad.
  221. #define OPT6_PAD_N 1 // Multiple byte pad.
  222. #define OPT6_JUMBO_PAYLOAD 194 // Jumbo payload (greater than 64KB).
  223. #define OPT6_TUNNEL_ENCAP_LIMIT 4 // REVIEW: Tentative, waiting for IANA.
  224. #define OPT6_ROUTER_ALERT 5 // REVIEW: Tentative, waiting for IANA.
  225. // Options related to IPv6 Mobility.
  226. // REVIEW: These are all tentative, waiting for IANA approval.
  227. #define OPT6_BINDING_UPDATE 198
  228. #define OPT6_BINDING_ACK 7
  229. #define OPT6_BINDING_REQUEST 8
  230. #define OPT6_HOME_ADDRESS 201
  231. // Options we don't yet care about.
  232. #define OPT6_ENDPOINT_ID 168 // Charles Lynn?
  233. #define OPT6_NSAP_ADDR 195 // RFC 1888.
  234. // REVIEW: The below duplicates the IPv6_OPT_* stuff above.
  235. // REVIEW: The above is nicely commented, but the below is what we use.
  236. // Type of actions to be taken with unrecognized header options.
  237. #define OPT6_ACTION(a) ((a) & 0xc0) // Get action bits.
  238. #define OPT6_A_SKIP 0x00 // Skip and continue.
  239. #define OPT6_A_DISCARD 0x40 // Discard packet.
  240. #define OPT6_A_SEND_ICMP_ALL 0x80 // Send ICMP regardless of source addr.
  241. #define OPT6_A_SEND_ICMP_NON_MULTI 0xc0 // Send ICMP if non-multicast src addr.
  242. // Determining whether and option is mutiple or not.
  243. #define OPT6_MUTABLE 0x20
  244. #define OPT6_ISMUTABLE(t) ((t) & OPT6_MUTABLE)
  245. //
  246. // Authentication Header.
  247. //
  248. // The header conceptually includes a variable amount of Authentication Data
  249. // which follows these fixed-size fields.
  250. //
  251. // Calling this "AHHeader" is redundant, but then again so is "TCP Protocol".
  252. //
  253. typedef struct AHHeader {
  254. u_char NextHeader;
  255. u_char PayloadLen; // In 4-byte units, not counting first 8 bytes.
  256. u_short Reserved; // Padding. Must be zero on transmit.
  257. u_long SPI; // Security Parameters Index.
  258. u_long Seq; // Sequence number for anti-replay algorithms.
  259. } AHHeader;
  260. //
  261. // Encapsulating Security Payload header and trailer.
  262. //
  263. // The header is followed by a variable amount of payload data, followed by
  264. // a variable amount of padding (255 bytes maximum), followed by a byte for
  265. // the Pad Length and a byte for the Next Header field, followed by a
  266. // variable amount of Authentication Data.
  267. //
  268. // The amount of padding should be picked such that the Pad Length and
  269. // Next Header field end up aligned on a 32 bit boundary.
  270. //
  271. typedef struct ESPHeader{
  272. u_long SPI; // Security Parameters Index.
  273. u_long Seq; // Sequence number for anti-replay algorithms.
  274. } ESPHeader;
  275. typedef struct ESPTrailer{
  276. u_char PadLength; // Number of bytes in pad.
  277. u_char NextHeader;
  278. } ESPTrailer;
  279. #endif // IP6_INCLUDED