1 | /*
|
---|
2 | * TAP-Win32 -- A kernel driver to provide virtual tap device functionality
|
---|
3 | * on Windows. Originally derived from the CIPE-Win32
|
---|
4 | * project by Damion K. Wilson, with extensive modifications by
|
---|
5 | * James Yonan.
|
---|
6 | *
|
---|
7 | * All source code which derives from the CIPE-Win32 project is
|
---|
8 | * Copyright (C) Damion K. Wilson, 2003, and is released under the
|
---|
9 | * GPL version 2 (see below).
|
---|
10 | *
|
---|
11 | * All other source code is Copyright (C) 2002-2005 OpenVPN Solutions LLC,
|
---|
12 | * and is released under the GPL version 2 (see below).
|
---|
13 | *
|
---|
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.
|
---|
17 | *
|
---|
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.
|
---|
22 | *
|
---|
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
|
---|
27 | */
|
---|
28 |
|
---|
29 | #ifndef TAP_TYPES_DEFINED
|
---|
30 | #define TAP_TYPES_DEFINED
|
---|
31 |
|
---|
32 | typedef struct _Queue
|
---|
33 | {
|
---|
34 | ULONG base;
|
---|
35 | ULONG size;
|
---|
36 | ULONG capacity;
|
---|
37 | ULONG max_size;
|
---|
38 | PVOID data[];
|
---|
39 | } Queue;
|
---|
40 |
|
---|
41 | typedef struct _TapAdapter;
|
---|
42 | typedef struct _TapPacket;
|
---|
43 |
|
---|
44 | typedef union _TapAdapterQuery
|
---|
45 | {
|
---|
46 | NDIS_HARDWARE_STATUS m_HardwareStatus;
|
---|
47 | NDIS_MEDIUM m_Medium;
|
---|
48 | NDIS_PHYSICAL_MEDIUM m_PhysicalMedium;
|
---|
49 | UCHAR m_MacAddress [6];
|
---|
50 | UCHAR m_Buffer [256];
|
---|
51 | ULONG m_Long;
|
---|
52 | USHORT m_Short;
|
---|
53 | UCHAR m_Byte;
|
---|
54 | }
|
---|
55 | TapAdapterQuery, *TapAdapterQueryPointer;
|
---|
56 |
|
---|
57 | typedef struct _TapExtension
|
---|
58 | {
|
---|
59 | // TAP device object and packet queues
|
---|
60 | Queue *m_PacketQueue, *m_IrpQueue;
|
---|
61 | PDEVICE_OBJECT m_TapDevice;
|
---|
62 | NDIS_HANDLE m_TapDeviceHandle;
|
---|
63 | ULONG m_TapOpens;
|
---|
64 |
|
---|
65 | // Used to lock packet queues
|
---|
66 | NDIS_SPIN_LOCK m_QueueLock;
|
---|
67 | BOOLEAN m_AllocatedSpinlocks;
|
---|
68 |
|
---|
69 | // Used to bracket open/close
|
---|
70 | // state changes.
|
---|
71 | MUTEX m_OpenCloseMutex;
|
---|
72 |
|
---|
73 | // True if device has been permanently halted
|
---|
74 | BOOLEAN m_Halt;
|
---|
75 |
|
---|
76 | // TAP device name
|
---|
77 | unsigned char *m_TapName;
|
---|
78 | UNICODE_STRING m_UnicodeLinkName;
|
---|
79 | BOOLEAN m_CreatedUnicodeLinkName;
|
---|
80 |
|
---|
81 | // Used for device status ioctl only
|
---|
82 | const char *m_LastErrorFilename;
|
---|
83 | int m_LastErrorLineNumber;
|
---|
84 | LONG m_NumTapOpens;
|
---|
85 |
|
---|
86 | // Flags
|
---|
87 | BOOLEAN m_TapIsRunning;
|
---|
88 | BOOLEAN m_CalledTapDeviceFreeResources;
|
---|
89 | }
|
---|
90 | TapExtension, *TapExtensionPointer;
|
---|
91 |
|
---|
92 | typedef struct _TapPacket
|
---|
93 | {
|
---|
94 | # define TAP_PACKET_SIZE(data_size) (sizeof (TapPacket) + (data_size))
|
---|
95 | # define TP_POINT_TO_POINT 0x80000000
|
---|
96 | # define TP_SIZE_MASK (~TP_POINT_TO_POINT)
|
---|
97 | ULONG m_SizeFlags;
|
---|
98 | UCHAR m_Data []; // m_Data must be the last struct member
|
---|
99 | }
|
---|
100 | TapPacket, *TapPacketPointer;
|
---|
101 |
|
---|
102 | typedef struct _TapAdapter
|
---|
103 | {
|
---|
104 | # define NAME(a) ((a)->m_NameAnsi.Buffer)
|
---|
105 | ANSI_STRING m_NameAnsi;
|
---|
106 | MACADDR m_MAC;
|
---|
107 | BOOLEAN m_InterfaceIsRunning;
|
---|
108 | NDIS_HANDLE m_MiniportAdapterHandle;
|
---|
109 | LONG m_Rx, m_Tx, m_RxErr, m_TxErr;
|
---|
110 | NDIS_MEDIUM m_Medium;
|
---|
111 | ULONG m_Lookahead;
|
---|
112 | ULONG m_MTU;
|
---|
113 |
|
---|
114 | // TRUE if adapter should always be
|
---|
115 | // "connected" even when device node
|
---|
116 | // is not open by a userspace process.
|
---|
117 | BOOLEAN m_MediaStateAlwaysConnected;
|
---|
118 |
|
---|
119 | // TRUE if device is "connected"
|
---|
120 | BOOLEAN m_MediaState;
|
---|
121 |
|
---|
122 | // Adapter power state
|
---|
123 | char m_DeviceState;
|
---|
124 |
|
---|
125 | // Info for point-to-point mode
|
---|
126 | BOOLEAN m_PointToPoint;
|
---|
127 | IPADDR m_localIP;
|
---|
128 | IPADDR m_remoteIP;
|
---|
129 | ETH_HEADER m_TapToUser;
|
---|
130 | ETH_HEADER m_UserToTap;
|
---|
131 | MACADDR m_MAC_Broadcast;
|
---|
132 |
|
---|
133 | // Used for DHCP server masquerade
|
---|
134 | BOOLEAN m_dhcp_enabled;
|
---|
135 | IPADDR m_dhcp_addr;
|
---|
136 | ULONG m_dhcp_netmask;
|
---|
137 | IPADDR m_dhcp_server_ip;
|
---|
138 | BOOLEAN m_dhcp_server_arp;
|
---|
139 | MACADDR m_dhcp_server_mac;
|
---|
140 | ULONG m_dhcp_lease_time;
|
---|
141 | UCHAR m_dhcp_user_supplied_options_buffer[DHCP_USER_SUPPLIED_OPTIONS_BUFFER_SIZE];
|
---|
142 | ULONG m_dhcp_user_supplied_options_buffer_len;
|
---|
143 | BOOLEAN m_dhcp_received_discover;
|
---|
144 | ULONG m_dhcp_bad_requests;
|
---|
145 |
|
---|
146 | // Help to tear down the adapter by keeping
|
---|
147 | // some state information on allocated
|
---|
148 | // resources.
|
---|
149 | BOOLEAN m_CalledAdapterFreeResources;
|
---|
150 | BOOLEAN m_RegisteredAdapterShutdownHandler;
|
---|
151 |
|
---|
152 | // Multicast list info
|
---|
153 | NDIS_SPIN_LOCK m_MCLock;
|
---|
154 | BOOLEAN m_MCLockAllocated;
|
---|
155 | ULONG m_MCListSize;
|
---|
156 | MC_LIST m_MCList;
|
---|
157 |
|
---|
158 | // Information on the TAP device
|
---|
159 | TapExtension m_Extension;
|
---|
160 | } TapAdapter, *TapAdapterPointer;
|
---|
161 |
|
---|
162 | #endif
|
---|
163 |
|
---|