ip4.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. ip4.h
  9. Abstract:
  10. This header contains public definitions for the IPv4 network layer.
  11. Author:
  12. Evan Green 5-Apr-2013
  13. --*/
  14. //
  15. // ------------------------------------------------------------------- Includes
  16. //
  17. //
  18. // --------------------------------------------------------------------- Macros
  19. //
  20. //
  21. // This macro determines whether or not the given IPv4 address is a multicast
  22. // address. The address is treated as being in network byte order.
  23. //
  24. #define IP4_IS_MULTICAST_ADDRESS(_Ip4Address) \
  25. (((_Ip4Address) & 0x000000F0) == 0x000000E0)
  26. //
  27. // ---------------------------------------------------------------- Definitions
  28. //
  29. #define IP4_ALLOCATION_TAG 0x21347049 // '!4pI'
  30. #define IP4_VERSION 0x40
  31. #define IP4_VERSION_MASK 0xF0
  32. #define IP4_HEADER_LENGTH_MASK 0x0F
  33. #define IP4_MAX_PACKET_SIZE 0xFFFF
  34. #define IP4_TYPE_ECN_MASK 0x03
  35. #define IP4_TYPE_DSCP_MASK 0xFC
  36. #define IP4_PRECEDENCE_NETWORK_CONTROL 0xC0
  37. #define IP4_FLAG_MORE_FRAGMENTS 0x1
  38. #define IP4_FLAG_DO_NOT_FRAGMENT 0x2
  39. #define IP4_FLAG_RESERVED 0x4
  40. #define IP4_FLAGS \
  41. (IP4_FLAG_RESERVED | \
  42. IP4_FLAG_DO_NOT_FRAGMENT | \
  43. IP4_FLAG_MORE_FRAGMENTS)
  44. #define IP4_FRAGMENT_FLAGS_MASK 0x7
  45. #define IP4_FRAGMENT_FLAGS_SHIFT 13
  46. #define IP4_FRAGMENT_OFFSET_MASK 0x1FFF
  47. #define IP4_FRAGMENT_OFFSET_SHIFT 0
  48. #define IP4_INITIAL_TIME_TO_LIVE 63
  49. #define IP4_INITIAL_MULTICAST_TIME_TO_LIVE 1
  50. #define IP4_LINK_LOCAL_TIME_TO_LIVE 1
  51. #define IP4_MAX_TIME_TO_LIVE 255
  52. #define IP4_BROADCAST_ADDRESS 0xFFFFFFFF
  53. #define IP4_ADDRESS_SIZE 4
  54. //
  55. // Define the flags for the IPv4 option type.
  56. //
  57. #define IP4_OPTION_TYPE_COPIED 0x80
  58. #define IP4_OPTION_TYPE_CLASS_MASK 0x60
  59. #define IP4_OPTION_TYPE_CLASS_SHIFT 5
  60. #define IP4_OPTION_TYPE_CLASS_CONTROL 0x0
  61. #define IP4_OPTION_TYPE_CLASS_DEBUG 0x2
  62. #define IP4_OPTION_TYPE_NUMBER_MASK 0x1F
  63. #define IP4_OPTION_TYPE_NUMBER_SHIFT 0
  64. //
  65. // Define specific IPv4 option types.
  66. //
  67. #define IP4_OPTION_END 0x00
  68. #define IP4_OPTION_NOP 0x01
  69. #define IP4_OPTION_ROUTER_ALERT 0x94
  70. //
  71. // Define the details of the router alert option.
  72. //
  73. #define IP4_ROUTER_ALERT_LENGTH 4
  74. #define IP4_ROUTER_ALERT_VALUE 0
  75. //
  76. // ------------------------------------------------------ Data Type Definitions
  77. //
  78. /*++
  79. Structure Description:
  80. This structure defines an IPv4 address.
  81. Members:
  82. Domain - Stores the network domain of this address.
  83. Port - Stores the 16 bit port number.
  84. Address - Stores the 32 bit IP address.
  85. NetworkAddress - Stores the unioned opaque version, used to ensure the
  86. structure is the proper size.
  87. --*/
  88. typedef struct _IP4_ADDRESS {
  89. union {
  90. struct {
  91. NET_DOMAIN_TYPE Domain;
  92. ULONG Port;
  93. ULONG Address;
  94. };
  95. NETWORK_ADDRESS NetworkAddress;
  96. };
  97. } IP4_ADDRESS, *PIP4_ADDRESS;
  98. /*++
  99. Structure Description:
  100. This structure defines an IPv4 header.
  101. Members:
  102. VersionAndHeaderLength - Stores the version number and header length.
  103. Type - Stores the Differentiated Services Code Point (originally called
  104. Type of Service), and the Explicit Congestion Notification.
  105. TotalLength - Stores the total length of the packet, including the header
  106. and data, in bytes.
  107. Identification - Stores an identification field, usually used for uniquely
  108. identifying fragments of an original IP datagram.
  109. FragmentOffset - Stores some flags, as well as the fragment offset
  110. relative to the beginning of the original unfragmented IP datagram.
  111. TimeToLive - Stores the number of remaining hops this packet can make
  112. before being discarded.
  113. Protocol - Stores the protocol number for the next protocol.
  114. HeaderChecksum - Stores the 16 bit one's complement of the one's complement
  115. sum of all 16 bit words in the header.
  116. SourceAddress - Stores the source IP address of the packet.
  117. DestinationAddress - Stores the destination IP address of the packet.
  118. --*/
  119. #pragma pack(push, 1)
  120. typedef struct _IP4_HEADER {
  121. UCHAR VersionAndHeaderLength;
  122. UCHAR Type;
  123. USHORT TotalLength;
  124. USHORT Identification;
  125. USHORT FragmentOffset;
  126. UCHAR TimeToLive;
  127. UCHAR Protocol;
  128. USHORT HeaderChecksum;
  129. ULONG SourceAddress;
  130. ULONG DestinationAddress;
  131. } PACKED IP4_HEADER, *PIP4_HEADER;
  132. /*++
  133. Structure Descriptoin:
  134. This structure defines an IPv4 header option.
  135. Members:
  136. Type - Supplies the type of the IPv4 header option.
  137. Length - Supplies the length of the IPv4 header option including the type
  138. and length, in bytes.
  139. --*/
  140. typedef struct _IP4_OPTION {
  141. UCHAR Type;
  142. UCHAR Length;
  143. } PACKED IP4_OPTION, *PIP4_OPTION;
  144. #pragma pack(pop)
  145. //
  146. // -------------------------------------------------------------------- Globals
  147. //
  148. //
  149. // -------------------------------------------------------- Function Prototypes
  150. //