2 * TAP-Win32/TAP-Win64 -- A kernel driver to provide virtual tap
3 * device functionality on Windows.
5 * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
7 * This source code is Copyright (C) 2002-2009 OpenVPN Technologies, Inc.,
8 * and is released under the GPL version 2 (see below), however due
9 * to the extra costs of supporting Windows Vista, OpenVPN Solutions
10 * LLC reserves the right to change the terms of the TAP-Win32/TAP-Win64
11 * license for versions 9.1 and higher prior to the official release of
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2
16 * as published by the Free Software Foundation.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program (see the file COPYING included with this
25 * distribution); if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #ifndef TAP_TYPES_DEFINED
30 #define TAP_TYPES_DEFINED
41 typedef struct _TapAdapter
;
42 typedef struct _TapPacket
;
44 typedef union _TapAdapterQuery
46 NDIS_HARDWARE_STATUS m_HardwareStatus
;
48 NDIS_PHYSICAL_MEDIUM m_PhysicalMedium
;
49 UCHAR m_MacAddress
[6];
55 TapAdapterQuery
, *TapAdapterQueryPointer
;
57 typedef struct _TapExtension
59 // TAP device object and packet queues
60 Queue
*m_PacketQueue
, *m_IrpQueue
;
61 PDEVICE_OBJECT m_TapDevice
;
62 NDIS_HANDLE m_TapDeviceHandle
;
65 // Used to lock packet queues
66 NDIS_SPIN_LOCK m_QueueLock
;
67 BOOLEAN m_AllocatedSpinlocks
;
69 // Used to bracket open/close
71 MUTEX m_OpenCloseMutex
;
73 // True if device has been permanently halted
77 unsigned char *m_TapName
;
78 UNICODE_STRING m_UnicodeLinkName
;
79 BOOLEAN m_CreatedUnicodeLinkName
;
81 // Used for device status ioctl only
82 const char *m_LastErrorFilename
;
83 int m_LastErrorLineNumber
;
87 BOOLEAN m_TapIsRunning
;
88 BOOLEAN m_CalledTapDeviceFreeResources
;
90 // DPC queue for deferred packet injection
91 BOOLEAN m_InjectDpcInitialized
;
93 NDIS_SPIN_LOCK m_InjectLock
;
96 TapExtension
, *TapExtensionPointer
;
98 typedef struct _TapPacket
100 # define TAP_PACKET_SIZE(data_size) (sizeof (TapPacket) + (data_size))
101 # define TP_TUN 0x80000000
102 # define TP_SIZE_MASK (~TP_TUN)
104 UCHAR m_Data
[]; // m_Data must be the last struct member
106 TapPacket
, *TapPacketPointer
;
108 typedef struct _InjectPacket
110 # define INJECT_PACKET_SIZE(data_size) (sizeof (InjectPacket) + (data_size))
111 # define INJECT_PACKET_FREE(ib) NdisFreeMemory ((ib), INJECT_PACKET_SIZE ((ib)->m_Size), 0)
113 UCHAR m_Data
[]; // m_Data must be the last struct member
115 InjectPacket
, *InjectPacketPointer
;
117 typedef struct _TapAdapter
119 # define NAME(a) ((a)->m_NameAnsi.Buffer)
120 ANSI_STRING m_NameAnsi
;
122 BOOLEAN m_InterfaceIsRunning
;
123 NDIS_HANDLE m_MiniportAdapterHandle
;
124 LONG m_Rx
, m_Tx
, m_RxErr
, m_TxErr
;
125 #if PACKET_TRUNCATION_CHECK
126 LONG m_RxTrunc
, m_TxTrunc
;
128 NDIS_MEDIUM m_Medium
;
132 // TRUE if adapter should always be
133 // "connected" even when device node
134 // is not open by a userspace process.
135 BOOLEAN m_MediaStateAlwaysConnected
;
137 // TRUE if device is "connected"
138 BOOLEAN m_MediaState
;
140 // Adapter power state
143 // Info for point-to-point mode
146 IPADDR m_remoteNetwork
;
147 IPADDR m_remoteNetmask
;
148 ETH_HEADER m_TapToUser
;
149 ETH_HEADER m_UserToTap
;
150 MACADDR m_MAC_Broadcast
;
152 // Used for DHCP server masquerade
153 BOOLEAN m_dhcp_enabled
;
155 ULONG m_dhcp_netmask
;
156 IPADDR m_dhcp_server_ip
;
157 BOOLEAN m_dhcp_server_arp
;
158 MACADDR m_dhcp_server_mac
;
159 ULONG m_dhcp_lease_time
;
160 UCHAR m_dhcp_user_supplied_options_buffer
[DHCP_USER_SUPPLIED_OPTIONS_BUFFER_SIZE
];
161 ULONG m_dhcp_user_supplied_options_buffer_len
;
162 BOOLEAN m_dhcp_received_discover
;
163 ULONG m_dhcp_bad_requests
;
165 // Help to tear down the adapter by keeping
166 // some state information on allocated
168 BOOLEAN m_CalledAdapterFreeResources
;
169 BOOLEAN m_RegisteredAdapterShutdownHandler
;
171 // Multicast list info
172 NDIS_SPIN_LOCK m_MCLock
;
173 BOOLEAN m_MCLockAllocated
;
177 // Information on the TAP device
178 TapExtension m_Extension
;
179 } TapAdapter
, *TapAdapterPointer
;