Upgrade to OpenVPN 2.1.0
[tomato.git] / release / src / router / openvpn / tap-win32 / types.h
blob48bdff74babc8ff3496de8cf2d64a6499843a6aa
1 /*
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
28 typedef struct _Queue
30 ULONG base;
31 ULONG size;
32 ULONG capacity;
33 ULONG max_size;
34 PVOID data[];
35 } Queue;
37 typedef struct _TapAdapter;
38 typedef struct _TapPacket;
40 typedef union _TapAdapterQuery
42 NDIS_HARDWARE_STATUS m_HardwareStatus;
43 NDIS_MEDIUM m_Medium;
44 NDIS_PHYSICAL_MEDIUM m_PhysicalMedium;
45 UCHAR m_MacAddress [6];
46 UCHAR m_Buffer [256];
47 ULONG m_Long;
48 USHORT m_Short;
49 UCHAR m_Byte;
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;
59 ULONG m_TapOpens;
61 // Used to lock packet queues
62 NDIS_SPIN_LOCK m_QueueLock;
63 BOOLEAN m_AllocatedSpinlocks;
65 // Used to bracket open/close
66 // state changes.
67 MUTEX m_OpenCloseMutex;
69 // True if device has been permanently halted
70 BOOLEAN m_Halt;
72 // TAP device name
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;
80 LONG m_NumTapOpens;
82 // Flags
83 BOOLEAN m_TapIsRunning;
84 BOOLEAN m_CalledTapDeviceFreeResources;
86 // DPC queue for deferred packet injection
87 BOOLEAN m_InjectDpcInitialized;
88 KDPC m_InjectDpc;
89 NDIS_SPIN_LOCK m_InjectLock;
90 Queue *m_InjectQueue;
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)
99 ULONG m_SizeFlags;
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)
108 ULONG m_Size;
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;
117 MACADDR m_MAC;
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;
123 #endif
124 NDIS_MEDIUM m_Medium;
125 ULONG m_Lookahead;
126 ULONG m_MTU;
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
137 char m_DeviceState;
139 // Info for point-to-point mode
140 BOOLEAN m_tun;
141 IPADDR m_localIP;
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;
150 IPADDR m_dhcp_addr;
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
163 // resources.
164 BOOLEAN m_CalledAdapterFreeResources;
165 BOOLEAN m_RegisteredAdapterShutdownHandler;
167 // Multicast list info
168 NDIS_SPIN_LOCK m_MCLock;
169 BOOLEAN m_MCLockAllocated;
170 ULONG m_MCListSize;
171 MC_LIST m_MCList;
173 // Information on the TAP device
174 TapExtension m_Extension;
175 } TapAdapter, *TapAdapterPointer;
177 #endif