1 | /* $Id: VBoxNetFltCmn-win.h 69498 2017-10-28 15:07:25Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxNetFltCmn-win.h - Bridged Networking Driver, Windows Specific Code.
|
---|
4 | * Common header with configuration defines and global defs
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2011-2016 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * The contents of this file may alternatively be used under the terms
|
---|
19 | * of the Common Development and Distribution License Version 1.0
|
---|
20 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
21 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
22 | * CDDL are applicable instead of those of the GPL.
|
---|
23 | *
|
---|
24 | * You may elect to license modified versions of this file under the
|
---|
25 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef ___VBoxNetFltCmn_win_h___
|
---|
29 | #define ___VBoxNetFltCmn_win_h___
|
---|
30 |
|
---|
31 | #define LOG_GROUP LOG_GROUP_NET_FLT_DRV
|
---|
32 |
|
---|
33 | /* debugging flags */
|
---|
34 | #ifdef DEBUG
|
---|
35 | //# define DEBUG_NETFLT_PACKETS
|
---|
36 | # ifndef DEBUG_misha
|
---|
37 | # define RT_NO_STRICT
|
---|
38 | # endif
|
---|
39 | /* # define DEBUG_NETFLT_LOOPBACK */
|
---|
40 | /* receive logic has several branches */
|
---|
41 | /* the DEBUG_NETFLT_RECV* macros used to debug the ProtocolReceive callback
|
---|
42 | * which is typically not used in case the underlying miniport indicates the packets with NdisMIndicateReceivePacket
|
---|
43 | * the best way to debug the ProtocolReceive (which in turn has several branches) is to enable the DEBUG_NETFLT_RECV
|
---|
44 | * one by one in the below order, i.e.
|
---|
45 | * first DEBUG_NETFLT_RECV
|
---|
46 | * then DEBUG_NETFLT_RECV + DEBUG_NETFLT_RECV_NOPACKET */
|
---|
47 | //# define DEBUG_NETFLT_RECV
|
---|
48 | //# define DEBUG_NETFLT_RECV_NOPACKET
|
---|
49 | //# define DEBUG_NETFLT_RECV_TRANSFERDATA
|
---|
50 | /* use ExAllocatePoolWithTag instead of NdisAllocateMemoryWithTag */
|
---|
51 | // #define DEBUG_NETFLT_USE_EXALLOC
|
---|
52 | #endif
|
---|
53 |
|
---|
54 | #include <VBox/intnet.h>
|
---|
55 | #include <VBox/log.h>
|
---|
56 | #include <VBox/err.h>
|
---|
57 | #include <VBox/version.h>
|
---|
58 | #include <iprt/initterm.h>
|
---|
59 | #include <iprt/assert.h>
|
---|
60 | #include <iprt/spinlock.h>
|
---|
61 | #include <iprt/semaphore.h>
|
---|
62 | #include <iprt/process.h>
|
---|
63 | #include <iprt/alloc.h>
|
---|
64 | #include <iprt/alloca.h>
|
---|
65 | #include <iprt/time.h>
|
---|
66 | #include <iprt/net.h>
|
---|
67 | #include <iprt/list.h>
|
---|
68 |
|
---|
69 | #include <iprt/nt/ntddk.h>
|
---|
70 | #include <iprt/nt/ndis.h>
|
---|
71 |
|
---|
72 | #define VBOXNETFLT_OS_SPECFIC 1
|
---|
73 |
|
---|
74 | /** version
|
---|
75 | * NOTE: we are NOT using NDIS 5.1 features now */
|
---|
76 | #ifdef NDIS51_MINIPORT
|
---|
77 | # define VBOXNETFLT_VERSION_MP_NDIS_MAJOR 5
|
---|
78 | # define VBOXNETFLT_VERSION_MP_NDIS_MINOR 1
|
---|
79 | #else
|
---|
80 | # define VBOXNETFLT_VERSION_MP_NDIS_MAJOR 5
|
---|
81 | # define VBOXNETFLT_VERSION_MP_NDIS_MINOR 0
|
---|
82 | #endif
|
---|
83 |
|
---|
84 | #ifndef VBOXNETADP
|
---|
85 | #ifdef NDIS51
|
---|
86 | # define VBOXNETFLT_VERSION_PT_NDIS_MAJOR 5
|
---|
87 | # define VBOXNETFLT_VERSION_PT_NDIS_MINOR 1 /* todo: use 0 here as well ? */
|
---|
88 | #else
|
---|
89 | # define VBOXNETFLT_VERSION_PT_NDIS_MAJOR 5
|
---|
90 | # define VBOXNETFLT_VERSION_PT_NDIS_MINOR 0
|
---|
91 | #endif
|
---|
92 |
|
---|
93 | # define VBOXNETFLT_NAME_PROTOCOL L"VBoxNetFlt"
|
---|
94 | /** device to be used to prevent the driver unload & ioctl interface (if necessary in the future) */
|
---|
95 | # define VBOXNETFLT_NAME_LINK L"\\DosDevices\\Global\\VBoxNetFlt"
|
---|
96 | # define VBOXNETFLT_NAME_DEVICE L"\\Device\\VBoxNetFlt"
|
---|
97 | #else
|
---|
98 | # define VBOXNETFLT_NAME_LINK L"\\DosDevices\\Global\\VBoxNetAdp"
|
---|
99 | # define VBOXNETFLT_NAME_DEVICE L"\\Device\\VBoxNetAdp"
|
---|
100 | #endif
|
---|
101 |
|
---|
102 | typedef struct VBOXNETFLTINS *PVBOXNETFLTINS;
|
---|
103 |
|
---|
104 | /** configuration */
|
---|
105 |
|
---|
106 | /** Ndis Packet pool settings
|
---|
107 | * these are applied to both receive and send packet pools */
|
---|
108 | /* number of packets for normal used */
|
---|
109 | #define VBOXNETFLT_PACKET_POOL_SIZE_NORMAL 0x000000FF
|
---|
110 | /* number of additional overflow packets */
|
---|
111 | #define VBOXNETFLT_PACKET_POOL_SIZE_OVERFLOW 0x0000FF00
|
---|
112 |
|
---|
113 | /** packet queue size used when the driver is working in the "active" mode */
|
---|
114 | #define VBOXNETFLT_PACKET_INFO_POOL_SIZE 0x0000FFFF
|
---|
115 |
|
---|
116 | #ifndef VBOXNETADP
|
---|
117 | /** memory tag used for memory allocations
|
---|
118 | * (VBNF stands for VBox NetFlt) */
|
---|
119 | # define VBOXNETFLT_MEM_TAG 'FNBV'
|
---|
120 | #else
|
---|
121 | /** memory tag used for memory allocations
|
---|
122 | * (VBNA stands for VBox NetAdp) */
|
---|
123 | # define VBOXNETFLT_MEM_TAG 'ANBV'
|
---|
124 | #endif
|
---|
125 |
|
---|
126 | /** receive and transmit Ndis buffer pool size */
|
---|
127 | #define VBOXNETFLT_BUFFER_POOL_SIZE_TX 128
|
---|
128 | #define VBOXNETFLT_BUFFER_POOL_SIZE_RX 128
|
---|
129 |
|
---|
130 | #define VBOXNETFLT_PACKET_ETHEADER_SIZE 14
|
---|
131 | #define VBOXNETFLT_PACKET_HEADER_MATCH_SIZE 24
|
---|
132 | #define VBOXNETFLT_PACKET_QUEUE_SG_SEGS_ALLOC 32
|
---|
133 |
|
---|
134 |
|
---|
135 | #if defined(DEBUG_NETFLT_PACKETS) || !defined(VBOX_LOOPBACK_USEFLAGS)
|
---|
136 | # define VBOXNETFLT_PACKETMATCH_LENGTH (VBOXNETFLT_PACKET_ETHEADER_SIZE + 2)
|
---|
137 | #endif
|
---|
138 |
|
---|
139 | #ifdef VBOXNETADP
|
---|
140 | #define VBOXNETADP_HEADER_SIZE 14
|
---|
141 | #define VBOXNETADP_MAX_DATA_SIZE 1500
|
---|
142 | #define VBOXNETADP_MAX_PACKET_SIZE (VBOXNETADP_HEADER_SIZE + VBOXNETADP_MAX_DATA_SIZE)
|
---|
143 | #define VBOXNETADP_MIN_PACKET_SIZE 60
|
---|
144 | /* link speed 100Mbps (measured in 100 bps) */
|
---|
145 | #define VBOXNETADP_LINK_SPEED 1000000
|
---|
146 | #define VBOXNETADP_MAX_LOOKAHEAD_SIZE VBOXNETADP_MAX_DATA_SIZE
|
---|
147 | #define VBOXNETADP_VENDOR_ID 0x080027
|
---|
148 | #define VBOXNETADP_VENDOR_DRIVER_VERSION 0x00010000
|
---|
149 | #define VBOXNETADP_VENDOR_DESC "Sun"
|
---|
150 | #define VBOXNETADP_MAX_MCAST_LIST 32
|
---|
151 | #define VBOXNETADP_ETH_ADDRESS_LENGTH 6
|
---|
152 |
|
---|
153 | //#define VBOXNETADP_REPORT_DISCONNECTED
|
---|
154 | #endif
|
---|
155 | /* type defs */
|
---|
156 |
|
---|
157 | /** Flag specifying that the type of enqueued packet
|
---|
158 | * if set the info contains the PINTNETSG packet
|
---|
159 | * if clear the packet info contains the PNDIS_PACKET packet
|
---|
160 | * Typically the packet queue we are maintaining contains PNDIS_PACKETs only,
|
---|
161 | * however in case the underlying miniport indicates a packet with the NDIS_STATUS_RESOURCES status
|
---|
162 | * we MUST return the packet back to the miniport immediately
|
---|
163 | * this is why we are creating the INTNETSG, copying the ndis packet info there and enqueueing it */
|
---|
164 | #define VBOXNETFLT_PACKET_SG 0x00000001
|
---|
165 |
|
---|
166 | /** the flag specifying that the packet source
|
---|
167 | * if set the packet comes from the host (upperlying protocol)
|
---|
168 | * if clear the packet comes from the wire (underlying miniport) */
|
---|
169 | #define VBOXNETFLT_PACKET_SRC_HOST 0x00000002
|
---|
170 |
|
---|
171 | #ifndef VBOXNETFLT_NO_PACKET_QUEUE
|
---|
172 | /** flag specifying the packet was originated by our driver
|
---|
173 | * i.e. we could use it on our needs and should not return it
|
---|
174 | * we are enqueueing "our" packets on ProtocolReceive call-back when
|
---|
175 | * Ndis does not give us a receive packet (the driver below us has called NdisM..IndicateReceive)
|
---|
176 | * this is supported for Ndis Packet only */
|
---|
177 | #define VBOXNETFLT_PACKET_MINE 0x00000004
|
---|
178 |
|
---|
179 | /** flag passed to vboxNetFltWinQuEnqueuePacket specifying that the packet should be copied
|
---|
180 | * this is supported for Ndis Packet only */
|
---|
181 | #define VBOXNETFLT_PACKET_COPY 0x00000008
|
---|
182 | #endif
|
---|
183 |
|
---|
184 | /** packet queue element containing the packet info */
|
---|
185 | typedef struct VBOXNETFLT_PACKET_INFO
|
---|
186 | {
|
---|
187 | /** list entry used for enqueueing the info */
|
---|
188 | LIST_ENTRY ListEntry;
|
---|
189 | /** pointer to the pool containing this packet info */
|
---|
190 | struct VBOXNETFLT_PACKET_INFO_POOL *pPool;
|
---|
191 | /** flags describing the referenced packet. Contains PACKET_xxx flags (i.e. PACKET_SG, PACKET_SRC_HOST) */
|
---|
192 | uint32_t fFlags;
|
---|
193 | /** pointer to the packet this info represents */
|
---|
194 | PVOID pPacket;
|
---|
195 | } VBOXNETFLT_PACKET_INFO, *PVBOXNETFLT_PACKET_INFO;
|
---|
196 |
|
---|
197 | /* paranoid check to make sure the elements in the packet info array are properly aligned */
|
---|
198 | AssertCompile((sizeof(VBOXNETFLT_PACKET_INFO) & (sizeof(PVOID) - 1)) == 0);
|
---|
199 |
|
---|
200 | /** represents the packet queue */
|
---|
201 | typedef LIST_ENTRY PVBOXNETFLT_ACKET_QUEUE, *PVBOXNETFLT_PACKET_QUEUE;
|
---|
202 |
|
---|
203 | /*
|
---|
204 | * we are using non-interlocked versions of LIST_ENTRY-related operations macros and synchronize
|
---|
205 | * access to the queue and its elements by acquiring/releasing a spinlock using Ndis[Acquire,Release]Spinlock
|
---|
206 | *
|
---|
207 | * we are NOT using interlocked versions of insert/remove head/tail list functions because we need to iterate though
|
---|
208 | * the queue elements as well as remove elements from the midle of the queue
|
---|
209 | *
|
---|
210 | * * @todo: it seems that we can switch to using interlocked versions of list-entry functions
|
---|
211 | * since we have removed all functionality (mentioned above, i.e. queue elements iteration, etc.) that might prevent us from doing this
|
---|
212 | */
|
---|
213 | typedef struct VBOXNETFLT_INTERLOCKED_PACKET_QUEUE
|
---|
214 | {
|
---|
215 | /** queue */
|
---|
216 | PVBOXNETFLT_ACKET_QUEUE Queue;
|
---|
217 | /** queue lock */
|
---|
218 | NDIS_SPIN_LOCK Lock;
|
---|
219 | } VBOXNETFLT_INTERLOCKED_PACKET_QUEUE, *PVBOXNETFLT_INTERLOCKED_PACKET_QUEUE;
|
---|
220 |
|
---|
221 | typedef struct VBOXNETFLT_SINGLE_LIST
|
---|
222 | {
|
---|
223 | /** queue */
|
---|
224 | SINGLE_LIST_ENTRY Head;
|
---|
225 | /** pointer to the list tail. used to enqueue elements to the tail of the list */
|
---|
226 | PSINGLE_LIST_ENTRY pTail;
|
---|
227 | } VBOXNETFLT_SINGLE_LIST, *PVBOXNETFLT_SINGLE_LIST;
|
---|
228 |
|
---|
229 | typedef struct VBOXNETFLT_INTERLOCKED_SINGLE_LIST
|
---|
230 | {
|
---|
231 | /** queue */
|
---|
232 | VBOXNETFLT_SINGLE_LIST List;
|
---|
233 | /** queue lock */
|
---|
234 | NDIS_SPIN_LOCK Lock;
|
---|
235 | } VBOXNETFLT_INTERLOCKED_SINGLE_LIST, *PVBOXNETFLT_INTERLOCKED_SINGLE_LIST;
|
---|
236 |
|
---|
237 | /** packet info pool contains free packet info elements to be used for the packet queue
|
---|
238 | * we are using the pool mechanism to allocate packet queue elements
|
---|
239 | * the pool mechanism is pretty simple now, we are allocating a bunch of memory
|
---|
240 | * for maintaining VBOXNETFLT_PACKET_INFO_POOL_SIZE queue elements and just returning null when the pool is exhausted
|
---|
241 | * This mechanism seems to be enough for now since we are using VBOXNETFLT_PACKET_INFO_POOL_SIZE = 0xffff which is
|
---|
242 | * the maximum size of packets the ndis packet pool supports */
|
---|
243 | typedef struct VBOXNETFLT_PACKET_INFO_POOL
|
---|
244 | {
|
---|
245 | /** free packet info queue */
|
---|
246 | VBOXNETFLT_INTERLOCKED_PACKET_QUEUE Queue;
|
---|
247 | /** memory bugger used by the pool */
|
---|
248 | PVOID pBuffer;
|
---|
249 | } VBOXNETFLT_PACKET_INFO_POOL, *PVBOXNETFLT_PACKET_INFO_POOL;
|
---|
250 |
|
---|
251 | typedef enum VBOXNETDEVOPSTATE
|
---|
252 | {
|
---|
253 | kVBoxNetDevOpState_InvalidValue = 0,
|
---|
254 | kVBoxNetDevOpState_Initializing,
|
---|
255 | kVBoxNetDevOpState_Initialized,
|
---|
256 | kVBoxNetDevOpState_Deinitializing,
|
---|
257 | kVBoxNetDevOpState_Deinitialized,
|
---|
258 |
|
---|
259 | } VBOXNETDEVOPSTATE;
|
---|
260 |
|
---|
261 | typedef enum VBOXNETFLT_WINIFSTATE
|
---|
262 | {
|
---|
263 | /** The usual invalid state. */
|
---|
264 | kVBoxWinIfState_Invalid = 0,
|
---|
265 | /** Initialization. */
|
---|
266 | kVBoxWinIfState_Connecting,
|
---|
267 | /** Connected fuly functional state */
|
---|
268 | kVBoxWinIfState_Connected,
|
---|
269 | /** Disconnecting */
|
---|
270 | kVBoxWinIfState_Disconnecting,
|
---|
271 | /** Disconnected */
|
---|
272 | kVBoxWinIfState_Disconnected,
|
---|
273 | } VBOXNETFLT_WINIFSTATE;
|
---|
274 |
|
---|
275 | /** structure used to maintain the state and reference count of the miniport and protocol */
|
---|
276 | typedef struct VBOXNETFLT_WINIF_DEVICE
|
---|
277 | {
|
---|
278 | /** initialize state */
|
---|
279 | VBOXNETDEVOPSTATE OpState;
|
---|
280 | /** ndis power state */
|
---|
281 | NDIS_DEVICE_POWER_STATE PowerState;
|
---|
282 | /** reference count */
|
---|
283 | uint32_t cReferences;
|
---|
284 | } VBOXNETFLT_WINIF_DEVICE, *PVBOXNETFLT_WINIF_DEVICE;
|
---|
285 |
|
---|
286 | #define VBOXNDISREQUEST_INPROGRESS 1
|
---|
287 | #define VBOXNDISREQUEST_QUEUED 2
|
---|
288 |
|
---|
289 | typedef struct VBOXNETFLTWIN_STATE
|
---|
290 | {
|
---|
291 | union
|
---|
292 | {
|
---|
293 | struct
|
---|
294 | {
|
---|
295 | UINT fRequestInfo : 2;
|
---|
296 | UINT fInterfaceClosing : 1;
|
---|
297 | UINT fStandBy : 1;
|
---|
298 | UINT fProcessingPacketFilter : 1;
|
---|
299 | UINT fPPFNetFlt : 1;
|
---|
300 | UINT fUpperProtSetFilterInitialized : 1;
|
---|
301 | UINT Reserved : 25;
|
---|
302 | };
|
---|
303 | UINT Value;
|
---|
304 | };
|
---|
305 | } VBOXNETFLTWIN_STATE, *PVBOXNETFLTWIN_STATE;
|
---|
306 |
|
---|
307 | DECLINLINE(VBOXNETFLTWIN_STATE) vboxNetFltWinAtomicUoReadWinState(VBOXNETFLTWIN_STATE State)
|
---|
308 | {
|
---|
309 | UINT fValue = ASMAtomicUoReadU32((volatile uint32_t *)&State.Value);
|
---|
310 | return *((PVBOXNETFLTWIN_STATE)((void*)&fValue));
|
---|
311 | }
|
---|
312 |
|
---|
313 | /* miniport layer globals */
|
---|
314 | typedef struct VBOXNETFLTGLOBALS_MP
|
---|
315 | {
|
---|
316 | /** our miniport handle */
|
---|
317 | NDIS_HANDLE hMiniport;
|
---|
318 | /** ddis wrapper handle */
|
---|
319 | NDIS_HANDLE hNdisWrapper;
|
---|
320 | } VBOXNETFLTGLOBALS_MP, *PVBOXNETFLTGLOBALS_MP;
|
---|
321 |
|
---|
322 | #ifndef VBOXNETADP
|
---|
323 | /* protocol layer globals */
|
---|
324 | typedef struct VBOXNETFLTGLOBALS_PT
|
---|
325 | {
|
---|
326 | /** our protocol handle */
|
---|
327 | NDIS_HANDLE hProtocol;
|
---|
328 | } VBOXNETFLTGLOBALS_PT, *PVBOXNETFLTGLOBALS_PT;
|
---|
329 | #endif /* #ifndef VBOXNETADP */
|
---|
330 |
|
---|
331 | typedef struct VBOXNETFLTGLOBALS_WIN
|
---|
332 | {
|
---|
333 | /** synch event used for device creation synchronization */
|
---|
334 | KEVENT SynchEvent;
|
---|
335 | /** Device reference count */
|
---|
336 | int cDeviceRefs;
|
---|
337 | /** ndis device */
|
---|
338 | NDIS_HANDLE hDevice;
|
---|
339 | /** device object */
|
---|
340 | PDEVICE_OBJECT pDevObj;
|
---|
341 | /* loopback flags */
|
---|
342 | /* ndis packet flags to disable packet loopback */
|
---|
343 | UINT fPacketDontLoopBack;
|
---|
344 | /* ndis packet flags specifying whether the packet is looped back */
|
---|
345 | UINT fPacketIsLoopedBack;
|
---|
346 | /* Minport info */
|
---|
347 | VBOXNETFLTGLOBALS_MP Mp;
|
---|
348 | #ifndef VBOXNETADP
|
---|
349 | /* Protocol info */
|
---|
350 | VBOXNETFLTGLOBALS_PT Pt;
|
---|
351 | /** lock protecting the filter list */
|
---|
352 | NDIS_SPIN_LOCK lockFilters;
|
---|
353 | /** the head of filter list */
|
---|
354 | RTLISTANCHOR listFilters;
|
---|
355 | /** IP address change notifier handle */
|
---|
356 | HANDLE hNotifier;
|
---|
357 | #endif
|
---|
358 | } VBOXNETFLTGLOBALS_WIN, *PVBOXNETFLTGLOBALS_WIN;
|
---|
359 |
|
---|
360 | extern VBOXNETFLTGLOBALS_WIN g_VBoxNetFltGlobalsWin;
|
---|
361 |
|
---|
362 | /** represents filter driver device context*/
|
---|
363 | typedef struct VBOXNETFLTWIN
|
---|
364 | {
|
---|
365 | /** handle used by miniport edge for ndis calls */
|
---|
366 | NDIS_HANDLE hMiniport;
|
---|
367 | /** miniport edge state */
|
---|
368 | VBOXNETFLT_WINIF_DEVICE MpState;
|
---|
369 | /** ndis packet pool used for receives */
|
---|
370 | NDIS_HANDLE hRecvPacketPool;
|
---|
371 | /** ndis buffer pool used for receives */
|
---|
372 | NDIS_HANDLE hRecvBufferPool;
|
---|
373 | /** driver bind adapter state. */
|
---|
374 | VBOXNETFLT_WINIFSTATE enmState;
|
---|
375 | #ifndef VBOXNETADP
|
---|
376 | /* misc state flags */
|
---|
377 | VBOXNETFLTWIN_STATE StateFlags;
|
---|
378 | /** handle used by protocol edge for ndis calls */
|
---|
379 | NDIS_HANDLE hBinding;
|
---|
380 | /** protocol edge state */
|
---|
381 | VBOXNETFLT_WINIF_DEVICE PtState;
|
---|
382 | /** ndis packet pool used for receives */
|
---|
383 | NDIS_HANDLE hSendPacketPool;
|
---|
384 | /** ndis buffer pool used for receives */
|
---|
385 | NDIS_HANDLE hSendBufferPool;
|
---|
386 | /** used for maintaining the pending send packets for handling packet loopback */
|
---|
387 | VBOXNETFLT_INTERLOCKED_SINGLE_LIST SendPacketQueue;
|
---|
388 | /** used for serializing calls to the NdisRequest in the vboxNetFltWinSynchNdisRequest */
|
---|
389 | RTSEMFASTMUTEX hSynchRequestMutex;
|
---|
390 | /** event used to synchronize with the Ndis Request completion in the vboxNetFltWinSynchNdisRequest */
|
---|
391 | KEVENT hSynchCompletionEvent;
|
---|
392 | /** status of the Ndis Request initiated by the vboxNetFltWinSynchNdisRequest */
|
---|
393 | NDIS_STATUS volatile SynchCompletionStatus;
|
---|
394 | /** pointer to the Ndis Request being executed by the vboxNetFltWinSynchNdisRequest */
|
---|
395 | PNDIS_REQUEST volatile pSynchRequest;
|
---|
396 | /** open/close adapter status.
|
---|
397 | * Since ndis adapter open and close requests may complete asynchronously,
|
---|
398 | * we are using event mechanism to wait for open/close completion
|
---|
399 | * the status field is being set by the completion call-back */
|
---|
400 | NDIS_STATUS OpenCloseStatus;
|
---|
401 | /** open/close adaptor completion event */
|
---|
402 | NDIS_EVENT OpenCloseEvent;
|
---|
403 | /** medium we are attached to */
|
---|
404 | NDIS_MEDIUM enmMedium;
|
---|
405 | /**
|
---|
406 | * Passdown request info
|
---|
407 | */
|
---|
408 | /** ndis request we pass down to the miniport below */
|
---|
409 | NDIS_REQUEST PassDownRequest;
|
---|
410 | /** Ndis pass down request bytes read or written original pointer */
|
---|
411 | PULONG pcPDRBytesRW;
|
---|
412 | /** Ndis pass down request bytes needed original pointer */
|
---|
413 | PULONG pcPDRBytesNeeded;
|
---|
414 | /** true if we should indicate the receive complete used by the ProtocolReceive mechanism.
|
---|
415 | * We need to indicate it only with the ProtocolReceive + NdisMEthIndicateReceive path.
|
---|
416 | * Note: we're using KeGetCurrentProcessorNumber, which is not entirely correct in case
|
---|
417 | * we're running on 64bit win7+, which can handle > 64 CPUs, however since KeGetCurrentProcessorNumber
|
---|
418 | * always returns the number < than the number of CPUs in the first group, we're guaranteed to have CPU index < 64
|
---|
419 | * @todo: use KeGetCurrentProcessorNumberEx for Win7+ 64 and dynamically extended array */
|
---|
420 | bool abIndicateRxComplete[64];
|
---|
421 | /** Pending transfer data packet queue (i.e. packets that were indicated as pending on NdisTransferData call */
|
---|
422 | VBOXNETFLT_INTERLOCKED_SINGLE_LIST TransferDataList;
|
---|
423 | /* mac options initialized on OID_GEN_MAC_OPTIONS */
|
---|
424 | ULONG fMacOptions;
|
---|
425 | /** our miniport devuice name */
|
---|
426 | NDIS_STRING MpDeviceName;
|
---|
427 | /** synchronize with unbind with Miniport initialization */
|
---|
428 | NDIS_EVENT MpInitCompleteEvent;
|
---|
429 | /** media connect status that we indicated */
|
---|
430 | NDIS_STATUS MpIndicatedMediaStatus;
|
---|
431 | /** media connect status pending to indicate */
|
---|
432 | NDIS_STATUS MpUnindicatedMediaStatus;
|
---|
433 | /** packet filter flags set by the upper protocols */
|
---|
434 | ULONG fUpperProtocolSetFilter;
|
---|
435 | /** packet filter flags set by the upper protocols */
|
---|
436 | ULONG fSetFilterBuffer;
|
---|
437 | /** packet filter flags set by us */
|
---|
438 | ULONG fOurSetFilter;
|
---|
439 | /** our own list of filters, needed by notifier */
|
---|
440 | RTLISTNODE node;
|
---|
441 | #else
|
---|
442 | volatile ULONG cTxSuccess;
|
---|
443 | volatile ULONG cRxSuccess;
|
---|
444 | volatile ULONG cTxError;
|
---|
445 | volatile ULONG cRxError;
|
---|
446 | #endif
|
---|
447 | } VBOXNETFLTWIN, *PVBOXNETFLTWIN;
|
---|
448 |
|
---|
449 | typedef struct VBOXNETFLT_PACKET_QUEUE_WORKER
|
---|
450 | {
|
---|
451 | /** this event is used to initiate a packet queue worker thread kill */
|
---|
452 | KEVENT KillEvent;
|
---|
453 | /** this event is used to notify a worker thread that the packets are added to the queue */
|
---|
454 | KEVENT NotifyEvent;
|
---|
455 | /** pointer to the packet queue worker thread object */
|
---|
456 | PKTHREAD pThread;
|
---|
457 | /** pointer to the SG used by the packet queue for IntNet receive notifications */
|
---|
458 | PINTNETSG pSG;
|
---|
459 | /** Packet queue */
|
---|
460 | VBOXNETFLT_INTERLOCKED_PACKET_QUEUE PacketQueue;
|
---|
461 | /** Packet info pool, i.e. the pool for the packet queue elements */
|
---|
462 | VBOXNETFLT_PACKET_INFO_POOL PacketInfoPool;
|
---|
463 | } VBOXNETFLT_PACKET_QUEUE_WORKER, *PVBOXNETFLT_PACKET_QUEUE_WORKER;
|
---|
464 |
|
---|
465 | /* protocol reserved data held in ndis packet */
|
---|
466 | typedef struct VBOXNETFLT_PKTRSVD_PT
|
---|
467 | {
|
---|
468 | /** original packet received from the upperlying protocol
|
---|
469 | * can be null if the packet was originated by intnet */
|
---|
470 | PNDIS_PACKET pOrigPacket;
|
---|
471 | /** pointer to the buffer to be freed on send completion
|
---|
472 | * can be null if no buffer is to be freed */
|
---|
473 | PVOID pBufToFree;
|
---|
474 | #if !defined(VBOX_LOOPBACK_USEFLAGS) || defined(DEBUG_NETFLT_PACKETS)
|
---|
475 | SINGLE_LIST_ENTRY ListEntry;
|
---|
476 | /* true if the packet is from IntNet */
|
---|
477 | bool bFromIntNet;
|
---|
478 | #endif
|
---|
479 | } VBOXNETFLT_PKTRSVD_PT, *PVBOXNETFLT_PKTRSVD_PT;
|
---|
480 |
|
---|
481 | /** miniport reserved data held in ndis packet */
|
---|
482 | typedef struct VBOXNETFLT_PKTRSVD_MP
|
---|
483 | {
|
---|
484 | /** original packet received from the underling miniport
|
---|
485 | * can be null if the packet was originated by intnet */
|
---|
486 | PNDIS_PACKET pOrigPacket;
|
---|
487 | /** pointer to the buffer to be freed on receive completion
|
---|
488 | * can be null if no buffer is to be freed */
|
---|
489 | PVOID pBufToFree;
|
---|
490 | } VBOXNETFLT_PKTRSVD_MP, *PVBOXNETFLT_PKTRSVD_MP;
|
---|
491 |
|
---|
492 | /** represents the data stored in the protocol reserved field of ndis packet on NdisTransferData processing */
|
---|
493 | typedef struct VBOXNETFLT_PKTRSVD_TRANSFERDATA_PT
|
---|
494 | {
|
---|
495 | /** next packet in a list */
|
---|
496 | SINGLE_LIST_ENTRY ListEntry;
|
---|
497 | /* packet buffer start */
|
---|
498 | PNDIS_BUFFER pOrigBuffer;
|
---|
499 | } VBOXNETFLT_PKTRSVD_TRANSFERDATA_PT, *PVBOXNETFLT_PKTRSVD_TRANSFERDATA_PT;
|
---|
500 |
|
---|
501 | /* VBOXNETFLT_PKTRSVD_TRANSFERDATA_PT should fit into PROTOCOL_RESERVED_SIZE_IN_PACKET because we use protocol reserved part
|
---|
502 | * of our miniport edge on transfer data processing for honding our own info */
|
---|
503 | AssertCompile(sizeof (VBOXNETFLT_PKTRSVD_TRANSFERDATA_PT) <= PROTOCOL_RESERVED_SIZE_IN_PACKET);
|
---|
504 | /* this should fit in MiniportReserved */
|
---|
505 | AssertCompile(sizeof (VBOXNETFLT_PKTRSVD_MP) <= RT_SIZEOFMEMB(NDIS_PACKET, MiniportReserved));
|
---|
506 | /* we use RTAsmAtomic*U32 for those, make sure we're correct */
|
---|
507 | AssertCompile(sizeof (NDIS_DEVICE_POWER_STATE) == sizeof (uint32_t));
|
---|
508 | AssertCompile(sizeof (UINT) == sizeof (uint32_t));
|
---|
509 |
|
---|
510 |
|
---|
511 | #define NDIS_FLAGS_SKIP_LOOPBACK_W2K 0x400
|
---|
512 |
|
---|
513 | #include "../../VBoxNetFltInternal.h"
|
---|
514 | #include "VBoxNetFltRt-win.h"
|
---|
515 | #ifndef VBOXNETADP
|
---|
516 | # include "VBoxNetFltP-win.h"
|
---|
517 | #endif
|
---|
518 | #include "VBoxNetFltM-win.h"
|
---|
519 |
|
---|
520 | #endif /* #ifndef ___VBoxNetFltCmn_win_h___ */
|
---|