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).
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.
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.
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
25 #ifndef TAP_TYPES_DEFINED
26 #define TAP_TYPES_DEFINED
37 typedef struct _TapAdapter
;
38 typedef struct _TapPacket
;
40 typedef union _TapAdapterQuery
42 NDIS_HARDWARE_STATUS m_HardwareStatus
;
44 NDIS_PHYSICAL_MEDIUM m_PhysicalMedium
;
45 UCHAR m_MacAddress
[6];
51 TapAdapterQuery
, *TapAdapterQueryPointer
;
53 typedef struct _TapExtension
55 // TAP device object and packet queues
56 Queue
*m_PacketQueue
, *m_IrpQueue
;
57 PDEVICE_OBJECT m_TapDevice
;
58 NDIS_HANDLE m_TapDeviceHandle
;
61 // Used to lock packet queues
62 NDIS_SPIN_LOCK m_QueueLock
;
63 BOOLEAN m_AllocatedSpinlocks
;
65 // Used to bracket open/close
67 MUTEX m_OpenCloseMutex
;
69 // True if device has been permanently halted
73 unsigned char *m_TapName
;
74 UNICODE_STRING m_UnicodeLinkName
;
75 BOOLEAN m_CreatedUnicodeLinkName
;
77 // Used for device status ioctl only
78 const char *m_LastErrorFilename
;
79 int m_LastErrorLineNumber
;
83 BOOLEAN m_TapIsRunning
;
84 BOOLEAN m_CalledTapDeviceFreeResources
;
86 // DPC queue for deferred packet injection
87 BOOLEAN m_InjectDpcInitialized
;
89 NDIS_SPIN_LOCK m_InjectLock
;
92 TapExtension
, *TapExtensionPointer
;
94 typedef struct _TapPacket
96 # define TAP_PACKET_SIZE(data_size) (sizeof (TapPacket) + (data_size))
97 # define TP_TUN 0x80000000
98 # define TP_SIZE_MASK (~TP_TUN)
100 UCHAR m_Data
[]; // m_Data must be the last struct member
102 TapPacket
, *TapPacketPointer
;
104 typedef struct _InjectPacket
106 # define INJECT_PACKET_SIZE(data_size) (sizeof (InjectPacket) + (data_size))
107 # define INJECT_PACKET_FREE(ib) NdisFreeMemory ((ib), INJECT_PACKET_SIZE ((ib)->m_Size), 0)
109 UCHAR m_Data
[]; // m_Data must be the last struct member
111 InjectPacket
, *InjectPacketPointer
;
113 typedef struct _TapAdapter
115 # define NAME(a) ((a)->m_NameAnsi.Buffer)
116 ANSI_STRING m_NameAnsi
;
118 BOOLEAN m_InterfaceIsRunning
;
119 NDIS_HANDLE m_MiniportAdapterHandle
;
120 LONG m_Rx
, m_Tx
, m_RxErr
, m_TxErr
;
121 #if PACKET_TRUNCATION_CHECK
122 LONG m_RxTrunc
, m_TxTrunc
;
124 NDIS_MEDIUM m_Medium
;
128 // TRUE if adapter should always be
129 // "connected" even when device node
130 // is not open by a userspace process.
131 BOOLEAN m_MediaStateAlwaysConnected
;
133 // TRUE if device is "connected"
134 BOOLEAN m_MediaState
;
136 // Adapter power state
139 // Info for point-to-point mode
142 IPADDR m_remoteNetwork
;
143 IPADDR m_remoteNetmask
;
144 ETH_HEADER m_TapToUser
;
145 ETH_HEADER m_UserToTap
;
146 MACADDR m_MAC_Broadcast
;
148 // Used for DHCP server masquerade
149 BOOLEAN m_dhcp_enabled
;
151 ULONG m_dhcp_netmask
;
152 IPADDR m_dhcp_server_ip
;
153 BOOLEAN m_dhcp_server_arp
;
154 MACADDR m_dhcp_server_mac
;
155 ULONG m_dhcp_lease_time
;
156 UCHAR m_dhcp_user_supplied_options_buffer
[DHCP_USER_SUPPLIED_OPTIONS_BUFFER_SIZE
];
157 ULONG m_dhcp_user_supplied_options_buffer_len
;
158 BOOLEAN m_dhcp_received_discover
;
159 ULONG m_dhcp_bad_requests
;
161 // Help to tear down the adapter by keeping
162 // some state information on allocated
164 BOOLEAN m_CalledAdapterFreeResources
;
165 BOOLEAN m_RegisteredAdapterShutdownHandler
;
167 // Multicast list info
168 NDIS_SPIN_LOCK m_MCLock
;
169 BOOLEAN m_MCLockAllocated
;
173 // Information on the TAP device
174 TapExtension m_Extension
;
175 } TapAdapter
, *TapAdapterPointer
;