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