ip6.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*++
  2. Copyright (c) 2017 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. ip6.h
  5. Abstract:
  6. This header contains public definitions for the IPv6 network layer.
  7. Author:
  8. Chris Stevens 22-Aug-2017
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // --------------------------------------------------------------------- Macros
  15. //
  16. //
  17. // This macros determines whether or not the given IPv6 address is the
  18. // unspecified address.
  19. //
  20. #define IP6_IS_UNSPECIFIED_ADDRESS(_Ip6Address) \
  21. (((_Ip6Address)[0] == 0) && ((_Ip6Address)[1] == 0) && \
  22. ((_Ip6Address)[2] == 0) && ((_Ip6Address)[3] == 0))
  23. //
  24. // This macros determines whether or not the given IPv6 address is a multicast
  25. // address.
  26. //
  27. #define IP6_IS_MULTICAST_ADDRESS(_Ip6Address) \
  28. ((UCHAR)(_Ip6Address)[0] == 0xFF)
  29. //
  30. // This macros determines whether or not the given IPv6 address is a multicast
  31. // link-local address.
  32. //
  33. #define IP6_IS_MULTICAST_LINK_LOCAL_ADDRESS(_Ip6Address) \
  34. (((_Ip6Address)[0] & CPU_TO_NETWORK32(0xFF0F0000)) == \
  35. CPU_TO_NETWORK32(0xFF020000))
  36. //
  37. // This macros determines whether or not the given IPv6 address is a unicast
  38. // link-local address.
  39. //
  40. #define IP6_IS_UNICAST_LINK_LOCAL_ADDRESS(_Ip6Address) \
  41. (((_Ip6Address)[0] == CPU_TO_NETWORK32(IP6_LINK_LOCAL_PREFIX)) && \
  42. ((_Ip6Address)[1] == 0))
  43. //
  44. // This macro determines whether or not the given IPv6 address is a
  45. // solicited-node multicast address.
  46. //
  47. #define IP6_IS_SOLICITED_NODE_MULTICAST_ADDRESS(_Ip6Address) \
  48. (((_Ip6Address)[0] == CPU_TO_NETWORK32(0xFF020000)) && \
  49. ((_Ip6Address)[1] == 0) && \
  50. ((_Ip6Address)[2] == CPU_TO_NETWORK32(0x00000001)) && \
  51. (((_Ip6Address)[3] & CPU_TO_NETWORK32(0xFF000000)) == \
  52. CPU_TO_NETWORK32(0xFF000000)))
  53. //
  54. // ---------------------------------------------------------------- Definitions
  55. //
  56. //
  57. // Define the current IPv6 version number.
  58. //
  59. #define IP6_VERSION 6
  60. //
  61. // Define the bits for the header member that stores the version, traffic
  62. // class, and flow label.
  63. //
  64. #define IP6_VERSION_MASK 0xF0000000
  65. #define IP6_VERSION_SHIFT 28
  66. #define IP6_TRAFFIC_CLASS_MASK 0x0FF00000
  67. #define IP6_TRAFFIC_CLASS_SHIFT 20
  68. #define IP6_FLOW_LABEL_MASK 0x000FFFFF
  69. #define IP6_FLOW_LABEL_SHIFT 0
  70. //
  71. // Define the maximum payload length that can be stored in an IPv6 header.
  72. //
  73. #define IP6_MAX_PAYLOAD_LENGTH 0xFFFF
  74. //
  75. // Define the minimum link MTU required by IPv6.
  76. //
  77. #define IP6_MINIMUM_LINK_MTU 1280
  78. //
  79. // Define the base length of all IPv6 extension headers and the multiple of the
  80. // header's stored length value.
  81. //
  82. #define IP6_EXTENSION_HEADER_LENGTH_BASE 8
  83. #define IP6_EXTENSION_HEADER_LENGTH_MULTIPLE 8
  84. //
  85. // Define default and maximum values for the IPv6 header hop limit.
  86. //
  87. #define IP6_DEFAULT_HOP_LIMIT 64
  88. #define IP6_DEFAULT_MULTICAST_HOP_LIMIT 1
  89. #define IP6_MAX_HOP_LIMIT 0xFF
  90. //
  91. // Define the hop limit that indicates a link local packet.
  92. //
  93. #define IP6_LINK_LOCAL_HOP_LIMIT 1
  94. //
  95. // Define the size of an IPv6 address, in bytes.
  96. //
  97. #define IP6_ADDRESS_SIZE 16
  98. //
  99. // Define the IPv6 extension header options types.
  100. //
  101. #define IP6_OPTION_TYPE_PAD1 0
  102. #define IP6_OPTION_TYPE_PADN 1
  103. #define IP6_OPTION_TYPE_ROUTER_ALERT 5
  104. //
  105. // Define the IPv6 router alert codes.
  106. //
  107. #define IP6_ROUTER_ALERT_CODE_MLD 0
  108. #define IP6_ROUTER_ALERT_CODE_RSVP 1
  109. #define IP6_ROUTER_ALERT_CODE_ACTIVE_NETWORK 2
  110. //
  111. // Define the IPv6 link local prefix, in CPU byte order.
  112. //
  113. #define IP6_LINK_LOCAL_PREFIX 0xFE800000
  114. //
  115. // ------------------------------------------------------ Data Type Definitions
  116. //
  117. /*++
  118. Structure Description:
  119. This structure defines an IPv6 address.
  120. Members:
  121. Domain - Stores the network domain of this address.
  122. Port - Stores the 16 bit port number.
  123. Address - Stores the 128 bit IP address.
  124. NetworkAddress - Stores the unioned opaque version, used to ensure the
  125. structure is the proper size.
  126. --*/
  127. typedef struct _IP6_ADDRESS {
  128. union {
  129. struct {
  130. NET_DOMAIN_TYPE Domain;
  131. ULONG Port;
  132. ULONG Address[IP6_ADDRESS_SIZE / sizeof(ULONG)];
  133. };
  134. NETWORK_ADDRESS NetworkAddress;
  135. };
  136. } IP6_ADDRESS, *PIP6_ADDRESS;
  137. /*++
  138. Structure Description:
  139. This structure defines an IPv6 header.
  140. Members:
  141. VersionClassFlow - Stores the version number, traffic class, and flow label.
  142. PayloadLength - Store the length of the rest of the packet, in bytes. This
  143. does not include the IPv6 header.
  144. NextHeader - Stores the type of the next header in the packet. This takes
  145. the same values as the IPv4 header's protocol field.
  146. HopLimit - Stores the limit on the number of intermediate nodes the packet
  147. can encounter before being discarded.
  148. SourceAddress - Stores the source IP address of the packet.
  149. DestinationAddress - Stores the destination IP address of the packet.
  150. --*/
  151. #pragma pack(push, 1)
  152. typedef struct _IP6_HEADER {
  153. ULONG VersionClassFlow;
  154. USHORT PayloadLength;
  155. UCHAR NextHeader;
  156. UCHAR HopLimit;
  157. BYTE SourceAddress[IP6_ADDRESS_SIZE];
  158. BYTE DestinationAddress[IP6_ADDRESS_SIZE];
  159. } PACKED IP6_HEADER, *PIP6_HEADER;
  160. /*++
  161. Structure Description:
  162. This structure defines the header common to all IPv6 extension headers.
  163. Members:
  164. NextHeader - Stores the type of the header following this extension header.
  165. Length - Stores the length of the extension header, not including the first
  166. 8 bytes; all extension headers must be an integer multiple of 8 bytes.
  167. --*/
  168. typedef struct _IP6_EXTENSION_HEADER {
  169. UCHAR NextHeader;
  170. UCHAR Length;
  171. } PACKED IP6_EXTENSION_HEADER, *PIP6_EXTENSION_HEADER;
  172. /*++
  173. Structure Description:
  174. This structure defines an IPv6 extension header option. The variable-length
  175. option data immediately follows this structure.
  176. Members:
  177. Type - Stores the type of IPv6 option. See IP6_OPTION_TYPE_* for
  178. definitions.
  179. Length - Stores the length of the IPv6 option, in bytes.
  180. --*/
  181. typedef struct _IP6_OPTION {
  182. UCHAR Type;
  183. UCHAR Length;
  184. } PACKED IP6_OPTION, *PIP6_OPTION;
  185. #pragma pack(pop)
  186. //
  187. // -------------------------------------------------------------------- Globals
  188. //
  189. //
  190. // -------------------------------------------------------- Function Prototypes
  191. //