types.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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-2010 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. #ifndef TAP_TYPES_DEFINED
  25. #define TAP_TYPES_DEFINED
  26. typedef struct _Queue
  27. {
  28. ULONG base;
  29. ULONG size;
  30. ULONG capacity;
  31. ULONG max_size;
  32. PVOID data[];
  33. } Queue;
  34. typedef struct _TapAdapter;
  35. typedef struct _TapPacket;
  36. typedef union _TapAdapterQuery
  37. {
  38. NDIS_HARDWARE_STATUS m_HardwareStatus;
  39. NDIS_MEDIUM m_Medium;
  40. NDIS_PHYSICAL_MEDIUM m_PhysicalMedium;
  41. UCHAR m_MacAddress [6];
  42. UCHAR m_Buffer [256];
  43. ULONG m_Long;
  44. USHORT m_Short;
  45. UCHAR m_Byte;
  46. }
  47. TapAdapterQuery, *TapAdapterQueryPointer;
  48. typedef struct _TapExtension
  49. {
  50. // TAP device object and packet queues
  51. Queue *m_PacketQueue, *m_IrpQueue;
  52. PDEVICE_OBJECT m_TapDevice;
  53. NDIS_HANDLE m_TapDeviceHandle;
  54. ULONG m_TapOpens;
  55. // Used to lock packet queues
  56. NDIS_SPIN_LOCK m_QueueLock;
  57. BOOLEAN m_AllocatedSpinlocks;
  58. // Used to bracket open/close
  59. // state changes.
  60. MUTEX m_OpenCloseMutex;
  61. // True if device has been permanently halted
  62. BOOLEAN m_Halt;
  63. // TAP device name
  64. unsigned char *m_TapName;
  65. UNICODE_STRING m_UnicodeLinkName;
  66. BOOLEAN m_CreatedUnicodeLinkName;
  67. // Used for device status ioctl only
  68. const char *m_LastErrorFilename;
  69. int m_LastErrorLineNumber;
  70. LONG m_NumTapOpens;
  71. // Flags
  72. BOOLEAN m_TapIsRunning;
  73. BOOLEAN m_CalledTapDeviceFreeResources;
  74. // DPC queue for deferred packet injection
  75. BOOLEAN m_InjectDpcInitialized;
  76. KDPC m_InjectDpc;
  77. NDIS_SPIN_LOCK m_InjectLock;
  78. Queue *m_InjectQueue;
  79. }
  80. TapExtension, *TapExtensionPointer;
  81. typedef struct _TapPacket
  82. {
  83. # define TAP_PACKET_SIZE(data_size) (sizeof (TapPacket) + (data_size))
  84. # define TP_TUN 0x80000000
  85. # define TP_SIZE_MASK (~TP_TUN)
  86. ULONG m_SizeFlags;
  87. UCHAR m_Data []; // m_Data must be the last struct member
  88. }
  89. TapPacket, *TapPacketPointer;
  90. typedef struct _InjectPacket
  91. {
  92. # define INJECT_PACKET_SIZE(data_size) (sizeof (InjectPacket) + (data_size))
  93. # define INJECT_PACKET_FREE(ib) NdisFreeMemory ((ib), INJECT_PACKET_SIZE ((ib)->m_Size), 0)
  94. ULONG m_Size;
  95. UCHAR m_Data []; // m_Data must be the last struct member
  96. }
  97. InjectPacket, *InjectPacketPointer;
  98. typedef struct _TapAdapter
  99. {
  100. # define NAME(a) ((a)->m_NameAnsi.Buffer)
  101. ANSI_STRING m_NameAnsi;
  102. MACADDR m_MAC;
  103. BOOLEAN m_InterfaceIsRunning;
  104. NDIS_HANDLE m_MiniportAdapterHandle;
  105. LONG m_Rx, m_Tx, m_RxErr, m_TxErr;
  106. #if PACKET_TRUNCATION_CHECK
  107. LONG m_RxTrunc, m_TxTrunc;
  108. #endif
  109. NDIS_MEDIUM m_Medium;
  110. ULONG m_Lookahead;
  111. ULONG m_MTU;
  112. // TRUE if adapter should always be
  113. // "connected" even when device node
  114. // is not open by a userspace process.
  115. BOOLEAN m_MediaStateAlwaysConnected;
  116. // TRUE if device is "connected"
  117. BOOLEAN m_MediaState;
  118. // Adapter power state
  119. char m_DeviceState;
  120. // Info for point-to-point mode
  121. BOOLEAN m_tun;
  122. IPADDR m_localIP;
  123. IPADDR m_remoteNetwork;
  124. IPADDR m_remoteNetmask;
  125. ETH_HEADER m_TapToUser;
  126. ETH_HEADER m_UserToTap;
  127. ETH_HEADER m_UserToTap_IPv6; // same as UserToTap but proto=ipv6
  128. MACADDR m_MAC_Broadcast;
  129. // Used for DHCP server masquerade
  130. BOOLEAN m_dhcp_enabled;
  131. IPADDR m_dhcp_addr;
  132. ULONG m_dhcp_netmask;
  133. IPADDR m_dhcp_server_ip;
  134. BOOLEAN m_dhcp_server_arp;
  135. MACADDR m_dhcp_server_mac;
  136. ULONG m_dhcp_lease_time;
  137. UCHAR m_dhcp_user_supplied_options_buffer[DHCP_USER_SUPPLIED_OPTIONS_BUFFER_SIZE];
  138. ULONG m_dhcp_user_supplied_options_buffer_len;
  139. BOOLEAN m_dhcp_received_discover;
  140. ULONG m_dhcp_bad_requests;
  141. // Help to tear down the adapter by keeping
  142. // some state information on allocated
  143. // resources.
  144. BOOLEAN m_CalledAdapterFreeResources;
  145. BOOLEAN m_RegisteredAdapterShutdownHandler;
  146. // Multicast list info
  147. NDIS_SPIN_LOCK m_MCLock;
  148. BOOLEAN m_MCLockAllocated;
  149. ULONG m_MCListSize;
  150. MC_LIST m_MCList;
  151. // Information on the TAP device
  152. TapExtension m_Extension;
  153. } TapAdapter, *TapAdapterPointer;
  154. #endif