proto.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * TAP-Windows -- A kernel driver to provide virtual tap
  3. * device functionality on Windows.
  4. *
  5. * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
  6. *
  7. * This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
  8. * and is released under the GPL version 2 (see below).
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program (see the file COPYING included with this
  21. * distribution); if not, write to the Free Software Foundation, Inc.,
  22. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. //============================================================
  25. // MAC address, Ethernet header, and ARP
  26. //============================================================
  27. #pragma pack(1)
  28. #define IP_HEADER_SIZE 20
  29. #define IPV6_HEADER_SIZE 40
  30. #define MACADDR_SIZE 6
  31. typedef unsigned char MACADDR[MACADDR_SIZE];
  32. typedef unsigned long IPADDR;
  33. typedef unsigned char IPV6ADDR[16];
  34. //-----------------
  35. // Ethernet address
  36. //-----------------
  37. typedef struct {
  38. MACADDR addr;
  39. } ETH_ADDR;
  40. typedef struct {
  41. ETH_ADDR list[TAP_MAX_MCAST_LIST];
  42. } MC_LIST;
  43. // BUGBUG!!! Consider using ststem defines in netiodef.h!!!
  44. //----------------
  45. // Ethernet header
  46. //----------------
  47. typedef struct
  48. {
  49. MACADDR dest; /* destination eth addr */
  50. MACADDR src; /* source ether addr */
  51. USHORT proto; /* packet type ID field */
  52. } ETH_HEADER, *PETH_HEADER;
  53. //----------------
  54. // ARP packet
  55. //----------------
  56. typedef struct
  57. {
  58. MACADDR m_MAC_Destination; // Reverse these two
  59. MACADDR m_MAC_Source; // to answer ARP requests
  60. USHORT m_Proto; // 0x0806
  61. # define MAC_ADDR_TYPE 0x0001
  62. USHORT m_MAC_AddressType; // 0x0001
  63. USHORT m_PROTO_AddressType; // 0x0800
  64. UCHAR m_MAC_AddressSize; // 0x06
  65. UCHAR m_PROTO_AddressSize; // 0x04
  66. # define ARP_REQUEST 0x0001
  67. # define ARP_REPLY 0x0002
  68. USHORT m_ARP_Operation; // 0x0001 for ARP request, 0x0002 for ARP reply
  69. MACADDR m_ARP_MAC_Source;
  70. IPADDR m_ARP_IP_Source;
  71. MACADDR m_ARP_MAC_Destination;
  72. IPADDR m_ARP_IP_Destination;
  73. }
  74. ARP_PACKET, *PARP_PACKET;
  75. //----------
  76. // IP Header
  77. //----------
  78. typedef struct {
  79. # define IPH_GET_VER(v) (((v) >> 4) & 0x0F)
  80. # define IPH_GET_LEN(v) (((v) & 0x0F) << 2)
  81. UCHAR version_len;
  82. UCHAR tos;
  83. USHORT tot_len;
  84. USHORT id;
  85. # define IP_OFFMASK 0x1fff
  86. USHORT frag_off;
  87. UCHAR ttl;
  88. # define IPPROTO_UDP 17 /* UDP protocol */
  89. # define IPPROTO_TCP 6 /* TCP protocol */
  90. # define IPPROTO_ICMP 1 /* ICMP protocol */
  91. # define IPPROTO_IGMP 2 /* IGMP protocol */
  92. UCHAR protocol;
  93. USHORT check;
  94. ULONG saddr;
  95. ULONG daddr;
  96. /* The options start here. */
  97. } IPHDR;
  98. //-----------
  99. // UDP header
  100. //-----------
  101. typedef struct {
  102. USHORT source;
  103. USHORT dest;
  104. USHORT len;
  105. USHORT check;
  106. } UDPHDR;
  107. //--------------------------
  108. // TCP header, per RFC 793.
  109. //--------------------------
  110. typedef struct {
  111. USHORT source; /* source port */
  112. USHORT dest; /* destination port */
  113. ULONG seq; /* sequence number */
  114. ULONG ack_seq; /* acknowledgement number */
  115. # define TCPH_GET_DOFF(d) (((d) & 0xF0) >> 2)
  116. UCHAR doff_res;
  117. # define TCPH_FIN_MASK (1<<0)
  118. # define TCPH_SYN_MASK (1<<1)
  119. # define TCPH_RST_MASK (1<<2)
  120. # define TCPH_PSH_MASK (1<<3)
  121. # define TCPH_ACK_MASK (1<<4)
  122. # define TCPH_URG_MASK (1<<5)
  123. # define TCPH_ECE_MASK (1<<6)
  124. # define TCPH_CWR_MASK (1<<7)
  125. UCHAR flags;
  126. USHORT window;
  127. USHORT check;
  128. USHORT urg_ptr;
  129. } TCPHDR;
  130. #define TCPOPT_EOL 0
  131. #define TCPOPT_NOP 1
  132. #define TCPOPT_MAXSEG 2
  133. #define TCPOLEN_MAXSEG 4
  134. //------------
  135. // IPv6 Header
  136. //------------
  137. typedef struct {
  138. UCHAR version_prio;
  139. UCHAR flow_lbl[3];
  140. USHORT payload_len;
  141. # define IPPROTO_ICMPV6 0x3a /* ICMP protocol v6 */
  142. UCHAR nexthdr;
  143. UCHAR hop_limit;
  144. IPV6ADDR saddr;
  145. IPV6ADDR daddr;
  146. } IPV6HDR;
  147. //--------------------------------------------
  148. // IPCMPv6 NS/NA Packets (RFC4443 and RFC4861)
  149. //--------------------------------------------
  150. // Neighbor Solictiation - RFC 4861, 4.3
  151. // (this is just the ICMPv6 part of the packet)
  152. typedef struct {
  153. UCHAR type;
  154. # define ICMPV6_TYPE_NS 135 // neighbour solicitation
  155. UCHAR code;
  156. # define ICMPV6_CODE_0 0 // no specific sub-code for NS/NA
  157. USHORT checksum;
  158. ULONG reserved;
  159. IPV6ADDR target_addr;
  160. } ICMPV6_NS;
  161. // Neighbor Advertisement - RFC 4861, 4.4 + 4.6/4.6.1
  162. // (this is just the ICMPv6 payload)
  163. typedef struct {
  164. UCHAR type;
  165. # define ICMPV6_TYPE_NA 136 // neighbour advertisement
  166. UCHAR code;
  167. # define ICMPV6_CODE_0 0 // no specific sub-code for NS/NA
  168. USHORT checksum;
  169. UCHAR rso_bits; // Router(0), Solicited(2), Ovrrd(4)
  170. UCHAR reserved[3];
  171. IPV6ADDR target_addr;
  172. // always include "Target Link-layer Address" option (RFC 4861 4.6.1)
  173. UCHAR opt_type;
  174. #define ICMPV6_OPTION_TLLA 2
  175. UCHAR opt_length;
  176. #define ICMPV6_LENGTH_TLLA 1 // multiplied by 8 -> 1 = 8 bytes
  177. MACADDR target_macaddr;
  178. } ICMPV6_NA;
  179. // this is the complete packet with Ethernet and IPv6 headers
  180. typedef struct {
  181. ETH_HEADER eth;
  182. IPV6HDR ipv6;
  183. ICMPV6_NA icmpv6;
  184. } ICMPV6_NA_PKT;
  185. #pragma pack()