Browse code

Remove tap-win32

Introduce tap-windows.h which is modified tap-win32/common.h.
Except of function rename, it is the same without the tap_id.
This file should be provided as part of tap-win32 MSI.
For now we hold a copy.

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
Acked-by: Samuli Seppänen <samuli@openvpn.net>
Signed-off-by: David Sommerseth <davids@redhat.com>

Alon Bar-Lev authored on 2012/03/01 05:11:49
Showing 27 changed files
... ...
@@ -44,7 +44,6 @@ EXTRA_DIST = \
44 44
 	sample-keys \
45 45
 	sample-scripts \
46 46
 	suse \
47
-	tap-win32 \
48 47
 	contrib \
49 48
 	debug \
50 49
 	plugins \
... ...
@@ -147,7 +146,7 @@ openvpn_SOURCES = \
147 147
 	ssl_verify_polarssl.c ssl_verify_polarssl.h \
148 148
 	status.c status.h \
149 149
 	syshead.h \
150
-	tun.c tun.h \
150
+	tun.c tun.h tap-windows.h \
151 151
 	win32.h win32.c \
152 152
 	cryptoapi.h cryptoapi.c
153 153
 
... ...
@@ -959,15 +959,15 @@ if test "$SELINUX" = "yes"; then
959 959
    )
960 960
 fi
961 961
 
962
-TAP_ID="PRODUCT_TAP_ID"
962
+TAP_COMPONENT_ID="PRODUCT_TAP_ID"
963 963
 TAP_WIN32_MIN_MAJOR="PRODUCT_TAP_WIN32_MIN_MAJOR"
964 964
 TAP_WIN32_MIN_MINOR="PRODUCT_TAP_WIN32_MIN_MINOR"
965
-AC_DEFINE_UNQUOTED(TAP_ID, "${TAP_ID}", [The TAP-Win32 id defined in tap-win32/SOURCES])
966
-AC_DEFINE_UNQUOTED(TAP_WIN32_MIN_MAJOR, ${TAP_WIN32_MIN_MAJOR}, [The TAP-Win32 version number is defined in tap-win32/SOURCES])
967
-AC_DEFINE_UNQUOTED(TAP_WIN32_MIN_MINOR, ${TAP_WIN32_MIN_MINOR}, [The TAP-Win32 version number is defined in tap-win32/SOURCES])
968
-AC_SUBST(TAP_ID)
969
-AC_SUBST(TAP_WIN32_MIN_MAJOR)
970
-AC_SUBST(TAP_WIN32_MIN_MINOR)
965
+AC_DEFINE_UNQUOTED([TAP_ID], ["${TAP_ID}"], [The TAP-Win32 id])
966
+AC_DEFINE_UNQUOTED([TAP_WIN32_MIN_MAJOR], [${TAP_WIN32_MIN_MAJOR}], [The TAP-Win32 version number is defined in tap-win32/SOURCES])
967
+AC_DEFINE_UNQUOTED([TAP_WIN32_MIN_MINOR], [${TAP_WIN32_MIN_MINOR}], [The TAP-Win32 version number is defined in tap-win32/SOURCES])
968
+AC_SUBST([TAP_COMPONENT_ID])
969
+AC_SUBST([TAP_WIN32_MIN_MAJOR])
970
+AC_SUBST([TAP_WIN32_MIN_MINOR])
971 971
 
972 972
 win32datadir="\${datadir}/${PACKAGE}-win32"
973 973
 AC_SUBST(win32datadir)
974 974
deleted file mode 100755
... ...
@@ -1,6 +0,0 @@
1
-#
2
-# DO NOT EDIT THIS FILE!!!  Edit .\sources. if you want to add a new source
3
-# file to this component.  This file merely indirects to the real make file
4
-# that is shared by all the components of NT OS/2
5
-#
6
-!INCLUDE $(NTMAKEENV)\makefile.def
7 1
deleted file mode 100755
... ...
@@ -1,64 +0,0 @@
1
-# Build TAP-Win32 driver.
2
-# Build Command: build -cef
3
-
4
-MAJORCOMP=ntos
5
-MINORCOMP=ndis
6
-
7
-TARGETNAME=@@PRODUCT_TAP_ID@@
8
-TARGETTYPE=DRIVER
9
-TARGETPATH=.
10
-TARGETLIBS=$(DDK_LIB_PATH)\ndis.lib $(DDK_LIB_PATH)\ntstrsafe.lib
11
-INCLUDES=$(DDK_INCLUDE_PATH) ..
12
-
13
-# The TAP version numbers here must be >=
14
-# PRODUCT_TAP_WIN32_MIN_x values defined in version.m4
15
-C_DEFINES=
16
-C_DEFINES=$(C_DEFINES) -DTAP_DRIVER_MAJOR_VERSION=@@PRODUCT_TAP_MAJOR_VER@@
17
-C_DEFINES=$(C_DEFINES) -DTAP_DRIVER_MINOR_VERSION=@@PRODUCT_TAP_MINOR_VER@@
18
-
19
-# Produce the same symbolic information for both free & checked builds.
20
-# This will allow us to perform full source-level debugging on both
21
-# builds without affecting the free build's performance.
22
-!IF "$(DDKBUILDENV)" != "chk"
23
-NTDEBUGTYPE=both
24
-USE_PDB=1
25
-!ELSE
26
-NTDEBUGTYPE=both
27
-USE_PDB=1
28
-!ENDIF
29
-
30
-# Set compiler optimizations:
31
-# /Ox - Full optimization enabled
32
-# /Os - favor speed over size when optimizing
33
-# /Od - Disable all optimizations
34
-# /Oi - Enable optimization for intrinsic functions
35
-# /Fc - Generate mixed assembler/source code files
36
-#
37
-# For both checked and free builds, make sure that any intrinsic
38
-# functions are compiled correctly. To do this, ensure that /Oi
39
-# is selected for both free and checked builds. There is a bug in
40
-# VC++ 6.0 (at least through SP4) where, if you specify any
41
-# intrinsic functions in your code with "#pragma intrinsic" but
42
-# you don't have the /Oi optimization enabled, neither a call
43
-# to the function, nor the intrinsic inline version of the function
44
-# will end up in your object code. This bug only applies to free
45
-# builds, but just to be safe we'll make sure that the flag is
46
-# enabled for all builds.
47
-
48
-!IF "$(DDKBUILDENV)" != "chk"
49
-MSC_OPTIMIZATION=/Ox /Oi /Fc
50
-!ELSE
51
-MSC_OPTIMIZATION=/Od /Oi /Fc
52
-!ENDIF
53
-
54
-# Generate a linker map file just in case we need one for debugging
55
-LINKER_FLAGS=$(LINKER_FLAGS) /INCREMENTAL:NO /MAP /MAPINFO:EXPORTS
56
-
57
-# Generate a browser information file for use in IDE development
58
-#BROWSER_INFO=1
59
-#BROWSERFILE=$(TARGETNAME).BSC -n
60
-
61
-# Abort compilation on warnings by adding /WX
62
-MSC_WARNING_LEVEL=/W3
63
-
64
-SOURCES=tapdrvr.c resource.rc
65 1
deleted file mode 100755
... ...
@@ -1,82 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-//===============================================
26
-// This file is included both by OpenVPN and
27
-// the TAP-Win32 driver and contains definitions
28
-// common to both.
29
-//===============================================
30
-
31
-#ifndef HAVE_CONFIG_H
32
-#include "autodefs.h"
33
-#endif
34
-
35
-//=============
36
-// TAP IOCTLs
37
-//=============
38
-
39
-#define TAP_CONTROL_CODE(request,method) \
40
-  CTL_CODE (FILE_DEVICE_UNKNOWN, request, method, FILE_ANY_ACCESS)
41
-
42
-// Present in 8.1
43
-
44
-#define TAP_IOCTL_GET_MAC               TAP_CONTROL_CODE (1, METHOD_BUFFERED)
45
-#define TAP_IOCTL_GET_VERSION           TAP_CONTROL_CODE (2, METHOD_BUFFERED)
46
-#define TAP_IOCTL_GET_MTU               TAP_CONTROL_CODE (3, METHOD_BUFFERED)
47
-#define TAP_IOCTL_GET_INFO              TAP_CONTROL_CODE (4, METHOD_BUFFERED)
48
-#define TAP_IOCTL_CONFIG_POINT_TO_POINT TAP_CONTROL_CODE (5, METHOD_BUFFERED)
49
-#define TAP_IOCTL_SET_MEDIA_STATUS      TAP_CONTROL_CODE (6, METHOD_BUFFERED)
50
-#define TAP_IOCTL_CONFIG_DHCP_MASQ      TAP_CONTROL_CODE (7, METHOD_BUFFERED)
51
-#define TAP_IOCTL_GET_LOG_LINE          TAP_CONTROL_CODE (8, METHOD_BUFFERED)
52
-#define TAP_IOCTL_CONFIG_DHCP_SET_OPT   TAP_CONTROL_CODE (9, METHOD_BUFFERED)
53
-
54
-// Added in 8.2
55
-
56
-/* obsoletes TAP_IOCTL_CONFIG_POINT_TO_POINT */
57
-#define TAP_IOCTL_CONFIG_TUN            TAP_CONTROL_CODE (10, METHOD_BUFFERED)
58
-
59
-//=================
60
-// Registry keys
61
-//=================
62
-
63
-#define ADAPTER_KEY "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
64
-
65
-#define NETWORK_CONNECTIONS_KEY "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
66
-
67
-//======================
68
-// Filesystem prefixes
69
-//======================
70
-
71
-#define USERMODEDEVICEDIR "\\\\.\\Global\\"
72
-#define SYSDEVICEDIR      "\\Device\\"
73
-#define USERDEVICEDIR     "\\DosDevices\\Global\\"
74
-#define TAPSUFFIX         ".tap"
75
-
76
-//=========================================================
77
-// TAP_COMPONENT_ID -- This string defines the TAP driver
78
-// type -- different component IDs can reside in the system
79
-// simultaneously.
80
-//=========================================================
81
-
82
-#define TAP_COMPONENT_ID TAP_ID
83 1
deleted file mode 100755
... ...
@@ -1,52 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-//====================================================================
26
-//                        Product and Version public settings
27
-//====================================================================
28
-
29
-#define PRODUCT_STRING PRODUCT_TAP_DEVICE_DESCRIPTION
30
-
31
-#define TAP_NDIS_MAJOR_VERSION 5
32
-#define TAP_NDIS_MINOR_VERSION 0
33
-
34
-//===========================================================
35
-// Driver constants
36
-//===========================================================
37
-
38
-#define ETHERNET_HEADER_SIZE     (sizeof (ETH_HEADER))
39
-#define ETHERNET_MTU             1500
40
-#define ETHERNET_PACKET_SIZE     (ETHERNET_MTU + ETHERNET_HEADER_SIZE)
41
-#define DEFAULT_PACKET_LOOKAHEAD (ETHERNET_PACKET_SIZE)
42
-
43
-#define NIC_MAX_MCAST_LIST 32  // Max length of multicast address list
44
-
45
-#define MINIMUM_MTU 576        // USE TCP Minimum MTU
46
-#define MAXIMUM_MTU 65536      // IP maximum MTU
47
-
48
-#define PACKET_QUEUE_SIZE   64 // tap -> userspace queue size
49
-#define IRP_QUEUE_SIZE      16 // max number of simultaneous i/o operations from userspace
50
-#define INJECT_QUEUE_SIZE   16 // DHCP/ARP -> tap injection queue
51
-
52
-#define TAP_LITTLE_ENDIAN      // affects ntohs, htonl, etc. functions
53 1
deleted file mode 100755
... ...
@@ -1,599 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-//=========================
26
-// Code to set DHCP options
27
-//=========================
28
-
29
-VOID
30
-SetDHCPOpt (DHCPMsg *m, void *data, unsigned int len)
31
-{
32
-  if (!m->overflow)
33
-    {
34
-      if (m->optlen + len <= DHCP_OPTIONS_BUFFER_SIZE)
35
-	{
36
-	  if (len)
37
-	    {
38
-	      NdisMoveMemory (m->msg.options + m->optlen, data, len);
39
-	      m->optlen += len;
40
-	    }
41
-	}
42
-      else
43
-	{
44
-	  m->overflow = TRUE;
45
-	}
46
-    }
47
-}
48
-
49
-VOID
50
-SetDHCPOpt0 (DHCPMsg *msg, int type)
51
-{
52
-  DHCPOPT0 opt;
53
-  opt.type = (UCHAR) type;
54
-  SetDHCPOpt (msg, &opt, sizeof (opt));
55
-}
56
-
57
-VOID
58
-SetDHCPOpt8 (DHCPMsg *msg, int type, ULONG data)
59
-{
60
-  DHCPOPT8 opt;
61
-  opt.type = (UCHAR) type;
62
-  opt.len = sizeof (opt.data);
63
-  opt.data = (UCHAR) data;
64
-  SetDHCPOpt (msg, &opt, sizeof (opt));
65
-}
66
-
67
-VOID
68
-SetDHCPOpt32 (DHCPMsg *msg, int type, ULONG data)
69
-{
70
-  DHCPOPT32 opt;
71
-  opt.type = (UCHAR) type;
72
-  opt.len = sizeof (opt.data);
73
-  opt.data = data;
74
-  SetDHCPOpt (msg, &opt, sizeof (opt));
75
-}
76
-
77
-//==============
78
-// Checksum code
79
-//==============
80
-
81
-USHORT
82
-ip_checksum (const UCHAR *buf, const int len_ip_header)
83
-{
84
-  USHORT word16;
85
-  ULONG sum = 0;
86
-  int i;
87
-    
88
-  // make 16 bit words out of every two adjacent 8 bit words in the packet
89
-  // and add them up
90
-  for (i = 0; i < len_ip_header - 1; i += 2) {
91
-    word16 = ((buf[i] << 8) & 0xFF00) + (buf[i+1] & 0xFF);
92
-    sum += (ULONG) word16;
93
-  }
94
-
95
-  // take only 16 bits out of the 32 bit sum and add up the carries
96
-  while (sum >> 16)
97
-    sum = (sum & 0xFFFF) + (sum >> 16);
98
-
99
-  // one's complement the result
100
-  return ((USHORT) ~sum);
101
-}
102
-
103
-USHORT
104
-udp_checksum (const UCHAR *buf,
105
-	      const int len_udp,
106
-	      const UCHAR *src_addr,
107
-	      const UCHAR *dest_addr)
108
-{
109
-  USHORT word16;
110
-  ULONG sum = 0;
111
-  int i;
112
-	
113
-  // make 16 bit words out of every two adjacent 8 bit words and 
114
-  // calculate the sum of all 16 bit words
115
-  for (i = 0; i < len_udp; i += 2){
116
-    word16 = ((buf[i] << 8) & 0xFF00) + ((i + 1 < len_udp) ? (buf[i+1] & 0xFF) : 0);
117
-    sum += word16;
118
-  }
119
-
120
-  // add the UDP pseudo header which contains the IP source and destination addresses
121
-  for (i = 0; i < 4; i += 2){
122
-    word16 =((src_addr[i] << 8) & 0xFF00) + (src_addr[i+1] & 0xFF);
123
-    sum += word16;
124
-  }
125
-  for (i = 0; i < 4; i += 2){
126
-    word16 =((dest_addr[i] << 8) & 0xFF00) + (dest_addr[i+1] & 0xFF);
127
-    sum += word16; 	
128
-  }
129
-
130
-  // the protocol number and the length of the UDP packet
131
-  sum += (USHORT) IPPROTO_UDP + (USHORT) len_udp;
132
-
133
-  // keep only the last 16 bits of the 32 bit calculated sum and add the carries
134
-  while (sum >> 16)
135
-    sum = (sum & 0xFFFF) + (sum >> 16);
136
-		
137
-  // Take the one's complement of sum
138
-  return ((USHORT) ~sum);
139
-}
140
-
141
-//================================
142
-// Set IP and UDP packet checksums
143
-//================================
144
-
145
-VOID
146
-SetChecksumDHCPMsg (DHCPMsg *m)
147
-{
148
-  // Set IP checksum
149
-  m->msg.pre.ip.check = htons (ip_checksum ((UCHAR *) &m->msg.pre.ip, sizeof (IPHDR)));
150
-
151
-  // Set UDP Checksum
152
-  m->msg.pre.udp.check = htons (udp_checksum ((UCHAR *) &m->msg.pre.udp, 
153
-					      sizeof (UDPHDR) + sizeof (DHCP) + m->optlen,
154
-					      (UCHAR *)&m->msg.pre.ip.saddr,
155
-					      (UCHAR *)&m->msg.pre.ip.daddr));
156
-}
157
-
158
-//===================
159
-// DHCP message tests
160
-//===================
161
-
162
-int
163
-GetDHCPMessageType (const DHCP *dhcp, const int optlen)
164
-{
165
-  const UCHAR *p = (UCHAR *) (dhcp + 1);
166
-  int i;
167
-
168
-  for (i = 0; i < optlen; ++i)
169
-    {
170
-      const UCHAR type = p[i];
171
-      const int room = optlen - i - 1;
172
-      if (type == DHCP_END)           // didn't find what we were looking for
173
-	return -1;
174
-      else if (type == DHCP_PAD)      // no-operation
175
-	;
176
-      else if (type == DHCP_MSG_TYPE) // what we are looking for
177
-	{
178
-	  if (room >= 2)
179
-	    {
180
-	      if (p[i+1] == 1)        // message length should be 1
181
-		return p[i+2];        // return message type
182
-	    }
183
-	  return -1;
184
-	}
185
-      else                            // some other message
186
-	{
187
-	  if (room >= 1)
188
-	    {
189
-	      const int len = p[i+1]; // get message length
190
-	      i += (len + 1);         // advance to next message
191
-	    }
192
-	}
193
-    }
194
-  return -1;
195
-}
196
-
197
-BOOLEAN
198
-DHCPMessageOurs (const TapAdapterPointer p_Adapter,
199
-		 const ETH_HEADER *eth,
200
-		 const IPHDR *ip,
201
-		 const UDPHDR *udp,
202
-		 const DHCP *dhcp)
203
-{
204
-  // Must be UDPv4 protocol
205
-  if (!(eth->proto == htons (ETH_P_IP) && ip->protocol == IPPROTO_UDP))
206
-    return FALSE;
207
-
208
-  // Source MAC must be our adapter
209
-  if (!MAC_EQUAL (eth->src, p_Adapter->m_MAC))
210
-    return FALSE;
211
-
212
-  // Dest MAC must be either broadcast or our virtual DHCP server
213
-  if (!(MAC_EQUAL (eth->dest, p_Adapter->m_MAC_Broadcast)
214
-	|| MAC_EQUAL (eth->dest, p_Adapter->m_dhcp_server_mac)))
215
-    return FALSE;
216
-
217
-  // Port numbers must be correct
218
-  if (!(udp->dest == htons (BOOTPS_PORT)
219
-	&& udp->source == htons (BOOTPC_PORT)))
220
-    return FALSE;
221
-
222
-  // Hardware address must be MAC addr sized
223
-  if (!(dhcp->hlen == sizeof (MACADDR)))
224
-    return FALSE;
225
-
226
-  // Hardware address must match our adapter
227
-  if (!MAC_EQUAL (eth->src, dhcp->chaddr))
228
-    return FALSE;
229
-
230
-  return TRUE;
231
-}
232
-
233
-
234
-//=====================================================
235
-// Build all of DHCP packet except for DHCP options.
236
-// Assume that *p has been zeroed before we are called.
237
-//=====================================================
238
-
239
-VOID
240
-BuildDHCPPre (const TapAdapterPointer a,
241
-	      DHCPPre *p,
242
-	      const ETH_HEADER *eth,
243
-	      const IPHDR *ip,
244
-	      const UDPHDR *udp,
245
-	      const DHCP *dhcp,
246
-	      const int optlen,
247
-	      const int type)
248
-{
249
-  // Should we broadcast or direct to a specific MAC / IP address?
250
-  const BOOLEAN broadcast = (type == DHCPNAK
251
-			     || MAC_EQUAL (eth->dest, a->m_MAC_Broadcast));
252
-  // Build ethernet header
253
-
254
-  COPY_MAC (p->eth.src, a->m_dhcp_server_mac);
255
-
256
-  if (broadcast)
257
-    COPY_MAC (p->eth.dest, a->m_MAC_Broadcast);
258
-  else
259
-    COPY_MAC (p->eth.dest, eth->src);
260
-
261
-  p->eth.proto = htons (ETH_P_IP);
262
-
263
-  // Build IP header
264
-
265
-  p->ip.version_len = (4 << 4) | (sizeof (IPHDR) >> 2);
266
-  p->ip.tos = 0;
267
-  p->ip.tot_len = htons (sizeof (IPHDR) + sizeof (UDPHDR) + sizeof (DHCP) + optlen);
268
-  p->ip.id = 0;
269
-  p->ip.frag_off = 0;
270
-  p->ip.ttl = 16;
271
-  p->ip.protocol = IPPROTO_UDP;
272
-  p->ip.check = 0;
273
-  p->ip.saddr = a->m_dhcp_server_ip;
274
-
275
-  if (broadcast)
276
-    p->ip.daddr = ~0;
277
-  else
278
-    p->ip.daddr = a->m_dhcp_addr;
279
-
280
-  // Build UDP header
281
-
282
-  p->udp.source = htons (BOOTPS_PORT);
283
-  p->udp.dest = htons (BOOTPC_PORT);
284
-  p->udp.len = htons (sizeof (UDPHDR) + sizeof (DHCP) + optlen);
285
-  p->udp.check = 0;
286
-
287
-  // Build DHCP response
288
-
289
-  p->dhcp.op = BOOTREPLY;
290
-  p->dhcp.htype = 1;
291
-  p->dhcp.hlen = sizeof (MACADDR);
292
-  p->dhcp.hops = 0;
293
-  p->dhcp.xid = dhcp->xid;
294
-  p->dhcp.secs = 0;
295
-  p->dhcp.flags = 0;
296
-  p->dhcp.ciaddr = 0;
297
-
298
-  if (type == DHCPNAK)
299
-    p->dhcp.yiaddr = 0;
300
-  else
301
-    p->dhcp.yiaddr = a->m_dhcp_addr;
302
-
303
-  p->dhcp.siaddr = a->m_dhcp_server_ip;
304
-  p->dhcp.giaddr = 0;
305
-  COPY_MAC (p->dhcp.chaddr, eth->src);
306
-  p->dhcp.magic = htonl (0x63825363);
307
-}
308
-//=============================
309
-// Build specific DHCP messages
310
-//=============================
311
-
312
-VOID
313
-SendDHCPMsg (const TapAdapterPointer a,
314
-	     const int type,
315
-	     const ETH_HEADER *eth,
316
-	     const IPHDR *ip,
317
-	     const UDPHDR *udp,
318
-	     const DHCP *dhcp)
319
-{
320
-  DHCPMsg *pkt;
321
-
322
-  if (!(type == DHCPOFFER || type == DHCPACK || type == DHCPNAK))
323
-    {
324
-      DEBUGP (("[TAP] SendDHCPMsg: Bad DHCP type: %d\n", type));
325
-      return;
326
-    }
327
-
328
-  pkt = (DHCPMsg *) MemAlloc (sizeof (DHCPMsg), TRUE);
329
-
330
-  if (pkt)
331
-    {
332
-      //-----------------------
333
-      // Build DHCP options
334
-      //-----------------------
335
-
336
-      // Message Type
337
-      SetDHCPOpt8 (pkt, DHCP_MSG_TYPE, type);
338
-
339
-      // Server ID
340
-      SetDHCPOpt32 (pkt, DHCP_SERVER_ID, a->m_dhcp_server_ip);
341
-
342
-      if (type == DHCPOFFER || type == DHCPACK)
343
-	{
344
-	  // Lease Time
345
-	  SetDHCPOpt32 (pkt, DHCP_LEASE_TIME, htonl (a->m_dhcp_lease_time));
346
-
347
-	  // Netmask
348
-	  SetDHCPOpt32 (pkt, DHCP_NETMASK, a->m_dhcp_netmask);
349
-
350
-	  // Other user-defined options
351
-	  SetDHCPOpt (pkt,
352
-		      a->m_dhcp_user_supplied_options_buffer,
353
-		      a->m_dhcp_user_supplied_options_buffer_len);
354
-	}
355
-
356
-      // End
357
-      SetDHCPOpt0 (pkt, DHCP_END);
358
-
359
-      if (!DHCPMSG_OVERFLOW (pkt))
360
-	{
361
-	  // The initial part of the DHCP message (not including options) gets built here
362
-	  BuildDHCPPre (a,
363
-			&pkt->msg.pre,
364
-			eth,
365
-			ip,
366
-			udp,
367
-			dhcp,
368
-			DHCPMSG_LEN_OPT (pkt),
369
-			type);
370
-
371
-	  SetChecksumDHCPMsg (pkt);
372
-
373
-	  DUMP_PACKET ("DHCPMsg",
374
-		       DHCPMSG_BUF (pkt),
375
-		       DHCPMSG_LEN_FULL (pkt));
376
-
377
-	  // Return DHCP response to kernel
378
-	  InjectPacketDeferred (a,
379
-				DHCPMSG_BUF (pkt),
380
-				DHCPMSG_LEN_FULL (pkt));
381
-	}
382
-      else
383
-	{
384
-	  DEBUGP (("[TAP] SendDHCPMsg: DHCP buffer overflow\n"));
385
-	}
386
-
387
-      MemFree (pkt, sizeof (DHCPMsg));
388
-    }
389
-}
390
-
391
-//===================================================================
392
-// Handle a BOOTPS packet produced by the local system to
393
-// resolve the address/netmask of this adapter.
394
-// If we are in TAP_IOCTL_CONFIG_DHCP_MASQ mode, reply
395
-// to the message.  Return TRUE if we processed the passed
396
-// message, so that downstream stages can ignore it.
397
-//===================================================================
398
-
399
-BOOLEAN
400
-ProcessDHCP (TapAdapterPointer p_Adapter,
401
-	     const ETH_HEADER *eth,
402
-	     const IPHDR *ip,
403
-	     const UDPHDR *udp,
404
-	     const DHCP *dhcp,
405
-	     int optlen)
406
-{
407
-  int msg_type;
408
-
409
-  // Sanity check IP header
410
-  if (!(ntohs (ip->tot_len) == sizeof (IPHDR) + sizeof (UDPHDR) + sizeof (DHCP) + optlen
411
-	&& (ntohs (ip->frag_off) & IP_OFFMASK) == 0))
412
-    return TRUE;
413
-
414
-  // Does this message belong to us?
415
-  if (!DHCPMessageOurs (p_Adapter, eth, ip, udp, dhcp))
416
-    return FALSE;
417
-
418
-  msg_type = GetDHCPMessageType (dhcp, optlen);
419
-
420
-  // Drop non-BOOTREQUEST messages
421
-  if (dhcp->op != BOOTREQUEST)
422
-    return TRUE;
423
-
424
-  // Drop any messages except DHCPDISCOVER or DHCPREQUEST
425
-  if (!(msg_type == DHCPDISCOVER || msg_type == DHCPREQUEST))
426
-    return TRUE;
427
-
428
-  // Should we reply with DHCPOFFER, DHCPACK, or DHCPNAK?
429
-  if (msg_type == DHCPREQUEST
430
-      && ((dhcp->ciaddr && dhcp->ciaddr != p_Adapter->m_dhcp_addr)
431
-	  || !p_Adapter->m_dhcp_received_discover
432
-	  || p_Adapter->m_dhcp_bad_requests >= BAD_DHCPREQUEST_NAK_THRESHOLD))
433
-    SendDHCPMsg (p_Adapter,
434
-		 DHCPNAK,
435
-		 eth, ip, udp, dhcp);
436
-  else
437
-    SendDHCPMsg (p_Adapter,
438
-		 (msg_type == DHCPDISCOVER ? DHCPOFFER : DHCPACK),
439
-		 eth, ip, udp, dhcp);
440
-
441
-  // Remember if we received a DHCPDISCOVER
442
-  if (msg_type == DHCPDISCOVER)
443
-    p_Adapter->m_dhcp_received_discover = TRUE;
444
-
445
-  // Is this a bad DHCPREQUEST?
446
-  if (msg_type == DHCPREQUEST && dhcp->ciaddr != p_Adapter->m_dhcp_addr)
447
-    ++p_Adapter->m_dhcp_bad_requests;
448
-
449
-  return TRUE;
450
-}
451
-
452
-#if DBG
453
-
454
-const char *
455
-message_op_text (int op)
456
-{
457
-  switch (op)
458
-    {
459
-    case BOOTREQUEST:
460
-      return "BOOTREQUEST";
461
-    case BOOTREPLY:
462
-      return "BOOTREPLY";
463
-    default:
464
-      return "???";
465
-    }
466
-}
467
-
468
-const char *
469
-message_type_text (int type)
470
-{
471
-  switch (type)
472
-    {
473
-    case DHCPDISCOVER:
474
-      return "DHCPDISCOVER";
475
-    case DHCPOFFER:
476
-      return "DHCPOFFER";
477
-    case DHCPREQUEST:
478
-      return "DHCPREQUEST";
479
-    case DHCPDECLINE:
480
-      return "DHCPDECLINE";
481
-    case DHCPACK:
482
-      return "DHCPACK";
483
-    case DHCPNAK:
484
-      return "DHCPNAK";
485
-    case DHCPRELEASE:
486
-      return "DHCPRELEASE";
487
-    case DHCPINFORM:
488
-      return "DHCPINFORM";
489
-    default:
490
-      return "???";
491
-    }
492
-}
493
-
494
-const char *
495
-port_name (int port)
496
-{
497
-  switch (port)
498
-    {
499
-    case BOOTPS_PORT:
500
-      return "BOOTPS";
501
-    case BOOTPC_PORT:
502
-      return "BOOTPC";
503
-    default:
504
-      return "unknown";
505
-    }
506
-}
507
-
508
-VOID
509
-DumpDHCP (const ETH_HEADER *eth,
510
-	  const IPHDR *ip,
511
-	  const UDPHDR *udp,
512
-	  const DHCP *dhcp,
513
-	  const int optlen)
514
-{
515
-  DEBUGP ((" %s", message_op_text (dhcp->op)));
516
-  DEBUGP ((" %s ", message_type_text (GetDHCPMessageType (dhcp, optlen))));
517
-  PrIP (ip->saddr);
518
-  DEBUGP ((":%s[", port_name (ntohs (udp->source))));
519
-  PrMac (eth->src);
520
-  DEBUGP (("] -> "));
521
-  PrIP (ip->daddr);
522
-  DEBUGP ((":%s[", port_name (ntohs (udp->dest))));
523
-  PrMac (eth->dest);
524
-  DEBUGP (("]"));
525
-  if (dhcp->ciaddr)
526
-    {
527
-      DEBUGP ((" ci="));
528
-      PrIP (dhcp->ciaddr);
529
-    }
530
-  if (dhcp->yiaddr)
531
-    {
532
-      DEBUGP ((" yi="));
533
-      PrIP (dhcp->yiaddr);
534
-    }
535
-  if (dhcp->siaddr)
536
-    {
537
-      DEBUGP ((" si="));
538
-      PrIP (dhcp->siaddr);
539
-    }
540
-  if (dhcp->hlen == sizeof (MACADDR))
541
-    {
542
-      DEBUGP ((" ch="));
543
-      PrMac (dhcp->chaddr);
544
-    }
545
-
546
-  DEBUGP ((" xid=0x%08x", ntohl (dhcp->xid)));
547
-
548
-  if (ntohl (dhcp->magic) != 0x63825363)
549
-    DEBUGP ((" ma=0x%08x", ntohl (dhcp->magic)));
550
-  if (dhcp->htype != 1)
551
-    DEBUGP ((" htype=%d", dhcp->htype));
552
-  if (dhcp->hops)
553
-    DEBUGP ((" hops=%d", dhcp->hops));
554
-  if (ntohs (dhcp->secs))
555
-    DEBUGP ((" secs=%d", ntohs (dhcp->secs)));
556
-  if (ntohs (dhcp->flags))
557
-    DEBUGP ((" flags=0x%04x", ntohs (dhcp->flags)));
558
-
559
-  // extra stuff
560
-  
561
-  if (ip->version_len != 0x45)
562
-    DEBUGP ((" vl=0x%02x", ip->version_len));
563
-  if (ntohs (ip->tot_len) != sizeof (IPHDR) + sizeof (UDPHDR) + sizeof (DHCP) + optlen)
564
-    DEBUGP ((" tl=%d", ntohs (ip->tot_len)));
565
-  if (ntohs (udp->len) != sizeof (UDPHDR) + sizeof (DHCP) + optlen)
566
-    DEBUGP ((" ul=%d", ntohs (udp->len)));
567
-
568
-  if (ip->tos)
569
-    DEBUGP ((" tos=0x%02x", ip->tos));
570
-  if (ntohs (ip->id))
571
-    DEBUGP ((" id=0x%04x", ntohs (ip->id)));
572
-  if (ntohs (ip->frag_off))
573
-    DEBUGP ((" frag_off=0x%04x", ntohs (ip->frag_off)));
574
-  
575
-  DEBUGP ((" ttl=%d", ip->ttl));
576
-  DEBUGP ((" ic=0x%04x [0x%04x]", ntohs (ip->check),
577
-	    ip_checksum ((UCHAR*)ip, sizeof (IPHDR))));
578
-  DEBUGP ((" uc=0x%04x [0x%04x/%d]", ntohs (udp->check),
579
-	    udp_checksum ((UCHAR *) udp,
580
-			  sizeof (UDPHDR) + sizeof (DHCP) + optlen,
581
-			  (UCHAR *) &ip->saddr,
582
-			  (UCHAR *) &ip->daddr),
583
-	    optlen));
584
-
585
-  // Options
586
-  {
587
-    const UCHAR *opt = (UCHAR *) (dhcp + 1);
588
-    int i;
589
-
590
-    DEBUGP ((" OPT"));
591
-    for (i = 0; i < optlen; ++i)
592
-      {
593
-	const UCHAR data = opt[i];
594
-	DEBUGP ((".%d", data));
595
-      }
596
-  }
597
-}
598
-
599
-#endif /* DBG */
600 1
deleted file mode 100755
... ...
@@ -1,164 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-#pragma pack(1)
26
-
27
-//===================================================
28
-// How many bad DHCPREQUESTs do we receive before we
29
-// return a NAK?
30
-//
31
-// A bad DHCPREQUEST is defined to be one where the
32
-// requestor doesn't know its IP address.
33
-//===================================================
34
-
35
-#define BAD_DHCPREQUEST_NAK_THRESHOLD 3
36
-
37
-//==============================================
38
-// Maximum number of DHCP options bytes supplied
39
-//==============================================
40
-
41
-#define DHCP_USER_SUPPLIED_OPTIONS_BUFFER_SIZE 256
42
-#define DHCP_OPTIONS_BUFFER_SIZE               256
43
-
44
-//===================================
45
-// UDP port numbers of DHCP messages.
46
-//===================================
47
-
48
-#define BOOTPS_PORT 67
49
-#define BOOTPC_PORT 68
50
-
51
-//===========================
52
-// The DHCP message structure
53
-//===========================
54
-
55
-typedef struct {
56
-# define BOOTREQUEST 1
57
-# define BOOTREPLY   2
58
-  UCHAR op;          /* message op */
59
-
60
-  UCHAR  htype;      /* hardware address type (e.g. '1' = 10Mb Ethernet) */
61
-  UCHAR  hlen;       /* hardware address length (e.g. '6' for 10Mb Ethernet) */
62
-  UCHAR  hops;       /* client sets to 0, may be used by relay agents */
63
-  ULONG  xid;        /* transaction ID, chosen by client */
64
-  USHORT secs;       /* seconds since request process began, set by client */
65
-  USHORT flags;
66
-  ULONG  ciaddr;     /* client IP address, client sets if known */
67
-  ULONG  yiaddr;     /* 'your' IP address -- server's response to client */
68
-  ULONG  siaddr;     /* server IP address */
69
-  ULONG  giaddr;     /* relay agent IP address */
70
-  UCHAR  chaddr[16]; /* client hardware address */
71
-  UCHAR  sname[64];  /* optional server host name */
72
-  UCHAR  file[128];  /* boot file name */
73
-  ULONG  magic;      /* must be 0x63825363 (network order) */
74
-} DHCP;
75
-
76
-typedef struct {
77
-  ETH_HEADER eth;
78
-  IPHDR ip;
79
-  UDPHDR udp;
80
-  DHCP dhcp;
81
-} DHCPPre;
82
-
83
-typedef struct {
84
-  DHCPPre pre;
85
-  UCHAR options[DHCP_OPTIONS_BUFFER_SIZE];
86
-} DHCPFull;
87
-
88
-typedef struct {
89
-  unsigned int optlen;
90
-  BOOLEAN overflow;
91
-  DHCPFull msg;
92
-} DHCPMsg;
93
-
94
-//===================
95
-// Macros for DHCPMSG
96
-//===================
97
-
98
-#define DHCPMSG_LEN_BASE(p) (sizeof (DHCPPre))
99
-#define DHCPMSG_LEN_OPT(p)  ((p)->optlen)
100
-#define DHCPMSG_LEN_FULL(p) (DHCPMSG_LEN_BASE(p) + DHCPMSG_LEN_OPT(p))
101
-#define DHCPMSG_BUF(p)      ((UCHAR*) &(p)->msg)
102
-#define DHCPMSG_OVERFLOW(p) ((p)->overflow)
103
-
104
-//========================================
105
-// structs to hold individual DHCP options
106
-//========================================
107
-
108
-typedef struct {
109
-  UCHAR type;
110
-} DHCPOPT0;
111
-
112
-typedef struct {
113
-  UCHAR type;
114
-  UCHAR len;
115
-  UCHAR data;
116
-} DHCPOPT8;
117
-
118
-typedef struct {
119
-  UCHAR type;
120
-  UCHAR len;
121
-  ULONG data;
122
-} DHCPOPT32;
123
-
124
-#pragma pack()
125
-
126
-//==================
127
-// DHCP Option types
128
-//==================
129
-
130
-#define DHCP_MSG_TYPE    53  /* message type (u8) */
131
-#define DHCP_PARM_REQ    55  /* parameter request list: c1 (u8), ... */
132
-#define DHCP_CLIENT_ID   61  /* client ID: type (u8), i1 (u8), ... */
133
-#define DHCP_IP          50  /* requested IP addr (u32) */
134
-#define DHCP_NETMASK      1  /* subnet mask (u32) */
135
-#define DHCP_LEASE_TIME  51  /* lease time sec (u32) */
136
-#define DHCP_RENEW_TIME  58  /* renewal time sec (u32) */
137
-#define DHCP_REBIND_TIME 59  /* rebind time sec (u32) */
138
-#define DHCP_SERVER_ID   54  /* server ID: IP addr (u32) */
139
-#define DHCP_PAD          0
140
-#define DHCP_END        255
141
-
142
-//====================
143
-// DHCP Messages types
144
-//====================
145
-
146
-#define DHCPDISCOVER 1
147
-#define DHCPOFFER    2
148
-#define DHCPREQUEST  3
149
-#define DHCPDECLINE  4
150
-#define DHCPACK      5
151
-#define DHCPNAK      6
152
-#define DHCPRELEASE  7
153
-#define DHCPINFORM   8
154
-
155
-#if DBG
156
-
157
-VOID
158
-DumpDHCP (const ETH_HEADER *eth,
159
-	  const IPHDR *ip,
160
-	  const UDPHDR *udp,
161
-	  const DHCP *dhcp,
162
-	  const int optlen);
163
-
164
-#endif
165 1
deleted file mode 100755
... ...
@@ -1,35 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-#ifdef TAP_LITTLE_ENDIAN
26
-#define ntohs(x) RtlUshortByteSwap(x)
27
-#define htons(x) RtlUshortByteSwap(x)
28
-#define ntohl(x) RtlUlongByteSwap(x)
29
-#define htonl(x) RtlUlongByteSwap(x)
30
-#else
31
-#define ntohs(x) ((USHORT)(x))
32
-#define htons(x) ((USHORT)(x))
33
-#define ntohl(x) ((ULONG)(x))
34
-#define htonl(x) ((ULONG)(x))
35
-#endif
36 1
deleted file mode 100755
... ...
@@ -1,378 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-//-----------------
26
-// DEBUGGING OUTPUT
27
-//-----------------
28
-
29
-const char *g_LastErrorFilename;
30
-int g_LastErrorLineNumber;
31
-
32
-#if DBG
33
-
34
-DebugOutput g_Debug;
35
-
36
-BOOLEAN
37
-NewlineExists (const char *str, int len)
38
-{
39
-  while (len-- > 0)
40
-    {
41
-      const char c = *str++;
42
-      if (c == '\n')
43
-	return TRUE;
44
-      else if (c == '\0')
45
-	break;
46
-    }
47
-  return FALSE;
48
-}
49
-
50
-VOID
51
-MyDebugInit (unsigned int bufsiz)
52
-{
53
-  NdisZeroMemory (&g_Debug, sizeof (g_Debug));
54
-  g_Debug.text = (char *) MemAlloc (bufsiz, FALSE);
55
-  if (g_Debug.text)
56
-    g_Debug.capacity = bufsiz;
57
-}
58
-
59
-VOID
60
-MyDebugFree ()
61
-{
62
-  if (g_Debug.text)
63
-    MemFree (g_Debug.text, g_Debug.capacity);
64
-  NdisZeroMemory (&g_Debug, sizeof (g_Debug));
65
-}
66
-
67
-VOID
68
-MyDebugPrint (const unsigned char* format, ...)
69
-{
70
-  if (g_Debug.text && g_Debug.capacity > 0 && CAN_WE_PRINT)
71
-    {
72
-      BOOLEAN owned;
73
-      ACQUIRE_MUTEX_ADAPTIVE (&g_Debug.lock, owned);
74
-      if (owned)
75
-	{
76
-	  const int remaining = (int)g_Debug.capacity - (int)g_Debug.out;
77
-
78
-	  if (remaining > 0)
79
-	    {
80
-	      va_list args;
81
-	      NTSTATUS status;
82
-	      char *end;
83
-
84
-	      va_start (args, format);
85
-	      status = RtlStringCchVPrintfExA (g_Debug.text + g_Debug.out,
86
-					       remaining,
87
-					       &end,
88
-					       NULL,
89
-					       STRSAFE_NO_TRUNCATION | STRSAFE_IGNORE_NULLS,
90
-					       format,
91
-					       args);
92
-	      va_end (args);
93
-
94
-	      if (status == STATUS_SUCCESS)
95
-		g_Debug.out = (unsigned int) (end - g_Debug.text);
96
-	      else
97
-		g_Debug.error = TRUE;
98
-	    }
99
-	  else
100
-	    g_Debug.error = TRUE;
101
-
102
-	  RELEASE_MUTEX (&g_Debug.lock);
103
-	}
104
-      else
105
-	g_Debug.error = TRUE;
106
-    }
107
-}
108
-
109
-BOOLEAN
110
-GetDebugLine (char *buf, const int len)
111
-{
112
-  static const char *truncated = "[OUTPUT TRUNCATED]\n";
113
-  BOOLEAN ret = FALSE;
114
-
115
-  NdisZeroMemory (buf, len);
116
-
117
-  if (g_Debug.text && g_Debug.capacity > 0)
118
-    {
119
-      BOOLEAN owned;
120
-      ACQUIRE_MUTEX_ADAPTIVE (&g_Debug.lock, owned);
121
-      if (owned)
122
-	{
123
-	  int i = 0;
124
-
125
-	  if (g_Debug.error || NewlineExists (g_Debug.text + g_Debug.in, (int)g_Debug.out - (int)g_Debug.in))
126
-	    {
127
-	      while (i < (len - 1) && g_Debug.in < g_Debug.out)
128
-		{
129
-		  const char c = g_Debug.text[g_Debug.in++];
130
-		  if (c == '\n')
131
-		    break;
132
-		  buf[i++] = c;
133
-		}
134
-	      if (i < len)
135
-		buf[i] = '\0';
136
-	    }
137
-
138
-	  if (!i)
139
-	    {
140
-	      if (g_Debug.in == g_Debug.out)
141
-		{
142
-		  g_Debug.in = g_Debug.out = 0;
143
-		  if (g_Debug.error)
144
-		    {
145
-		      const unsigned int tlen = strlen (truncated);
146
-		      if (tlen < g_Debug.capacity)
147
-			{
148
-			  NdisMoveMemory (g_Debug.text, truncated, tlen+1);
149
-			  g_Debug.out = tlen;
150
-			}
151
-		      g_Debug.error = FALSE;
152
-		    }
153
-		}
154
-	    }
155
-	  else
156
-	    ret = TRUE;
157
-
158
-	  RELEASE_MUTEX (&g_Debug.lock);
159
-	}      
160
-    }
161
-  return ret;
162
-}
163
-
164
-VOID
165
-MyAssert (const unsigned char *file, int line)
166
-{
167
-      DEBUGP (("MYASSERT failed %s/%d\n", file, line));
168
-      KeBugCheckEx (0x0F00BABA,
169
-		    (ULONG_PTR) line,
170
-		    (ULONG_PTR) 0,
171
-		    (ULONG_PTR) 0,
172
-		    (ULONG_PTR) 0);
173
-}
174
-
175
-VOID
176
-PrMac (const MACADDR mac)
177
-{
178
-  DEBUGP (("%x:%x:%x:%x:%x:%x",
179
-	    mac[0], mac[1], mac[2],
180
-	    mac[3], mac[4], mac[5]));
181
-}
182
-
183
-VOID
184
-PrIP (IPADDR ip_addr)
185
-{
186
-  const unsigned char *ip = (const unsigned char *) &ip_addr;
187
-
188
-  DEBUGP (("%d.%d.%d.%d",
189
-	    ip[0], ip[1], ip[2], ip[3]));
190
-}
191
-
192
-const char *
193
-PrIPProto (int proto)
194
-{
195
-  switch (proto)
196
-    {
197
-    case IPPROTO_UDP:
198
-      return "UDP";
199
-    case IPPROTO_TCP:
200
-      return "TCP";
201
-    case IPPROTO_ICMP:
202
-      return "ICMP";
203
-    case IPPROTO_IGMP:
204
-      return "IGMP";
205
-    default:
206
-      return "???";
207
-    }
208
-}
209
-
210
-VOID
211
-DumpARP (const char *prefix, const ARP_PACKET *arp)
212
-{
213
-  DEBUGP (("%s ARP src=", prefix));
214
-  PrMac (arp->m_MAC_Source);
215
-  DEBUGP ((" dest="));
216
-  PrMac (arp->m_MAC_Destination);
217
-  DEBUGP ((" OP=0x%04x",
218
-	    (int)ntohs(arp->m_ARP_Operation)));
219
-  DEBUGP ((" M=0x%04x(%d)",
220
-	    (int)ntohs(arp->m_MAC_AddressType),
221
-	    (int)arp->m_MAC_AddressSize));
222
-  DEBUGP ((" P=0x%04x(%d)",
223
-	    (int)ntohs(arp->m_PROTO_AddressType),
224
-	    (int)arp->m_PROTO_AddressSize));
225
-
226
-  DEBUGP ((" MacSrc="));
227
-  PrMac (arp->m_ARP_MAC_Source);
228
-  DEBUGP ((" MacDest="));
229
-  PrMac (arp->m_ARP_MAC_Destination);
230
-
231
-  DEBUGP ((" IPSrc="));
232
-  PrIP (arp->m_ARP_IP_Source);
233
-  DEBUGP ((" IPDest="));
234
-  PrIP (arp->m_ARP_IP_Destination);
235
-
236
-  DEBUGP (("\n"));
237
-}
238
-
239
-struct ethpayload {
240
-  ETH_HEADER eth;
241
-  UCHAR payload[DEFAULT_PACKET_LOOKAHEAD];
242
-};
243
-
244
-VOID
245
-DumpPacket2 (const char *prefix,
246
-	     const ETH_HEADER *eth,
247
-	     const unsigned char *data,
248
-	     unsigned int len)
249
-{
250
-  struct ethpayload *ep = (struct ethpayload *) MemAlloc (sizeof (struct ethpayload), TRUE);
251
-  if (ep)
252
-    {
253
-      if (len > DEFAULT_PACKET_LOOKAHEAD)
254
-	len = DEFAULT_PACKET_LOOKAHEAD;
255
-      ep->eth = *eth;
256
-      NdisMoveMemory (ep->payload, data, len);
257
-      DumpPacket (prefix, (unsigned char *) ep, sizeof (ETH_HEADER) + len);
258
-      MemFree (ep, sizeof (struct ethpayload));
259
-    }
260
-}
261
-
262
-VOID
263
-DumpPacket (const char *prefix,
264
-	    const unsigned char *data,
265
-	    unsigned int len)
266
-{
267
-  const ETH_HEADER *eth = (const ETH_HEADER *) data;
268
-  const IPHDR *ip = (const IPHDR *) (data + sizeof (ETH_HEADER));
269
-
270
-  if (len < sizeof (ETH_HEADER))
271
-    {
272
-      DEBUGP (("%s TRUNCATED PACKET LEN=%d\n", prefix, len));
273
-      return;
274
-    }
275
-
276
-  // ARP Packet?
277
-  if (len >= sizeof (ARP_PACKET) && eth->proto == htons (ETH_P_ARP))
278
-    {
279
-      DumpARP (prefix, (const ARP_PACKET *) data);
280
-      return;
281
-    }
282
-
283
-  // IPv4 packet?
284
-  if (len >= (sizeof (IPHDR) + sizeof (ETH_HEADER))
285
-      && eth->proto == htons (ETH_P_IP)
286
-      && IPH_GET_VER (ip->version_len) == 4)
287
-    {
288
-      const int hlen = IPH_GET_LEN (ip->version_len);
289
-      const int blen = len - sizeof (ETH_HEADER);
290
-      BOOLEAN did = FALSE;
291
-
292
-      DEBUGP (("%s IPv4 %s[%d]", prefix, PrIPProto (ip->protocol), len));
293
-
294
-      if (!(ntohs (ip->tot_len) == blen && hlen <= blen))
295
-	{
296
-	  DEBUGP ((" XXX"));
297
-	  return;
298
-	}
299
-      
300
-      // TCP packet?
301
-      if (ip->protocol == IPPROTO_TCP
302
-	  && blen - hlen >= (sizeof (TCPHDR)))
303
-	{
304
-	  const TCPHDR *tcp = (TCPHDR *) (data + sizeof (ETH_HEADER) + hlen);
305
-	  DEBUGP ((" "));
306
-	  PrIP (ip->saddr);
307
-	  DEBUGP ((":%d", ntohs (tcp->source)));
308
-	  DEBUGP ((" -> "));
309
-	  PrIP (ip->daddr);
310
-	  DEBUGP ((":%d", ntohs (tcp->dest)));
311
-	  did = TRUE;
312
-	}
313
-
314
-      // UDP packet?
315
-      else if ((ntohs (ip->frag_off) & IP_OFFMASK) == 0
316
-	       && ip->protocol == IPPROTO_UDP
317
-	       && blen - hlen >= (sizeof (UDPHDR)))
318
-	{
319
-	  const UDPHDR *udp = (UDPHDR *) (data + sizeof (ETH_HEADER) + hlen);
320
-	  
321
-	  // DHCP packet?
322
-	  if ((udp->dest == htons (BOOTPC_PORT) || udp->dest == htons (BOOTPS_PORT))
323
-	      && blen - hlen >= (sizeof (UDPHDR) + sizeof (DHCP)))
324
-	    {
325
-	      const DHCP *dhcp = (DHCP *) (data
326
-					   + hlen
327
-					   + sizeof (ETH_HEADER)
328
-					   + sizeof (UDPHDR));
329
-	      
330
-	      int optlen = len
331
-		- sizeof (ETH_HEADER)
332
-		- hlen
333
-		- sizeof (UDPHDR)
334
-		- sizeof (DHCP);
335
-
336
-	      if (optlen < 0)
337
-		optlen = 0;
338
-
339
-	      DumpDHCP (eth, ip, udp, dhcp, optlen);
340
-	      did = TRUE;
341
-	    }
342
-
343
-	  if (!did)
344
-	    {
345
-	      DEBUGP ((" "));
346
-	      PrIP (ip->saddr);
347
-	      DEBUGP ((":%d", ntohs (udp->source)));
348
-	      DEBUGP ((" -> "));
349
-	      PrIP (ip->daddr);
350
-	      DEBUGP ((":%d", ntohs (udp->dest)));
351
-	      did = TRUE;
352
-	    }
353
-	}
354
-
355
-      if (!did)
356
-	{
357
-	  DEBUGP ((" ipproto=%d ", ip->protocol));
358
-	  PrIP (ip->saddr);
359
-	  DEBUGP ((" -> "));
360
-	  PrIP (ip->daddr);
361
-	}
362
-
363
-      DEBUGP (("\n"));
364
-      return;
365
-    }
366
-
367
-  {
368
-    DEBUGP (("%s ??? src=", prefix));
369
-    PrMac (eth->src);
370
-    DEBUGP ((" dest="));
371
-    PrMac (eth->dest);
372
-    DEBUGP ((" proto=0x%04x len=%d\n",
373
-	      (int) ntohs(eth->proto),
374
-	      len));
375
-  }
376
-}
377
-
378
-#endif
379 1
deleted file mode 100755
... ...
@@ -1,88 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-//-----------------
26
-// DEBUGGING OUTPUT
27
-//-----------------
28
-
29
-#define NOTE_ERROR() \
30
-{ \
31
-  g_LastErrorFilename = __FILE__; \
32
-  g_LastErrorLineNumber = __LINE__; \
33
-}
34
-
35
-#if DBG
36
-
37
-typedef struct {
38
-  unsigned int in;
39
-  unsigned int out;
40
-  unsigned int capacity;
41
-  char *text;
42
-  BOOLEAN error;
43
-  MUTEX lock;
44
-} DebugOutput;
45
-
46
-VOID MyDebugPrint (const unsigned char* format, ...);
47
-
48
-VOID MyAssert (const unsigned char *file, int line);
49
-
50
-VOID DumpPacket (const char *prefix,
51
-		 const unsigned char *data,
52
-		 unsigned int len);
53
-
54
-VOID DumpPacket2 (const char *prefix,
55
-		  const ETH_HEADER *eth,
56
-		  const unsigned char *data,
57
-		  unsigned int len);
58
-
59
-#define CAN_WE_PRINT (DEBUGP_AT_DISPATCH || KeGetCurrentIrql () < DISPATCH_LEVEL)
60
-
61
-#if ALSO_DBGPRINT
62
-#define DEBUGP(fmt) { MyDebugPrint fmt; if (CAN_WE_PRINT) DbgPrint fmt; }
63
-#else
64
-#define DEBUGP(fmt) { MyDebugPrint fmt; }
65
-#endif
66
-
67
-#define MYASSERT(exp) \
68
-{ \
69
-  if (!(exp)) \
70
-    { \
71
-      MyAssert(__FILE__, __LINE__); \
72
-    } \
73
-}
74
-
75
-#define DUMP_PACKET(prefix, data, len) \
76
-  DumpPacket (prefix, data, len)
77
-
78
-#define DUMP_PACKET2(prefix, eth, data, len) \
79
-  DumpPacket2 (prefix, eth, data, len)
80
-
81
-#else 
82
-
83
-#define DEBUGP(fmt)
84
-#define MYASSERT(exp)
85
-#define DUMP_PACKET(prefix, data, len)
86
-#define DUMP_PACKET2(prefix, eth, data, len)
87
-
88
-#endif
89 1
deleted file mode 100755
... ...
@@ -1,69 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-#ifdef __cplusplus
26
-extern "C" {
27
-#endif
28
-
29
-#include "hexdump.h"
30
-
31
-#ifndef NDIS_MINIPORT_DRIVER
32
-
33
-VOID (*DbgMessage)(char *p_Format, ...) = DisplayDebugString;
34
-
35
-VOID DisplayDebugString (char *p_Format, ...)
36
-   {
37
-    static char l_Buffer [4096];
38
-
39
-    va_list l_ArgumentList; 
40
-    va_start (l_ArgumentList, p_Format); 
41
-    vsprintf (l_Buffer, p_Format, l_ArgumentList); 
42
-    va_end (l_ArgumentList); 
43
-
44
-    OutputDebugStringA (l_Buffer);
45
-   }
46
-
47
-#endif
48
-
49
-VOID HexDump (unsigned char *p_Buffer, unsigned long p_Size)
50
-   {
51
-    unsigned long l_Index, l_Idx;
52
-    unsigned char l_Row [17];
53
-
54
-    for (l_Index = l_Row [16] = 0; l_Index < p_Size || l_Index % 16; ++l_Index)
55
-       {
56
-        if (l_Index % 16 == 0)
57
-	  DEBUGP (("%05x   ", l_Index));
58
-        DEBUGP (("%02x ", l_Row [l_Index % 16] = (l_Index < p_Size ? p_Buffer [l_Index] : 0)));
59
-        l_Row [l_Index % 16] = IfPrint (l_Row [l_Index % 16]);
60
-        if ((l_Index + 1) % 16 == 0)
61
-	  DEBUGP (("   %s\n", l_Row));
62
-       }
63
-
64
-    DEBUGP (("\n"));
65
-   }
66
-
67
-#ifdef __cplusplus
68
-}
69
-#endif
70 1
deleted file mode 100755
... ...
@@ -1,63 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-#ifndef HEXDUMP_DEFINED
26
-#define HEXDUMP_DEFINED
27
-
28
-#ifdef __cplusplus
29
-extern "C" {
30
-#endif
31
-
32
-//=====================================================================================
33
-//                                   Debug Routines
34
-//=====================================================================================
35
-
36
-#ifndef NDIS_MINIPORT_DRIVER
37
-#   include <stdio.h>
38
-#   include <ctype.h>
39
-#   include <windows.h>
40
-#   include <winnt.h>
41
-#   include <memory.h>
42
-
43
-#   ifndef DEBUGP
44
-#      define DEBUGP(fmt) { DbgMessage fmt; }
45
-#   endif
46
-
47
-    extern VOID (*DbgMessage)(char *p_Format, ...);
48
-
49
-    VOID DisplayDebugString (char *p_Format, ...);
50
-#endif
51
-
52
-//===================================================================================
53
-//                              Reporting / Debugging
54
-//===================================================================================
55
-#define IfPrint(c) (c >= 32 && c < 127 ? c : '.')
56
-
57
-VOID HexDump (unsigned char *p_Buffer, unsigned long p_Size);
58
-
59
-#ifdef __cplusplus
60
-}
61
-#endif
62
-
63
-#endif
64 1
deleted file mode 100755
... ...
@@ -1,195 +0,0 @@
1
-; ****************************************************************************
2
-; * Copyright (C) 2002-2010 OpenVPN Technologies, Inc.                            *
3
-; *  This program is free software; you can redistribute it and/or modify    *
4
-; *  it under the terms of the GNU General Public License version 2          *
5
-; *  as published by the Free Software Foundation.                           *
6
-; ****************************************************************************
7
-
8
-; SYNTAX CHECKER
9
-; cd \WINDDK\3790\tools\chkinf
10
-; chkinf c:\src\openvpn\tap-win32\i386\oemwin2k.inf
11
-; OUTPUT -> file:///c:/WINDDK/3790/tools/chkinf/htm/c%23+src+openvpn+tap-win32+i386+__OemWin2k.htm
12
-
13
-; INSTALL/REMOVE DRIVER
14
-;   tapinstall install OemWin2k.inf TAP0901
15
-;   tapinstall update OemWin2k.inf TAP0901
16
-;   tapinstall remove TAP0901
17
-
18
-;*********************************************************
19
-; Note to Developers:
20
-;
21
-; If you are bundling the TAP-Win32 driver with your app,
22
-; you should try to rename it in such a way that it will
23
-; not collide with other instances of TAP-Win32 defined
24
-; by other apps.  Multiple versions of the TAP-Win32
25
-; driver, each installed by different apps, can coexist
26
-; on the same machine if you follow these guidelines.
27
-; NOTE: these instructions assume you are editing the
28
-; generated OemWin2k.inf file, not the source
29
-; OemWin2k.inf.in file which is preprocessed by winconfig
30
-; and uses macro definitions from settings.in.
31
-;
32
-; (1) Rename all tapXXXX instances in this file to
33
-;     something different (use at least 5 characters
34
-;     for this name!)
35
-; (2) Change the "!define TAP" definition in openvpn.nsi
36
-;     to match what you changed tapXXXX to.
37
-; (3) Change TARGETNAME in SOURCES to match what you
38
-;     changed tapXXXX to.
39
-; (4) Change TAP_COMPONENT_ID in common.h to match what
40
-;     you changed tapXXXX to.
41
-; (5) Change SZDEPENDENCIES in service.h to match what
42
-;     you changed tapXXXX to.
43
-; (6) Change DeviceDescription and Provider strings.
44
-; (7) Change PRODUCT_STRING in constants.h to what you
45
-;     set DeviceDescription to.
46
-;
47
-;*********************************************************
48
-
49
-[Version]
50
-   Signature = "$Windows NT$"
51
-   CatalogFile = @@PRODUCT_TAP_ID@@.cat
52
-   ClassGUID = {4d36e972-e325-11ce-bfc1-08002be10318}
53
-   Provider = %Provider%
54
-   Class = Net
55
-
56
-; This version number should match the version
57
-; number given in SOURCES.
58
-   DriverVer=@@PRODUCT_TAP_RELDATE@@,@@PRODUCT_TAP_MAJOR_VER@@.00.00.@@PRODUCT_TAP_MINOR_VER@@
59
-
60
-[Strings]
61
-   DeviceDescription = "@@PRODUCT_TAP_DEVICE_DESCRIPTION@@"
62
-   Provider = "@@PRODUCT_TAP_PROVIDER@@"
63
-
64
-;----------------------------------------------------------------
65
-;                      Manufacturer + Product Section (Done)
66
-;----------------------------------------------------------------
67
-[Manufacturer]
68
-!ifdef AMD64
69
-   %Provider% = @@PRODUCT_TAP_ID@@, NTamd64
70
-!else
71
-   %Provider% = @@PRODUCT_TAP_ID@@
72
-!endif
73
-
74
-!ifdef AMD64
75
-[@@PRODUCT_TAP_ID@@.NTamd64]
76
-!else
77
-[@@PRODUCT_TAP_ID@@]
78
-!endif
79
-   %DeviceDescription% = @@PRODUCT_TAP_ID@@.ndi, @@PRODUCT_TAP_ID@@
80
-
81
-;---------------------------------------------------------------
82
-;                             Driver Section (Done)
83
-;---------------------------------------------------------------
84
-
85
-;----------------- Characteristics ------------
86
-;    NCF_PHYSICAL = 0x04
87
-;    NCF_VIRTUAL = 0x01
88
-;    NCF_SOFTWARE_ENUMERATED = 0x02
89
-;    NCF_HIDDEN = 0x08
90
-;    NCF_NO_SERVICE = 0x10
91
-;    NCF_HAS_UI = 0x80
92
-;----------------- Characteristics ------------
93
-
94
-[@@PRODUCT_TAP_ID@@.ndi]
95
-   CopyFiles       = @@PRODUCT_TAP_ID@@.driver, @@PRODUCT_TAP_ID@@.files
96
-   AddReg          = @@PRODUCT_TAP_ID@@.reg
97
-   AddReg          = @@PRODUCT_TAP_ID@@.params.reg
98
-   Characteristics = @@PRODUCT_TAP_CHARACTERISTICS@@
99
-
100
-[@@PRODUCT_TAP_ID@@.ndi.Services]
101
-   AddService = @@PRODUCT_TAP_ID@@,        2, @@PRODUCT_TAP_ID@@.service
102
-
103
-[@@PRODUCT_TAP_ID@@.reg]
104
-   HKR, Ndi,            Service,      0, "@@PRODUCT_TAP_ID@@"
105
-   HKR, Ndi\Interfaces, UpperRange,   0, "ndis5"
106
-   HKR, Ndi\Interfaces, LowerRange,   0, "ethernet"
107
-   HKR, ,               Manufacturer, 0, "%Provider%"
108
-   HKR, ,               ProductName,  0, "%DeviceDescription%"
109
-
110
-[@@PRODUCT_TAP_ID@@.params.reg]
111
-   HKR, Ndi\params\MTU,                  ParamDesc, 0, "MTU"
112
-   HKR, Ndi\params\MTU,                  Type,      0, "int"
113
-   HKR, Ndi\params\MTU,                  Default,   0, "1500"
114
-   HKR, Ndi\params\MTU,                  Optional,  0, "0"
115
-   HKR, Ndi\params\MTU,                  Min,       0, "100"
116
-   HKR, Ndi\params\MTU,                  Max,       0, "1500"
117
-   HKR, Ndi\params\MTU,                  Step,      0, "1"
118
-   HKR, Ndi\params\MediaStatus,          ParamDesc, 0, "Media Status"
119
-   HKR, Ndi\params\MediaStatus,          Type,      0, "enum"
120
-   HKR, Ndi\params\MediaStatus,          Default,   0, "0"
121
-   HKR, Ndi\params\MediaStatus,          Optional,  0, "0"
122
-   HKR, Ndi\params\MediaStatus\enum,     "0",       0, "Application Controlled"
123
-   HKR, Ndi\params\MediaStatus\enum,     "1",       0, "Always Connected"
124
-   HKR, Ndi\params\MAC,                  ParamDesc, 0, "MAC Address"
125
-   HKR, Ndi\params\MAC,                  Type,      0, "edit"
126
-   HKR, Ndi\params\MAC,                  Optional,  0, "1"
127
-   HKR, Ndi\params\AllowNonAdmin,        ParamDesc, 0, "Non-Admin Access"
128
-   HKR, Ndi\params\AllowNonAdmin,        Type,      0, "enum"
129
-   HKR, Ndi\params\AllowNonAdmin,        Default,   0, "1"
130
-   HKR, Ndi\params\AllowNonAdmin,        Optional,  0, "0"
131
-   HKR, Ndi\params\AllowNonAdmin\enum,   "0",       0, "Not Allowed"
132
-   HKR, Ndi\params\AllowNonAdmin\enum,   "1",       0, "Allowed"
133
-
134
-;----------------------------------------------------------------
135
-;                             Service Section
136
-;----------------------------------------------------------------
137
-
138
-;---------- Service Type -------------
139
-;    SERVICE_KERNEL_DRIVER     = 0x01
140
-;    SERVICE_WIN32_OWN_PROCESS = 0x10
141
-;---------- Service Type -------------
142
-
143
-;---------- Start Mode ---------------
144
-;    SERVICE_BOOT_START   = 0x0
145
-;    SERVICE_SYSTEM_START = 0x1
146
-;    SERVICE_AUTO_START   = 0x2
147
-;    SERVICE_DEMAND_START = 0x3
148
-;    SERVICE_DISABLED     = 0x4
149
-;---------- Start Mode ---------------
150
-
151
-[@@PRODUCT_TAP_ID@@.service]
152
-   DisplayName = %DeviceDescription%
153
-   ServiceType = 1
154
-   StartType = 3
155
-   ErrorControl = 1
156
-   LoadOrderGroup = NDIS
157
-   ServiceBinary = %12%\@@PRODUCT_TAP_ID@@.sys
158
-
159
-;-----------------------------------------------------------------
160
-;                                File Installation
161
-;-----------------------------------------------------------------
162
-
163
-;----------------- Copy Flags ------------
164
-;    COPYFLG_NOSKIP = 0x02
165
-;    COPYFLG_NOVERSIONCHECK = 0x04
166
-;----------------- Copy Flags ------------
167
-
168
-; SourceDisksNames
169
-; diskid = description[, [tagfile] [, <unused>, subdir]]
170
-; 1 = "Intel Driver Disk 1",e100bex.sys,,
171
-
172
-[SourceDisksNames]
173
-   1 = %DeviceDescription%, @@PRODUCT_TAP_ID@@.sys
174
-
175
-; SourceDisksFiles
176
-; filename_on_source = diskID[, [subdir][, size]]
177
-; e100bex.sys = 1,, ; on distribution disk 1
178
-
179
-[SourceDisksFiles]
180
-@@PRODUCT_TAP_ID@@.sys = 1
181
-
182
-[DestinationDirs]
183
-   @@PRODUCT_TAP_ID@@.files  = 11
184
-   @@PRODUCT_TAP_ID@@.driver = 12
185
-
186
-[@@PRODUCT_TAP_ID@@.files]
187
-;   TapPanel.cpl,,,6   ; COPYFLG_NOSKIP | COPYFLG_NOVERSIONCHECK
188
-;   cipsrvr.exe,,,6     ; COPYFLG_NOSKIP | COPYFLG_NOVERSIONCHECK
189
-
190
-[@@PRODUCT_TAP_ID@@.driver]
191
-   @@PRODUCT_TAP_ID@@.sys,,,6     ; COPYFLG_NOSKIP | COPYFLG_NOVERSIONCHECK
192
-
193
-;---------------------------------------------------------------
194
-;                                      End
195
-;---------------------------------------------------------------
196 1
deleted file mode 100755
... ...
@@ -1,241 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-#define INSTANCE_KEY(a) ((PVOID)((a)->m_Extension.m_TapDevice))
26
-
27
-#define N_INSTANCE_BUCKETS 256
28
-
29
-typedef struct _INSTANCE {
30
-  struct _INSTANCE *next;
31
-  TapAdapterPointer m_Adapter;
32
-} INSTANCE;
33
-
34
-typedef struct {
35
-  INSTANCE *list;
36
-  MUTEX lock;
37
-} INSTANCE_BUCKET;
38
-
39
-typedef struct {
40
-  INSTANCE_BUCKET buckets[N_INSTANCE_BUCKETS];
41
-} INSTANCE_HASH;
42
-
43
-INSTANCE_HASH *g_InstanceHash = NULL;
44
-
45
-// must return a hash >= 0 and < N_INSTANCE_BUCKETS
46
-int
47
-InstanceHashValue (PVOID addr)
48
-{
49
-  UCHAR *p = (UCHAR *) &addr;
50
-
51
-  if (sizeof (addr) == 4)
52
-    return p[0] ^ p[1] ^ p[2] ^ p[3];
53
-  else if (sizeof (addr) == 8)
54
-    return p[0] ^ p[1] ^ p[2] ^ p[3] ^ p[4] ^ p[5] ^ p[6] ^ p[7];
55
-  else
56
-    {
57
-      MYASSERT (0);
58
-    }
59
-}
60
-
61
-BOOLEAN
62
-InitInstanceList (VOID)
63
-{
64
-  MYASSERT (g_InstanceHash == NULL);
65
-  g_InstanceHash = MemAlloc (sizeof (INSTANCE_HASH), TRUE);
66
-  if (g_InstanceHash)
67
-    {
68
-      int i;
69
-      for (i = 0; i < N_INSTANCE_BUCKETS; ++i)
70
-	INIT_MUTEX (&g_InstanceHash->buckets[i].lock);
71
-      return TRUE;
72
-    }
73
-  else
74
-    return FALSE;
75
-}
76
-
77
-int
78
-NInstances (VOID)
79
-{
80
-  int i, n = 0;
81
-
82
-  if (g_InstanceHash)
83
-    {
84
-      for (i = 0; i < N_INSTANCE_BUCKETS; ++i)
85
-	{
86
-	  BOOLEAN got_lock;
87
-	  INSTANCE_BUCKET *ib = &g_InstanceHash->buckets[i];
88
-	  ACQUIRE_MUTEX_ADAPTIVE (&ib->lock, got_lock);
89
-
90
-	  if (got_lock)
91
-	    {
92
-	      INSTANCE *current;
93
-	      for (current = ib->list; current != NULL; current = current->next)
94
-		++n;
95
-	      RELEASE_MUTEX (&ib->lock);
96
-	    }
97
-	  else
98
-	    return -1;
99
-	}
100
-    }
101
-
102
-  return n;
103
-}
104
-
105
-int
106
-InstanceMaxBucketSize (VOID)
107
-{
108
-  int i, n = 0;
109
-
110
-  if (g_InstanceHash)
111
-    {
112
-      for (i = 0; i < N_INSTANCE_BUCKETS; ++i)
113
-	{
114
-	  BOOLEAN got_lock;
115
-	  int bucket_size = 0;
116
-	  INSTANCE_BUCKET *ib = &g_InstanceHash->buckets[i];
117
-	  ACQUIRE_MUTEX_ADAPTIVE (&ib->lock, got_lock);
118
-
119
-	  if (got_lock)
120
-	    {
121
-	      INSTANCE *current;
122
-	      for (current = ib->list; current != NULL; current = current->next)
123
-		  ++bucket_size;
124
-	      if (bucket_size > n)
125
-		n = bucket_size;
126
-	      RELEASE_MUTEX (&ib->lock);
127
-	    }
128
-	  else
129
-	    return -1;
130
-	}
131
-    }
132
-
133
-  return n;
134
-}
135
-
136
-VOID
137
-FreeInstanceList (VOID)
138
-{
139
-  if (g_InstanceHash)
140
-    {
141
-      MYASSERT (NInstances() == 0);
142
-      MemFree (g_InstanceHash, sizeof (INSTANCE_HASH));
143
-      g_InstanceHash = NULL;
144
-    }
145
-}
146
-
147
-BOOLEAN
148
-AddAdapterToInstanceList (TapAdapterPointer p_Adapter)
149
-{
150
-  BOOLEAN got_lock;
151
-  BOOLEAN ret = FALSE;
152
-  const int hash = InstanceHashValue(INSTANCE_KEY(p_Adapter));
153
-  INSTANCE_BUCKET *ib = &g_InstanceHash->buckets[hash];
154
-
155
-  DEBUGP (("[TAP] AddAdapterToInstanceList hash=%d\n", hash));
156
-
157
-  ACQUIRE_MUTEX_ADAPTIVE (&ib->lock, got_lock);
158
-
159
-  if (got_lock)
160
-    {
161
-      INSTANCE *i = MemAlloc (sizeof (INSTANCE), FALSE);
162
-      if (i)
163
-	{
164
-	  MYASSERT (p_Adapter);
165
-	  i->m_Adapter = p_Adapter;
166
-	  i->next = ib->list;
167
-	  ib->list = i;
168
-	  ret = TRUE;
169
-	}
170
-      RELEASE_MUTEX (&ib->lock);
171
-    }
172
-
173
-  return ret;
174
-}
175
-
176
-BOOLEAN
177
-RemoveAdapterFromInstanceList (TapAdapterPointer p_Adapter)
178
-{
179
-  BOOLEAN got_lock;
180
-  BOOLEAN ret = FALSE;
181
-  INSTANCE_BUCKET *ib = &g_InstanceHash->buckets[InstanceHashValue(INSTANCE_KEY(p_Adapter))];
182
-
183
-  ACQUIRE_MUTEX_ADAPTIVE (&ib->lock, got_lock);
184
-
185
-  if (got_lock)
186
-    {
187
-      INSTANCE *current, *prev=NULL;
188
-      for (current = ib->list; current != NULL; current = current->next)
189
-	{
190
-	  if (current->m_Adapter == p_Adapter) // found match
191
-	    {
192
-	      if (prev)
193
-		prev->next = current->next;
194
-	      else
195
-		ib->list = current->next;
196
-	      MemFree (current->m_Adapter, sizeof (TapAdapter));
197
-	      MemFree (current, sizeof (INSTANCE));
198
-	      ret = TRUE;
199
-	      break;
200
-	    }
201
-	  prev = current;
202
-	}
203
-      RELEASE_MUTEX (&ib->lock);
204
-    }
205
-
206
-  return ret;
207
-}
208
-
209
-TapAdapterPointer
210
-LookupAdapterInInstanceList (PDEVICE_OBJECT p_DeviceObject)
211
-{
212
-  BOOLEAN got_lock;
213
-  TapAdapterPointer ret = NULL;
214
-  INSTANCE_BUCKET *ib = &g_InstanceHash->buckets[InstanceHashValue((PVOID)p_DeviceObject)];
215
-
216
-  ACQUIRE_MUTEX_ADAPTIVE (&ib->lock, got_lock);
217
-
218
-  if (got_lock)
219
-    {
220
-      INSTANCE *current, *prev=NULL;
221
-      for (current = ib->list; current != NULL; current = current->next)
222
-	{
223
-	  if (p_DeviceObject == INSTANCE_KEY (current->m_Adapter)) // found match
224
-	    {
225
-	      // move it to head of list
226
-	      if (prev)
227
-		{
228
-		  prev->next = current->next;
229
-		  current->next = ib->list;
230
-		  ib->list = current;
231
-		}
232
-	      ret = ib->list->m_Adapter;
233
-	      break;
234
-	    }
235
-	  prev = current;
236
-	}
237
-      RELEASE_MUTEX (&ib->lock);
238
-    }
239
-
240
-  return ret;
241
-}
242 1
deleted file mode 100755
... ...
@@ -1,75 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-typedef struct
26
-{
27
-  volatile long count;
28
-} MUTEX;
29
-
30
-#define MUTEX_SLEEP_TIME  10000 // microseconds
31
-
32
-#define INIT_MUTEX(m) { (m)->count = 0; }
33
-
34
-#define ACQUIRE_MUTEX_BLOCKING(m)                         \
35
-{                                                         \
36
-    while (NdisInterlockedIncrement (&((m)->count)) != 1) \
37
-    {                                                     \
38
-        NdisInterlockedDecrement(&((m)->count));          \
39
-        NdisMSleep(MUTEX_SLEEP_TIME);                     \
40
-    }                                                     \
41
-}
42
-
43
-#define RELEASE_MUTEX(m)                                  \
44
-{                                                         \
45
-        NdisInterlockedDecrement(&((m)->count));          \
46
-}
47
-
48
-#define ACQUIRE_MUTEX_NONBLOCKING(m, result)              \
49
-{                                                         \
50
-    if (NdisInterlockedIncrement (&((m)->count)) != 1)    \
51
-    {                                                     \
52
-        NdisInterlockedDecrement(&((m)->count));          \
53
-        result = FALSE;                                   \
54
-    }                                                     \
55
-    else                                                  \
56
-    {                                                     \
57
-	result = TRUE;                                    \
58
-    }                                                     \
59
-}
60
-
61
-#define ACQUIRE_MUTEX_ADAPTIVE(m, result)                 \
62
-{                                                         \
63
-    result = TRUE;                                        \
64
-    while (NdisInterlockedIncrement (&((m)->count)) != 1) \
65
-    {                                                     \
66
-        NdisInterlockedDecrement(&((m)->count));          \
67
-        if (KeGetCurrentIrql () < DISPATCH_LEVEL)         \
68
-            NdisMSleep(MUTEX_SLEEP_TIME);                 \
69
-        else                                              \
70
-        {                                                 \
71
-	    result = FALSE;                               \
72
-	    break;                                        \
73
-        }                                                 \
74
-    }                                                     \
75
-}
76 1
deleted file mode 100755
... ...
@@ -1,154 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-#include "macinfo.h"
26
-
27
-int
28
-HexStringToDecimalInt (const int p_Character)
29
-{
30
-  int l_Value = 0;
31
-
32
-  if (p_Character >= 'A' && p_Character <= 'F')
33
-    l_Value = (p_Character - 'A') + 10;
34
-  else if (p_Character >= 'a' && p_Character <= 'f')
35
-    l_Value = (p_Character - 'a') + 10;
36
-  else if (p_Character >= '0' && p_Character <= '9')
37
-    l_Value = p_Character - '0';
38
-
39
-  return l_Value;
40
-}
41
-
42
-BOOLEAN
43
-ParseMAC (MACADDR dest, const char *src)
44
-{
45
-  int c;
46
-  int mac_index = 0;
47
-  BOOLEAN high_digit = FALSE;
48
-  int delim_action = 1;
49
-
50
-  MYASSERT (src);
51
-  MYASSERT (dest);
52
-
53
-  CLEAR_MAC (dest);
54
-
55
-  while (c = *src++)
56
-    {
57
-      if (IsMacDelimiter (c))
58
-	{
59
-	  mac_index += delim_action;
60
-	  high_digit = FALSE;
61
-	  delim_action = 1;
62
-	}
63
-      else if (IsHexDigit (c))
64
-	{
65
-	  const int digit = HexStringToDecimalInt (c);
66
-	  if (mac_index < sizeof (MACADDR))
67
-	    {
68
-	      if (!high_digit)
69
-		{
70
-		  dest[mac_index] = (char)(digit);
71
-		  high_digit = TRUE;
72
-		  delim_action = 1;
73
-		}
74
-	      else
75
-		{
76
-		  dest[mac_index] = (char)(dest[mac_index] * 16 + digit);
77
-		  ++mac_index;
78
-		  high_digit = FALSE;
79
-		  delim_action = 0;
80
-		}
81
-	    }
82
-	  else
83
-	    return FALSE;
84
-	}
85
-      else
86
-	return FALSE;
87
-    }
88
-
89
-  return (mac_index + delim_action) >= sizeof (MACADDR);
90
-}
91
-
92
-/*
93
- * Generate a MAC using the GUID in the adapter name.
94
- *
95
- * The mac is constructed as 00:FF:xx:xx:xx:xx where
96
- * the Xs are taken from the first 32 bits of the GUID in the
97
- * adapter name.  This is similar to the Linux 2.4 tap MAC
98
- * generator, except linux uses 32 random bits for the Xs.
99
- *
100
- * In general, this solution is reasonable for most
101
- * applications except for very large bridged TAP networks,
102
- * where the probability of address collisions becomes more
103
- * than infintesimal.
104
- *
105
- * Using the well-known "birthday paradox", on a 1000 node
106
- * network the probability of collision would be
107
- * 0.000116292153.  On a 10,000 node network, the probability
108
- * of collision would be 0.01157288998621678766.
109
- */
110
-
111
-VOID GenerateRandomMac (MACADDR mac, const unsigned char *adapter_name)
112
-{
113
-  unsigned const char *cp = adapter_name;
114
-  unsigned char c;
115
-  unsigned int i = 2;
116
-  unsigned int byte = 0;
117
-  int brace = 0;
118
-  int state = 0;
119
-
120
-  CLEAR_MAC (mac);
121
-
122
-  mac[0] = 0x00;
123
-  mac[1] = 0xFF;
124
-
125
-  while (c = *cp++)
126
-    {
127
-      if (i >= sizeof (MACADDR))
128
-	break;
129
-      if (c == '{')
130
-	brace = 1;
131
-      if (IsHexDigit (c) && brace)
132
-	{
133
-	  const unsigned int digit = HexStringToDecimalInt (c);
134
-	  if (state)
135
-	    {
136
-	      byte <<= 4;
137
-	      byte |= digit;
138
-	      mac[i++] = (unsigned char) byte;
139
-	      state = 0;
140
-	    }
141
-	  else
142
-	    {
143
-	      byte = digit;
144
-	      state = 1;
145
-	    }
146
-	}
147
-    }
148
-}
149
-
150
-VOID GenerateRelatedMAC (MACADDR dest, const MACADDR src, const int delta)
151
-{
152
-  COPY_MAC (dest, src);
153
-  dest[2] += (UCHAR) delta;
154
-}
155 1
deleted file mode 100755
... ...
@@ -1,38 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-#ifndef MacInfoDefined
26
-#define MacInfoDefined
27
-
28
-//===================================================================================
29
-//                                      Macros
30
-//===================================================================================
31
-#define IsMacDelimiter(a) (a == ':' || a == '-' || a == '.')
32
-#define IsHexDigit(c) ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))
33
-
34
-#define COPY_MAC(dest, src) NdisMoveMemory ((dest), (src), sizeof (MACADDR))
35
-#define CLEAR_MAC(dest)     NdisZeroMemory ((dest), sizeof (MACADDR))
36
-#define MAC_EQUAL(a,b)      (memcmp ((a), (b), sizeof (MACADDR)) == 0)
37
-
38
-#endif
39 1
deleted file mode 100755
... ...
@@ -1,186 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-//------------------
26
-// Memory Management
27
-//------------------
28
-
29
-PVOID
30
-MemAlloc (ULONG p_Size, BOOLEAN zero)
31
-{
32
-  PVOID l_Return = NULL;
33
-
34
-  if (p_Size)
35
-    {
36
-      __try
37
-      {
38
-	if (NdisAllocateMemoryWithTag (&l_Return, p_Size, 'APAT')
39
-	    == NDIS_STATUS_SUCCESS)
40
-	  {
41
-	    if (zero)
42
-	      NdisZeroMemory (l_Return, p_Size);
43
-	  }
44
-	else
45
-	  l_Return = NULL;
46
-      }
47
-      __except (EXCEPTION_EXECUTE_HANDLER)
48
-      {
49
-	l_Return = NULL;
50
-      }
51
-    }
52
-
53
-  return l_Return;
54
-}
55
-
56
-VOID
57
-MemFree (PVOID p_Addr, ULONG p_Size)
58
-{
59
-  if (p_Addr && p_Size)
60
-    {
61
-      __try
62
-      {
63
-#if DBG
64
-	NdisZeroMemory (p_Addr, p_Size);
65
-#endif
66
-	NdisFreeMemory (p_Addr, p_Size, 0);
67
-      }
68
-      __except (EXCEPTION_EXECUTE_HANDLER)
69
-      {
70
-      }
71
-    }
72
-}
73
-
74
-/*
75
- * Circular queue management routines.
76
- */
77
-
78
-#define QUEUE_BYTE_ALLOCATION(size) \
79
-  (sizeof (Queue) + (size * sizeof (PVOID)))
80
-
81
-#define QUEUE_ADD_INDEX(var, inc) \
82
-{ \
83
-  var += inc; \
84
-  if (var >= q->capacity) \
85
-    var -= q->capacity; \
86
-  MYASSERT (var < q->capacity); \
87
-}
88
-
89
-#define QUEUE_SANITY_CHECK() \
90
-  MYASSERT (q != NULL && q->base < q->capacity && q->size <= q->capacity)
91
-
92
-#define QueueCount(q) (q->size)
93
-
94
-#define UPDATE_MAX_SIZE() \
95
-{ \
96
-  if (q->size > q->max_size) \
97
-    q->max_size = q->size; \
98
-}
99
-
100
-Queue *
101
-QueueInit (ULONG capacity)
102
-{
103
-  Queue *q;
104
-
105
-  MYASSERT (capacity > 0);
106
-  q = (Queue *) MemAlloc (QUEUE_BYTE_ALLOCATION (capacity), TRUE);
107
-  if (!q)
108
-    return NULL;
109
-
110
-  q->base = q->size = 0;
111
-  q->capacity = capacity;
112
-  q->max_size = 0;
113
-  return q;
114
-}
115
-
116
-VOID
117
-QueueFree (Queue *q)
118
-{
119
-  if (q)
120
-    {
121
-      QUEUE_SANITY_CHECK ();
122
-      MemFree (q, QUEUE_BYTE_ALLOCATION (q->capacity));
123
-    }
124
-}
125
-
126
-PVOID
127
-QueuePush (Queue *q, PVOID item)
128
-{
129
-  ULONG dest;
130
-  QUEUE_SANITY_CHECK ();
131
-  if (q->size == q->capacity)
132
-    return NULL;
133
-  dest = q->base;
134
-  QUEUE_ADD_INDEX (dest, q->size);
135
-  q->data[dest] = item;
136
-  ++q->size;
137
-  UPDATE_MAX_SIZE();
138
-  return item;
139
-}
140
-
141
-PVOID
142
-QueuePop (Queue *q)
143
-{
144
-  ULONG oldbase;
145
-  QUEUE_SANITY_CHECK ();
146
-  if (!q->size)
147
-    return NULL;
148
-  oldbase = q->base;
149
-  QUEUE_ADD_INDEX (q->base, 1);
150
-  --q->size;
151
-  UPDATE_MAX_SIZE();
152
-  return q->data[oldbase];
153
-}
154
-
155
-PVOID
156
-QueueExtract (Queue *q, PVOID item)
157
-{
158
-  ULONG src, dest, count, n;
159
-  QUEUE_SANITY_CHECK ();
160
-  n = 0;
161
-  src = dest = q->base;
162
-  count = q->size;
163
-  while (count--)
164
-    {
165
-      if (item == q->data[src])
166
-	{
167
-	  ++n;
168
-	  --q->size;
169
-	}
170
-      else
171
-	{
172
-	  q->data[dest] = q->data[src];
173
-	  QUEUE_ADD_INDEX (dest, 1);	  
174
-	}
175
-      QUEUE_ADD_INDEX (src, 1);
176
-    }
177
-  if (n)
178
-    return item;
179
-  else
180
-    return NULL;
181
-}
182
-
183
-#undef QUEUE_BYTE_ALLOCATION
184
-#undef QUEUE_ADD_INDEX
185
-#undef QUEUE_SANITY_CHECK
186
-#undef UPDATE_MAX_SIZE
187 1
deleted file mode 100755
... ...
@@ -1,224 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-//============================================================
26
-// MAC address, Ethernet header, and ARP
27
-//============================================================
28
-
29
-#pragma pack(1)
30
-
31
-#define IP_HEADER_SIZE 20
32
-#define IPV6_HEADER_SIZE 40
33
-
34
-typedef unsigned char MACADDR [6];
35
-typedef unsigned long IPADDR;
36
-typedef unsigned char IPV6ADDR [16];
37
-
38
-//-----------------
39
-// Ethernet address
40
-//-----------------
41
-
42
-typedef struct {
43
-  MACADDR addr;
44
-} ETH_ADDR;
45
-
46
-typedef struct {
47
-  ETH_ADDR list[NIC_MAX_MCAST_LIST];
48
-} MC_LIST;
49
-
50
-//----------------
51
-// Ethernet header
52
-//----------------
53
-
54
-typedef struct
55
-{
56
-  MACADDR dest;               /* destination eth addr	*/
57
-  MACADDR src;                /* source ether addr	*/
58
-
59
-# define ETH_P_IP   0x0800    /* IPv4 protocol */
60
-# define ETH_P_IPV6 0x86DD    /* IPv6 protocol */
61
-# define ETH_P_ARP  0x0806    /* ARP protocol */
62
-  USHORT proto;               /* packet type ID field	*/
63
-} ETH_HEADER, *PETH_HEADER;
64
-
65
-//----------------
66
-// ARP packet
67
-//----------------
68
-
69
-typedef struct
70
-   {
71
-    MACADDR        m_MAC_Destination;        // Reverse these two
72
-    MACADDR        m_MAC_Source;             // to answer ARP requests
73
-    USHORT         m_Proto;                  // 0x0806
74
-
75
-#   define MAC_ADDR_TYPE 0x0001
76
-    USHORT         m_MAC_AddressType;        // 0x0001
77
-
78
-    USHORT         m_PROTO_AddressType;      // 0x0800
79
-    UCHAR          m_MAC_AddressSize;        // 0x06
80
-    UCHAR          m_PROTO_AddressSize;      // 0x04
81
-
82
-#   define ARP_REQUEST 0x0001
83
-#   define ARP_REPLY   0x0002
84
-    USHORT         m_ARP_Operation;          // 0x0001 for ARP request, 0x0002 for ARP reply
85
-
86
-    MACADDR        m_ARP_MAC_Source;
87
-    IPADDR         m_ARP_IP_Source;
88
-    MACADDR        m_ARP_MAC_Destination;
89
-    IPADDR         m_ARP_IP_Destination;
90
-   }
91
-ARP_PACKET, *PARP_PACKET;
92
-
93
-//----------
94
-// IP Header
95
-//----------
96
-
97
-typedef struct {
98
-# define IPH_GET_VER(v) (((v) >> 4) & 0x0F)
99
-# define IPH_GET_LEN(v) (((v) & 0x0F) << 2)
100
-  UCHAR    version_len;
101
-
102
-  UCHAR    tos;
103
-  USHORT   tot_len;
104
-  USHORT   id;
105
-
106
-# define IP_OFFMASK 0x1fff
107
-  USHORT   frag_off;
108
-
109
-  UCHAR    ttl;
110
-
111
-# define IPPROTO_UDP  17  /* UDP protocol */
112
-# define IPPROTO_TCP   6  /* TCP protocol */
113
-# define IPPROTO_ICMP  1  /* ICMP protocol */
114
-# define IPPROTO_IGMP  2  /* IGMP protocol */
115
-  UCHAR    protocol;
116
-
117
-  USHORT   check;
118
-  ULONG    saddr;
119
-  ULONG    daddr;
120
-  /* The options start here. */
121
-} IPHDR;
122
-
123
-//-----------
124
-// UDP header
125
-//-----------
126
-
127
-typedef struct {
128
-  USHORT   source;
129
-  USHORT   dest;
130
-  USHORT   len;
131
-  USHORT   check;
132
-} UDPHDR;
133
-
134
-//--------------------------
135
-// TCP header, per RFC 793.
136
-//--------------------------
137
-
138
-typedef struct {
139
-  USHORT      source;    /* source port */
140
-  USHORT      dest;      /* destination port */
141
-  ULONG       seq;       /* sequence number */
142
-  ULONG       ack_seq;   /* acknowledgement number */
143
-
144
-# define TCPH_GET_DOFF(d) (((d) & 0xF0) >> 2)
145
-  UCHAR       doff_res;
146
-
147
-# define TCPH_FIN_MASK (1<<0)
148
-# define TCPH_SYN_MASK (1<<1)
149
-# define TCPH_RST_MASK (1<<2)
150
-# define TCPH_PSH_MASK (1<<3)
151
-# define TCPH_ACK_MASK (1<<4)
152
-# define TCPH_URG_MASK (1<<5)
153
-# define TCPH_ECE_MASK (1<<6)
154
-# define TCPH_CWR_MASK (1<<7)
155
-  UCHAR       flags;
156
-
157
-  USHORT      window;
158
-  USHORT      check;
159
-  USHORT      urg_ptr;
160
-} TCPHDR;
161
-
162
-#define	TCPOPT_EOL     0
163
-#define	TCPOPT_NOP     1
164
-#define	TCPOPT_MAXSEG  2
165
-#define TCPOLEN_MAXSEG 4
166
-
167
-//------------
168
-// IPv6 Header
169
-//------------
170
-
171
-typedef struct {
172
-  UCHAR    version_prio;
173
-  UCHAR    flow_lbl[3];
174
-  USHORT   payload_len;
175
-# define IPPROTO_ICMPV6  0x3a  /* ICMP protocol v6 */
176
-  UCHAR    nexthdr;
177
-  UCHAR    hop_limit;
178
-  IPV6ADDR saddr;
179
-  IPV6ADDR daddr;
180
-} IPV6HDR;
181
-
182
-//--------------------------------------------
183
-// IPCMPv6 NS/NA Packets (RFC4443 and RFC4861)
184
-//--------------------------------------------
185
-
186
-// Neighbor Solictiation - RFC 4861, 4.3
187
-// (this is just the ICMPv6 part of the packet)
188
-typedef struct {
189
-  UCHAR    type;
190
-# define ICMPV6_TYPE_NS	135		// neighbour solicitation
191
-  UCHAR    code;
192
-# define ICMPV6_CODE_0	0		// no specific sub-code for NS/NA
193
-  USHORT   checksum;
194
-  ULONG    reserved;
195
-  IPV6ADDR target_addr;
196
-} ICMPV6_NS;
197
-
198
-// Neighbor Advertisement - RFC 4861, 4.4 + 4.6/4.6.1
199
-// (this is just the ICMPv6 payload)
200
-typedef struct {
201
-  UCHAR    type;
202
-# define ICMPV6_TYPE_NA	136		// neighbour advertisement
203
-  UCHAR    code;
204
-# define ICMPV6_CODE_0	0		// no specific sub-code for NS/NA
205
-  USHORT   checksum;
206
-  UCHAR    rso_bits;			// Router(0), Solicited(2), Ovrrd(4)
207
-  UCHAR	   reserved[3];
208
-  IPV6ADDR target_addr;
209
-// always include "Target Link-layer Address" option (RFC 4861 4.6.1)
210
-  UCHAR    opt_type;
211
-#define ICMPV6_OPTION_TLLA 2
212
-  UCHAR    opt_length;
213
-#define ICMPV6_LENGTH_TLLA 1		// multiplied by 8 -> 1 = 8 bytes
214
-  MACADDR  target_macaddr;
215
-} ICMPV6_NA;
216
-
217
-// this is the complete packet with Ethernet and IPv6 headers
218
-typedef struct {
219
-  ETH_HEADER eth;
220
-  IPV6HDR    ipv6;
221
-  ICMPV6_NA  icmpv6;
222
-} ICMPV6_NA_PKT;
223
-
224
-#pragma pack()
225 1
deleted file mode 100755
... ...
@@ -1,260 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-#ifndef TAP_PROTOTYPES_DEFINED
26
-#define TAP_PROTOTYPES_DEFINED
27
-
28
-NTSTATUS DriverEntry
29
-   (
30
-    IN PDRIVER_OBJECT p_DriverObject,
31
-    IN PUNICODE_STRING p_RegistryPath
32
-   );
33
-
34
-VOID TapDriverUnload
35
-   (
36
-    IN PDRIVER_OBJECT p_DriverObject
37
-   );
38
-
39
-NDIS_STATUS AdapterCreate
40
-   (
41
-    OUT PNDIS_STATUS p_ErrorStatus,
42
-    OUT PUINT p_MediaIndex,
43
-    IN PNDIS_MEDIUM p_Media,
44
-    IN UINT p_MediaCount,
45
-    IN NDIS_HANDLE p_AdapterHandle,
46
-    IN NDIS_HANDLE p_ConfigurationHandle
47
-   );
48
-
49
-VOID AdapterHalt
50
-   (
51
-    IN NDIS_HANDLE p_AdapterContext
52
-   );
53
-
54
-VOID AdapterFreeResources
55
-   (
56
-    TapAdapterPointer p_Adapter
57
-   );
58
-
59
-NDIS_STATUS AdapterReset
60
-   (
61
-    OUT PBOOLEAN p_AddressingReset,
62
-    IN NDIS_HANDLE p_AdapterContext
63
-   );
64
-
65
-NDIS_STATUS AdapterQuery
66
-   (
67
-    IN NDIS_HANDLE p_AdapterContext,
68
-    IN NDIS_OID p_OID,
69
-    IN PVOID p_Buffer,
70
-    IN ULONG p_BufferLength,
71
-    OUT PULONG p_BytesWritten,
72
-    OUT PULONG p_BytesNeeded
73
-   );
74
-
75
-NDIS_STATUS AdapterModify
76
-   (
77
-    IN NDIS_HANDLE p_AdapterContext,
78
-    IN NDIS_OID p_OID,
79
-    IN PVOID p_Buffer,
80
-    IN ULONG p_BufferLength,
81
-    OUT PULONG p_BytesRead,
82
-    OUT PULONG p_BytesNeeded
83
-   );
84
-
85
-NDIS_STATUS AdapterTransmit
86
-   (
87
-    IN NDIS_HANDLE p_AdapterContext,
88
-    IN PNDIS_PACKET p_Packet,
89
-    IN UINT p_Flags
90
-   );
91
-
92
-NDIS_STATUS AdapterReceive
93
-   (
94
-    OUT PNDIS_PACKET p_Packet,
95
-    OUT PUINT p_Transferred,
96
-    IN NDIS_HANDLE p_AdapterContext,
97
-    IN NDIS_HANDLE p_ReceiveContext,
98
-    IN UINT p_Offset,
99
-    IN UINT p_ToTransfer
100
-   );
101
-
102
-NTSTATUS TapDeviceHook
103
-   (
104
-    IN PDEVICE_OBJECT p_DeviceObject,
105
-    IN PIRP p_IRP
106
-   );
107
-
108
-NDIS_STATUS CreateTapDevice
109
-   (
110
-    TapExtensionPointer p_Extension,
111
-    const char *p_Name
112
-   );
113
-
114
-VOID DestroyTapDevice
115
-   (
116
-    TapExtensionPointer p_Extension
117
-   );
118
-
119
-VOID TapDeviceFreeResources
120
-   (
121
-    TapExtensionPointer p_Extension
122
-    );
123
-
124
-NTSTATUS CompleteIRP
125
-   (
126
-    IN PIRP p_IRP,
127
-    IN TapPacketPointer p_PacketBuffer,
128
-    IN CCHAR PriorityBoost
129
-   );
130
-
131
-VOID CancelIRPCallback
132
-   (
133
-    IN PDEVICE_OBJECT p_DeviceObject,
134
-    IN PIRP p_IRP
135
-   );
136
-
137
-VOID CancelIRP
138
-   (
139
-    TapExtensionPointer p_Extension,
140
-    IN PIRP p_IRP,
141
-    BOOLEAN callback
142
-   );
143
-
144
-VOID FlushQueues
145
-   (
146
-    TapExtensionPointer p_Extension
147
-   );
148
-
149
-VOID ResetTapAdapterState
150
-   (
151
-    TapAdapterPointer p_Adapter
152
-   );
153
-
154
-BOOLEAN ProcessARP
155
-   (
156
-    TapAdapterPointer p_Adapter,
157
-    const PARP_PACKET src,
158
-    const IPADDR adapter_ip,
159
-    const IPADDR ip_network,
160
-    const IPADDR ip_netmask,
161
-    const MACADDR mac
162
-   );
163
-
164
-VOID SetMediaStatus
165
-   (
166
-    TapAdapterPointer p_Adapter,
167
-    BOOLEAN state
168
-   );
169
-
170
-VOID InjectPacketDeferred
171
-   (
172
-    TapAdapterPointer p_Adapter,
173
-    UCHAR *packet,
174
-    const unsigned int len
175
-   );
176
-
177
-VOID InjectPacketNow
178
-   (
179
-    TapAdapterPointer p_Adapter,
180
-    UCHAR *packet,
181
-    const unsigned int len
182
-   );
183
-
184
-// for KDEFERRED_ROUTINE and Static Driver Verifier
185
-//#include <wdm.h>
186
-//KDEFERRED_ROUTINE InjectPacketDpc;
187
-
188
-VOID InjectPacketDpc
189
-   (
190
-    KDPC *Dpc,
191
-    PVOID DeferredContext,
192
-    PVOID SystemArgument1,
193
-    PVOID SystemArgument2
194
-    );
195
-
196
-VOID CheckIfDhcpAndTunMode
197
-   (
198
-    TapAdapterPointer p_Adapter
199
-   );
200
-
201
-VOID HookDispatchFunctions();
202
-
203
-#if ENABLE_NONADMIN
204
-
205
-#if DDKVER_MAJOR < 5600
206
-/*
207
- * Better solution for use on Vista DDK, but possibly not compatible with
208
- * earlier DDKs:
209
- *
210
- * Eliminate the definition of SECURITY_DESCRIPTOR (and even ZwSetSecurityObject),
211
- * and at the top of tapdrv.c change:
212
- *
213
- * #include <ndis.h>
214
- * #include <ntstrsafe.h>
215
- * #include <ntddk.h>
216
- *
217
- * To
218
- *
219
- * #include <ntifs.h>
220
- * #include <ndis.h>
221
- * #include <ntstrsafe.h>
222
- */
223
-typedef struct _SECURITY_DESCRIPTOR {
224
-  unsigned char opaque[64];
225
-} SECURITY_DESCRIPTOR;
226
-
227
-NTSYSAPI
228
-NTSTATUS
229
-NTAPI
230
-ZwSetSecurityObject (
231
-  IN HANDLE  Handle,
232
-  IN SECURITY_INFORMATION  SecurityInformation,
233
-  IN PSECURITY_DESCRIPTOR  SecurityDescriptor);
234
-
235
-#endif
236
-
237
-VOID AllowNonAdmin (TapExtensionPointer p_Extension);
238
-
239
-#endif
240
-
241
-struct WIN2K_NDIS_MINIPORT_BLOCK
242
-{
243
-  unsigned char  opaque[16];
244
-  UNICODE_STRING MiniportName;       // how mini-port refers to us
245
-};
246
-
247
-#if PACKET_TRUNCATION_CHECK
248
-
249
-VOID IPv4PacketSizeVerify
250
-   (
251
-    const UCHAR *data,
252
-    ULONG length,
253
-    BOOLEAN tun,
254
-    const char *prefix,
255
-    LONG *counter
256
-   );
257
-
258
-#endif
259
-
260
-#endif
261 1
deleted file mode 100755
... ...
@@ -1,58 +0,0 @@
1
-#include <windows.h>
2
-#include <ntverp.h>
3
-
4
-/* get VERSION */
5
-#include "common.h"
6
-
7
-/* VER_FILETYPE, VER_FILESUBTYPE, VER_FILEDESCRIPTION_STR
8
- * and VER_INTERNALNAME_STR must be defined before including COMMON.VER
9
- * The strings don't need a '\0', since common.ver has them.
10
- */
11
-
12
-#define	VER_FILETYPE	VFT_DRV
13
-/* possible values:		VFT_UNKNOWN
14
-				VFT_APP
15
-				VFT_DLL
16
-				VFT_DRV
17
-				VFT_FONT
18
-				VFT_VXD
19
-				VFT_STATIC_LIB
20
-*/
21
-#define	VER_FILESUBTYPE	VFT2_DRV_NETWORK
22
-/* possible values		VFT2_UNKNOWN
23
-				VFT2_DRV_PRINTER
24
-				VFT2_DRV_KEYBOARD
25
-				VFT2_DRV_LANGUAGE
26
-				VFT2_DRV_DISPLAY
27
-				VFT2_DRV_MOUSE
28
-				VFT2_DRV_NETWORK
29
-				VFT2_DRV_SYSTEM
30
-				VFT2_DRV_INSTALLABLE
31
-				VFT2_DRV_SOUND
32
-				VFT2_DRV_COMM
33
-*/
34
-
35
-#define VER_COMPANYNAME_STR         "The OpenVPN Project"
36
-#define VER_FILEDESCRIPTION_STR     "TAP-Win32 Virtual Network Driver"
37
-#define VER_ORIGINALFILENAME_STR    TAP_COMPONENT_ID ".sys"
38
-#define VER_LEGALCOPYRIGHT_YEARS    "2003-2010"
39
-#define VER_LEGALCOPYRIGHT_STR      "OpenVPN Technologies, Inc."
40
-
41
-
42
-#define VER_PRODUCTNAME_STR         VER_FILEDESCRIPTION_STR
43
-#define VER_PRODUCTVERSION	    TAP_DRIVER_MAJOR_VERSION,00,00,TAP_DRIVER_MINOR_VERSION
44
-
45
-#define XSTR(s) STR(s)
46
-#define STR(s) #s
47
-
48
-#define VSTRING PACKAGE_VERSION " " XSTR(TAP_DRIVER_MAJOR_VERSION) "/" XSTR(TAP_DRIVER_MINOR_VERSION)
49
-
50
-#ifdef DBG
51
-#define VER_PRODUCTVERSION_STR      VSTRING " (DEBUG)"
52
-#else
53
-#define VER_PRODUCTVERSION_STR      VSTRING
54
-#endif
55
-
56
-#define VER_INTERNALNAME_STR        VER_ORIGINALFILENAME_STR
57
-
58
-#include "common.ver"
59 1
deleted file mode 100755
... ...
@@ -1,3146 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-//======================================================
26
-// This driver is designed to work on Win 2000 or higher
27
-// versions of Windows.
28
-//
29
-// It is SMP-safe and handles NDIS 5 power management.
30
-//
31
-// By default we operate as a "tap" virtual ethernet
32
-// 802.3 interface, but we can emulate a "tun"
33
-// interface (point-to-point IPv4) through the
34
-// TAP_IOCTL_CONFIG_POINT_TO_POINT or
35
-// TAP_IOCTL_CONFIG_TUN ioctl.
36
-//======================================================
37
-
38
-#include "common.h"
39
-#ifndef DDKVER_MAJOR
40
-#error DDKVER_MAJOR must be defined as the major number of the DDK Version
41
-#endif
42
-
43
-#define NDIS_MINIPORT_DRIVER
44
-#define BINARY_COMPATIBLE 0
45
-#define NDIS50_MINIPORT 1
46
-#define NDIS_WDM 0
47
-#define NDIS50 1
48
-#define NTSTRSAFE_LIB
49
-
50
-// Debug info output
51
-#define ALSO_DBGPRINT           1
52
-#define DEBUGP_AT_DISPATCH      0
53
-
54
-//========================================================
55
-// Check for truncated IPv4 packets, log errors if found.
56
-//========================================================
57
-#define PACKET_TRUNCATION_CHECK 0
58
-
59
-//========================================================
60
-// EXPERIMENTAL -- Configure TAP device object to be
61
-// accessible from non-administrative accounts, based
62
-// on an advanced properties setting.
63
-//
64
-// Duplicates the functionality of OpenVPN's
65
-// --allow-nonadmin directive.
66
-//========================================================
67
-#define ENABLE_NONADMIN 1
68
-
69
-#if DDKVER_MAJOR < 5600
70
-#include <ndis.h>
71
-#include <ntstrsafe.h>
72
-#include <ntddk.h>
73
-#else
74
-#include <ntifs.h>
75
-#include <ndis.h>
76
-#include <ntstrsafe.h>
77
-#endif
78
-
79
-#include "lock.h"
80
-#include "constants.h"
81
-#include "proto.h"
82
-#include "error.h"
83
-#include "endian.h"
84
-#include "dhcp.h"
85
-#include "types.h"
86
-#include "prototypes.h"
87
-
88
-#include "mem.c"
89
-#include "macinfo.c"
90
-#include "error.c"
91
-#include "dhcp.c"
92
-#include "instance.c"
93
-
94
-#define IS_UP(ta) \
95
-  ((ta)->m_InterfaceIsRunning && (ta)->m_Extension.m_TapIsRunning)
96
-
97
-#define INCREMENT_STAT(s) ++(s)
98
-
99
-#define NAME_BUFFER_SIZE 80
100
-
101
-//========================================================
102
-//                            Globals
103
-//========================================================
104
-
105
-NDIS_HANDLE g_NdisWrapperHandle;
106
-
107
-const UINT g_SupportedOIDList[] = {
108
-  OID_GEN_HARDWARE_STATUS,
109
-  OID_GEN_MEDIA_SUPPORTED,
110
-  OID_GEN_MEDIA_IN_USE,
111
-  OID_GEN_MAXIMUM_LOOKAHEAD,
112
-  OID_GEN_MAC_OPTIONS,
113
-  OID_GEN_LINK_SPEED,
114
-  OID_GEN_TRANSMIT_BLOCK_SIZE,
115
-  OID_GEN_RECEIVE_BLOCK_SIZE,
116
-  OID_GEN_VENDOR_DESCRIPTION,
117
-  OID_GEN_DRIVER_VERSION,
118
-  OID_GEN_XMIT_OK,
119
-  OID_GEN_RCV_OK,
120
-  OID_GEN_XMIT_ERROR,
121
-  OID_GEN_RCV_ERROR,
122
-  OID_802_3_PERMANENT_ADDRESS,
123
-  OID_802_3_CURRENT_ADDRESS,
124
-  OID_GEN_RCV_NO_BUFFER,
125
-  OID_802_3_RCV_ERROR_ALIGNMENT,
126
-  OID_802_3_XMIT_ONE_COLLISION,
127
-  OID_802_3_XMIT_MORE_COLLISIONS,
128
-  OID_802_3_MULTICAST_LIST,
129
-  OID_802_3_MAXIMUM_LIST_SIZE,
130
-  OID_GEN_VENDOR_ID,
131
-  OID_GEN_CURRENT_LOOKAHEAD,
132
-  OID_GEN_CURRENT_PACKET_FILTER,
133
-  OID_GEN_PROTOCOL_OPTIONS,
134
-  OID_GEN_MAXIMUM_TOTAL_SIZE,
135
-  OID_GEN_TRANSMIT_BUFFER_SPACE,
136
-  OID_GEN_RECEIVE_BUFFER_SPACE,
137
-  OID_GEN_MAXIMUM_FRAME_SIZE,
138
-  OID_GEN_VENDOR_DRIVER_VERSION,
139
-  OID_GEN_MAXIMUM_SEND_PACKETS,
140
-  OID_GEN_MEDIA_CONNECT_STATUS,
141
-  OID_GEN_SUPPORTED_LIST
142
-};
143
-
144
-//============================================================
145
-//                         Driver Entry
146
-//============================================================
147
-#pragma NDIS_INIT_FUNCTION (DriverEntry)
148
-
149
-NTSTATUS
150
-DriverEntry (IN PDRIVER_OBJECT p_DriverObject,
151
-	     IN PUNICODE_STRING p_RegistryPath)
152
-{
153
-  NDIS_STATUS l_Status = NDIS_STATUS_FAILURE;
154
-  NDIS_MINIPORT_CHARACTERISTICS *l_Properties = NULL;
155
-
156
-  //========================================================
157
-  // Notify NDIS that a new miniport driver is initializing.
158
-  //========================================================
159
-
160
-  NdisMInitializeWrapper (&g_NdisWrapperHandle,
161
-			  p_DriverObject,
162
-			  p_RegistryPath, NULL);
163
-
164
-  //======================
165
-  // Global initialization
166
-  //======================
167
-
168
-#if DBG
169
-  MyDebugInit (10000); // Allocate debugging text space
170
-#endif
171
-
172
-  if (!InitInstanceList ())
173
-    {
174
-      DEBUGP (("[TAP] Allocation failed for adapter instance list\n"));
175
-      goto cleanup;
176
-    }
177
-
178
-  //=======================================
179
-  // Set and register miniport entry points
180
-  //=======================================
181
-
182
-  l_Properties = MemAlloc (sizeof (NDIS_MINIPORT_CHARACTERISTICS), TRUE);
183
-
184
-  if (l_Properties == NULL)
185
-    {
186
-      DEBUGP (("[TAP] Allocation failed for miniport entry points\n"));
187
-      goto cleanup;
188
-    }
189
-
190
-  l_Properties->MajorNdisVersion = TAP_NDIS_MAJOR_VERSION;
191
-  l_Properties->MinorNdisVersion = TAP_NDIS_MINOR_VERSION;
192
-  l_Properties->InitializeHandler = AdapterCreate;
193
-  l_Properties->HaltHandler = AdapterHalt;
194
-  l_Properties->ResetHandler = AdapterReset;               /* DISPATCH_LEVEL */
195
-  l_Properties->TransferDataHandler = AdapterReceive;      /* DISPATCH_LEVEL */
196
-  l_Properties->SendHandler = AdapterTransmit;             /* DISPATCH_LEVEL */
197
-  l_Properties->QueryInformationHandler = AdapterQuery;    /* DISPATCH_LEVEL */
198
-  l_Properties->SetInformationHandler = AdapterModify;     /* DISPATCH_LEVEL */
199
-
200
-  switch (l_Status =
201
-	  NdisMRegisterMiniport (g_NdisWrapperHandle, l_Properties,
202
-				 sizeof (NDIS_MINIPORT_CHARACTERISTICS)))
203
-    {
204
-    case NDIS_STATUS_SUCCESS:
205
-      {
206
-	DEBUGP (("[TAP] version [%d.%d] %s %s registered miniport successfully\n",
207
-		 TAP_DRIVER_MAJOR_VERSION,
208
-		 TAP_DRIVER_MINOR_VERSION,
209
-		 __DATE__,
210
-		 __TIME__));
211
-	DEBUGP (("Registry Path: '%.*S'\n", p_RegistryPath->Length/2, p_RegistryPath->Buffer));
212
-	break;
213
-      }
214
-
215
-    case NDIS_STATUS_BAD_CHARACTERISTICS:
216
-      {
217
-	DEBUGP (("[TAP] Miniport characteristics were badly defined\n"));
218
-	NdisTerminateWrapper (g_NdisWrapperHandle, NULL);
219
-	break;
220
-      }
221
-
222
-    case NDIS_STATUS_BAD_VERSION:
223
-      {
224
-	DEBUGP
225
-	  (("[TAP] NDIS Version is wrong for the given characteristics\n"));
226
-	NdisTerminateWrapper (g_NdisWrapperHandle, NULL);
227
-	break;
228
-      }
229
-
230
-    case NDIS_STATUS_RESOURCES:
231
-      {
232
-	DEBUGP (("[TAP] Insufficient resources\n"));
233
-	NdisTerminateWrapper (g_NdisWrapperHandle, NULL);
234
-	break;
235
-      }
236
-
237
-    default:
238
-    case NDIS_STATUS_FAILURE:
239
-      {
240
-	DEBUGP (("[TAP] Unknown fatal registration error\n"));
241
-	NdisTerminateWrapper (g_NdisWrapperHandle, NULL);
242
-	break;
243
-      }
244
-    }
245
-
246
- cleanup:
247
-  if (l_Properties)
248
-    MemFree (l_Properties, sizeof (NDIS_MINIPORT_CHARACTERISTICS));
249
-
250
-  if (l_Status == NDIS_STATUS_SUCCESS)
251
-    NdisMRegisterUnloadHandler (g_NdisWrapperHandle, TapDriverUnload);
252
-  else
253
-    TapDriverUnload (p_DriverObject);
254
-
255
-  return l_Status;
256
-}
257
-
258
-//============================================================
259
-//                         Driver Unload
260
-//============================================================
261
-VOID 
262
-TapDriverUnload (IN PDRIVER_OBJECT p_DriverObject)
263
-{
264
-  DEBUGP (("[TAP] version [%d.%d] %s %s unloaded, instances=%d, imbs=%d\n",
265
-	   TAP_DRIVER_MAJOR_VERSION,
266
-	   TAP_DRIVER_MINOR_VERSION,
267
-	   __DATE__,
268
-	   __TIME__,
269
-	   NInstances(),
270
-	   InstanceMaxBucketSize()));
271
-
272
-  FreeInstanceList ();
273
-
274
-  //==============================
275
-  // Free debugging text space
276
-  //==============================
277
-#if DBG
278
-  MyDebugFree ();
279
-#endif
280
-}
281
-
282
-//==========================================================
283
-//                            Adapter Initialization
284
-//==========================================================
285
-NDIS_STATUS AdapterCreate
286
-(OUT PNDIS_STATUS p_ErrorStatus,
287
- OUT PUINT p_MediaIndex,
288
- IN PNDIS_MEDIUM p_Media,
289
- IN UINT p_MediaCount,
290
- IN NDIS_HANDLE p_AdapterHandle,
291
- IN NDIS_HANDLE p_ConfigurationHandle)
292
-{
293
-  TapAdapterPointer l_Adapter = NULL;
294
-
295
-  NDIS_MEDIUM l_PreferredMedium = NdisMedium802_3; // Ethernet
296
-  BOOLEAN l_MacFromRegistry = FALSE;
297
-  UINT l_Index;
298
-  NDIS_STATUS status;
299
-
300
-#if ENABLE_NONADMIN
301
-  BOOLEAN enable_non_admin = FALSE;
302
-#endif
303
-
304
-  DEBUGP (("[TAP] AdapterCreate called\n"));
305
-
306
-  //====================================
307
-  // Make sure adapter type is supported
308
-  //====================================
309
-
310
-  for (l_Index = 0;
311
-       l_Index < p_MediaCount && p_Media[l_Index] != l_PreferredMedium;
312
-       ++l_Index);
313
-
314
-  if (l_Index == p_MediaCount)
315
-    {
316
-      DEBUGP (("[TAP] Unsupported adapter type [wanted: %d]\n",
317
-	       l_PreferredMedium));
318
-      return NDIS_STATUS_UNSUPPORTED_MEDIA;
319
-    }
320
-
321
-  *p_MediaIndex = l_Index;
322
-
323
-  //=========================================
324
-  // Allocate memory for TapAdapter structure
325
-  //=========================================
326
-
327
-  l_Adapter = MemAlloc (sizeof (TapAdapter), TRUE);
328
-
329
-  if (l_Adapter == NULL)
330
-    {
331
-      DEBUGP (("[TAP] Couldn't allocate adapter memory\n"));
332
-      return NDIS_STATUS_RESOURCES;
333
-    }
334
-
335
-  //==========================================
336
-  // Inform the NDIS library about significant
337
-  // features of our virtual NIC.
338
-  //==========================================
339
-
340
-  NdisMSetAttributesEx
341
-    (p_AdapterHandle,
342
-     (NDIS_HANDLE) l_Adapter,
343
-     16,
344
-     NDIS_ATTRIBUTE_DESERIALIZE
345
-     | NDIS_ATTRIBUTE_IGNORE_PACKET_TIMEOUT
346
-     | NDIS_ATTRIBUTE_IGNORE_REQUEST_TIMEOUT
347
-     | NDIS_ATTRIBUTE_NO_HALT_ON_SUSPEND,
348
-     NdisInterfaceInternal);
349
-
350
-  //=====================================
351
-  // Initialize simple Adapter parameters
352
-  //=====================================
353
-
354
-  l_Adapter->m_Lookahead = DEFAULT_PACKET_LOOKAHEAD;
355
-  l_Adapter->m_Medium = l_PreferredMedium;
356
-  l_Adapter->m_DeviceState = '?';
357
-  l_Adapter->m_MiniportAdapterHandle = p_AdapterHandle;
358
-
359
-  //==================================
360
-  // Allocate spinlock for controlling
361
-  // access to multicast address list.
362
-  //==================================
363
-  NdisAllocateSpinLock (&l_Adapter->m_MCLock);
364
-  l_Adapter->m_MCLockAllocated = TRUE;
365
-
366
-  //====================================================
367
-  // Register a shutdown handler which will be called
368
-  // on system restart/shutdown to halt our virtual NIC.
369
-  //====================================================
370
-
371
-  NdisMRegisterAdapterShutdownHandler (p_AdapterHandle, l_Adapter,
372
-				       AdapterHalt);
373
-  l_Adapter->m_RegisteredAdapterShutdownHandler = TRUE;
374
-
375
-  //============================================
376
-  // Get parameters from registry which were set
377
-  // in the adapter advanced properties dialog.
378
-  //============================================
379
-  {
380
-    NDIS_STATUS status;
381
-    NDIS_HANDLE configHandle;
382
-    NDIS_CONFIGURATION_PARAMETER *parm;
383
-
384
-    // set defaults in case our registry query fails
385
-    l_Adapter->m_MTU = ETHERNET_MTU;
386
-    l_Adapter->m_MediaStateAlwaysConnected = FALSE;
387
-    l_Adapter->m_MediaState = FALSE;
388
-
389
-    NdisOpenConfiguration (&status, &configHandle, p_ConfigurationHandle);
390
-    if (status != NDIS_STATUS_SUCCESS)
391
-      {
392
-	DEBUGP (("[TAP] Couldn't open adapter registry\n"));
393
-	AdapterFreeResources (l_Adapter);
394
-	return status;
395
-      }
396
-
397
-    //====================================
398
-    // Allocate and construct adapter name
399
-    //====================================
400
-    {
401
-      
402
-      NDIS_STRING mkey = NDIS_STRING_CONST("MiniportName");
403
-      NDIS_STRING vkey = NDIS_STRING_CONST("NdisVersion");
404
-      NDIS_STATUS vstatus;
405
-      NDIS_CONFIGURATION_PARAMETER *vparm;
406
-
407
-      NdisReadConfiguration (&vstatus, &vparm, configHandle, &vkey, NdisParameterInteger);
408
-      if (vstatus == NDIS_STATUS_SUCCESS)
409
-	DEBUGP (("[TAP] NdisReadConfiguration NdisVersion=%X\n", vparm->ParameterData.IntegerData));
410
-
411
-      NdisReadConfiguration (&status, &parm, configHandle, &mkey, NdisParameterString);
412
-      if (status == NDIS_STATUS_SUCCESS)
413
-	{
414
-	  if (parm->ParameterType == NdisParameterString)
415
-	    {
416
-	      DEBUGP (("[TAP] NdisReadConfiguration (MiniportName=%.*S)\n",
417
-		       parm->ParameterData.StringData.Length/2,
418
-		       parm->ParameterData.StringData.Buffer));
419
-
420
-	      if (RtlUnicodeStringToAnsiString (
421
-						&l_Adapter->m_NameAnsi,
422
-						&parm->ParameterData.StringData,
423
-						TRUE) != STATUS_SUCCESS)
424
-		{
425
-		  DEBUGP (("[TAP] MiniportName failed\n"));
426
-		  status = NDIS_STATUS_RESOURCES;
427
-		}
428
-	    }
429
-	}
430
-      else
431
-	{
432
-	  /* "MiniportName" is available only XP and above.  Not on Windows 2000. */
433
-	  if (vstatus == NDIS_STATUS_SUCCESS && vparm->ParameterData.IntegerData == 0x50000)
434
-	    {
435
-	      /* Fallback for Windows 2000 with NDIS version 5.00.00
436
-		 Don't use this on Vista, 'NDIS_MINIPORT_BLOCK' was changed! */
437
-	      if (RtlUnicodeStringToAnsiString (&l_Adapter->m_NameAnsi,
438
-						&((struct WIN2K_NDIS_MINIPORT_BLOCK *) p_AdapterHandle)->MiniportName,
439
-						TRUE) != STATUS_SUCCESS)
440
-		{
441
-		  DEBUGP (("[TAP] MiniportName (W2K) failed\n"));
442
-		  status = NDIS_STATUS_RESOURCES;
443
-		}
444
-	      else
445
-		{
446
-		  DEBUGP (("[TAP] MiniportName (W2K) succeeded: %s\n", l_Adapter->m_NameAnsi.Buffer));
447
-		  status = NDIS_STATUS_SUCCESS;
448
-		}
449
-	    }
450
-	}
451
-    }
452
-
453
-    /* Can't continue without name (see macro 'NAME') */
454
-    if (status != NDIS_STATUS_SUCCESS || !l_Adapter->m_NameAnsi.Buffer)
455
-      {
456
-	NdisCloseConfiguration (configHandle);
457
-	AdapterFreeResources (l_Adapter);
458
-	DEBUGP (("[TAP] failed to get miniport name\n"));
459
-	return NDIS_STATUS_RESOURCES;
460
-      }
461
-
462
-    /* Read MTU setting from registry */
463
-    {
464
-      NDIS_STRING key = NDIS_STRING_CONST("MTU");
465
-      NdisReadConfiguration (&status, &parm, configHandle,
466
-			     &key, NdisParameterInteger);
467
-      if (status == NDIS_STATUS_SUCCESS)
468
-	{
469
-	  if (parm->ParameterType == NdisParameterInteger)
470
-	    {
471
-	      int mtu = parm->ParameterData.IntegerData;
472
-	      if (mtu < MINIMUM_MTU)
473
-		mtu = MINIMUM_MTU;
474
-	      if (mtu > MAXIMUM_MTU)
475
-		mtu = MAXIMUM_MTU;
476
-	      l_Adapter->m_MTU = mtu;
477
-	    }
478
-	}
479
-    }
480
-
481
-    /* Read Media Status setting from registry */
482
-    {
483
-      NDIS_STRING key = NDIS_STRING_CONST("MediaStatus");
484
-      NdisReadConfiguration (&status, &parm, configHandle,
485
-			     &key, NdisParameterInteger);
486
-      if (status == NDIS_STATUS_SUCCESS)
487
-	{
488
-	  if (parm->ParameterType == NdisParameterInteger)
489
-	    {
490
-	      if (parm->ParameterData.IntegerData)
491
-		{
492
-		  l_Adapter->m_MediaStateAlwaysConnected = TRUE;
493
-		  l_Adapter->m_MediaState = TRUE;
494
-		}
495
-	    }
496
-	}
497
-    }
498
-
499
-#if ENABLE_NONADMIN
500
-    /* Read AllowNonAdmin setting from registry */
501
-    {
502
-      NDIS_STRING key = NDIS_STRING_CONST("AllowNonAdmin");
503
-      NdisReadConfiguration (&status, &parm, configHandle,
504
-			     &key, NdisParameterInteger);
505
-      if (status == NDIS_STATUS_SUCCESS)
506
-	{
507
-	  if (parm->ParameterType == NdisParameterInteger)
508
-	    {
509
-	      if (parm->ParameterData.IntegerData)
510
-		{
511
-		  enable_non_admin = TRUE;
512
-		}
513
-	    }
514
-	}
515
-    }
516
-#endif
517
-
518
-    /* Read optional MAC setting from registry */
519
-    {
520
-      NDIS_STRING key = NDIS_STRING_CONST("MAC");
521
-      ANSI_STRING mac_string;
522
-      NdisReadConfiguration (&status, &parm, configHandle,
523
-			     &key, NdisParameterString);
524
-      if (status == NDIS_STATUS_SUCCESS)
525
-	{
526
-	  if (parm->ParameterType == NdisParameterString)
527
-	    {
528
-	      if (RtlUnicodeStringToAnsiString (&mac_string, &parm->ParameterData.StringData, TRUE) == STATUS_SUCCESS)
529
-		{
530
-		  l_MacFromRegistry = ParseMAC (l_Adapter->m_MAC, mac_string.Buffer);
531
-		  RtlFreeAnsiString (&mac_string);
532
-		}
533
-	    }
534
-	}
535
-    }
536
-
537
-    NdisCloseConfiguration (configHandle);
538
-
539
-    DEBUGP (("[%s] MTU=%d\n", NAME (l_Adapter), l_Adapter->m_MTU));
540
-  }
541
-
542
-  //==================================
543
-  // Store and update MAC address info
544
-  //==================================
545
-
546
-  if (!l_MacFromRegistry)
547
-    GenerateRandomMac (l_Adapter->m_MAC, NAME (l_Adapter));
548
-
549
-  DEBUGP (("[%s] Using MAC %x:%x:%x:%x:%x:%x\n",
550
-	   NAME (l_Adapter),
551
-	   l_Adapter->m_MAC[0], l_Adapter->m_MAC[1], l_Adapter->m_MAC[2],
552
-	   l_Adapter->m_MAC[3], l_Adapter->m_MAC[4], l_Adapter->m_MAC[5]));
553
-
554
-  //==================
555
-  // Set broadcast MAC
556
-  //==================
557
-  {
558
-    int i;
559
-    for (i = 0; i < sizeof (MACADDR); ++i)
560
-      l_Adapter->m_MAC_Broadcast[i] = 0xFF;
561
-  }
562
-
563
-  //====================================
564
-  // Initialize TAP device
565
-  //====================================
566
-  {
567
-    NDIS_STATUS tap_status;
568
-    tap_status = CreateTapDevice (&l_Adapter->m_Extension, NAME (l_Adapter));
569
-    if (tap_status != NDIS_STATUS_SUCCESS)
570
-      {
571
-	AdapterFreeResources (l_Adapter);
572
-	DEBUGP (("[TAP] CreateTapDevice failed\n"));
573
-	return tap_status;
574
-      }
575
-  }
576
-
577
-  if (!AddAdapterToInstanceList (l_Adapter))
578
-    {
579
-      NOTE_ERROR ();
580
-      TapDeviceFreeResources (&l_Adapter->m_Extension);
581
-      AdapterFreeResources (l_Adapter);
582
-      DEBUGP (("[TAP] AddAdapterToInstanceList failed\n"));
583
-      return NDIS_STATUS_RESOURCES;
584
-    }
585
-
586
-  l_Adapter->m_InterfaceIsRunning = TRUE;
587
-
588
-#if ENABLE_NONADMIN
589
-  if (enable_non_admin)
590
-    AllowNonAdmin (&l_Adapter->m_Extension);
591
-#endif
592
-
593
-  return NDIS_STATUS_SUCCESS;
594
-}
595
-
596
-VOID
597
-AdapterHalt (IN NDIS_HANDLE p_AdapterContext)
598
-{
599
-  BOOLEAN status;
600
-
601
-  TapAdapterPointer l_Adapter = (TapAdapterPointer) p_AdapterContext;
602
-
603
-  NOTE_ERROR ();
604
-
605
-  l_Adapter->m_InterfaceIsRunning = FALSE;
606
-
607
-  DEBUGP (("[%s] is being halted\n", NAME (l_Adapter)));
608
-  
609
-  DestroyTapDevice (&l_Adapter->m_Extension);
610
-
611
-  // Free resources
612
-  DEBUGP (("[%s] Freeing Resources\n", NAME (l_Adapter)));
613
-  AdapterFreeResources (l_Adapter);
614
-
615
-  status = RemoveAdapterFromInstanceList (l_Adapter);
616
-  DEBUGP (("[TAP] RemoveAdapterFromInstanceList returned %d\n", (int) status));
617
-
618
-  DEBUGP (("[TAP] version [%d.%d] %s %s AdapterHalt returning\n",
619
-	   TAP_DRIVER_MAJOR_VERSION,
620
-	   TAP_DRIVER_MINOR_VERSION,
621
-	   __DATE__,
622
-	   __TIME__));
623
-}
624
-
625
-VOID
626
-AdapterFreeResources (TapAdapterPointer p_Adapter)
627
-{
628
-  MYASSERT (!p_Adapter->m_CalledAdapterFreeResources);
629
-  p_Adapter->m_CalledAdapterFreeResources = TRUE;
630
-
631
-  if (p_Adapter->m_NameAnsi.Buffer)
632
-    RtlFreeAnsiString (&p_Adapter->m_NameAnsi);
633
-  
634
-  if (p_Adapter->m_RegisteredAdapterShutdownHandler)
635
-    NdisMDeregisterAdapterShutdownHandler (p_Adapter->m_MiniportAdapterHandle);
636
-
637
-  if (p_Adapter->m_MCLockAllocated)
638
-    NdisFreeSpinLock (&p_Adapter->m_MCLock);
639
-}
640
-
641
-VOID
642
-DestroyTapDevice (TapExtensionPointer p_Extension)
643
-{
644
-  DEBUGP (("[%s] Destroying tap device\n", p_Extension->m_TapName));
645
-
646
-  //======================================
647
-  // Let clients know we are shutting down
648
-  //======================================
649
-  p_Extension->m_TapIsRunning = FALSE;
650
-  p_Extension->m_TapOpens = 0;
651
-  p_Extension->m_Halt = TRUE;
652
-
653
-  //=====================================
654
-  // If we are concurrently executing in
655
-  // TapDeviceHook or AdapterTransmit,
656
-  // give those calls time to finish.
657
-  // Note that we must be running at IRQL
658
-  // < DISPATCH_LEVEL in order to call
659
-  // NdisMSleep.
660
-  //=====================================
661
-  NdisMSleep (500000);
662
-
663
-  //===========================================================
664
-  // Exhaust IRP and packet queues.  Any pending IRPs will
665
-  // be cancelled, causing user-space to get this error
666
-  // on overlapped reads:
667
-  //   The I/O operation has been aborted because of either a
668
-  //   thread exit or an application request.   (code=995)
669
-  // It's important that user-space close the device handle
670
-  // when this code is returned, so that when we finally
671
-  // do a NdisMDeregisterDevice, the device reference count
672
-  // is 0.  Otherwise the driver will not unload even if the
673
-  // the last adapter has been halted.
674
-  //===========================================================
675
-  FlushQueues (p_Extension);
676
-  NdisMSleep (500000); // give user space time to respond to IRP cancel
677
-
678
-  TapDeviceFreeResources (p_Extension);
679
-}
680
-
681
-VOID
682
-TapDeviceFreeResources (TapExtensionPointer p_Extension)
683
-{
684
-  MYASSERT (p_Extension);
685
-  MYASSERT (!p_Extension->m_CalledTapDeviceFreeResources);
686
-  p_Extension->m_CalledTapDeviceFreeResources = TRUE;
687
-
688
-  if (p_Extension->m_PacketQueue)
689
-    QueueFree (p_Extension->m_PacketQueue);
690
-  if (p_Extension->m_IrpQueue)
691
-    QueueFree (p_Extension->m_IrpQueue);
692
-  if (p_Extension->m_InjectQueue)
693
-    QueueFree (p_Extension->m_InjectQueue);
694
-
695
-  if (p_Extension->m_CreatedUnicodeLinkName)
696
-    RtlFreeUnicodeString (&p_Extension->m_UnicodeLinkName);
697
-
698
-  //==========================================================
699
-  // According to DDK docs, the device is not actually deleted
700
-  // until its reference count falls to zero.  That means we
701
-  // still need to gracefully fail TapDeviceHook requests
702
-  // after this point, otherwise ugly things would happen if
703
-  // the device was disabled (e.g. in the network connections
704
-  // control panel) while a userspace app still held an open
705
-  // file handle to it.
706
-  //==========================================================
707
-  
708
-  if (p_Extension->m_TapDevice)
709
-    {
710
-      BOOLEAN status;
711
-      status = (NdisMDeregisterDevice (p_Extension->m_TapDeviceHandle)
712
-		== NDIS_STATUS_SUCCESS);
713
-      DEBUGP (("[TAP] Deregistering TAP device, status=%d\n", (int)status));
714
-    }
715
-
716
-  if (p_Extension->m_TapName)
717
-    MemFree (p_Extension->m_TapName, NAME_BUFFER_SIZE);
718
-  
719
-  if (p_Extension->m_InjectDpcInitialized)
720
-    KeRemoveQueueDpc (&p_Extension->m_InjectDpc);
721
-
722
-  if (p_Extension->m_AllocatedSpinlocks)
723
-    {
724
-      NdisFreeSpinLock (&p_Extension->m_QueueLock);
725
-      NdisFreeSpinLock (&p_Extension->m_InjectLock);
726
-    }
727
-}
728
-
729
-//========================================================================
730
-//                             Tap Device Initialization
731
-//========================================================================
732
-
733
-NDIS_STATUS
734
-CreateTapDevice (TapExtensionPointer p_Extension, const char *p_Name)
735
-{
736
-# define SIZEOF_DISPATCH (sizeof(PDRIVER_DISPATCH) * (IRP_MJ_MAXIMUM_FUNCTION + 1))
737
-  PDRIVER_DISPATCH *l_Dispatch = NULL;
738
-  ANSI_STRING l_TapString, l_LinkString;
739
-  UNICODE_STRING l_TapUnicode;
740
-  BOOLEAN l_FreeTapUnicode = FALSE;
741
-  NTSTATUS l_Status, l_Return = NDIS_STATUS_SUCCESS;
742
-  const char *l_UsableName;
743
-
744
-  DEBUGP (("[TAP] version [%d.%d] creating tap device: %s\n",
745
-	   TAP_DRIVER_MAJOR_VERSION,
746
-	   TAP_DRIVER_MINOR_VERSION,
747
-	   p_Name));
748
-
749
-  NdisZeroMemory (p_Extension, sizeof (TapExtension));
750
-
751
-  INIT_MUTEX (&p_Extension->m_OpenCloseMutex);
752
-
753
-  l_LinkString.Buffer = NULL;
754
-  l_TapString.Buffer = NULL;
755
-
756
-  l_TapString.MaximumLength = l_LinkString.MaximumLength = NAME_BUFFER_SIZE;
757
-
758
-  //=======================================
759
-  // Set TAP device entry points
760
-  //=======================================
761
-
762
-  if ((l_Dispatch = MemAlloc (SIZEOF_DISPATCH, TRUE)) == NULL)
763
-    {
764
-      DEBUGP (("[%s] couldn't alloc TAP dispatch table\n", p_Name));
765
-      l_Return = NDIS_STATUS_RESOURCES;
766
-      goto cleanup;
767
-    }
768
-
769
-  l_Dispatch[IRP_MJ_DEVICE_CONTROL] = TapDeviceHook;
770
-  l_Dispatch[IRP_MJ_READ] = TapDeviceHook;
771
-  l_Dispatch[IRP_MJ_WRITE] = TapDeviceHook;
772
-  l_Dispatch[IRP_MJ_CREATE] = TapDeviceHook;
773
-  l_Dispatch[IRP_MJ_CLOSE] = TapDeviceHook;
774
-
775
-  //==================================
776
-  // Find the beginning of the GUID
777
-  //==================================
778
-  l_UsableName = p_Name;
779
-  while (*l_UsableName != '{')
780
-    {
781
-      if (*l_UsableName == '\0')
782
-	{
783
-	  DEBUGP (("[%s] couldn't find leading '{' in name\n", p_Name));
784
-	  l_Return = NDIS_STATUS_RESOURCES;
785
-	  goto cleanup;
786
-	}
787
-      ++l_UsableName;
788
-    }
789
-
790
-  //==================================
791
-  // Allocate pool for TAP device name
792
-  //==================================
793
-
794
-  if ((p_Extension->m_TapName = l_TapString.Buffer =
795
-       MemAlloc (NAME_BUFFER_SIZE, TRUE)) == NULL)
796
-    {
797
-      DEBUGP (("[%s] couldn't alloc TAP name buffer\n", p_Name));
798
-      l_Return = NDIS_STATUS_RESOURCES;
799
-      goto cleanup;
800
-    }
801
-
802
-  //================================================
803
-  // Allocate pool for TAP symbolic link name buffer
804
-  //================================================
805
-
806
-  if ((l_LinkString.Buffer =
807
-       MemAlloc (NAME_BUFFER_SIZE, TRUE)) == NULL)
808
-    {
809
-      DEBUGP (("[%s] couldn't alloc TAP symbolic link name buffer\n",
810
-	       p_Name));
811
-      l_Return = NDIS_STATUS_RESOURCES;
812
-      goto cleanup;
813
-    }
814
-
815
-  //=======================================================
816
-  // Set TAP device name
817
-  //=======================================================
818
-
819
-  l_Status = RtlStringCchPrintfExA
820
-    (l_TapString.Buffer,
821
-     l_TapString.MaximumLength,
822
-     NULL,
823
-     NULL,
824
-     STRSAFE_FILL_BEHIND_NULL | STRSAFE_IGNORE_NULLS,
825
-     "%s%s%s",
826
-     SYSDEVICEDIR,
827
-     l_UsableName,
828
-     TAPSUFFIX);
829
-
830
-  if (l_Status != STATUS_SUCCESS)
831
-    {
832
-      DEBUGP (("[%s] couldn't format TAP device name\n",
833
-	       p_Name));
834
-      l_Return = NDIS_STATUS_RESOURCES;
835
-      goto cleanup;
836
-    }
837
-  l_TapString.Length = (USHORT) strlen (l_TapString.Buffer);
838
-
839
-  DEBUGP (("TAP DEV NAME: '%s'\n", l_TapString.Buffer));
840
-
841
-  //=======================================================
842
-  // Set TAP link name
843
-  //=======================================================
844
-
845
-  l_Status = RtlStringCchPrintfExA
846
-    (l_LinkString.Buffer,
847
-     l_LinkString.MaximumLength,
848
-     NULL,
849
-     NULL,
850
-     STRSAFE_FILL_BEHIND_NULL | STRSAFE_IGNORE_NULLS,
851
-     "%s%s%s",
852
-     USERDEVICEDIR,
853
-     l_UsableName,
854
-     TAPSUFFIX);
855
-
856
-  if (l_Status != STATUS_SUCCESS)
857
-    {
858
-      DEBUGP (("[%s] couldn't format TAP device symbolic link\n",
859
-	       p_Name));
860
-      l_Return = NDIS_STATUS_RESOURCES;
861
-      goto cleanup;
862
-    }
863
-  l_LinkString.Length = (USHORT) strlen (l_LinkString.Buffer);
864
-
865
-  DEBUGP (("TAP LINK NAME: '%s'\n", l_LinkString.Buffer));
866
-
867
-  //==================================================
868
-  // Convert strings to unicode
869
-  //==================================================
870
-  if (RtlAnsiStringToUnicodeString (&l_TapUnicode, &l_TapString, TRUE) !=
871
-      STATUS_SUCCESS)
872
-    {
873
-      DEBUGP (("[%s] couldn't alloc TAP unicode name buffer\n",
874
-		p_Name));
875
-      l_Return = NDIS_STATUS_RESOURCES;
876
-      goto cleanup;
877
-    }
878
-  l_FreeTapUnicode = TRUE;
879
-
880
-  if (RtlAnsiStringToUnicodeString
881
-      (&p_Extension->m_UnicodeLinkName, &l_LinkString, TRUE)
882
-      != STATUS_SUCCESS)
883
-    {
884
-      DEBUGP
885
-	(("[%s] Couldn't allocate unicode string for symbolic link name\n",
886
-	 p_Name));
887
-      l_Return = NDIS_STATUS_RESOURCES;
888
-      goto cleanup;
889
-    }
890
-  p_Extension->m_CreatedUnicodeLinkName = TRUE;
891
-
892
-  //==================================================
893
-  // Create new TAP device with symbolic
894
-  // link and associate with adapter.
895
-  //==================================================
896
-
897
-  l_Status = NdisMRegisterDevice
898
-    (g_NdisWrapperHandle,
899
-     &l_TapUnicode,
900
-     &p_Extension->m_UnicodeLinkName,
901
-     l_Dispatch,
902
-     &p_Extension->m_TapDevice,
903
-     &p_Extension->m_TapDeviceHandle
904
-     );
905
-
906
-  if (l_Status != STATUS_SUCCESS)
907
-    {
908
-      DEBUGP (("[%s] couldn't be created\n", p_Name));
909
-      l_Return = NDIS_STATUS_RESOURCES;
910
-      goto cleanup;
911
-    }
912
-
913
-  /* Set TAP device flags */
914
-  p_Extension->m_TapDevice->Flags |= DO_DIRECT_IO;
915
-
916
-  //========================================================
917
-  // Initialize Packet and IRP queues.
918
-  //
919
-  // The packet queue is used to buffer data which has been
920
-  // "transmitted" by the virtual NIC, before user space
921
-  // has had a chance to read it.
922
-  //
923
-  // The IRP queue is used to buffer pending I/O requests
924
-  // from userspace, i.e. read requests on the TAP device
925
-  // waiting for the system to "transmit" something through
926
-  // the virtual NIC.
927
-  //
928
-  // Basically, packets in the packet queue are used
929
-  // to satisfy IRP requests in the IRP queue.
930
-  //
931
-  // QueueLock is used to lock the packet queue used
932
-  // for the TAP-Win32 NIC -> User Space packet flow direction.
933
-  //
934
-  // All accesses to packet or IRP queues should be
935
-  // bracketed by the QueueLock spinlock,
936
-  // in order to be SMP-safe.
937
-  //========================================================
938
-
939
-  NdisAllocateSpinLock (&p_Extension->m_QueueLock);
940
-  NdisAllocateSpinLock (&p_Extension->m_InjectLock);
941
-  p_Extension->m_AllocatedSpinlocks = TRUE;
942
-
943
-  p_Extension->m_PacketQueue = QueueInit (PACKET_QUEUE_SIZE);
944
-  p_Extension->m_IrpQueue = QueueInit (IRP_QUEUE_SIZE);
945
-  p_Extension->m_InjectQueue = QueueInit (INJECT_QUEUE_SIZE);
946
-  if (!p_Extension->m_PacketQueue
947
-      || !p_Extension->m_IrpQueue
948
-      || !p_Extension->m_InjectQueue)
949
-    {
950
-      DEBUGP (("[%s] couldn't alloc TAP queues\n", p_Name));
951
-      l_Return = NDIS_STATUS_RESOURCES;
952
-      goto cleanup;
953
-    }
954
-
955
-  //=================================================================
956
-  // Initialize deferred procedure call for DHCP/ARP packet injection
957
-  //=================================================================
958
-
959
-  KeInitializeDpc (&p_Extension->m_InjectDpc, InjectPacketDpc, NULL);
960
-  p_Extension->m_InjectDpcInitialized = TRUE;
961
-
962
-  //========================
963
-  // Finalize initialization
964
-  //========================
965
-
966
-  p_Extension->m_TapIsRunning = TRUE;
967
-
968
-  DEBUGP (("[%s] successfully created TAP device [%s]\n", p_Name,
969
-	    p_Extension->m_TapName));
970
-
971
- cleanup:
972
-  if (l_FreeTapUnicode)
973
-    RtlFreeUnicodeString (&l_TapUnicode);
974
-  if (l_LinkString.Buffer)
975
-    MemFree (l_LinkString.Buffer, NAME_BUFFER_SIZE);
976
-  if (l_Dispatch)
977
-    MemFree (l_Dispatch, SIZEOF_DISPATCH);
978
-
979
-  if (l_Return != NDIS_STATUS_SUCCESS)
980
-    TapDeviceFreeResources (p_Extension);
981
-
982
-  return l_Return;
983
-}
984
-#undef SIZEOF_DISPATCH
985
-
986
-//========================================================
987
-//                      Adapter Control
988
-//========================================================
989
-NDIS_STATUS
990
-AdapterReset (OUT PBOOLEAN p_AddressingReset, IN NDIS_HANDLE p_AdapterContext)
991
-{
992
-  TapAdapterPointer l_Adapter = (TapAdapterPointer) p_AdapterContext;
993
-  DEBUGP (("[%s] is resetting\n", NAME (l_Adapter)));
994
-  return NDIS_STATUS_SUCCESS;
995
-}
996
-
997
-NDIS_STATUS AdapterReceive
998
-  (OUT PNDIS_PACKET p_Packet,
999
-   OUT PUINT p_Transferred,
1000
-   IN NDIS_HANDLE p_AdapterContext,
1001
-   IN NDIS_HANDLE p_ReceiveContext,
1002
-   IN UINT p_Offset,
1003
-   IN UINT p_ToTransfer)
1004
-{
1005
-  return NDIS_STATUS_SUCCESS;
1006
-}
1007
-
1008
-//==============================================================
1009
-//                  Adapter Option Query/Modification
1010
-//==============================================================
1011
-NDIS_STATUS AdapterQuery
1012
-(IN NDIS_HANDLE p_AdapterContext,
1013
- IN NDIS_OID p_OID,
1014
- IN PVOID p_Buffer,
1015
- IN ULONG p_BufferLength,
1016
- OUT PULONG p_BytesWritten, OUT PULONG p_BytesNeeded)
1017
-{
1018
-  TapAdapterPointer l_Adapter = (TapAdapterPointer) p_AdapterContext;
1019
-  TapAdapterQuery l_Query, *l_QueryPtr = &l_Query;
1020
-  NDIS_STATUS l_Status = NDIS_STATUS_SUCCESS;
1021
-  UINT l_QueryLength = 4;
1022
-  BOOLEAN lock_succeeded;
1023
-
1024
-  NdisZeroMemory (&l_Query, sizeof (l_Query));
1025
-
1026
-  switch (p_OID)
1027
-    {
1028
-      //===================================================================
1029
-      //                       Vendor & Driver version Info
1030
-      //===================================================================
1031
-    case OID_GEN_VENDOR_DESCRIPTION:
1032
-      l_QueryPtr = (TapAdapterQueryPointer) PRODUCT_STRING;
1033
-      l_QueryLength = strlen (PRODUCT_STRING) + 1;
1034
-      break;
1035
-
1036
-    case OID_GEN_VENDOR_ID:
1037
-      l_Query.m_Long = 0xffffff;
1038
-      break;
1039
-
1040
-    case OID_GEN_DRIVER_VERSION:
1041
-      l_Query.m_Short =
1042
-	(((USHORT) TAP_NDIS_MAJOR_VERSION) << 8 | (USHORT)
1043
-	 TAP_NDIS_MINOR_VERSION);
1044
-      l_QueryLength = sizeof (unsigned short);
1045
-      break;
1046
-
1047
-    case OID_GEN_VENDOR_DRIVER_VERSION:
1048
-      l_Query.m_Long =
1049
-	(((USHORT) TAP_DRIVER_MAJOR_VERSION) << 8 | (USHORT)
1050
-	 TAP_DRIVER_MINOR_VERSION);
1051
-      break;
1052
-
1053
-      //=================================================================
1054
-      //                             Statistics
1055
-      //=================================================================
1056
-    case OID_GEN_RCV_NO_BUFFER:
1057
-      l_Query.m_Long = 0;
1058
-      break;
1059
-
1060
-    case OID_802_3_RCV_ERROR_ALIGNMENT:
1061
-      l_Query.m_Long = 0;
1062
-      break;
1063
-
1064
-    case OID_802_3_XMIT_ONE_COLLISION:
1065
-      l_Query.m_Long = 0;
1066
-      break;
1067
-
1068
-    case OID_802_3_XMIT_MORE_COLLISIONS:
1069
-      l_Query.m_Long = 0;
1070
-      break;
1071
-
1072
-    case OID_GEN_XMIT_OK:
1073
-      l_Query.m_Long = l_Adapter->m_Tx;
1074
-      break;
1075
-
1076
-    case OID_GEN_RCV_OK:
1077
-      l_Query.m_Long = l_Adapter->m_Rx;
1078
-      break;
1079
-
1080
-    case OID_GEN_XMIT_ERROR:
1081
-      l_Query.m_Long = l_Adapter->m_TxErr;
1082
-      break;
1083
-
1084
-    case OID_GEN_RCV_ERROR:
1085
-      l_Query.m_Long = l_Adapter->m_RxErr;
1086
-      break;
1087
-
1088
-      //===================================================================
1089
-      //                       Device & Protocol Options
1090
-      //===================================================================
1091
-    case OID_GEN_SUPPORTED_LIST:
1092
-      l_QueryPtr = (TapAdapterQueryPointer) g_SupportedOIDList;
1093
-      l_QueryLength = sizeof (g_SupportedOIDList);
1094
-      break;
1095
-
1096
-    case OID_GEN_MAC_OPTIONS:
1097
-      // This MUST be here !!!
1098
-      l_Query.m_Long = (NDIS_MAC_OPTION_RECEIVE_SERIALIZED
1099
-			| NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA
1100
-			| NDIS_MAC_OPTION_NO_LOOPBACK
1101
-			| NDIS_MAC_OPTION_TRANSFERS_NOT_PEND);
1102
-
1103
-      break;
1104
-
1105
-    case OID_GEN_CURRENT_PACKET_FILTER:
1106
-      l_Query.m_Long =
1107
-	(NDIS_PACKET_TYPE_ALL_LOCAL |
1108
-	 NDIS_PACKET_TYPE_BROADCAST |
1109
-	 NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_ALL_FUNCTIONAL);
1110
-
1111
-      break;
1112
-
1113
-    case OID_GEN_PROTOCOL_OPTIONS:
1114
-      l_Query.m_Long = 0;
1115
-      break;
1116
-
1117
-      //==================================================================
1118
-      //                            Device Info
1119
-      //==================================================================
1120
-    case OID_GEN_MEDIA_CONNECT_STATUS:
1121
-      l_Query.m_Long = l_Adapter->m_MediaState
1122
-	? NdisMediaStateConnected : NdisMediaStateDisconnected;
1123
-      break;
1124
-
1125
-    case OID_GEN_HARDWARE_STATUS:
1126
-      l_Query.m_HardwareStatus = NdisHardwareStatusReady;
1127
-      l_QueryLength = sizeof (NDIS_HARDWARE_STATUS);
1128
-      break;
1129
-
1130
-    case OID_GEN_MEDIA_SUPPORTED:
1131
-    case OID_GEN_MEDIA_IN_USE:
1132
-      l_Query.m_Medium = l_Adapter->m_Medium;
1133
-      l_QueryLength = sizeof (NDIS_MEDIUM);
1134
-      break;
1135
-
1136
-    case OID_GEN_PHYSICAL_MEDIUM:
1137
-      l_Query.m_PhysicalMedium = NdisPhysicalMediumUnspecified;
1138
-      l_QueryLength = sizeof (NDIS_PHYSICAL_MEDIUM);
1139
-      break;
1140
-      
1141
-    case OID_GEN_LINK_SPEED:
1142
-      l_Query.m_Long = 100000; // rate / 100 bps
1143
-      break;
1144
-
1145
-    case OID_802_3_PERMANENT_ADDRESS:
1146
-    case OID_802_3_CURRENT_ADDRESS:
1147
-      COPY_MAC (l_Query.m_MacAddress, l_Adapter->m_MAC);
1148
-      l_QueryLength = sizeof (MACADDR);
1149
-      break;
1150
-
1151
-      //==================================================================
1152
-      //                             Limits
1153
-      //==================================================================
1154
-
1155
-    case OID_GEN_MAXIMUM_SEND_PACKETS:
1156
-      l_Query.m_Long = 1;
1157
-      break;
1158
-
1159
-    case OID_802_3_MAXIMUM_LIST_SIZE:
1160
-      l_Query.m_Long = NIC_MAX_MCAST_LIST;
1161
-      break;
1162
-
1163
-    case OID_GEN_CURRENT_LOOKAHEAD:
1164
-      l_Query.m_Long = l_Adapter->m_Lookahead;
1165
-      break;
1166
-
1167
-    case OID_GEN_MAXIMUM_LOOKAHEAD:
1168
-    case OID_GEN_MAXIMUM_TOTAL_SIZE:
1169
-    case OID_GEN_RECEIVE_BUFFER_SPACE:
1170
-    case OID_GEN_RECEIVE_BLOCK_SIZE:
1171
-      l_Query.m_Long = DEFAULT_PACKET_LOOKAHEAD;
1172
-      break;
1173
-
1174
-    case OID_GEN_MAXIMUM_FRAME_SIZE:
1175
-    case OID_GEN_TRANSMIT_BLOCK_SIZE:
1176
-    case OID_GEN_TRANSMIT_BUFFER_SPACE:
1177
-      l_Query.m_Long = l_Adapter->m_MTU;
1178
-      break;
1179
-
1180
-    case OID_PNP_CAPABILITIES:
1181
-      do
1182
-	{
1183
-	  PNDIS_PNP_CAPABILITIES pPNPCapabilities;
1184
-	  PNDIS_PM_WAKE_UP_CAPABILITIES pPMstruct;
1185
-
1186
-	  if (p_BufferLength >= sizeof (NDIS_PNP_CAPABILITIES))
1187
-	    {
1188
-	      pPNPCapabilities = (PNDIS_PNP_CAPABILITIES) (p_Buffer);
1189
-
1190
-	      //
1191
-	      // Setting up the buffer to be returned
1192
-	      // to the Protocol above the Passthru miniport
1193
-	      //
1194
-	      pPMstruct = &pPNPCapabilities->WakeUpCapabilities;
1195
-	      pPMstruct->MinMagicPacketWakeUp = NdisDeviceStateUnspecified;
1196
-	      pPMstruct->MinPatternWakeUp = NdisDeviceStateUnspecified;
1197
-	      pPMstruct->MinLinkChangeWakeUp = NdisDeviceStateUnspecified;
1198
-	    }
1199
-	  l_QueryLength = sizeof (NDIS_PNP_CAPABILITIES);
1200
-	}
1201
-      while (FALSE);
1202
-      break;
1203
-    case OID_PNP_QUERY_POWER:
1204
-      break;
1205
-
1206
-      // Required OIDs that we don't support
1207
-
1208
-    case OID_GEN_SUPPORTED_GUIDS:
1209
-    case OID_GEN_MEDIA_CAPABILITIES:
1210
-    case OID_TCP_TASK_OFFLOAD:
1211
-    case OID_FFP_SUPPORT:
1212
-      l_Status = NDIS_STATUS_INVALID_OID;
1213
-      break;
1214
-
1215
-      // Optional stats OIDs
1216
-
1217
-    case OID_GEN_DIRECTED_BYTES_XMIT:
1218
-    case OID_GEN_DIRECTED_FRAMES_XMIT:
1219
-    case OID_GEN_MULTICAST_BYTES_XMIT:
1220
-    case OID_GEN_MULTICAST_FRAMES_XMIT:
1221
-    case OID_GEN_BROADCAST_BYTES_XMIT:
1222
-    case OID_GEN_BROADCAST_FRAMES_XMIT:
1223
-    case OID_GEN_DIRECTED_BYTES_RCV:
1224
-    case OID_GEN_DIRECTED_FRAMES_RCV:
1225
-    case OID_GEN_MULTICAST_BYTES_RCV:
1226
-    case OID_GEN_MULTICAST_FRAMES_RCV:
1227
-    case OID_GEN_BROADCAST_BYTES_RCV:
1228
-    case OID_GEN_BROADCAST_FRAMES_RCV:
1229
-      l_Status = NDIS_STATUS_INVALID_OID;
1230
-      break;
1231
-
1232
-      //===================================================================
1233
-      //                          Not Handled
1234
-      //===================================================================
1235
-    default:
1236
-      DEBUGP (("[%s] Unhandled OID %lx\n", NAME (l_Adapter), p_OID));
1237
-      l_Status = NDIS_STATUS_INVALID_OID;
1238
-      break;
1239
-    }
1240
-
1241
-  if (l_Status != NDIS_STATUS_SUCCESS)
1242
-    ;
1243
-  else if (l_QueryLength > p_BufferLength)
1244
-    {
1245
-      l_Status = NDIS_STATUS_INVALID_LENGTH;
1246
-      *p_BytesNeeded = l_QueryLength;
1247
-    }
1248
-  else
1249
-    NdisMoveMemory (p_Buffer, (PVOID) l_QueryPtr,
1250
-		    (*p_BytesWritten = l_QueryLength));
1251
-
1252
-  return l_Status;
1253
-}
1254
-
1255
-NDIS_STATUS AdapterModify
1256
-(IN NDIS_HANDLE p_AdapterContext,
1257
- IN NDIS_OID p_OID,
1258
- IN PVOID p_Buffer,
1259
- IN ULONG p_BufferLength,
1260
- OUT PULONG p_BytesRead,
1261
- OUT PULONG p_BytesNeeded)
1262
-{
1263
-  TapAdapterQueryPointer l_Query = (TapAdapterQueryPointer) p_Buffer;
1264
-  TapAdapterPointer l_Adapter = (TapAdapterPointer) p_AdapterContext;
1265
-  NDIS_STATUS l_Status = NDIS_STATUS_INVALID_OID;
1266
-  ULONG l_Long;
1267
-
1268
-  switch (p_OID)
1269
-    {
1270
-      //==================================================================
1271
-      //                            Device Info
1272
-      //==================================================================
1273
-    case OID_802_3_MULTICAST_LIST:
1274
-      DEBUGP (("[%s] Setting [OID_802_3_MULTICAST_LIST]\n",
1275
-	       NAME (l_Adapter)));
1276
-
1277
-      *p_BytesNeeded = sizeof (ETH_ADDR);
1278
-      *p_BytesRead = p_BufferLength;
1279
-
1280
-      if (p_BufferLength % sizeof (ETH_ADDR))
1281
-	l_Status = NDIS_STATUS_INVALID_LENGTH;
1282
-      else if (p_BufferLength > sizeof (MC_LIST))
1283
-	{
1284
-	  l_Status = NDIS_STATUS_MULTICAST_FULL;
1285
-	  *p_BytesNeeded = sizeof (MC_LIST);
1286
-	}
1287
-      else
1288
-	{
1289
-	  NdisAcquireSpinLock (&l_Adapter->m_MCLock);
1290
-
1291
-	  NdisZeroMemory(&l_Adapter->m_MCList, sizeof (MC_LIST));
1292
-        
1293
-	  NdisMoveMemory(&l_Adapter->m_MCList,
1294
-			 p_Buffer,
1295
-			 p_BufferLength);
1296
-
1297
-	  l_Adapter->m_MCListSize = p_BufferLength / sizeof (ETH_ADDR);
1298
-        
1299
-	  NdisReleaseSpinLock (&l_Adapter->m_MCLock);
1300
-
1301
-	  l_Status = NDIS_STATUS_SUCCESS;
1302
-	}
1303
-      break;
1304
-
1305
-    case OID_GEN_CURRENT_PACKET_FILTER:
1306
-      l_Status = NDIS_STATUS_INVALID_LENGTH;
1307
-      *p_BytesNeeded = 4;
1308
-
1309
-      if (p_BufferLength >= sizeof (ULONG))
1310
-	{
1311
-	  DEBUGP
1312
-	    (("[%s] Setting [OID_GEN_CURRENT_PACKET_FILTER] to [0x%02lx]\n",
1313
-	      NAME (l_Adapter), l_Query->m_Long));
1314
-	  l_Status = NDIS_STATUS_SUCCESS;
1315
-	  *p_BytesRead = sizeof (ULONG);
1316
-	}
1317
-      break;
1318
-
1319
-    case OID_GEN_CURRENT_LOOKAHEAD:
1320
-      if (p_BufferLength < sizeof (ULONG))
1321
-	{
1322
-	  l_Status = NDIS_STATUS_INVALID_LENGTH;
1323
-	  *p_BytesNeeded = 4;
1324
-	}
1325
-      else if (l_Query->m_Long > DEFAULT_PACKET_LOOKAHEAD
1326
-	       || l_Query->m_Long <= 0)
1327
-	{
1328
-	  l_Status = NDIS_STATUS_INVALID_DATA;
1329
-	}
1330
-      else
1331
-	{
1332
-	  DEBUGP (("[%s] Setting [OID_GEN_CURRENT_LOOKAHEAD] to [%d]\n",
1333
-		   NAME (l_Adapter), l_Query->m_Long));
1334
-	  l_Adapter->m_Lookahead = l_Query->m_Long;
1335
-	  l_Status = NDIS_STATUS_SUCCESS;
1336
-	  *p_BytesRead = sizeof (ULONG);
1337
-	}
1338
-      break;
1339
-
1340
-    case OID_GEN_NETWORK_LAYER_ADDRESSES:
1341
-      l_Status = NDIS_STATUS_SUCCESS;
1342
-      *p_BytesRead = *p_BytesNeeded = 0;
1343
-      break;
1344
-
1345
-    case OID_GEN_TRANSPORT_HEADER_OFFSET:
1346
-      l_Status = NDIS_STATUS_SUCCESS;
1347
-      *p_BytesRead = *p_BytesNeeded = 0;
1348
-      break;
1349
-
1350
-    case OID_PNP_SET_POWER:
1351
-      do
1352
-	{
1353
-	  NDIS_DEVICE_POWER_STATE NewDeviceState;
1354
-
1355
-	  NewDeviceState = (*(PNDIS_DEVICE_POWER_STATE) p_Buffer);
1356
-
1357
-	  switch (NewDeviceState)
1358
-	    {
1359
-	    case NdisDeviceStateD0:
1360
-	      l_Adapter->m_DeviceState = '0';
1361
-	      break;
1362
-	    case NdisDeviceStateD1:
1363
-	      l_Adapter->m_DeviceState = '1';
1364
-	      break;
1365
-	    case NdisDeviceStateD2:
1366
-	      l_Adapter->m_DeviceState = '2';
1367
-	      break;
1368
-	    case NdisDeviceStateD3:
1369
-	      l_Adapter->m_DeviceState = '3';
1370
-	      break;
1371
-	    default:
1372
-	      l_Adapter->m_DeviceState = '?';
1373
-	      break;
1374
-	    }
1375
-
1376
-	  l_Status = NDIS_STATUS_FAILURE;
1377
-
1378
-	  //
1379
-	  // Check for invalid length
1380
-	  //
1381
-	  if (p_BufferLength < sizeof (NDIS_DEVICE_POWER_STATE))
1382
-	    {
1383
-	      l_Status = NDIS_STATUS_INVALID_LENGTH;
1384
-	      break;
1385
-	    }
1386
-
1387
-	  if (NewDeviceState > NdisDeviceStateD0)
1388
-	    {
1389
-	      l_Adapter->m_InterfaceIsRunning = FALSE;
1390
-	      DEBUGP (("[%s] Power management device state OFF\n",
1391
-		       NAME (l_Adapter)));
1392
-	    }
1393
-	  else
1394
-	    {
1395
-	      l_Adapter->m_InterfaceIsRunning = TRUE;
1396
-	      DEBUGP (("[%s] Power management device state ON\n",
1397
-		       NAME (l_Adapter)));
1398
-	    }
1399
-
1400
-	  l_Status = NDIS_STATUS_SUCCESS;
1401
-	}
1402
-      while (FALSE);
1403
-
1404
-      if (l_Status == NDIS_STATUS_SUCCESS)
1405
-	{
1406
-	  *p_BytesRead = sizeof (NDIS_DEVICE_POWER_STATE);
1407
-	  *p_BytesNeeded = 0;
1408
-	}
1409
-      else
1410
-	{
1411
-	  *p_BytesRead = 0;
1412
-	  *p_BytesNeeded = sizeof (NDIS_DEVICE_POWER_STATE);
1413
-	}
1414
-      break;
1415
-
1416
-    case OID_PNP_REMOVE_WAKE_UP_PATTERN:
1417
-    case OID_PNP_ADD_WAKE_UP_PATTERN:
1418
-      l_Status = NDIS_STATUS_SUCCESS;
1419
-      *p_BytesRead = *p_BytesNeeded = 0;
1420
-      break;
1421
-
1422
-    default:
1423
-      DEBUGP (("[%s] Can't set value for OID %lx\n", NAME (l_Adapter),
1424
-	       p_OID));
1425
-      l_Status = NDIS_STATUS_INVALID_OID;
1426
-      *p_BytesRead = *p_BytesNeeded = 0;
1427
-      break;
1428
-    }
1429
-
1430
-  return l_Status;
1431
-}
1432
-
1433
-// checksum code for ICMPv6 packet, taken from dhcp.c / udp_checksum
1434
-// see RFC 4443, 2.3, and RFC 2460, 8.1
1435
-USHORT
1436
-icmpv6_checksum (const UCHAR *buf,
1437
-	         const int len_icmpv6,
1438
-	         const UCHAR *saddr6,
1439
-	         const UCHAR *daddr6)
1440
-{
1441
-  USHORT word16;
1442
-  ULONG sum = 0;
1443
-  int i;
1444
-
1445
-  // make 16 bit words out of every two adjacent 8 bit words and
1446
-  // calculate the sum of all 16 bit words
1447
-  for (i = 0; i < len_icmpv6; i += 2){
1448
-    word16 = ((buf[i] << 8) & 0xFF00) + ((i + 1 < len_icmpv6) ? (buf[i+1] & 0xFF) : 0);
1449
-    sum += word16;
1450
-  }
1451
-
1452
-  // add the IPv6 pseudo header which contains the IP source and destination addresses
1453
-  for (i = 0; i < 16; i += 2){
1454
-    word16 =((saddr6[i] << 8) & 0xFF00) + (saddr6[i+1] & 0xFF);
1455
-    sum += word16;
1456
-  }
1457
-  for (i = 0; i < 16; i += 2){
1458
-    word16 =((daddr6[i] << 8) & 0xFF00) + (daddr6[i+1] & 0xFF);
1459
-    sum += word16;
1460
-  }
1461
-
1462
-  // the next-header number and the length of the ICMPv6 packet
1463
-  sum += (USHORT) IPPROTO_ICMPV6 + (USHORT) len_icmpv6;
1464
-
1465
-  // keep only the last 16 bits of the 32 bit calculated sum and add the carries
1466
-  while (sum >> 16)
1467
-    sum = (sum & 0xFFFF) + (sum >> 16);
1468
-
1469
-  // Take the one's complement of sum
1470
-  return ((USHORT) ~sum);
1471
-}
1472
-
1473
-// check IPv6 packet for "is this an IPv6 Neighbor Solicitation that
1474
-// the tap driver needs to answer?"
1475
-// see RFC 4861 4.3 for the different cases
1476
-static IPV6ADDR IPV6_NS_TARGET_MCAST =
1477
-	{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1478
-          0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x08 };
1479
-static IPV6ADDR IPV6_NS_TARGET_UNICAST =
1480
-	{ 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1481
-          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08 };
1482
-
1483
-BOOLEAN
1484
-HandleIPv6NeighborDiscovery( TapAdapterPointer p_Adapter, UCHAR * m_Data )
1485
-{
1486
-    const ETH_HEADER * e = (ETH_HEADER *) m_Data;
1487
-    const IPV6HDR *ipv6 = (IPV6HDR *) (m_Data + sizeof (ETH_HEADER));
1488
-    const ICMPV6_NS * icmpv6_ns = (ICMPV6_NS *) (m_Data + sizeof (ETH_HEADER) + sizeof (IPV6HDR));
1489
-    ICMPV6_NA_PKT *na;
1490
-    USHORT icmpv6_len, icmpv6_csum;
1491
-
1492
-    // we don't really care about the destination MAC address here
1493
-    // - it's either a multicast MAC, or the userland destination MAC
1494
-    // but since the TAP driver is point-to-point, all packets are "for us"
1495
-
1496
-    // IPv6 target address must be ff02::1::ff00:8 (multicast for
1497
-    // initial NS) or fe80::1 (unicast for recurrent NUD)
1498
-    if ( memcmp( ipv6->daddr, IPV6_NS_TARGET_MCAST,
1499
-		 sizeof(IPV6ADDR) ) != 0 &&
1500
-         memcmp( ipv6->daddr, IPV6_NS_TARGET_UNICAST,
1501
-		 sizeof(IPV6ADDR) ) != 0 )
1502
-    {
1503
-	return FALSE;				// wrong target address
1504
-    }
1505
-
1506
-    // IPv6 Next-Header must be ICMPv6
1507
-    if ( ipv6->nexthdr != IPPROTO_ICMPV6 )
1508
-    {
1509
-	return FALSE;				// wrong next-header
1510
-    }
1511
-
1512
-    // ICMPv6 type+code must be 135/0 for NS
1513
-    if ( icmpv6_ns->type != ICMPV6_TYPE_NS ||
1514
-	 icmpv6_ns->code != ICMPV6_CODE_0 )
1515
-    {
1516
-	return FALSE;				// wrong ICMPv6 type
1517
-    }
1518
-
1519
-    // ICMPv6 target address must be fe80::8 (magic)
1520
-    if ( memcmp( icmpv6_ns->target_addr, IPV6_NS_TARGET_UNICAST,
1521
-	         sizeof(IPV6ADDR) ) != 0 )
1522
-    {
1523
-	return FALSE;				// not for us
1524
-    }
1525
-
1526
-    // packet identified, build magic response packet
1527
-
1528
-    na = (ICMPV6_NA_PKT *) MemAlloc (sizeof (ICMPV6_NA_PKT), TRUE);
1529
-    if ( !na ) return FALSE;
1530
-
1531
-    //------------------------------------------------
1532
-    // Initialize Neighbour Advertisement reply packet
1533
-    //------------------------------------------------
1534
-
1535
-    // ethernet header
1536
-    na->eth.proto = htons(ETH_P_IPV6);
1537
-    COPY_MAC(na->eth.dest, p_Adapter->m_MAC);
1538
-    COPY_MAC(na->eth.src, p_Adapter->m_TapToUser.dest);
1539
-
1540
-    // IPv6 header
1541
-    na->ipv6.version_prio = ipv6->version_prio;
1542
-    NdisMoveMemory( na->ipv6.flow_lbl, ipv6->flow_lbl,
1543
-		    sizeof(na->ipv6.flow_lbl) );
1544
-    icmpv6_len = sizeof(ICMPV6_NA_PKT) - sizeof(ETH_HEADER) - sizeof(IPV6HDR);
1545
-    na->ipv6.payload_len = htons(icmpv6_len);
1546
-    na->ipv6.nexthdr = IPPROTO_ICMPV6;
1547
-    na->ipv6.hop_limit = 255;
1548
-    NdisMoveMemory( na->ipv6.saddr, IPV6_NS_TARGET_UNICAST,
1549
-		    sizeof(IPV6ADDR) );
1550
-    NdisMoveMemory( na->ipv6.daddr, ipv6->saddr,
1551
-		    sizeof(IPV6ADDR) );
1552
-
1553
-    // ICMPv6
1554
-    na->icmpv6.type = ICMPV6_TYPE_NA;
1555
-    na->icmpv6.code = ICMPV6_CODE_0;
1556
-    na->icmpv6.checksum = 0;
1557
-    na->icmpv6.rso_bits = 0x60;		// Solicited + Override
1558
-    NdisZeroMemory( na->icmpv6.reserved, sizeof(na->icmpv6.reserved) );
1559
-    NdisMoveMemory( na->icmpv6.target_addr, IPV6_NS_TARGET_UNICAST,
1560
-		    sizeof(IPV6ADDR) );
1561
-
1562
-    // ICMPv6 option "Target Link Layer Address"
1563
-    na->icmpv6.opt_type = ICMPV6_OPTION_TLLA;
1564
-    na->icmpv6.opt_length = ICMPV6_LENGTH_TLLA;
1565
-    COPY_MAC( na->icmpv6.target_macaddr, p_Adapter->m_TapToUser.dest );
1566
-
1567
-    // calculate and set checksum
1568
-    icmpv6_csum = icmpv6_checksum ( (UCHAR*) &(na->icmpv6),
1569
-				    icmpv6_len,
1570
-				    na->ipv6.saddr,
1571
-				    na->ipv6.daddr );
1572
-    na->icmpv6.checksum = htons( icmpv6_csum );
1573
-
1574
-    DUMP_PACKET ("HandleIPv6NeighborDiscovery",
1575
-		 (unsigned char *) na,
1576
-		 sizeof (ICMPV6_NA_PKT));
1577
-
1578
-    InjectPacketDeferred (p_Adapter, (UCHAR *) na, sizeof (ICMPV6_NA_PKT));
1579
-
1580
-    MemFree (na, sizeof (ICMPV6_NA_PKT));
1581
-
1582
-    return TRUE;				// all fine
1583
-}
1584
-
1585
-//====================================================================
1586
-//                               Adapter Transmission
1587
-//====================================================================
1588
-NDIS_STATUS
1589
-AdapterTransmit (IN NDIS_HANDLE p_AdapterContext,
1590
-		 IN PNDIS_PACKET p_Packet,
1591
-		 IN UINT p_Flags)
1592
-{
1593
-  TapAdapterPointer l_Adapter = (TapAdapterPointer) p_AdapterContext;
1594
-  ULONG l_Index = 0, l_PacketLength = 0;
1595
-  UINT l_BufferLength = 0;
1596
-  PIRP l_IRP;
1597
-  TapPacketPointer l_PacketBuffer;
1598
-  PNDIS_BUFFER l_NDIS_Buffer;
1599
-  PUCHAR l_Buffer;
1600
-  PVOID result;
1601
-
1602
-  NdisQueryPacket (p_Packet, NULL, NULL, &l_NDIS_Buffer, &l_PacketLength);
1603
-
1604
-  //====================================================
1605
-  // Here we abandon the transmission attempt if any of
1606
-  // the parameters is wrong or memory allocation fails
1607
-  // but we do not indicate failure. The packet is
1608
-  // silently dropped.
1609
-  //====================================================
1610
-
1611
-  if (l_PacketLength < ETHERNET_HEADER_SIZE || l_PacketLength > 65535)
1612
-    goto exit_fail;
1613
-  else if (!l_Adapter->m_Extension.m_TapOpens || !l_Adapter->m_MediaState)
1614
-    goto exit_success;              // Nothing is bound to the TAP device
1615
-
1616
-  if (NdisAllocateMemoryWithTag (&l_PacketBuffer,
1617
-				 TAP_PACKET_SIZE (l_PacketLength),
1618
-				 '5PAT') != NDIS_STATUS_SUCCESS)
1619
-    goto exit_no_resources;
1620
-
1621
-  if (l_PacketBuffer == NULL)
1622
-    goto exit_no_resources;
1623
-
1624
-  l_PacketBuffer->m_SizeFlags = (l_PacketLength & TP_SIZE_MASK);
1625
-
1626
-  //===========================
1627
-  // Reassemble packet contents
1628
-  //===========================
1629
-
1630
-  __try
1631
-  {
1632
-    l_Index = 0;
1633
-    while (l_NDIS_Buffer && l_Index < l_PacketLength)
1634
-      {
1635
-	ULONG newlen;
1636
-	NdisQueryBuffer (l_NDIS_Buffer, (PVOID *) & l_Buffer,
1637
-			 &l_BufferLength);
1638
-	newlen = l_Index + l_BufferLength;
1639
-	if (newlen > l_PacketLength)
1640
-	  {
1641
-	    NOTE_ERROR ();
1642
-	    goto no_queue; /* overflow */
1643
-	  }
1644
-	NdisMoveMemory (l_PacketBuffer->m_Data + l_Index, l_Buffer,
1645
-			l_BufferLength);
1646
-	l_Index = newlen;
1647
-	NdisGetNextBuffer (l_NDIS_Buffer, &l_NDIS_Buffer);
1648
-      }
1649
-    if (l_Index != l_PacketLength)
1650
-      {
1651
-	NOTE_ERROR ();
1652
-	goto no_queue; /* underflow */
1653
-      }
1654
-
1655
-    DUMP_PACKET ("AdapterTransmit", l_PacketBuffer->m_Data, l_PacketLength);
1656
-
1657
-    //=====================================================
1658
-    // If IPv4 packet, check whether or not packet
1659
-    // was truncated.
1660
-    //=====================================================
1661
-#if PACKET_TRUNCATION_CHECK
1662
-    IPv4PacketSizeVerify (l_PacketBuffer->m_Data, l_PacketLength, FALSE, "TX", &l_Adapter->m_TxTrunc);
1663
-#endif
1664
-
1665
-    //=====================================================
1666
-    // Are we running in DHCP server masquerade mode?
1667
-    //
1668
-    // If so, catch both DHCP requests and ARP queries
1669
-    // to resolve the address of our virtual DHCP server.
1670
-    //=====================================================
1671
-    if (l_Adapter->m_dhcp_enabled)
1672
-      {
1673
-	const ETH_HEADER *eth = (ETH_HEADER *) l_PacketBuffer->m_Data;
1674
-	const IPHDR *ip = (IPHDR *) (l_PacketBuffer->m_Data + sizeof (ETH_HEADER));
1675
-	const UDPHDR *udp = (UDPHDR *) (l_PacketBuffer->m_Data + sizeof (ETH_HEADER) + sizeof (IPHDR));
1676
-
1677
-	// ARP packet?
1678
-	if (l_PacketLength == sizeof (ARP_PACKET)
1679
-	    && eth->proto == htons (ETH_P_ARP)
1680
-	    && l_Adapter->m_dhcp_server_arp)
1681
-	  {
1682
-	    if (ProcessARP (l_Adapter,
1683
-			    (PARP_PACKET) l_PacketBuffer->m_Data,
1684
-			    l_Adapter->m_dhcp_addr,
1685
-			    l_Adapter->m_dhcp_server_ip,
1686
-			    ~0,
1687
-			    l_Adapter->m_dhcp_server_mac))
1688
-	      goto no_queue;
1689
-	  }
1690
-
1691
-	// DHCP packet?
1692
-	else if (l_PacketLength >= sizeof (ETH_HEADER) + sizeof (IPHDR) + sizeof (UDPHDR) + sizeof (DHCP)
1693
-		 && eth->proto == htons (ETH_P_IP)
1694
-		 && ip->version_len == 0x45 // IPv4, 20 byte header
1695
-		 && ip->protocol == IPPROTO_UDP
1696
-		 && udp->dest == htons (BOOTPS_PORT))
1697
-	  {
1698
-	    const DHCP *dhcp = (DHCP *) (l_PacketBuffer->m_Data
1699
-					 + sizeof (ETH_HEADER)
1700
-					 + sizeof (IPHDR)
1701
-					 + sizeof (UDPHDR));
1702
-
1703
-	    const int optlen = l_PacketLength
1704
-	      - sizeof (ETH_HEADER)
1705
-	      - sizeof (IPHDR)
1706
-	      - sizeof (UDPHDR)
1707
-	      - sizeof (DHCP);
1708
-
1709
-	    if (optlen > 0) // we must have at least one DHCP option
1710
-	      {
1711
-		if (ProcessDHCP (l_Adapter, eth, ip, udp, dhcp, optlen))
1712
-		  goto no_queue;
1713
-	      }
1714
-	    else
1715
-	      goto no_queue;
1716
-	  }
1717
-      }
1718
-
1719
-    //===============================================
1720
-    // In Point-To-Point mode, check to see whether
1721
-    // packet is ARP (handled) or IPv4 (sent to app).
1722
-    // IPv6 packets are inspected for neighbour discovery
1723
-    // (to be handled locally), and the rest is forwarded
1724
-    // all other protocols are dropped
1725
-    //===============================================
1726
-    if (l_Adapter->m_tun)
1727
-      {
1728
-	ETH_HEADER *e;
1729
-
1730
-	if (l_PacketLength < ETHERNET_HEADER_SIZE)
1731
-	  goto no_queue;
1732
-
1733
-	e = (ETH_HEADER *) l_PacketBuffer->m_Data;
1734
-
1735
-	switch (ntohs (e->proto))
1736
-	  {
1737
-	  case ETH_P_ARP:
1738
-
1739
-	    // Make sure that packet is the
1740
-	    // right size for ARP.
1741
-	    if (l_PacketLength != sizeof (ARP_PACKET))
1742
-	      goto no_queue;
1743
-
1744
-	    ProcessARP (l_Adapter,
1745
-			(PARP_PACKET) l_PacketBuffer->m_Data,
1746
-			l_Adapter->m_localIP,
1747
-			l_Adapter->m_remoteNetwork,
1748
-			l_Adapter->m_remoteNetmask,
1749
-			l_Adapter->m_TapToUser.dest);
1750
-
1751
-	  default:
1752
-	    goto no_queue;
1753
-
1754
-	  case ETH_P_IP:
1755
-
1756
-	    // Make sure that packet is large
1757
-	    // enough to be IPv4.
1758
-	    if (l_PacketLength
1759
-		< ETHERNET_HEADER_SIZE + IP_HEADER_SIZE)
1760
-	      goto no_queue;
1761
-
1762
-	    // Only accept directed packets,
1763
-	    // not broadcasts.
1764
-	    if (memcmp (e, &l_Adapter->m_TapToUser, ETHERNET_HEADER_SIZE))
1765
-	      goto no_queue;
1766
-
1767
-	    // Packet looks like IPv4, queue it.
1768
-	    l_PacketBuffer->m_SizeFlags |= TP_TUN;
1769
-	    break;
1770
-
1771
-	  case ETH_P_IPV6:
1772
-	    // make sure that packet is large
1773
-	    // enough to be IPv6
1774
-	    if (l_PacketLength
1775
-		< ETHERNET_HEADER_SIZE + IPV6_HEADER_SIZE)
1776
-	      goto no_queue;
1777
-
1778
-	    // broadcasts and multicasts are handled specially
1779
-	    // (to be implemented)
1780
-
1781
-	    // neighbor discovery packets to fe80::8 are special
1782
-	    // OpenVPN sets this next-hop to signal "handled by tapdrv"
1783
-	    if ( HandleIPv6NeighborDiscovery( l_Adapter,
1784
-					      l_PacketBuffer->m_Data ))
1785
-	      {
1786
-		goto no_queue;
1787
-	      }
1788
-
1789
-	    // Packet looks like IPv6, queue it :-)
1790
-	    l_PacketBuffer->m_SizeFlags |= TP_TUN;
1791
-	  }
1792
-      }
1793
-
1794
-    //===============================================
1795
-    // Push packet onto queue to wait for read from
1796
-    // userspace.
1797
-    //===============================================
1798
-
1799
-    NdisAcquireSpinLock (&l_Adapter->m_Extension.m_QueueLock);
1800
-
1801
-    result = NULL;
1802
-    if (IS_UP (l_Adapter))
1803
-      result = QueuePush (l_Adapter->m_Extension.m_PacketQueue, l_PacketBuffer);
1804
-
1805
-    NdisReleaseSpinLock (&l_Adapter->m_Extension.m_QueueLock);
1806
-
1807
-    if ((TapPacketPointer) result != l_PacketBuffer)
1808
-      {
1809
-	// adapter receive overrun
1810
-	INCREMENT_STAT (l_Adapter->m_TxErr);
1811
-	goto no_queue;
1812
-      }
1813
-    else
1814
-      {
1815
-	INCREMENT_STAT (l_Adapter->m_Tx);
1816
-      }
1817
-
1818
-    //============================================================
1819
-    // Cycle through IRPs and packets, try to satisfy each pending
1820
-    // IRP with a queued packet.
1821
-    //============================================================
1822
-    while (TRUE)
1823
-      {
1824
-	l_IRP = NULL;
1825
-	l_PacketBuffer = NULL;
1826
-
1827
-	NdisAcquireSpinLock (&l_Adapter->m_Extension.m_QueueLock);
1828
-
1829
-	if (IS_UP (l_Adapter)
1830
-	    && QueueCount (l_Adapter->m_Extension.m_PacketQueue)
1831
-	    && QueueCount (l_Adapter->m_Extension.m_IrpQueue))
1832
-	  {
1833
-	    l_IRP = (PIRP) QueuePop (l_Adapter->m_Extension.m_IrpQueue);
1834
-	    l_PacketBuffer = (TapPacketPointer)
1835
-	      QueuePop (l_Adapter->m_Extension.m_PacketQueue);
1836
-	  }
1837
-
1838
-	NdisReleaseSpinLock (&l_Adapter->m_Extension.m_QueueLock);
1839
-
1840
-	MYASSERT ((l_IRP != NULL) + (l_PacketBuffer != NULL) != 1);
1841
-
1842
-	if (l_IRP && l_PacketBuffer)
1843
-	  {
1844
-	    CompleteIRP (l_IRP,
1845
-			 l_PacketBuffer, 
1846
-			 IO_NETWORK_INCREMENT);
1847
-	  }
1848
-	else
1849
-	  break;
1850
-      }
1851
-  }
1852
-  __except (EXCEPTION_EXECUTE_HANDLER)
1853
-    {
1854
-    }
1855
-
1856
-  return NDIS_STATUS_SUCCESS;
1857
-
1858
- no_queue:
1859
-  NdisFreeMemory (l_PacketBuffer,
1860
-		  TAP_PACKET_SIZE (l_PacketLength),
1861
-		  0);
1862
-  
1863
- exit_success:
1864
-  return NDIS_STATUS_SUCCESS;
1865
-    
1866
- exit_fail:
1867
-  return NDIS_STATUS_FAILURE;
1868
-
1869
- exit_no_resources:
1870
-  return NDIS_STATUS_RESOURCES;
1871
-}
1872
-
1873
-//======================================================================
1874
-// Hooks for catching TAP device IRP's.
1875
-//======================================================================
1876
-
1877
-NTSTATUS
1878
-TapDeviceHook (IN PDEVICE_OBJECT p_DeviceObject, IN PIRP p_IRP)
1879
-{
1880
-  TapAdapterPointer l_Adapter = LookupAdapterInInstanceList (p_DeviceObject);
1881
-  PIO_STACK_LOCATION l_IrpSp;
1882
-  NTSTATUS l_Status = STATUS_SUCCESS;
1883
-  BOOLEAN accessible;
1884
-
1885
-  l_IrpSp = IoGetCurrentIrpStackLocation (p_IRP);
1886
-
1887
-  p_IRP->IoStatus.Status = STATUS_SUCCESS;
1888
-  p_IRP->IoStatus.Information = 0;
1889
-
1890
-  if (!l_Adapter || l_Adapter->m_Extension.m_Halt)
1891
-    {
1892
-      DEBUGP (("TapDeviceHook called when TAP device is halted, MajorFunction=%d\n",
1893
-	       (int)l_IrpSp->MajorFunction));
1894
-
1895
-      if (l_IrpSp->MajorFunction == IRP_MJ_CLOSE)
1896
-	{
1897
-	  IoCompleteRequest (p_IRP, IO_NO_INCREMENT);
1898
-	  return STATUS_SUCCESS;
1899
-	}
1900
-      else
1901
-	{
1902
-	  p_IRP->IoStatus.Status = STATUS_NO_SUCH_DEVICE;
1903
-	  IoCompleteRequest (p_IRP, IO_NO_INCREMENT);
1904
-	  return STATUS_NO_SUCH_DEVICE;
1905
-	}
1906
-    }
1907
-
1908
-  switch (l_IrpSp->MajorFunction)
1909
-    {
1910
-      //===========================================================
1911
-      //                 Ioctl call handlers
1912
-      //===========================================================
1913
-    case IRP_MJ_DEVICE_CONTROL:
1914
-      {
1915
-	switch (l_IrpSp->Parameters.DeviceIoControl.IoControlCode)
1916
-	  {
1917
-	  case TAP_IOCTL_GET_MAC:
1918
-	    {
1919
-	      if (l_IrpSp->Parameters.DeviceIoControl.OutputBufferLength
1920
-		  >= sizeof (MACADDR))
1921
-		{
1922
-		  COPY_MAC (p_IRP->AssociatedIrp.SystemBuffer,
1923
-			    l_Adapter->m_MAC);
1924
-		  p_IRP->IoStatus.Information = sizeof (MACADDR);
1925
-		}
1926
-	      else
1927
-		{
1928
-		  NOTE_ERROR ();
1929
-		  p_IRP->IoStatus.Status = l_Status = STATUS_BUFFER_TOO_SMALL;
1930
-		}
1931
-	      break;
1932
-	    }
1933
-	  case TAP_IOCTL_GET_VERSION:
1934
-	    {
1935
-	      const ULONG size = sizeof (ULONG) * 3;
1936
-	      if (l_IrpSp->Parameters.DeviceIoControl.OutputBufferLength
1937
-		  >= size)
1938
-		{
1939
-		  ((PULONG) (p_IRP->AssociatedIrp.SystemBuffer))[0]
1940
-		    = TAP_DRIVER_MAJOR_VERSION;
1941
-		  ((PULONG) (p_IRP->AssociatedIrp.SystemBuffer))[1]
1942
-		    = TAP_DRIVER_MINOR_VERSION;
1943
-		  ((PULONG) (p_IRP->AssociatedIrp.SystemBuffer))[2]
1944
-#if DBG
1945
-		    = 1;
1946
-#else
1947
-		  = 0;
1948
-#endif
1949
-		  p_IRP->IoStatus.Information = size;
1950
-		}
1951
-	      else
1952
-		{
1953
-		  NOTE_ERROR ();
1954
-		  p_IRP->IoStatus.Status = l_Status = STATUS_BUFFER_TOO_SMALL;
1955
-		}
1956
-
1957
-	      break;
1958
-	    }
1959
-	  case TAP_IOCTL_GET_MTU:
1960
-	    {
1961
-	      const ULONG size = sizeof (ULONG) * 1;
1962
-	      if (l_IrpSp->Parameters.DeviceIoControl.OutputBufferLength
1963
-		  >= size)
1964
-		{
1965
-		  ((PULONG) (p_IRP->AssociatedIrp.SystemBuffer))[0]
1966
-		    = l_Adapter->m_MTU;
1967
-		  p_IRP->IoStatus.Information = size;
1968
-		}
1969
-	      else
1970
-		{
1971
-		  NOTE_ERROR ();
1972
-		  p_IRP->IoStatus.Status = l_Status = STATUS_BUFFER_TOO_SMALL;
1973
-		}
1974
-
1975
-	      break;
1976
-	    }
1977
-	  case TAP_IOCTL_GET_INFO:
1978
-	    {
1979
-	      char state[16];
1980
-	      if (l_Adapter->m_InterfaceIsRunning)
1981
-		state[0] = 'A';
1982
-	      else
1983
-		state[0] = 'a';
1984
-	      if (l_Adapter->m_Extension.m_TapIsRunning)
1985
-		state[1] = 'T';
1986
-	      else
1987
-		state[1] = 't';
1988
-	      state[2] = l_Adapter->m_DeviceState;
1989
-	      if (l_Adapter->m_MediaStateAlwaysConnected)
1990
-		state[3] = 'C';
1991
-	      else
1992
-		state[3] = 'c';
1993
-	      state[4] = '\0';
1994
-
1995
-	      p_IRP->IoStatus.Status = l_Status = RtlStringCchPrintfExA (
1996
-	        ((LPTSTR) (p_IRP->AssociatedIrp.SystemBuffer)),
1997
-		l_IrpSp->Parameters.DeviceIoControl.OutputBufferLength,
1998
-		NULL,
1999
-		NULL,
2000
-		STRSAFE_FILL_BEHIND_NULL | STRSAFE_IGNORE_NULLS,
2001
-#if PACKET_TRUNCATION_CHECK
2002
-		"State=%s Err=[%s/%d] #O=%d Tx=[%d,%d,%d] Rx=[%d,%d,%d] IrpQ=[%d,%d,%d] PktQ=[%d,%d,%d] InjQ=[%d,%d,%d]",
2003
-#else
2004
-		"State=%s Err=[%s/%d] #O=%d Tx=[%d,%d] Rx=[%d,%d] IrpQ=[%d,%d,%d] PktQ=[%d,%d,%d] InjQ=[%d,%d,%d]",
2005
-#endif
2006
-		state,
2007
-		g_LastErrorFilename,
2008
-		g_LastErrorLineNumber,
2009
-		(int)l_Adapter->m_Extension.m_NumTapOpens,
2010
-		(int)l_Adapter->m_Tx,
2011
-		(int)l_Adapter->m_TxErr,
2012
-#if PACKET_TRUNCATION_CHECK
2013
-		(int)l_Adapter->m_TxTrunc,
2014
-#endif
2015
-		(int)l_Adapter->m_Rx,
2016
-		(int)l_Adapter->m_RxErr,
2017
-#if PACKET_TRUNCATION_CHECK
2018
-		(int)l_Adapter->m_RxTrunc,
2019
-#endif
2020
-		(int)l_Adapter->m_Extension.m_IrpQueue->size,
2021
-		(int)l_Adapter->m_Extension.m_IrpQueue->max_size,
2022
-		(int)IRP_QUEUE_SIZE,
2023
-		(int)l_Adapter->m_Extension.m_PacketQueue->size,
2024
-		(int)l_Adapter->m_Extension.m_PacketQueue->max_size,
2025
-		(int)PACKET_QUEUE_SIZE,
2026
-		(int)l_Adapter->m_Extension.m_InjectQueue->size,
2027
-		(int)l_Adapter->m_Extension.m_InjectQueue->max_size,
2028
-		(int)INJECT_QUEUE_SIZE
2029
-		);
2030
-
2031
-	      p_IRP->IoStatus.Information
2032
-		= l_IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
2033
-
2034
-	      break;
2035
-	    }
2036
-
2037
-#if DBG
2038
-	  case TAP_IOCTL_GET_LOG_LINE:
2039
-	    {
2040
-	      if (GetDebugLine ((LPTSTR)p_IRP->AssociatedIrp.SystemBuffer,
2041
-				l_IrpSp->Parameters.DeviceIoControl.OutputBufferLength))
2042
-		p_IRP->IoStatus.Status = l_Status = STATUS_SUCCESS;
2043
-	      else
2044
-		p_IRP->IoStatus.Status = l_Status = STATUS_UNSUCCESSFUL;
2045
-
2046
-	      p_IRP->IoStatus.Information
2047
-		= l_IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
2048
-
2049
-	      break;
2050
-	    }
2051
-#endif
2052
-
2053
-	  case TAP_IOCTL_CONFIG_TUN:
2054
-	    {
2055
-	      if (l_IrpSp->Parameters.DeviceIoControl.InputBufferLength >=
2056
-		  (sizeof (IPADDR) * 3))
2057
-		{
2058
-		  MACADDR dest;
2059
-
2060
-		  l_Adapter->m_tun = FALSE;
2061
-
2062
-		  GenerateRelatedMAC (dest, l_Adapter->m_MAC, 1);
2063
-
2064
-		  l_Adapter->m_localIP =       ((IPADDR*) (p_IRP->AssociatedIrp.SystemBuffer))[0];
2065
-		  l_Adapter->m_remoteNetwork = ((IPADDR*) (p_IRP->AssociatedIrp.SystemBuffer))[1];
2066
-		  l_Adapter->m_remoteNetmask = ((IPADDR*) (p_IRP->AssociatedIrp.SystemBuffer))[2];
2067
-
2068
-		  // sanity check on network/netmask
2069
-		  if ((l_Adapter->m_remoteNetwork & l_Adapter->m_remoteNetmask) != l_Adapter->m_remoteNetwork)
2070
-		    {
2071
-		      NOTE_ERROR ();
2072
-		      p_IRP->IoStatus.Status = l_Status = STATUS_INVALID_PARAMETER;
2073
-		      break;
2074
-		    }
2075
-
2076
-		  COPY_MAC (l_Adapter->m_TapToUser.src, l_Adapter->m_MAC);
2077
-		  COPY_MAC (l_Adapter->m_TapToUser.dest, dest);
2078
-		  COPY_MAC (l_Adapter->m_UserToTap.src, dest);
2079
-		  COPY_MAC (l_Adapter->m_UserToTap.dest, l_Adapter->m_MAC);
2080
-
2081
-		  l_Adapter->m_TapToUser.proto = l_Adapter->m_UserToTap.proto = htons (ETH_P_IP);
2082
-		  l_Adapter->m_UserToTap_IPv6 = l_Adapter->m_UserToTap;
2083
-		  l_Adapter->m_UserToTap_IPv6.proto = htons(ETH_P_IPV6);
2084
-
2085
-		  l_Adapter->m_tun = TRUE;
2086
-
2087
-		  CheckIfDhcpAndTunMode (l_Adapter);
2088
-
2089
-		  p_IRP->IoStatus.Information = 1; // Simple boolean value
2090
-		}
2091
-	      else
2092
-		{
2093
-		  NOTE_ERROR ();
2094
-		  p_IRP->IoStatus.Status = l_Status = STATUS_INVALID_PARAMETER;
2095
-		}
2096
-	      
2097
-	      break;
2098
-	    }
2099
-
2100
-	  case TAP_IOCTL_CONFIG_POINT_TO_POINT: // Obsoleted by TAP_IOCTL_CONFIG_TUN
2101
-	    {
2102
-	      if (l_IrpSp->Parameters.DeviceIoControl.InputBufferLength >=
2103
-		  (sizeof (IPADDR) * 2))
2104
-		{
2105
-		  MACADDR dest;
2106
-
2107
-		  l_Adapter->m_tun = FALSE;
2108
-
2109
-		  GenerateRelatedMAC (dest, l_Adapter->m_MAC, 1);
2110
-
2111
-		  l_Adapter->m_localIP =       ((IPADDR*) (p_IRP->AssociatedIrp.SystemBuffer))[0];
2112
-		  l_Adapter->m_remoteNetwork = ((IPADDR*) (p_IRP->AssociatedIrp.SystemBuffer))[1];
2113
-		  l_Adapter->m_remoteNetmask = ~0;
2114
-
2115
-		  COPY_MAC (l_Adapter->m_TapToUser.src, l_Adapter->m_MAC);
2116
-		  COPY_MAC (l_Adapter->m_TapToUser.dest, dest);
2117
-		  COPY_MAC (l_Adapter->m_UserToTap.src, dest);
2118
-		  COPY_MAC (l_Adapter->m_UserToTap.dest, l_Adapter->m_MAC);
2119
-
2120
-		  l_Adapter->m_TapToUser.proto = l_Adapter->m_UserToTap.proto = htons (ETH_P_IP);
2121
-		  l_Adapter->m_UserToTap_IPv6 = l_Adapter->m_UserToTap;
2122
-		  l_Adapter->m_UserToTap_IPv6.proto = htons(ETH_P_IPV6);
2123
-
2124
-		  l_Adapter->m_tun = TRUE;
2125
-
2126
-		  CheckIfDhcpAndTunMode (l_Adapter);
2127
-
2128
-		  p_IRP->IoStatus.Information = 1; // Simple boolean value
2129
-		}
2130
-	      else
2131
-		{
2132
-		  NOTE_ERROR ();
2133
-		  p_IRP->IoStatus.Status = l_Status = STATUS_INVALID_PARAMETER;
2134
-		}
2135
-	      
2136
-	      break;
2137
-	    }
2138
-
2139
-	  case TAP_IOCTL_SET_MEDIA_STATUS:
2140
-	    {
2141
-	      if (l_IrpSp->Parameters.DeviceIoControl.InputBufferLength >=
2142
-		  (sizeof (ULONG) * 1))
2143
-		{
2144
-		  ULONG parm = ((PULONG) (p_IRP->AssociatedIrp.SystemBuffer))[0];
2145
-		  SetMediaStatus (l_Adapter, (BOOLEAN) parm);
2146
-		  p_IRP->IoStatus.Information = 1;
2147
-		}
2148
-	      else
2149
-		{
2150
-		  NOTE_ERROR ();
2151
-		  p_IRP->IoStatus.Status = l_Status = STATUS_INVALID_PARAMETER;
2152
-		}
2153
-	      break;
2154
-	    }
2155
-
2156
-	  case TAP_IOCTL_CONFIG_DHCP_MASQ:
2157
-	    {
2158
-	      if (l_IrpSp->Parameters.DeviceIoControl.InputBufferLength >=
2159
-		  (sizeof (IPADDR) * 4))
2160
-		{
2161
-		  l_Adapter->m_dhcp_enabled = FALSE;
2162
-		  l_Adapter->m_dhcp_server_arp = FALSE;
2163
-		  l_Adapter->m_dhcp_user_supplied_options_buffer_len = 0;
2164
-
2165
-		  // Adapter IP addr / netmask
2166
-		  l_Adapter->m_dhcp_addr =
2167
-		    ((IPADDR*) (p_IRP->AssociatedIrp.SystemBuffer))[0];
2168
-		  l_Adapter->m_dhcp_netmask =
2169
-		    ((IPADDR*) (p_IRP->AssociatedIrp.SystemBuffer))[1];
2170
-
2171
-		  // IP addr of DHCP masq server
2172
-		  l_Adapter->m_dhcp_server_ip =
2173
-		    ((IPADDR*) (p_IRP->AssociatedIrp.SystemBuffer))[2];
2174
-
2175
-		  // Lease time in seconds
2176
-		  l_Adapter->m_dhcp_lease_time =
2177
-		    ((IPADDR*) (p_IRP->AssociatedIrp.SystemBuffer))[3];
2178
-
2179
-		  GenerateRelatedMAC (l_Adapter->m_dhcp_server_mac, l_Adapter->m_MAC, 2);
2180
-
2181
-		  l_Adapter->m_dhcp_enabled = TRUE;
2182
-		  l_Adapter->m_dhcp_server_arp = TRUE;
2183
-
2184
-		  CheckIfDhcpAndTunMode (l_Adapter);
2185
-
2186
-		  p_IRP->IoStatus.Information = 1; // Simple boolean value
2187
-		}
2188
-	      else
2189
-		{
2190
-		  NOTE_ERROR ();
2191
-		  p_IRP->IoStatus.Status = l_Status = STATUS_INVALID_PARAMETER;
2192
-		}
2193
-	      
2194
-	      break;
2195
-	    }
2196
-
2197
-	  case TAP_IOCTL_CONFIG_DHCP_SET_OPT:
2198
-	    {
2199
-	      if (l_IrpSp->Parameters.DeviceIoControl.InputBufferLength <=
2200
-		  DHCP_USER_SUPPLIED_OPTIONS_BUFFER_SIZE
2201
-		  && l_Adapter->m_dhcp_enabled)
2202
-		{
2203
-		  l_Adapter->m_dhcp_user_supplied_options_buffer_len = 0;
2204
-
2205
-		  NdisMoveMemory (l_Adapter->m_dhcp_user_supplied_options_buffer,
2206
-				  p_IRP->AssociatedIrp.SystemBuffer,
2207
-				  l_IrpSp->Parameters.DeviceIoControl.InputBufferLength);
2208
-		  
2209
-		  l_Adapter->m_dhcp_user_supplied_options_buffer_len = 
2210
-		    l_IrpSp->Parameters.DeviceIoControl.InputBufferLength;
2211
-
2212
-		  p_IRP->IoStatus.Information = 1; // Simple boolean value
2213
-		}
2214
-	      else
2215
-		{
2216
-		  NOTE_ERROR ();
2217
-		  p_IRP->IoStatus.Status = l_Status = STATUS_INVALID_PARAMETER;
2218
-		}
2219
-	      
2220
-	      break;
2221
-	    }
2222
-
2223
-	  default:
2224
-	    {
2225
-	      NOTE_ERROR ();
2226
-	      p_IRP->IoStatus.Status = l_Status = STATUS_INVALID_PARAMETER;
2227
-	      break;
2228
-	    }
2229
-	  }
2230
-
2231
-	IoCompleteRequest (p_IRP, IO_NO_INCREMENT);
2232
-	break;
2233
-      }
2234
-
2235
-      //===========================================================
2236
-      // User mode thread issued a read request on the tap device
2237
-      // If there are packets waiting to be read, then the request
2238
-      // will be satisfied here. If not, then the request will be
2239
-      // queued and satisfied by any packet that is not used to
2240
-      // satisfy requests ahead of it.
2241
-      //===========================================================
2242
-    case IRP_MJ_READ:
2243
-      {
2244
-	TapPacketPointer l_PacketBuffer;
2245
-	BOOLEAN pending = FALSE;
2246
-
2247
-	// Save IRP-accessible copy of buffer length
2248
-	p_IRP->IoStatus.Information = l_IrpSp->Parameters.Read.Length;
2249
-
2250
-	if (p_IRP->MdlAddress == NULL)
2251
-	  {
2252
-	    DEBUGP (("[%s] MdlAddress is NULL for IRP_MJ_READ\n",
2253
-		     NAME (l_Adapter)));
2254
-	    NOTE_ERROR ();
2255
-	    p_IRP->IoStatus.Status = l_Status = STATUS_INVALID_PARAMETER;
2256
-	    p_IRP->IoStatus.Information = 0;
2257
-	    IoCompleteRequest (p_IRP, IO_NO_INCREMENT);
2258
-	    break;
2259
-	  }
2260
-	else if ((p_IRP->AssociatedIrp.SystemBuffer =
2261
-		  MmGetSystemAddressForMdlSafe
2262
-		  (p_IRP->MdlAddress, NormalPagePriority)) == NULL)
2263
-	  {
2264
-	    DEBUGP (("[%s] Could not map address in IRP_MJ_READ\n",
2265
-		     NAME (l_Adapter)));
2266
-	    NOTE_ERROR ();
2267
-	    p_IRP->IoStatus.Status = l_Status = STATUS_INSUFFICIENT_RESOURCES;
2268
-	    p_IRP->IoStatus.Information = 0;
2269
-	    IoCompleteRequest (p_IRP, IO_NO_INCREMENT);
2270
-	    break;
2271
-	  }
2272
-	else if (!l_Adapter->m_InterfaceIsRunning)
2273
-	  {
2274
-	    DEBUGP (("[%s] Interface is down in IRP_MJ_READ\n",
2275
-		     NAME (l_Adapter)));
2276
-	    NOTE_ERROR ();
2277
-	    p_IRP->IoStatus.Status = l_Status = STATUS_UNSUCCESSFUL;
2278
-	    p_IRP->IoStatus.Information = 0;
2279
-	    IoCompleteRequest (p_IRP, IO_NO_INCREMENT);
2280
-	    break;
2281
-	  }
2282
-
2283
-	//==================================
2284
-	// Can we provide immediate service?
2285
-	//==================================
2286
-
2287
-	l_PacketBuffer = NULL;
2288
-
2289
-	NdisAcquireSpinLock (&l_Adapter->m_Extension.m_QueueLock);
2290
-
2291
-	if (IS_UP (l_Adapter)
2292
-	    && QueueCount (l_Adapter->m_Extension.m_PacketQueue)
2293
-	    && QueueCount (l_Adapter->m_Extension.m_IrpQueue) == 0)
2294
-	  {
2295
-	    l_PacketBuffer = (TapPacketPointer)
2296
-	      QueuePop (l_Adapter->m_Extension.m_PacketQueue);
2297
-	  }
2298
-
2299
-	NdisReleaseSpinLock (&l_Adapter->m_Extension.m_QueueLock);
2300
-
2301
-	if (l_PacketBuffer)
2302
-	  {
2303
-	    l_Status = CompleteIRP (p_IRP,
2304
-				    l_PacketBuffer,
2305
-				    IO_NO_INCREMENT);
2306
-	    break;
2307
-	  }
2308
-
2309
-	//=============================
2310
-	// Attempt to pend read request
2311
-	//=============================
2312
-
2313
-	NdisAcquireSpinLock (&l_Adapter->m_Extension.m_QueueLock);
2314
-
2315
-	if (IS_UP (l_Adapter)
2316
-	    && QueuePush (l_Adapter->m_Extension.m_IrpQueue, p_IRP) == (PIRP) p_IRP)
2317
-	  {
2318
-	    IoSetCancelRoutine (p_IRP, CancelIRPCallback);
2319
-	    l_Status = STATUS_PENDING;
2320
-	    IoMarkIrpPending (p_IRP);
2321
-	    pending = TRUE;
2322
-	  }
2323
-
2324
-	NdisReleaseSpinLock (&l_Adapter->m_Extension.m_QueueLock);
2325
-
2326
-	if (pending)
2327
-	  break;
2328
-
2329
-	// Can't queue anymore IRP's
2330
-	DEBUGP (("[%s] TAP [%s] read IRP overrun\n",
2331
-		 NAME (l_Adapter), l_Adapter->m_Extension.m_TapName));
2332
-	NOTE_ERROR ();
2333
-	p_IRP->IoStatus.Status = l_Status = STATUS_UNSUCCESSFUL;
2334
-	p_IRP->IoStatus.Information = 0;
2335
-	IoCompleteRequest (p_IRP, IO_NO_INCREMENT);
2336
-	break;
2337
-      }
2338
-
2339
-      //==============================================================
2340
-      // User mode issued a WriteFile request on the TAP file handle.
2341
-      // The request will always get satisfied here.  The call may
2342
-      // fail if there are too many pending packets (queue full).
2343
-      //==============================================================
2344
-    case IRP_MJ_WRITE:
2345
-      {
2346
-	if (p_IRP->MdlAddress == NULL)
2347
-	  {
2348
-	    DEBUGP (("[%s] MdlAddress is NULL for IRP_MJ_WRITE\n",
2349
-		     NAME (l_Adapter)));
2350
-	    NOTE_ERROR ();
2351
-	    p_IRP->IoStatus.Status = l_Status = STATUS_INVALID_PARAMETER;
2352
-	    p_IRP->IoStatus.Information = 0;
2353
-	  }
2354
-	else if ((p_IRP->AssociatedIrp.SystemBuffer =
2355
-		  MmGetSystemAddressForMdlSafe
2356
-		  (p_IRP->MdlAddress, NormalPagePriority)) == NULL)
2357
-	  {
2358
-	    DEBUGP (("[%s] Could not map address in IRP_MJ_WRITE\n",
2359
-		     NAME (l_Adapter)));
2360
-	    NOTE_ERROR ();
2361
-	    p_IRP->IoStatus.Status = l_Status = STATUS_INSUFFICIENT_RESOURCES;
2362
-	    p_IRP->IoStatus.Information = 0;
2363
-	  }
2364
-	else if (!l_Adapter->m_InterfaceIsRunning)
2365
-	  {
2366
-	    DEBUGP (("[%s] Interface is down in IRP_MJ_WRITE\n",
2367
-		     NAME (l_Adapter)));
2368
-	    NOTE_ERROR ();
2369
-	    p_IRP->IoStatus.Status = l_Status = STATUS_UNSUCCESSFUL;
2370
-	    p_IRP->IoStatus.Information = 0;
2371
-	  }
2372
-	else if (!l_Adapter->m_tun && ((l_IrpSp->Parameters.Write.Length) >= ETHERNET_HEADER_SIZE))
2373
-	  {
2374
-	    __try
2375
-	      {
2376
-		p_IRP->IoStatus.Information = l_IrpSp->Parameters.Write.Length;
2377
-
2378
-		DUMP_PACKET ("IRP_MJ_WRITE ETH",
2379
-			     (unsigned char *) p_IRP->AssociatedIrp.SystemBuffer,
2380
-			     l_IrpSp->Parameters.Write.Length);
2381
-
2382
-    //=====================================================
2383
-    // If IPv4 packet, check whether or not packet
2384
-    // was truncated.
2385
-    //=====================================================
2386
-#if PACKET_TRUNCATION_CHECK
2387
-		IPv4PacketSizeVerify ((unsigned char *) p_IRP->AssociatedIrp.SystemBuffer,
2388
-				      l_IrpSp->Parameters.Write.Length,
2389
-				      FALSE,
2390
-				      "RX",
2391
-				      &l_Adapter->m_RxTrunc);
2392
-#endif
2393
-
2394
-		NdisMEthIndicateReceive
2395
-		  (l_Adapter->m_MiniportAdapterHandle,
2396
-		   (NDIS_HANDLE) l_Adapter,
2397
-		   (unsigned char *) p_IRP->AssociatedIrp.SystemBuffer,
2398
-		   ETHERNET_HEADER_SIZE,
2399
-		   (unsigned char *) p_IRP->AssociatedIrp.SystemBuffer + ETHERNET_HEADER_SIZE,
2400
-		   l_IrpSp->Parameters.Write.Length - ETHERNET_HEADER_SIZE,
2401
-		   l_IrpSp->Parameters.Write.Length - ETHERNET_HEADER_SIZE);
2402
-		
2403
-		NdisMEthIndicateReceiveComplete (l_Adapter->m_MiniportAdapterHandle);
2404
-
2405
-		p_IRP->IoStatus.Status = l_Status = STATUS_SUCCESS;
2406
-	      }
2407
-	    __except (EXCEPTION_EXECUTE_HANDLER)
2408
-	      {
2409
-		DEBUGP (("[%s] NdisMEthIndicateReceive failed in IRP_MJ_WRITE\n",
2410
-			 NAME (l_Adapter)));
2411
-		NOTE_ERROR ();
2412
-		p_IRP->IoStatus.Status = l_Status = STATUS_UNSUCCESSFUL;
2413
-		p_IRP->IoStatus.Information = 0;
2414
-	      }
2415
-	  }
2416
-	else if (l_Adapter->m_tun && ((l_IrpSp->Parameters.Write.Length) >= IP_HEADER_SIZE))
2417
-	  {
2418
-	    __try
2419
-	      {
2420
-		ETH_HEADER * p_UserToTap = &l_Adapter->m_UserToTap;
2421
-
2422
-		// for IPv6, need to use ethernet header with IPv6 proto
2423
-		if ( IPH_GET_VER( ((IPHDR*) p_IRP->AssociatedIrp.SystemBuffer)->version_len) == 6 )
2424
-		  {
2425
-		    p_UserToTap = &l_Adapter->m_UserToTap_IPv6;
2426
-		  }
2427
-
2428
-		p_IRP->IoStatus.Information = l_IrpSp->Parameters.Write.Length;
2429
-
2430
-		DUMP_PACKET2 ("IRP_MJ_WRITE P2P",
2431
-			      p_UserToTap,
2432
-			      (unsigned char *) p_IRP->AssociatedIrp.SystemBuffer,
2433
-			      l_IrpSp->Parameters.Write.Length);
2434
-
2435
-    //=====================================================
2436
-    // If IPv4 packet, check whether or not packet
2437
-    // was truncated.
2438
-    //=====================================================
2439
-#if PACKET_TRUNCATION_CHECK
2440
-		IPv4PacketSizeVerify ((unsigned char *) p_IRP->AssociatedIrp.SystemBuffer,
2441
-				      l_IrpSp->Parameters.Write.Length,
2442
-				      TRUE,
2443
-				      "RX",
2444
-				      &l_Adapter->m_RxTrunc);
2445
-#endif
2446
-
2447
-		NdisMEthIndicateReceive
2448
-		  (l_Adapter->m_MiniportAdapterHandle,
2449
-		   (NDIS_HANDLE) l_Adapter,
2450
-		   (unsigned char *) p_UserToTap,
2451
-		   sizeof (ETH_HEADER),
2452
-		   (unsigned char *) p_IRP->AssociatedIrp.SystemBuffer,
2453
-		   l_IrpSp->Parameters.Write.Length,
2454
-		   l_IrpSp->Parameters.Write.Length);
2455
-
2456
-		NdisMEthIndicateReceiveComplete (l_Adapter->m_MiniportAdapterHandle);
2457
-
2458
-		p_IRP->IoStatus.Status = l_Status = STATUS_SUCCESS;
2459
-	      }
2460
-	    __except (EXCEPTION_EXECUTE_HANDLER)
2461
-	      {
2462
-		DEBUGP (("[%s] NdisMEthIndicateReceive failed in IRP_MJ_WRITE (P2P)\n",
2463
-			 NAME (l_Adapter)));
2464
-		NOTE_ERROR ();
2465
-		p_IRP->IoStatus.Status = l_Status = STATUS_UNSUCCESSFUL;
2466
-		p_IRP->IoStatus.Information = 0;
2467
-	      }
2468
-	  }
2469
-	else
2470
-	  {
2471
-	    DEBUGP (("[%s] Bad buffer size in IRP_MJ_WRITE, len=%d\n",
2472
-		     NAME (l_Adapter),
2473
-		     l_IrpSp->Parameters.Write.Length));
2474
-	    NOTE_ERROR ();
2475
-	    p_IRP->IoStatus.Information = 0;	// ETHERNET_HEADER_SIZE;
2476
-	    p_IRP->IoStatus.Status = l_Status = STATUS_BUFFER_TOO_SMALL;
2477
-	  }
2478
-
2479
-	if (l_Status == STATUS_SUCCESS)
2480
-	  INCREMENT_STAT (l_Adapter->m_Rx);
2481
-	else
2482
-	  INCREMENT_STAT (l_Adapter->m_RxErr);
2483
-
2484
-	IoCompleteRequest (p_IRP, IO_NO_INCREMENT);
2485
-	break;
2486
-      }
2487
-
2488
-      //--------------------------------------------------------------
2489
-      //   User mode thread has called CreateFile() on the tap device
2490
-      //--------------------------------------------------------------
2491
-    case IRP_MJ_CREATE:
2492
-      {
2493
-	BOOLEAN succeeded = FALSE;
2494
-	BOOLEAN mutex_succeeded;
2495
-
2496
-	DEBUGP
2497
-	  (("[%s] [TAP] release [%d.%d] open request (m_TapOpens=%d)\n",
2498
-	    NAME (l_Adapter), TAP_DRIVER_MAJOR_VERSION,
2499
-	    TAP_DRIVER_MINOR_VERSION, l_Adapter->m_Extension.m_TapOpens));
2500
-
2501
-	ACQUIRE_MUTEX_ADAPTIVE (&l_Adapter->m_Extension.m_OpenCloseMutex, mutex_succeeded);
2502
-	if (mutex_succeeded)
2503
-	  {
2504
-	    if (l_Adapter->m_Extension.m_TapIsRunning && !l_Adapter->m_Extension.m_TapOpens)
2505
-	      {
2506
-		ResetTapAdapterState (l_Adapter);
2507
-		l_Adapter->m_Extension.m_TapOpens = 1;
2508
-		succeeded = TRUE;
2509
-	      }
2510
-
2511
-	    if (succeeded)
2512
-	      {
2513
-		INCREMENT_STAT (l_Adapter->m_Extension.m_NumTapOpens);
2514
-		p_IRP->IoStatus.Status = l_Status = STATUS_SUCCESS;
2515
-		p_IRP->IoStatus.Information = 0;
2516
-	      }
2517
-	    else
2518
-	      {
2519
-		DEBUGP (("[%s] TAP is presently unavailable (m_TapOpens=%d)\n",
2520
-			 NAME (l_Adapter), l_Adapter->m_Extension.m_TapOpens));
2521
-		NOTE_ERROR ();
2522
-		p_IRP->IoStatus.Status = l_Status = STATUS_UNSUCCESSFUL;
2523
-		p_IRP->IoStatus.Information = 0;
2524
-	      }
2525
-
2526
-	    RELEASE_MUTEX (&l_Adapter->m_Extension.m_OpenCloseMutex);
2527
-	  }
2528
-	else
2529
-	  {
2530
-	    DEBUGP (("[%s] TAP is presently locked (m_TapOpens=%d)\n",
2531
-		     NAME (l_Adapter), l_Adapter->m_Extension.m_TapOpens));
2532
-	    NOTE_ERROR ();
2533
-	    p_IRP->IoStatus.Status = l_Status = STATUS_UNSUCCESSFUL;
2534
-	    p_IRP->IoStatus.Information = 0;
2535
-	  }
2536
-	
2537
-	IoCompleteRequest (p_IRP, IO_NO_INCREMENT);
2538
-	break;
2539
-      }
2540
-      
2541
-      //-----------------------------------------------------------
2542
-      //  User mode thread called CloseHandle() on the tap device
2543
-      //-----------------------------------------------------------
2544
-    case IRP_MJ_CLOSE:
2545
-      {
2546
-	BOOLEAN mutex_succeeded;
2547
-
2548
-	DEBUGP (("[%s] [TAP] release [%d.%d] close/cleanup request\n",
2549
-		 NAME (l_Adapter), TAP_DRIVER_MAJOR_VERSION,
2550
-		 TAP_DRIVER_MINOR_VERSION));
2551
-
2552
-	ACQUIRE_MUTEX_ADAPTIVE (&l_Adapter->m_Extension.m_OpenCloseMutex, mutex_succeeded);
2553
-	if (mutex_succeeded)
2554
-	  {
2555
-	    l_Adapter->m_Extension.m_TapOpens = 0;
2556
-	    ResetTapAdapterState (l_Adapter);
2557
-	    FlushQueues (&l_Adapter->m_Extension);
2558
-	    SetMediaStatus (l_Adapter, FALSE);
2559
-	    RELEASE_MUTEX (&l_Adapter->m_Extension.m_OpenCloseMutex);
2560
-	  }
2561
-	else
2562
-	  {
2563
-	    DEBUGP (("[%s] TAP is presently locked (m_TapOpens=%d)\n",
2564
-		     NAME (l_Adapter), l_Adapter->m_Extension.m_TapOpens));
2565
-	    NOTE_ERROR ();
2566
-	    p_IRP->IoStatus.Status = l_Status = STATUS_UNSUCCESSFUL;
2567
-	    p_IRP->IoStatus.Information = 0;
2568
-	  }
2569
-	
2570
-	IoCompleteRequest (p_IRP, IO_NO_INCREMENT);
2571
-	break;
2572
-      }
2573
-
2574
-      //------------------
2575
-      // Strange Request
2576
-      //------------------
2577
-    default:
2578
-      {
2579
-	//NOTE_ERROR ();
2580
-	p_IRP->IoStatus.Status = l_Status = STATUS_UNSUCCESSFUL;
2581
-	IoCompleteRequest (p_IRP, IO_NO_INCREMENT);
2582
-	break;
2583
-      }
2584
-    }
2585
-
2586
-  return l_Status;
2587
-}
2588
-
2589
-//=============================================================
2590
-// CompleteIRP is normally called with an adapter -> userspace
2591
-// network packet and an IRP (Pending I/O request) from userspace.
2592
-//
2593
-// The IRP will normally represent a queued overlapped read
2594
-// operation from userspace that is in a wait state.
2595
-//
2596
-// Use the ethernet packet to satisfy the IRP.
2597
-//=============================================================
2598
-
2599
-NTSTATUS
2600
-CompleteIRP (IN PIRP p_IRP,
2601
-	     IN TapPacketPointer p_PacketBuffer,
2602
-	     IN CCHAR PriorityBoost)
2603
-{
2604
-  NTSTATUS l_Status = STATUS_UNSUCCESSFUL;
2605
-
2606
-  int offset;
2607
-  int len;
2608
-
2609
-  MYASSERT (p_IRP);
2610
-  MYASSERT (p_PacketBuffer);
2611
-
2612
-  IoSetCancelRoutine (p_IRP, NULL);  // Disable cancel routine
2613
-
2614
-  //-------------------------------------------
2615
-  // While p_PacketBuffer always contains a
2616
-  // full ethernet packet, including the
2617
-  // ethernet header, in point-to-point mode,
2618
-  // we only want to return the IPv4
2619
-  // component.
2620
-  //-------------------------------------------
2621
-
2622
-  if (p_PacketBuffer->m_SizeFlags & TP_TUN)
2623
-    {
2624
-      offset = ETHERNET_HEADER_SIZE;
2625
-      len = (int) (p_PacketBuffer->m_SizeFlags & TP_SIZE_MASK) - ETHERNET_HEADER_SIZE;
2626
-    }
2627
-  else
2628
-    {
2629
-      offset = 0;
2630
-      len = (p_PacketBuffer->m_SizeFlags & TP_SIZE_MASK);
2631
-    }
2632
-
2633
-  if (len < 0 || (int) p_IRP->IoStatus.Information < len)
2634
-    {
2635
-      p_IRP->IoStatus.Information = 0;
2636
-      p_IRP->IoStatus.Status = STATUS_BUFFER_OVERFLOW;
2637
-      NOTE_ERROR ();
2638
-    }
2639
-  else
2640
-    {
2641
-      p_IRP->IoStatus.Information = len;
2642
-      p_IRP->IoStatus.Status = l_Status = STATUS_SUCCESS;
2643
-
2644
-      __try
2645
-	{
2646
-	  NdisMoveMemory (p_IRP->AssociatedIrp.SystemBuffer,
2647
-			  p_PacketBuffer->m_Data + offset,
2648
-			  len);
2649
-	}
2650
-      __except (EXCEPTION_EXECUTE_HANDLER)
2651
-	{
2652
-	  NOTE_ERROR ();
2653
-	  p_IRP->IoStatus.Status = STATUS_UNSUCCESSFUL;
2654
-	  p_IRP->IoStatus.Information = 0;
2655
-	}
2656
-    }
2657
-
2658
-  __try
2659
-    {
2660
-      NdisFreeMemory (p_PacketBuffer,
2661
-		      TAP_PACKET_SIZE (p_PacketBuffer->m_SizeFlags & TP_SIZE_MASK),
2662
-		      0);
2663
-    }
2664
-  __except (EXCEPTION_EXECUTE_HANDLER)
2665
-    {
2666
-    }
2667
-  
2668
-  if (l_Status == STATUS_SUCCESS)
2669
-    {
2670
-      IoCompleteRequest (p_IRP, PriorityBoost);
2671
-    }
2672
-  else
2673
-    IoCompleteRequest (p_IRP, IO_NO_INCREMENT);
2674
-
2675
-  return l_Status;
2676
-}
2677
-
2678
-//==============================================
2679
-// IRPs get cancelled for a number of reasons.
2680
-//
2681
-// The TAP device could be closed by userspace
2682
-// when there are still pending read operations.
2683
-//
2684
-// The user could disable the TAP adapter in the
2685
-// network connections control panel, while the
2686
-// device is still open by a process.
2687
-//==============================================
2688
-VOID
2689
-CancelIRPCallback (IN PDEVICE_OBJECT p_DeviceObject,
2690
-		   IN PIRP p_IRP)
2691
-{
2692
-  TapAdapterPointer l_Adapter = LookupAdapterInInstanceList (p_DeviceObject);
2693
-  CancelIRP (l_Adapter ? &l_Adapter->m_Extension : NULL, p_IRP, TRUE);
2694
-}
2695
-
2696
-VOID
2697
-CancelIRP (TapExtensionPointer p_Extension,
2698
-	   IN PIRP p_IRP,
2699
-	   BOOLEAN callback)
2700
-{
2701
-  BOOLEAN exists = FALSE;
2702
-
2703
-  MYASSERT (p_IRP);
2704
-
2705
-  if (p_Extension)
2706
-    {
2707
-      NdisAcquireSpinLock (&p_Extension->m_QueueLock);
2708
-      exists = (QueueExtract (p_Extension->m_IrpQueue, p_IRP) == p_IRP);
2709
-      NdisReleaseSpinLock (&p_Extension->m_QueueLock);
2710
-    }
2711
-  else
2712
-    exists = TRUE;
2713
-
2714
-  if (exists)
2715
-    {
2716
-      IoSetCancelRoutine (p_IRP, NULL);
2717
-      p_IRP->IoStatus.Status = STATUS_CANCELLED;
2718
-      p_IRP->IoStatus.Information = 0;
2719
-    }
2720
-     
2721
-  if (callback)
2722
-    IoReleaseCancelSpinLock (p_IRP->CancelIrql);
2723
-
2724
-  if (exists)
2725
-    IoCompleteRequest (p_IRP, IO_NO_INCREMENT);
2726
-}
2727
-
2728
-//===========================================
2729
-// Exhaust packet, IRP, and injection queues.
2730
-//===========================================
2731
-VOID
2732
-FlushQueues (TapExtensionPointer p_Extension)
2733
-{
2734
-  PIRP l_IRP;
2735
-  TapPacketPointer l_PacketBuffer;
2736
-  InjectPacketPointer l_InjectBuffer;
2737
-  int n_IRP=0, n_Packet=0, n_Inject=0;
2738
-
2739
-  MYASSERT (p_Extension);
2740
-  MYASSERT (p_Extension->m_TapDevice);
2741
-
2742
-  while (TRUE)
2743
-    {
2744
-      NdisAcquireSpinLock (&p_Extension->m_QueueLock);
2745
-      l_IRP = QueuePop (p_Extension->m_IrpQueue);
2746
-      NdisReleaseSpinLock (&p_Extension->m_QueueLock);
2747
-      if (l_IRP)
2748
-	{
2749
-	  ++n_IRP;
2750
-	  CancelIRP (NULL, l_IRP, FALSE);
2751
-	}
2752
-      else
2753
-	break;
2754
-    }
2755
-
2756
-  while (TRUE)
2757
-    {
2758
-      NdisAcquireSpinLock (&p_Extension->m_QueueLock);
2759
-      l_PacketBuffer = QueuePop (p_Extension->m_PacketQueue);
2760
-      NdisReleaseSpinLock (&p_Extension->m_QueueLock);
2761
-      if (l_PacketBuffer)
2762
-	{
2763
-	  ++n_Packet;
2764
-	  MemFree (l_PacketBuffer, TAP_PACKET_SIZE (l_PacketBuffer->m_SizeFlags & TP_SIZE_MASK));
2765
-	}
2766
-      else
2767
-	break;
2768
-    }
2769
-
2770
-  while (TRUE)
2771
-    {
2772
-      NdisAcquireSpinLock (&p_Extension->m_InjectLock);
2773
-      l_InjectBuffer = QueuePop (p_Extension->m_InjectQueue);
2774
-      NdisReleaseSpinLock (&p_Extension->m_InjectLock);
2775
-      if (l_InjectBuffer)
2776
-	{
2777
-	  ++n_Inject;
2778
-	  INJECT_PACKET_FREE(l_InjectBuffer);
2779
-	}
2780
-      else
2781
-	break;
2782
-    }
2783
-
2784
-  DEBUGP ((
2785
-	   "[%s] [TAP] FlushQueues n_IRP=[%d,%d,%d] n_Packet=[%d,%d,%d] n_Inject=[%d,%d,%d]\n",
2786
-	   p_Extension->m_TapName,
2787
-	   n_IRP,
2788
-	   p_Extension->m_IrpQueue->max_size,
2789
-	   IRP_QUEUE_SIZE,
2790
-	   n_Packet,
2791
-	   p_Extension->m_PacketQueue->max_size,
2792
-	   PACKET_QUEUE_SIZE,
2793
-	   n_Inject,
2794
-	   p_Extension->m_InjectQueue->max_size,
2795
-	   INJECT_QUEUE_SIZE
2796
-	   ));
2797
-}
2798
-
2799
-//===================================================
2800
-// Tell Windows whether the TAP device should be
2801
-// considered "connected" or "disconnected".
2802
-//===================================================
2803
-VOID
2804
-SetMediaStatus (TapAdapterPointer p_Adapter, BOOLEAN state)
2805
-{
2806
-  if (p_Adapter->m_MediaState != state && !p_Adapter->m_MediaStateAlwaysConnected)
2807
-    {
2808
-      if (state)
2809
-	NdisMIndicateStatus (p_Adapter->m_MiniportAdapterHandle,
2810
-			     NDIS_STATUS_MEDIA_CONNECT, NULL, 0);
2811
-      else
2812
-	NdisMIndicateStatus (p_Adapter->m_MiniportAdapterHandle,
2813
-			     NDIS_STATUS_MEDIA_DISCONNECT, NULL, 0);
2814
-
2815
-      NdisMIndicateStatusComplete (p_Adapter->m_MiniportAdapterHandle);
2816
-      p_Adapter->m_MediaState = state;
2817
-    }
2818
-}
2819
-
2820
-
2821
-//======================================================
2822
-// If DHCP mode is used together with tun
2823
-// mode, consider the fact that the P2P remote subnet
2824
-// might enclose the DHCP masq server address.
2825
-//======================================================
2826
-VOID
2827
-CheckIfDhcpAndTunMode (TapAdapterPointer p_Adapter)
2828
-{
2829
-  if (p_Adapter->m_tun && p_Adapter->m_dhcp_enabled)
2830
-    {
2831
-      if ((p_Adapter->m_dhcp_server_ip & p_Adapter->m_remoteNetmask) == p_Adapter->m_remoteNetwork)
2832
-	{
2833
-	  COPY_MAC (p_Adapter->m_dhcp_server_mac, p_Adapter->m_TapToUser.dest);
2834
-	  p_Adapter->m_dhcp_server_arp = FALSE;
2835
-	}
2836
-    }
2837
-}
2838
-
2839
-//===================================================
2840
-// Generate an ARP reply message for specific kinds
2841
-// ARP queries.
2842
-//===================================================
2843
-BOOLEAN
2844
-ProcessARP (TapAdapterPointer p_Adapter,
2845
-	    const PARP_PACKET src,
2846
-	    const IPADDR adapter_ip,
2847
-	    const IPADDR ip_network,
2848
-	    const IPADDR ip_netmask,
2849
-	    const MACADDR mac)
2850
-{
2851
-  //-----------------------------------------------
2852
-  // Is this the kind of packet we are looking for?
2853
-  //-----------------------------------------------
2854
-  if (src->m_Proto == htons (ETH_P_ARP)
2855
-      && MAC_EQUAL (src->m_MAC_Source, p_Adapter->m_MAC)
2856
-      && MAC_EQUAL (src->m_ARP_MAC_Source, p_Adapter->m_MAC)
2857
-      && MAC_EQUAL (src->m_MAC_Destination, p_Adapter->m_MAC_Broadcast)
2858
-      && src->m_ARP_Operation == htons (ARP_REQUEST)
2859
-      && src->m_MAC_AddressType == htons (MAC_ADDR_TYPE)
2860
-      && src->m_MAC_AddressSize == sizeof (MACADDR)
2861
-      && src->m_PROTO_AddressType == htons (ETH_P_IP)
2862
-      && src->m_PROTO_AddressSize == sizeof (IPADDR)
2863
-      && src->m_ARP_IP_Source == adapter_ip
2864
-      && (src->m_ARP_IP_Destination & ip_netmask) == ip_network
2865
-      && src->m_ARP_IP_Destination != adapter_ip)
2866
-    {
2867
-      ARP_PACKET *arp = (ARP_PACKET *) MemAlloc (sizeof (ARP_PACKET), TRUE);
2868
-      if (arp)
2869
-	{
2870
-	  //----------------------------------------------
2871
-	  // Initialize ARP reply fields
2872
-	  //----------------------------------------------
2873
-	  arp->m_Proto = htons (ETH_P_ARP);
2874
-	  arp->m_MAC_AddressType = htons (MAC_ADDR_TYPE);
2875
-	  arp->m_PROTO_AddressType = htons (ETH_P_IP);
2876
-	  arp->m_MAC_AddressSize = sizeof (MACADDR);
2877
-	  arp->m_PROTO_AddressSize = sizeof (IPADDR);
2878
-	  arp->m_ARP_Operation = htons (ARP_REPLY);
2879
-
2880
-	  //----------------------------------------------
2881
-	  // ARP addresses
2882
-	  //----------------------------------------------      
2883
-	  COPY_MAC (arp->m_MAC_Source, mac);
2884
-	  COPY_MAC (arp->m_MAC_Destination, p_Adapter->m_MAC);
2885
-	  COPY_MAC (arp->m_ARP_MAC_Source, mac);
2886
-	  COPY_MAC (arp->m_ARP_MAC_Destination, p_Adapter->m_MAC);
2887
-	  arp->m_ARP_IP_Source = src->m_ARP_IP_Destination;
2888
-	  arp->m_ARP_IP_Destination = adapter_ip;
2889
-
2890
-	  DUMP_PACKET ("ProcessARP",
2891
-		       (unsigned char *) arp,
2892
-		       sizeof (ARP_PACKET));
2893
-
2894
-	  InjectPacketDeferred (p_Adapter, (UCHAR *) arp, sizeof (ARP_PACKET));
2895
-
2896
-	  MemFree (arp, sizeof (ARP_PACKET));
2897
-	}
2898
-
2899
-      return TRUE;
2900
-    }
2901
-  else
2902
-    return FALSE;
2903
-}
2904
-
2905
-//===============================================================
2906
-// Used in cases where internally generated packets such as
2907
-// ARP or DHCP replies must be returned to the kernel, to be
2908
-// seen as an incoming packet "arriving" on the interface.
2909
-//===============================================================
2910
-
2911
-// Defer packet injection till IRQL < DISPATCH_LEVEL
2912
-VOID
2913
-InjectPacketDeferred (TapAdapterPointer p_Adapter,
2914
-		      UCHAR *packet,
2915
-		      const unsigned int len)
2916
-{
2917
-  InjectPacketPointer l_InjectBuffer;
2918
-  PVOID result;
2919
-
2920
-  if (NdisAllocateMemoryWithTag (&l_InjectBuffer,
2921
-				 INJECT_PACKET_SIZE (len),
2922
-				 'IPAT') == NDIS_STATUS_SUCCESS)
2923
-    {
2924
-      l_InjectBuffer->m_Size = len;
2925
-      NdisMoveMemory (l_InjectBuffer->m_Data, packet, len);
2926
-      NdisAcquireSpinLock (&p_Adapter->m_Extension.m_InjectLock);
2927
-      result = QueuePush (p_Adapter->m_Extension.m_InjectQueue, l_InjectBuffer);
2928
-      NdisReleaseSpinLock (&p_Adapter->m_Extension.m_InjectLock);
2929
-      if (result)
2930
-	KeInsertQueueDpc (&p_Adapter->m_Extension.m_InjectDpc, p_Adapter, NULL);
2931
-      else
2932
-	INJECT_PACKET_FREE(l_InjectBuffer);
2933
-    }
2934
-}
2935
-
2936
-// Handle the injection of previously deferred packets
2937
-VOID
2938
-InjectPacketDpc(KDPC *Dpc,
2939
-		PVOID DeferredContext,
2940
-		PVOID SystemArgument1,
2941
-		PVOID SystemArgument2)
2942
-{
2943
-  InjectPacketPointer l_InjectBuffer;
2944
-  TapAdapterPointer l_Adapter = (TapAdapterPointer)SystemArgument1;
2945
-  while (TRUE)
2946
-    {
2947
-      NdisAcquireSpinLock (&l_Adapter->m_Extension.m_InjectLock);
2948
-      l_InjectBuffer = QueuePop (l_Adapter->m_Extension.m_InjectQueue);
2949
-      NdisReleaseSpinLock (&l_Adapter->m_Extension.m_InjectLock);
2950
-      if (l_InjectBuffer)
2951
-	{
2952
-	  InjectPacketNow(l_Adapter, l_InjectBuffer->m_Data, l_InjectBuffer->m_Size);
2953
-	  INJECT_PACKET_FREE(l_InjectBuffer);
2954
-	}
2955
-      else
2956
-	break;
2957
-    }
2958
-}
2959
-
2960
-// Do packet injection now
2961
-VOID
2962
-InjectPacketNow (TapAdapterPointer p_Adapter,
2963
-		 UCHAR *packet,
2964
-		 const unsigned int len)
2965
-{
2966
-  MYASSERT (len >= ETHERNET_HEADER_SIZE);
2967
-
2968
-  __try
2969
-    {
2970
-      //------------------------------------------------------------
2971
-      // NdisMEthIndicateReceive and NdisMEthIndicateReceiveComplete
2972
-      // could potentially be called reentrantly both here and in
2973
-      // TapDeviceHook/IRP_MJ_WRITE.
2974
-      //
2975
-      // The DDK docs imply that this is okay.
2976
-      //
2977
-      // Note that reentrant behavior could only occur if the
2978
-      // non-deferred version of InjectPacket is used.
2979
-      //------------------------------------------------------------
2980
-      NdisMEthIndicateReceive
2981
-	(p_Adapter->m_MiniportAdapterHandle,
2982
-	 (NDIS_HANDLE) p_Adapter,
2983
-	 packet,
2984
-	 ETHERNET_HEADER_SIZE,
2985
-	 packet + ETHERNET_HEADER_SIZE,
2986
-	 len - ETHERNET_HEADER_SIZE,
2987
-	 len - ETHERNET_HEADER_SIZE);
2988
-      
2989
-      NdisMEthIndicateReceiveComplete (p_Adapter->m_MiniportAdapterHandle);
2990
-    }
2991
-  __except (EXCEPTION_EXECUTE_HANDLER)
2992
-    {
2993
-      DEBUGP (("[%s] NdisMEthIndicateReceive failed in InjectPacketNow\n",
2994
-	       NAME (p_Adapter)));
2995
-      NOTE_ERROR ();
2996
-    }
2997
-}
2998
-
2999
-//===================================================================
3000
-// Go back to default TAP mode from Point-To-Point mode.
3001
-// Also reset (i.e. disable) DHCP Masq mode.
3002
-//===================================================================
3003
-VOID ResetTapAdapterState (TapAdapterPointer p_Adapter)
3004
-{
3005
-  // Point-To-Point
3006
-  p_Adapter->m_tun = FALSE;
3007
-  p_Adapter->m_localIP = 0;
3008
-  p_Adapter->m_remoteNetwork = 0;
3009
-  p_Adapter->m_remoteNetmask = 0;
3010
-  NdisZeroMemory (&p_Adapter->m_TapToUser, sizeof (p_Adapter->m_TapToUser));
3011
-  NdisZeroMemory (&p_Adapter->m_UserToTap, sizeof (p_Adapter->m_UserToTap));
3012
-  NdisZeroMemory (&p_Adapter->m_UserToTap_IPv6, sizeof (p_Adapter->m_UserToTap_IPv6));
3013
-
3014
-  // DHCP Masq
3015
-  p_Adapter->m_dhcp_enabled = FALSE;
3016
-  p_Adapter->m_dhcp_server_arp = FALSE;
3017
-  p_Adapter->m_dhcp_user_supplied_options_buffer_len = 0;
3018
-  p_Adapter->m_dhcp_addr = 0;
3019
-  p_Adapter->m_dhcp_netmask = 0;
3020
-  p_Adapter->m_dhcp_server_ip = 0;
3021
-  p_Adapter->m_dhcp_lease_time = 0;
3022
-  p_Adapter->m_dhcp_received_discover = FALSE;
3023
-  p_Adapter->m_dhcp_bad_requests = 0;
3024
-  NdisZeroMemory (p_Adapter->m_dhcp_server_mac, sizeof (MACADDR));
3025
-}
3026
-
3027
-#if ENABLE_NONADMIN
3028
-
3029
-//===================================================================
3030
-// Set TAP device handle to be accessible without admin privileges.
3031
-//===================================================================
3032
-VOID AllowNonAdmin (TapExtensionPointer p_Extension)
3033
-{
3034
-  NTSTATUS stat;
3035
-  SECURITY_DESCRIPTOR sd;
3036
-  OBJECT_ATTRIBUTES oa;
3037
-  IO_STATUS_BLOCK isb;
3038
-  HANDLE hand = NULL;
3039
-
3040
-  NdisZeroMemory (&sd, sizeof (sd));
3041
-  NdisZeroMemory (&oa, sizeof (oa));
3042
-  NdisZeroMemory (&isb, sizeof (isb));
3043
-
3044
-  if (!p_Extension->m_CreatedUnicodeLinkName)
3045
-    {
3046
-      DEBUGP (("[TAP] AllowNonAdmin: UnicodeLinkName is uninitialized\n"));
3047
-      NOTE_ERROR ();
3048
-      return;
3049
-    }
3050
-
3051
-  stat = RtlCreateSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION);
3052
-  if (stat != STATUS_SUCCESS)
3053
-    {
3054
-      DEBUGP (("[TAP] AllowNonAdmin: RtlCreateSecurityDescriptor failed\n"));
3055
-      NOTE_ERROR ();
3056
-      return;
3057
-    }
3058
-
3059
-  InitializeObjectAttributes (
3060
-    &oa,
3061
-    &p_Extension->m_UnicodeLinkName,
3062
-    OBJ_KERNEL_HANDLE,
3063
-    NULL,
3064
-    NULL
3065
-    );
3066
-
3067
-  stat = ZwOpenFile (
3068
-    &hand,
3069
-    WRITE_DAC,
3070
-    &oa,
3071
-    &isb,
3072
-    0,
3073
-    0
3074
-    );
3075
-  if (stat != STATUS_SUCCESS)
3076
-    {
3077
-      DEBUGP (("[TAP] AllowNonAdmin: ZwOpenFile failed, status=0x%08x\n", (unsigned int)stat));
3078
-      NOTE_ERROR ();
3079
-      return;
3080
-    }
3081
-
3082
-  stat = ZwSetSecurityObject (hand, DACL_SECURITY_INFORMATION, &sd);
3083
-  if (stat != STATUS_SUCCESS)
3084
-    {
3085
-      DEBUGP (("[TAP] AllowNonAdmin: ZwSetSecurityObject failed\n"));
3086
-      NOTE_ERROR ();
3087
-      return;
3088
-    }
3089
-
3090
-  stat = ZwClose (hand);
3091
-  if (stat != STATUS_SUCCESS)
3092
-    {
3093
-      DEBUGP (("[TAP] AllowNonAdmin: ZwClose failed\n"));
3094
-      NOTE_ERROR ();
3095
-      return;
3096
-    }
3097
-
3098
-  DEBUGP (("[TAP] AllowNonAdmin: SUCCEEDED\n"));
3099
-}
3100
-
3101
-#endif
3102
-
3103
-#if PACKET_TRUNCATION_CHECK
3104
-
3105
-VOID
3106
-IPv4PacketSizeVerify (const UCHAR *data, ULONG length, BOOLEAN tun, const char *prefix, LONG *counter)
3107
-{
3108
-  const IPHDR *ip;
3109
-  int len = length;
3110
-
3111
-  if (tun)
3112
-    {
3113
-      ip = (IPHDR *) data;
3114
-    }
3115
-  else
3116
-    {
3117
-      if (length >= sizeof (ETH_HEADER))
3118
-	{
3119
-	  const ETH_HEADER *eth = (ETH_HEADER *) data;
3120
-
3121
-	  if (eth->proto != htons (ETH_P_IP))
3122
-	    return;
3123
-
3124
-	  ip = (IPHDR *) (data + sizeof (ETH_HEADER));
3125
-	  len -= sizeof (ETH_HEADER);
3126
-	}
3127
-      else
3128
-	return;
3129
-    }
3130
-
3131
-  if (len >= sizeof (IPHDR))
3132
-    {
3133
-      const int totlen = ntohs (ip->tot_len);
3134
-
3135
-      DEBUGP (("[TAP] IPv4PacketSizeVerify %s len=%d totlen=%d\n", prefix, len, totlen));
3136
-
3137
-      if (len != totlen)
3138
-	++(*counter);
3139
-    }
3140
-}
3141
-
3142
-#endif
3143
-
3144
-//======================================================================
3145
-//                                    End of Source
3146
-//======================================================================
3147 1
deleted file mode 100755
... ...
@@ -1,178 +0,0 @@
1
-/*
2
- *  TAP-Win32/TAP-Win64 -- 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
-
25
-#ifndef TAP_TYPES_DEFINED
26
-#define TAP_TYPES_DEFINED
27
-
28
-typedef struct _Queue
29
-{
30
-  ULONG base;
31
-  ULONG size;
32
-  ULONG capacity;
33
-  ULONG max_size;
34
-  PVOID data[];
35
-} Queue;
36
-
37
-typedef struct _TapAdapter;
38
-typedef struct _TapPacket;
39
-
40
-typedef union _TapAdapterQuery
41
-{
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;
50
-}
51
-TapAdapterQuery, *TapAdapterQueryPointer;
52
-
53
-typedef struct _TapExtension
54
-{
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;
60
-
61
-  // Used to lock packet queues
62
-  NDIS_SPIN_LOCK m_QueueLock;
63
-  BOOLEAN m_AllocatedSpinlocks;
64
-
65
-  // Used to bracket open/close
66
-  // state changes.
67
-  MUTEX m_OpenCloseMutex;
68
-
69
-  // True if device has been permanently halted
70
-  BOOLEAN m_Halt;
71
-
72
-  // TAP device name
73
-  unsigned char *m_TapName;
74
-  UNICODE_STRING m_UnicodeLinkName;
75
-  BOOLEAN m_CreatedUnicodeLinkName;
76
-
77
-  // Used for device status ioctl only
78
-  const char *m_LastErrorFilename;
79
-  int m_LastErrorLineNumber;
80
-  LONG m_NumTapOpens;
81
-
82
-  // Flags
83
-  BOOLEAN m_TapIsRunning;
84
-  BOOLEAN m_CalledTapDeviceFreeResources;
85
-
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;
91
-}
92
-TapExtension, *TapExtensionPointer;
93
-
94
-typedef struct _TapPacket
95
-   {
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
101
-   }
102
-TapPacket, *TapPacketPointer;
103
-
104
-typedef struct _InjectPacket
105
-   {
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
110
-   }
111
-InjectPacket, *InjectPacketPointer;
112
-
113
-typedef struct _TapAdapter
114
-{
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;
127
-
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;
132
-
133
-  // TRUE if device is "connected"
134
-  BOOLEAN m_MediaState;
135
-
136
-  // Adapter power state
137
-  char m_DeviceState;
138
-
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
-  ETH_HEADER m_UserToTap_IPv6;		// same as UserToTap but proto=ipv6
147
-  MACADDR m_MAC_Broadcast;
148
-
149
-  // Used for DHCP server masquerade
150
-  BOOLEAN m_dhcp_enabled;
151
-  IPADDR m_dhcp_addr;
152
-  ULONG m_dhcp_netmask;
153
-  IPADDR m_dhcp_server_ip;
154
-  BOOLEAN m_dhcp_server_arp;
155
-  MACADDR m_dhcp_server_mac;
156
-  ULONG m_dhcp_lease_time;
157
-  UCHAR m_dhcp_user_supplied_options_buffer[DHCP_USER_SUPPLIED_OPTIONS_BUFFER_SIZE];
158
-  ULONG m_dhcp_user_supplied_options_buffer_len;
159
-  BOOLEAN m_dhcp_received_discover;
160
-  ULONG m_dhcp_bad_requests;
161
-
162
-  // Help to tear down the adapter by keeping
163
-  // some state information on allocated
164
-  // resources.
165
-  BOOLEAN m_CalledAdapterFreeResources;
166
-  BOOLEAN m_RegisteredAdapterShutdownHandler;
167
-
168
-  // Multicast list info
169
-  NDIS_SPIN_LOCK m_MCLock;
170
-  BOOLEAN m_MCLockAllocated;
171
-  ULONG m_MCListSize;
172
-  MC_LIST m_MCList;
173
-
174
-  // Information on the TAP device
175
-  TapExtension m_Extension;
176
-} TapAdapter, *TapAdapterPointer;
177
-
178
-#endif
179 1
new file mode 100644
... ...
@@ -0,0 +1,68 @@
0
+/*
1
+ *  TAP-Win32/TAP-Win64 -- A kernel driver to provide virtual tap
2
+ *                         device functionality on Windows.
3
+ *
4
+ *  This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
5
+ *
6
+ *  This source code is Copyright (C) 2002-2010 OpenVPN Technologies, Inc.,
7
+ *  and is released under the GPL version 2 (see below).
8
+ *
9
+ *  This program is free software; you can redistribute it and/or modify
10
+ *  it under the terms of the GNU General Public License version 2
11
+ *  as published by the Free Software Foundation.
12
+ *
13
+ *  This program is distributed in the hope that it will be useful,
14
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ *  GNU General Public License for more details.
17
+ *
18
+ *  You should have received a copy of the GNU General Public License
19
+ *  along with this program (see the file COPYING included with this
20
+ *  distribution); if not, write to the Free Software Foundation, Inc.,
21
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
+ */
23
+#ifndef __TAP_H
24
+#define __TAP_H
25
+
26
+//=============
27
+// TAP IOCTLs
28
+//=============
29
+
30
+#define TAP_CONTROL_CODE(request,method) \
31
+  CTL_CODE (FILE_DEVICE_UNKNOWN, request, method, FILE_ANY_ACCESS)
32
+
33
+// Present in 8.1
34
+
35
+#define TAP_IOCTL_GET_MAC               TAP_CONTROL_CODE (1, METHOD_BUFFERED)
36
+#define TAP_IOCTL_GET_VERSION           TAP_CONTROL_CODE (2, METHOD_BUFFERED)
37
+#define TAP_IOCTL_GET_MTU               TAP_CONTROL_CODE (3, METHOD_BUFFERED)
38
+#define TAP_IOCTL_GET_INFO              TAP_CONTROL_CODE (4, METHOD_BUFFERED)
39
+#define TAP_IOCTL_CONFIG_POINT_TO_POINT TAP_CONTROL_CODE (5, METHOD_BUFFERED)
40
+#define TAP_IOCTL_SET_MEDIA_STATUS      TAP_CONTROL_CODE (6, METHOD_BUFFERED)
41
+#define TAP_IOCTL_CONFIG_DHCP_MASQ      TAP_CONTROL_CODE (7, METHOD_BUFFERED)
42
+#define TAP_IOCTL_GET_LOG_LINE          TAP_CONTROL_CODE (8, METHOD_BUFFERED)
43
+#define TAP_IOCTL_CONFIG_DHCP_SET_OPT   TAP_CONTROL_CODE (9, METHOD_BUFFERED)
44
+
45
+// Added in 8.2
46
+
47
+/* obsoletes TAP_IOCTL_CONFIG_POINT_TO_POINT */
48
+#define TAP_IOCTL_CONFIG_TUN            TAP_CONTROL_CODE (10, METHOD_BUFFERED)
49
+
50
+//=================
51
+// Registry keys
52
+//=================
53
+
54
+#define ADAPTER_KEY "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
55
+
56
+#define NETWORK_CONNECTIONS_KEY "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
57
+
58
+//======================
59
+// Filesystem prefixes
60
+//======================
61
+
62
+#define USERMODEDEVICEDIR "\\\\.\\Global\\"
63
+#define SYSDEVICEDIR      "\\Device\\"
64
+#define USERDEVICEDIR     "\\DosDevices\\Global\\"
65
+#define TAPSUFFIX         ".tap"
66
+
67
+#endif
... ...
@@ -27,7 +27,7 @@
27 27
 
28 28
 #ifdef WIN32
29 29
 #include <winioctl.h>
30
-#include "tap-win32/common.h"
30
+#include <tap-windows.h>
31 31
 #endif
32 32
 
33 33
 #include "buffer.h"
... ...
@@ -6,7 +6,7 @@
6 6
  *
7 7
  * The TAP-Win32 version number is defined in tap-win32/SOURCES
8 8
  */
9
-#define TAP_ID "@PRODUCT_TAP_ID@"
9
+#define TAP_COMPONENT_ID "@PRODUCT_TAP_ID@"
10 10
 #define TAP_WIN32_MIN_MAJOR @PRODUCT_TAP_WIN32_MIN_MAJOR@
11 11
 #define TAP_WIN32_MIN_MINOR @PRODUCT_TAP_WIN32_MIN_MINOR@
12 12