1 | /* $Id: VBoxNetFltRt-win.h 40806 2012-04-06 21:05:19Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxNetFltRt-win.h - Bridged Networking Driver, Windows Specific Code.
|
---|
4 | * NetFlt Runtime API
|
---|
5 | */
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 | #ifndef ___VBoxNetFltRt_win_h___
|
---|
18 | #define ___VBoxNetFltRt_win_h___
|
---|
19 | DECLHIDDEN(VOID) vboxNetFltWinUnload(IN PDRIVER_OBJECT DriverObject);
|
---|
20 |
|
---|
21 | #ifndef VBOXNETADP
|
---|
22 | # if !defined(VBOX_LOOPBACK_USEFLAGS) || defined(DEBUG_NETFLT_PACKETS)
|
---|
23 | DECLHIDDEN(bool) vboxNetFltWinMatchPackets(PNDIS_PACKET pPacket1, PNDIS_PACKET pPacket2, const INT cbMatch);
|
---|
24 | DECLHIDDEN(bool) vboxNetFltWinMatchPacketAndSG(PNDIS_PACKET pPacket, PINTNETSG pSG, const INT cbMatch);
|
---|
25 | # endif
|
---|
26 | #endif
|
---|
27 |
|
---|
28 | /*************************
|
---|
29 | * packet queue API *
|
---|
30 | *************************/
|
---|
31 |
|
---|
32 |
|
---|
33 | #define LIST_ENTRY_2_PACKET_INFO(pListEntry) \
|
---|
34 | ( (PVBOXNETFLT_PACKET_INFO)((uint8_t *)(pListEntry) - RT_OFFSETOF(VBOXNETFLT_PACKET_INFO, ListEntry)) )
|
---|
35 |
|
---|
36 | #if !defined(VBOX_LOOPBACK_USEFLAGS) || defined(DEBUG_NETFLT_PACKETS)
|
---|
37 |
|
---|
38 | #define VBOX_SLE_2_PKTRSVD_PT(_pEntry) \
|
---|
39 | ( (PVBOXNETFLT_PKTRSVD_PT)((uint8_t *)(_pEntry) - RT_OFFSETOF(VBOXNETFLT_PKTRSVD_PT, ListEntry)) )
|
---|
40 |
|
---|
41 | #define VBOX_SLE_2_SENDPACKET(_pEntry) \
|
---|
42 | ( (PNDIS_PACKET)((uint8_t *)(VBOX_SLE_2_PKTRSVD_PT(_pEntry)) - RT_OFFSETOF(NDIS_PACKET, ProtocolReserved)) )
|
---|
43 |
|
---|
44 | #endif
|
---|
45 | /**
|
---|
46 | * enqueus the packet info to the tail of the queue
|
---|
47 | */
|
---|
48 | DECLINLINE(void) vboxNetFltWinQuEnqueueTail(PVBOXNETFLT_PACKET_QUEUE pQueue, PVBOXNETFLT_PACKET_INFO pPacketInfo)
|
---|
49 | {
|
---|
50 | InsertTailList(pQueue, &pPacketInfo->ListEntry);
|
---|
51 | }
|
---|
52 |
|
---|
53 | DECLINLINE(void) vboxNetFltWinQuEnqueueHead(PVBOXNETFLT_PACKET_QUEUE pQueue, PVBOXNETFLT_PACKET_INFO pPacketInfo)
|
---|
54 | {
|
---|
55 | Assert(pPacketInfo->pPool);
|
---|
56 | InsertHeadList(pQueue, &pPacketInfo->ListEntry);
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * enqueus the packet info to the tail of the queue
|
---|
61 | */
|
---|
62 | DECLINLINE(void) vboxNetFltWinQuInterlockedEnqueueTail(PVBOXNETFLT_INTERLOCKED_PACKET_QUEUE pQueue, PVBOXNETFLT_PACKET_INFO pPacketInfo)
|
---|
63 | {
|
---|
64 | Assert(pPacketInfo->pPool);
|
---|
65 | NdisAcquireSpinLock(&pQueue->Lock);
|
---|
66 | vboxNetFltWinQuEnqueueTail(&pQueue->Queue, pPacketInfo);
|
---|
67 | NdisReleaseSpinLock(&pQueue->Lock);
|
---|
68 | }
|
---|
69 |
|
---|
70 | DECLINLINE(void) vboxNetFltWinQuInterlockedEnqueueHead(PVBOXNETFLT_INTERLOCKED_PACKET_QUEUE pQueue, PVBOXNETFLT_PACKET_INFO pPacketInfo)
|
---|
71 | {
|
---|
72 | NdisAcquireSpinLock(&pQueue->Lock);
|
---|
73 | vboxNetFltWinQuEnqueueHead(&pQueue->Queue, pPacketInfo);
|
---|
74 | NdisReleaseSpinLock(&pQueue->Lock);
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * dequeus the packet info from the head of the queue
|
---|
79 | */
|
---|
80 | DECLINLINE(PVBOXNETFLT_PACKET_INFO) vboxNetFltWinQuDequeueHead(PVBOXNETFLT_PACKET_QUEUE pQueue)
|
---|
81 | {
|
---|
82 | PLIST_ENTRY pListEntry = RemoveHeadList(pQueue);
|
---|
83 | if(pListEntry != pQueue)
|
---|
84 | {
|
---|
85 | PVBOXNETFLT_PACKET_INFO pInfo = LIST_ENTRY_2_PACKET_INFO(pListEntry);
|
---|
86 | Assert(pInfo->pPool);
|
---|
87 | return pInfo;
|
---|
88 | }
|
---|
89 | return NULL;
|
---|
90 | }
|
---|
91 |
|
---|
92 | DECLINLINE(PVBOXNETFLT_PACKET_INFO) vboxNetFltWinQuDequeueTail(PVBOXNETFLT_PACKET_QUEUE pQueue)
|
---|
93 | {
|
---|
94 | PLIST_ENTRY pListEntry = RemoveTailList(pQueue);
|
---|
95 | if(pListEntry != pQueue)
|
---|
96 | {
|
---|
97 | PVBOXNETFLT_PACKET_INFO pInfo = LIST_ENTRY_2_PACKET_INFO(pListEntry);
|
---|
98 | Assert(pInfo->pPool);
|
---|
99 | return pInfo;
|
---|
100 | }
|
---|
101 | return NULL;
|
---|
102 | }
|
---|
103 |
|
---|
104 | DECLINLINE(PVBOXNETFLT_PACKET_INFO) vboxNetFltWinQuInterlockedDequeueHead(PVBOXNETFLT_INTERLOCKED_PACKET_QUEUE pInterlockedQueue)
|
---|
105 | {
|
---|
106 | PVBOXNETFLT_PACKET_INFO pInfo;
|
---|
107 | NdisAcquireSpinLock(&pInterlockedQueue->Lock);
|
---|
108 | pInfo = vboxNetFltWinQuDequeueHead(&pInterlockedQueue->Queue);
|
---|
109 | NdisReleaseSpinLock(&pInterlockedQueue->Lock);
|
---|
110 | return pInfo;
|
---|
111 | }
|
---|
112 |
|
---|
113 | DECLINLINE(PVBOXNETFLT_PACKET_INFO) vboxNetFltWinQuInterlockedDequeueTail(PVBOXNETFLT_INTERLOCKED_PACKET_QUEUE pInterlockedQueue)
|
---|
114 | {
|
---|
115 | PVBOXNETFLT_PACKET_INFO pInfo;
|
---|
116 | NdisAcquireSpinLock(&pInterlockedQueue->Lock);
|
---|
117 | pInfo = vboxNetFltWinQuDequeueTail(&pInterlockedQueue->Queue);
|
---|
118 | NdisReleaseSpinLock(&pInterlockedQueue->Lock);
|
---|
119 | return pInfo;
|
---|
120 | }
|
---|
121 |
|
---|
122 | DECLINLINE(void) vboxNetFltWinQuDequeue(PVBOXNETFLT_PACKET_INFO pInfo)
|
---|
123 | {
|
---|
124 | RemoveEntryList(&pInfo->ListEntry);
|
---|
125 | }
|
---|
126 |
|
---|
127 | DECLINLINE(void) vboxNetFltWinQuInterlockedDequeue(PVBOXNETFLT_INTERLOCKED_PACKET_QUEUE pInterlockedQueue, PVBOXNETFLT_PACKET_INFO pInfo)
|
---|
128 | {
|
---|
129 | NdisAcquireSpinLock(&pInterlockedQueue->Lock);
|
---|
130 | vboxNetFltWinQuDequeue(pInfo);
|
---|
131 | NdisReleaseSpinLock(&pInterlockedQueue->Lock);
|
---|
132 | }
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * allocates the packet info from the pool
|
---|
136 | */
|
---|
137 | DECLINLINE(PVBOXNETFLT_PACKET_INFO) vboxNetFltWinPpAllocPacketInfo(PVBOXNETFLT_PACKET_INFO_POOL pPool)
|
---|
138 | {
|
---|
139 | return vboxNetFltWinQuInterlockedDequeueHead(&pPool->Queue);
|
---|
140 | }
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * returns the packet info to the pool
|
---|
144 | */
|
---|
145 | DECLINLINE(void) vboxNetFltWinPpFreePacketInfo(PVBOXNETFLT_PACKET_INFO pInfo)
|
---|
146 | {
|
---|
147 | PVBOXNETFLT_PACKET_INFO_POOL pPool = pInfo->pPool;
|
---|
148 | vboxNetFltWinQuInterlockedEnqueueHead(&pPool->Queue, pInfo);
|
---|
149 | }
|
---|
150 |
|
---|
151 | /** initializes the packet queue */
|
---|
152 | #define INIT_PACKET_QUEUE(_pQueue) InitializeListHead((_pQueue))
|
---|
153 |
|
---|
154 | /** initializes the packet queue */
|
---|
155 | #define INIT_INTERLOCKED_PACKET_QUEUE(_pQueue) \
|
---|
156 | { \
|
---|
157 | INIT_PACKET_QUEUE(&(_pQueue)->Queue); \
|
---|
158 | NdisAllocateSpinLock(&(_pQueue)->Lock); \
|
---|
159 | }
|
---|
160 |
|
---|
161 | /** delete the packet queue */
|
---|
162 | #define FINI_INTERLOCKED_PACKET_QUEUE(_pQueue) NdisFreeSpinLock(&(_pQueue)->Lock)
|
---|
163 |
|
---|
164 | /** returns the packet the packet info contains */
|
---|
165 | #define GET_PACKET_FROM_INFO(_pPacketInfo) (ASMAtomicUoReadPtr((void * volatile *)&(_pPacketInfo)->pPacket))
|
---|
166 |
|
---|
167 | /** assignes the packet to the packet info */
|
---|
168 | #define SET_PACKET_TO_INFO(_pPacketInfo, _pPacket) (ASMAtomicUoWritePtr(&(_pPacketInfo)->pPacket, (_pPacket)))
|
---|
169 |
|
---|
170 | /** returns the flags the packet info contains */
|
---|
171 | #define GET_FLAGS_FROM_INFO(_pPacketInfo) (ASMAtomicUoReadU32((volatile uint32_t *)&(_pPacketInfo)->fFlags))
|
---|
172 |
|
---|
173 | /** sets flags to the packet info */
|
---|
174 | #define SET_FLAGS_TO_INFO(_pPacketInfo, _fFlags) (ASMAtomicUoWriteU32((volatile uint32_t *)&(_pPacketInfo)->fFlags, (_fFlags)))
|
---|
175 |
|
---|
176 | #ifdef VBOXNETFLT_NO_PACKET_QUEUE
|
---|
177 | DECLHIDDEN(bool) vboxNetFltWinPostIntnet(PVBOXNETFLTINS pInstance, PVOID pvPacket, const UINT fFlags);
|
---|
178 | #else
|
---|
179 | DECLHIDDEN(NDIS_STATUS) vboxNetFltWinQuEnqueuePacket(PVBOXNETFLTINS pInstance, PVOID pPacket, const UINT fPacketFlags);
|
---|
180 | DECLHIDDEN(void) vboxNetFltWinQuFiniPacketQueue(PVBOXNETFLTINS pInstance);
|
---|
181 | DECLHIDDEN(NTSTATUS) vboxNetFltWinQuInitPacketQueue(PVBOXNETFLTINS pInstance);
|
---|
182 | #endif /* #ifndef VBOXNETFLT_NO_PACKET_QUEUE */
|
---|
183 |
|
---|
184 |
|
---|
185 | #ifndef VBOXNETADP
|
---|
186 | /**
|
---|
187 | * searches the list entry in a single-linked list
|
---|
188 | */
|
---|
189 | DECLINLINE(bool) vboxNetFltWinSearchListEntry(PVBOXNETFLT_SINGLE_LIST pList, PSINGLE_LIST_ENTRY pEntry2Search, bool bRemove)
|
---|
190 | {
|
---|
191 | PSINGLE_LIST_ENTRY pHead = &pList->Head;
|
---|
192 | PSINGLE_LIST_ENTRY pCur;
|
---|
193 | PSINGLE_LIST_ENTRY pPrev;
|
---|
194 | for(pCur = pHead->Next, pPrev = pHead; pCur; pPrev = pCur, pCur = pCur->Next)
|
---|
195 | {
|
---|
196 | if(pEntry2Search == pCur)
|
---|
197 | {
|
---|
198 | if(bRemove)
|
---|
199 | {
|
---|
200 | pPrev->Next = pCur->Next;
|
---|
201 | if(pCur == pList->pTail)
|
---|
202 | {
|
---|
203 | pList->pTail = pPrev;
|
---|
204 | }
|
---|
205 | }
|
---|
206 | return true;
|
---|
207 | }
|
---|
208 | }
|
---|
209 | return false;
|
---|
210 | }
|
---|
211 |
|
---|
212 | #if !defined(VBOX_LOOPBACK_USEFLAGS) || defined(DEBUG_NETFLT_PACKETS)
|
---|
213 |
|
---|
214 | DECLINLINE(PNDIS_PACKET) vboxNetFltWinSearchPacket(PVBOXNETFLT_SINGLE_LIST pList, PNDIS_PACKET pPacket2Search, int cbMatch, bool bRemove)
|
---|
215 | {
|
---|
216 | PSINGLE_LIST_ENTRY pHead = &pList->Head;
|
---|
217 | PSINGLE_LIST_ENTRY pCur;
|
---|
218 | PSINGLE_LIST_ENTRY pPrev;
|
---|
219 | PNDIS_PACKET pCurPacket;
|
---|
220 | for(pCur = pHead->Next, pPrev = pHead; pCur; pPrev = pCur, pCur = pCur->Next)
|
---|
221 | {
|
---|
222 | pCurPacket = VBOX_SLE_2_SENDPACKET(pCur);
|
---|
223 | if(pCurPacket == pPacket2Search || vboxNetFltWinMatchPackets(pPacket2Search, pCurPacket, cbMatch))
|
---|
224 | {
|
---|
225 | if(bRemove)
|
---|
226 | {
|
---|
227 | pPrev->Next = pCur->Next;
|
---|
228 | if(pCur == pList->pTail)
|
---|
229 | {
|
---|
230 | pList->pTail = pPrev;
|
---|
231 | }
|
---|
232 | }
|
---|
233 | return pCurPacket;
|
---|
234 | }
|
---|
235 | }
|
---|
236 | return NULL;
|
---|
237 | }
|
---|
238 |
|
---|
239 | DECLINLINE(PNDIS_PACKET) vboxNetFltWinSearchPacketBySG(PVBOXNETFLT_SINGLE_LIST pList, PINTNETSG pSG, int cbMatch, bool bRemove)
|
---|
240 | {
|
---|
241 | PSINGLE_LIST_ENTRY pHead = &pList->Head;
|
---|
242 | PSINGLE_LIST_ENTRY pCur;
|
---|
243 | PSINGLE_LIST_ENTRY pPrev;
|
---|
244 | PNDIS_PACKET pCurPacket;
|
---|
245 | for(pCur = pHead->Next, pPrev = pHead; pCur; pPrev = pCur, pCur = pCur->Next)
|
---|
246 | {
|
---|
247 | pCurPacket = VBOX_SLE_2_SENDPACKET(pCur);
|
---|
248 | if(vboxNetFltWinMatchPacketAndSG(pCurPacket, pSG, cbMatch))
|
---|
249 | {
|
---|
250 | if(bRemove)
|
---|
251 | {
|
---|
252 | pPrev->Next = pCur->Next;
|
---|
253 | if(pCur == pList->pTail)
|
---|
254 | {
|
---|
255 | pList->pTail = pPrev;
|
---|
256 | }
|
---|
257 | }
|
---|
258 | return pCurPacket;
|
---|
259 | }
|
---|
260 | }
|
---|
261 | return NULL;
|
---|
262 | }
|
---|
263 |
|
---|
264 | #endif /* #if !defined(VBOX_LOOPBACK_USEFLAGS) || defined(DEBUG_NETFLT_PACKETS) */
|
---|
265 |
|
---|
266 | DECLINLINE(bool) vboxNetFltWinSListIsEmpty(PVBOXNETFLT_SINGLE_LIST pList)
|
---|
267 | {
|
---|
268 | return !pList->Head.Next;
|
---|
269 | }
|
---|
270 |
|
---|
271 | DECLINLINE(void) vboxNetFltWinPutTail(PVBOXNETFLT_SINGLE_LIST pList, PSINGLE_LIST_ENTRY pEntry)
|
---|
272 | {
|
---|
273 | pList->pTail->Next = pEntry;
|
---|
274 | pList->pTail = pEntry;
|
---|
275 | pEntry->Next = NULL;
|
---|
276 | }
|
---|
277 |
|
---|
278 | DECLINLINE(void) vboxNetFltWinPutHead(PVBOXNETFLT_SINGLE_LIST pList, PSINGLE_LIST_ENTRY pEntry)
|
---|
279 | {
|
---|
280 | pEntry->Next = pList->Head.Next;
|
---|
281 | pList->Head.Next = pEntry;
|
---|
282 | if(!pEntry->Next)
|
---|
283 | pList->pTail = pEntry;
|
---|
284 | }
|
---|
285 |
|
---|
286 | DECLINLINE(PSINGLE_LIST_ENTRY) vboxNetFltWinGetHead(PVBOXNETFLT_SINGLE_LIST pList)
|
---|
287 | {
|
---|
288 | PSINGLE_LIST_ENTRY pEntry = pList->Head.Next;
|
---|
289 | if(pEntry && pEntry == pList->pTail)
|
---|
290 | {
|
---|
291 | pList->Head.Next = NULL;
|
---|
292 | pList->pTail = &pList->Head;
|
---|
293 | }
|
---|
294 | return pEntry;
|
---|
295 | }
|
---|
296 |
|
---|
297 | DECLINLINE(bool) vboxNetFltWinInterlockedSearchListEntry(PVBOXNETFLT_INTERLOCKED_SINGLE_LIST pList, PSINGLE_LIST_ENTRY pEntry2Search, bool bRemove)
|
---|
298 | {
|
---|
299 | bool bFound;
|
---|
300 | NdisAcquireSpinLock(&pList->Lock);
|
---|
301 | bFound = vboxNetFltWinSearchListEntry(&pList->List, pEntry2Search, bRemove);
|
---|
302 | NdisReleaseSpinLock(&pList->Lock);
|
---|
303 | return bFound;
|
---|
304 | }
|
---|
305 |
|
---|
306 | #if !defined(VBOX_LOOPBACK_USEFLAGS) || defined(DEBUG_NETFLT_PACKETS)
|
---|
307 |
|
---|
308 | DECLINLINE(PNDIS_PACKET) vboxNetFltWinInterlockedSearchPacket(PVBOXNETFLT_INTERLOCKED_SINGLE_LIST pList, PNDIS_PACKET pPacket2Search, int cbMatch, bool bRemove)
|
---|
309 | {
|
---|
310 | PNDIS_PACKET pFound;
|
---|
311 | NdisAcquireSpinLock(&pList->Lock);
|
---|
312 | pFound = vboxNetFltWinSearchPacket(&pList->List, pPacket2Search, cbMatch, bRemove);
|
---|
313 | NdisReleaseSpinLock(&pList->Lock);
|
---|
314 | return pFound;
|
---|
315 | }
|
---|
316 |
|
---|
317 | DECLINLINE(PNDIS_PACKET) vboxNetFltWinInterlockedSearchPacketBySG(PVBOXNETFLT_INTERLOCKED_SINGLE_LIST pList, PINTNETSG pSG, int cbMatch, bool bRemove)
|
---|
318 | {
|
---|
319 | PNDIS_PACKET pFound;
|
---|
320 | NdisAcquireSpinLock(&pList->Lock);
|
---|
321 | pFound = vboxNetFltWinSearchPacketBySG(&pList->List, pSG, cbMatch, bRemove);
|
---|
322 | NdisReleaseSpinLock(&pList->Lock);
|
---|
323 | return pFound;
|
---|
324 | }
|
---|
325 | #endif /* #if !defined(VBOX_LOOPBACK_USEFLAGS) || defined(DEBUG_NETFLT_PACKETS) */
|
---|
326 |
|
---|
327 | DECLINLINE(void) vboxNetFltWinInterlockedPutTail(PVBOXNETFLT_INTERLOCKED_SINGLE_LIST pList, PSINGLE_LIST_ENTRY pEntry)
|
---|
328 | {
|
---|
329 | NdisAcquireSpinLock(&pList->Lock);
|
---|
330 | vboxNetFltWinPutTail(&pList->List, pEntry);
|
---|
331 | NdisReleaseSpinLock(&pList->Lock);
|
---|
332 | }
|
---|
333 |
|
---|
334 | DECLINLINE(void) vboxNetFltWinInterlockedPutHead(PVBOXNETFLT_INTERLOCKED_SINGLE_LIST pList, PSINGLE_LIST_ENTRY pEntry)
|
---|
335 | {
|
---|
336 | NdisAcquireSpinLock(&pList->Lock);
|
---|
337 | vboxNetFltWinPutHead(&pList->List, pEntry);
|
---|
338 | NdisReleaseSpinLock(&pList->Lock);
|
---|
339 | }
|
---|
340 |
|
---|
341 | DECLINLINE(PSINGLE_LIST_ENTRY) vboxNetFltWinInterlockedGetHead(PVBOXNETFLT_INTERLOCKED_SINGLE_LIST pList)
|
---|
342 | {
|
---|
343 | PSINGLE_LIST_ENTRY pEntry;
|
---|
344 | NdisAcquireSpinLock(&pList->Lock);
|
---|
345 | pEntry = vboxNetFltWinGetHead(&pList->List);
|
---|
346 | NdisReleaseSpinLock(&pList->Lock);
|
---|
347 | return pEntry;
|
---|
348 | }
|
---|
349 |
|
---|
350 | # if defined(DEBUG_NETFLT_PACKETS) || !defined(VBOX_LOOPBACK_USEFLAGS)
|
---|
351 | DECLINLINE(void) vboxNetFltWinLbPutSendPacket(PVBOXNETFLTINS pNetFlt, PNDIS_PACKET pPacket, bool bFromIntNet)
|
---|
352 | {
|
---|
353 | PVBOXNETFLT_PKTRSVD_PT pSrv = (PVBOXNETFLT_PKTRSVD_PT)pPacket->ProtocolReserved;
|
---|
354 | pSrv->bFromIntNet = bFromIntNet;
|
---|
355 | vboxNetFltWinInterlockedPutHead(&pNetFlt->u.s.WinIf.SendPacketQueue, &pSrv->ListEntry);
|
---|
356 | }
|
---|
357 |
|
---|
358 | DECLINLINE(bool) vboxNetFltWinLbIsFromIntNet(PNDIS_PACKET pPacket)
|
---|
359 | {
|
---|
360 | PVBOXNETFLT_PKTRSVD_PT pSrv = (PVBOXNETFLT_PKTRSVD_PT)pPacket->ProtocolReserved;
|
---|
361 | return pSrv->bFromIntNet;
|
---|
362 | }
|
---|
363 |
|
---|
364 | DECLINLINE(PNDIS_PACKET) vboxNetFltWinLbSearchLoopBack(PVBOXNETFLTINS pNetFlt, PNDIS_PACKET pPacket, bool bRemove)
|
---|
365 | {
|
---|
366 | return vboxNetFltWinInterlockedSearchPacket(&pNetFlt->u.s.WinIf.SendPacketQueue, pPacket, VBOXNETFLT_PACKETMATCH_LENGTH, bRemove);
|
---|
367 | }
|
---|
368 |
|
---|
369 | DECLINLINE(PNDIS_PACKET) vboxNetFltWinLbSearchLoopBackBySG(PVBOXNETFLTINS pNetFlt, PINTNETSG pSG, bool bRemove)
|
---|
370 | {
|
---|
371 | return vboxNetFltWinInterlockedSearchPacketBySG(&pNetFlt->u.s.WinIf.SendPacketQueue, pSG, VBOXNETFLT_PACKETMATCH_LENGTH, bRemove);
|
---|
372 | }
|
---|
373 |
|
---|
374 | DECLINLINE(bool) vboxNetFltWinLbRemoveSendPacket(PVBOXNETFLTINS pNetFlt, PNDIS_PACKET pPacket)
|
---|
375 | {
|
---|
376 | PVBOXNETFLT_PKTRSVD_PT pSrv = (PVBOXNETFLT_PKTRSVD_PT)pPacket->ProtocolReserved;
|
---|
377 | bool bRet = vboxNetFltWinInterlockedSearchListEntry(&pNetFlt->u.s.WinIf.SendPacketQueue, &pSrv->ListEntry, true);
|
---|
378 | #ifdef DEBUG_misha
|
---|
379 | Assert(bRet == (pNetFlt->enmTrunkState == INTNETTRUNKIFSTATE_ACTIVE));
|
---|
380 | #endif
|
---|
381 | return bRet;
|
---|
382 | }
|
---|
383 |
|
---|
384 | # endif
|
---|
385 |
|
---|
386 | #endif
|
---|
387 |
|
---|
388 | #ifdef DEBUG_misha
|
---|
389 | DECLHIDDEN(bool) vboxNetFltWinCheckMACs(PNDIS_PACKET pPacket, PRTMAC pDst, PRTMAC pSrc);
|
---|
390 | DECLHIDDEN(bool) vboxNetFltWinCheckMACsSG(PINTNETSG pSG, PRTMAC pDst, PRTMAC pSrc);
|
---|
391 | extern RTMAC g_vboxNetFltWinVerifyMACBroadcast;
|
---|
392 | extern RTMAC g_vboxNetFltWinVerifyMACGuest;
|
---|
393 |
|
---|
394 | # define VBOXNETFLT_LBVERIFY(_pnf, _p) \
|
---|
395 | do { \
|
---|
396 | Assert(!vboxNetFltWinCheckMACs(_p, NULL, &g_vboxNetFltWinVerifyMACGuest)); \
|
---|
397 | Assert(!vboxNetFltWinCheckMACs(_p, NULL, &(_pnf)->u.s.MacAddr)); \
|
---|
398 | } while(0)
|
---|
399 |
|
---|
400 | # define VBOXNETFLT_LBVERIFYSG(_pnf, _p) \
|
---|
401 | do { \
|
---|
402 | Assert(!vboxNetFltWinCheckMACsSG(_p, NULL, &g_vboxNetFltWinVerifyMACGuest)); \
|
---|
403 | Assert(!vboxNetFltWinCheckMACsSG(_p, NULL, &(_pnf)->u.s.MacAddr)); \
|
---|
404 | } while(0)
|
---|
405 |
|
---|
406 | #else
|
---|
407 | # define VBOXNETFLT_LBVERIFY(_pnf, _p) do{}while(0)
|
---|
408 | # define VBOXNETFLT_LBVERIFYSG(_pnf, _p) do{}while(0)
|
---|
409 | #endif
|
---|
410 |
|
---|
411 | /** initializes the list */
|
---|
412 | #define INIT_SINGLE_LIST(_pList) \
|
---|
413 | { \
|
---|
414 | (_pList)->Head.Next = NULL; \
|
---|
415 | (_pList)->pTail = &(_pList)->Head; \
|
---|
416 | }
|
---|
417 |
|
---|
418 | /** initializes the list */
|
---|
419 | #define INIT_INTERLOCKED_SINGLE_LIST(_pList) \
|
---|
420 | do { \
|
---|
421 | INIT_SINGLE_LIST(&(_pList)->List); \
|
---|
422 | NdisAllocateSpinLock(&(_pList)->Lock); \
|
---|
423 | } while(0)
|
---|
424 |
|
---|
425 | /** delete the packet queue */
|
---|
426 | #define FINI_INTERLOCKED_SINGLE_LIST(_pList) \
|
---|
427 | do { \
|
---|
428 | Assert(vboxNetFltWinSListIsEmpty(&(_pList)->List)); \
|
---|
429 | NdisFreeSpinLock(&(_pList)->Lock) \
|
---|
430 | } while(0)
|
---|
431 |
|
---|
432 |
|
---|
433 | /**************************************************************************
|
---|
434 | * PVBOXNETFLTINS , WinIf reference/dereference (i.e. retain/release) API *
|
---|
435 | **************************************************************************/
|
---|
436 |
|
---|
437 |
|
---|
438 | DECLHIDDEN(void) vboxNetFltWinWaitDereference(PVBOXNETFLT_WINIF_DEVICE pState);
|
---|
439 |
|
---|
440 | DECLINLINE(void) vboxNetFltWinReferenceModeNetFlt(PVBOXNETFLTINS pIns)
|
---|
441 | {
|
---|
442 | ASMAtomicIncU32((volatile uint32_t *)&pIns->u.s.cModeNetFltRefs);
|
---|
443 | }
|
---|
444 |
|
---|
445 | DECLINLINE(void) vboxNetFltWinReferenceModePassThru(PVBOXNETFLTINS pIns)
|
---|
446 | {
|
---|
447 | ASMAtomicIncU32((volatile uint32_t *)&pIns->u.s.cModePassThruRefs);
|
---|
448 | }
|
---|
449 |
|
---|
450 | DECLINLINE(void) vboxNetFltWinIncReferenceModeNetFlt(PVBOXNETFLTINS pIns, uint32_t v)
|
---|
451 | {
|
---|
452 | ASMAtomicAddU32((volatile uint32_t *)&pIns->u.s.cModeNetFltRefs, v);
|
---|
453 | }
|
---|
454 |
|
---|
455 | DECLINLINE(void) vboxNetFltWinIncReferenceModePassThru(PVBOXNETFLTINS pIns, uint32_t v)
|
---|
456 | {
|
---|
457 | ASMAtomicAddU32((volatile uint32_t *)&pIns->u.s.cModePassThruRefs, v);
|
---|
458 | }
|
---|
459 |
|
---|
460 | DECLINLINE(void) vboxNetFltWinDereferenceModeNetFlt(PVBOXNETFLTINS pIns)
|
---|
461 | {
|
---|
462 | ASMAtomicDecU32((volatile uint32_t *)&pIns->u.s.cModeNetFltRefs);
|
---|
463 | }
|
---|
464 |
|
---|
465 | DECLINLINE(void) vboxNetFltWinDereferenceModePassThru(PVBOXNETFLTINS pIns)
|
---|
466 | {
|
---|
467 | ASMAtomicDecU32((volatile uint32_t *)&pIns->u.s.cModePassThruRefs);
|
---|
468 | }
|
---|
469 |
|
---|
470 | DECLINLINE(void) vboxNetFltWinDecReferenceModeNetFlt(PVBOXNETFLTINS pIns, uint32_t v)
|
---|
471 | {
|
---|
472 | Assert(v);
|
---|
473 | ASMAtomicAddU32((volatile uint32_t *)&pIns->u.s.cModeNetFltRefs, (uint32_t)(-((int32_t)v)));
|
---|
474 | }
|
---|
475 |
|
---|
476 | DECLINLINE(void) vboxNetFltWinDecReferenceModePassThru(PVBOXNETFLTINS pIns, uint32_t v)
|
---|
477 | {
|
---|
478 | Assert(v);
|
---|
479 | ASMAtomicAddU32((volatile uint32_t *)&pIns->u.s.cModePassThruRefs, (uint32_t)(-((int32_t)v)));
|
---|
480 | }
|
---|
481 |
|
---|
482 | DECLINLINE(void) vboxNetFltWinSetPowerState(PVBOXNETFLT_WINIF_DEVICE pState, NDIS_DEVICE_POWER_STATE State)
|
---|
483 | {
|
---|
484 | ASMAtomicUoWriteU32((volatile uint32_t *)&pState->PowerState, State);
|
---|
485 | }
|
---|
486 |
|
---|
487 | DECLINLINE(NDIS_DEVICE_POWER_STATE) vboxNetFltWinGetPowerState(PVBOXNETFLT_WINIF_DEVICE pState)
|
---|
488 | {
|
---|
489 | return (NDIS_DEVICE_POWER_STATE)ASMAtomicUoReadU32((volatile uint32_t *)&pState->PowerState);
|
---|
490 | }
|
---|
491 |
|
---|
492 | DECLINLINE(void) vboxNetFltWinSetOpState(PVBOXNETFLT_WINIF_DEVICE pState, VBOXNETDEVOPSTATE State)
|
---|
493 | {
|
---|
494 | ASMAtomicUoWriteU32((volatile uint32_t *)&pState->OpState, State);
|
---|
495 | }
|
---|
496 |
|
---|
497 | DECLINLINE(VBOXNETDEVOPSTATE) vboxNetFltWinGetOpState(PVBOXNETFLT_WINIF_DEVICE pState)
|
---|
498 | {
|
---|
499 | return (VBOXNETDEVOPSTATE)ASMAtomicUoReadU32((volatile uint32_t *)&pState->OpState);
|
---|
500 | }
|
---|
501 |
|
---|
502 | DECLINLINE(bool) vboxNetFltWinDoReferenceDevice(PVBOXNETFLT_WINIF_DEVICE pState)
|
---|
503 | {
|
---|
504 | if (vboxNetFltWinGetPowerState(pState) == NdisDeviceStateD0 && vboxNetFltWinGetOpState(pState) == kVBoxNetDevOpState_Initialized)
|
---|
505 | {
|
---|
506 | /** @todo r=bird: Since this is a volatile member, why don't you declare it as
|
---|
507 | * such and save yourself all the casting? */
|
---|
508 | ASMAtomicIncU32((uint32_t volatile *)&pState->cReferences);
|
---|
509 | return true;
|
---|
510 | }
|
---|
511 | return false;
|
---|
512 | }
|
---|
513 |
|
---|
514 | #ifndef VBOXNETADP
|
---|
515 | DECLINLINE(bool) vboxNetFltWinDoReferenceDevices(PVBOXNETFLT_WINIF_DEVICE pState1, PVBOXNETFLT_WINIF_DEVICE pState2)
|
---|
516 | {
|
---|
517 | if (vboxNetFltWinGetPowerState(pState1) == NdisDeviceStateD0
|
---|
518 | && vboxNetFltWinGetOpState(pState1) == kVBoxNetDevOpState_Initialized
|
---|
519 | && vboxNetFltWinGetPowerState(pState2) == NdisDeviceStateD0
|
---|
520 | && vboxNetFltWinGetOpState(pState2) == kVBoxNetDevOpState_Initialized)
|
---|
521 | {
|
---|
522 | ASMAtomicIncU32((uint32_t volatile *)&pState1->cReferences);
|
---|
523 | ASMAtomicIncU32((uint32_t volatile *)&pState2->cReferences);
|
---|
524 | return true;
|
---|
525 | }
|
---|
526 | return false;
|
---|
527 | }
|
---|
528 | #endif
|
---|
529 |
|
---|
530 | DECLINLINE(void) vboxNetFltWinDereferenceDevice(PVBOXNETFLT_WINIF_DEVICE pState)
|
---|
531 | {
|
---|
532 | ASMAtomicDecU32((uint32_t volatile *)&pState->cReferences);
|
---|
533 | /** @todo r=bird: Add comment explaining why these cannot hit 0 or why
|
---|
534 | * reference are counted */
|
---|
535 | }
|
---|
536 |
|
---|
537 | #ifndef VBOXNETADP
|
---|
538 | DECLINLINE(void) vboxNetFltWinDereferenceDevices(PVBOXNETFLT_WINIF_DEVICE pState1, PVBOXNETFLT_WINIF_DEVICE pState2)
|
---|
539 | {
|
---|
540 | ASMAtomicDecU32((uint32_t volatile *)&pState1->cReferences);
|
---|
541 | ASMAtomicDecU32((uint32_t volatile *)&pState2->cReferences);
|
---|
542 | }
|
---|
543 | #endif
|
---|
544 |
|
---|
545 | DECLINLINE(void) vboxNetFltWinDecReferenceDevice(PVBOXNETFLT_WINIF_DEVICE pState, uint32_t v)
|
---|
546 | {
|
---|
547 | Assert(v);
|
---|
548 | ASMAtomicAddU32((uint32_t volatile *)&pState->cReferences, (uint32_t)(-((int32_t)v)));
|
---|
549 | }
|
---|
550 |
|
---|
551 | #ifndef VBOXNETADP
|
---|
552 | DECLINLINE(void) vboxNetFltWinDecReferenceDevices(PVBOXNETFLT_WINIF_DEVICE pState1, PVBOXNETFLT_WINIF_DEVICE pState2, uint32_t v)
|
---|
553 | {
|
---|
554 | ASMAtomicAddU32((uint32_t volatile *)&pState1->cReferences, (uint32_t)(-((int32_t)v)));
|
---|
555 | ASMAtomicAddU32((uint32_t volatile *)&pState2->cReferences, (uint32_t)(-((int32_t)v)));
|
---|
556 | }
|
---|
557 | #endif
|
---|
558 |
|
---|
559 | DECLINLINE(bool) vboxNetFltWinDoIncReferenceDevice(PVBOXNETFLT_WINIF_DEVICE pState, uint32_t v)
|
---|
560 | {
|
---|
561 | Assert(v);
|
---|
562 | if (vboxNetFltWinGetPowerState(pState) == NdisDeviceStateD0 && vboxNetFltWinGetOpState(pState) == kVBoxNetDevOpState_Initialized)
|
---|
563 | {
|
---|
564 | ASMAtomicAddU32((uint32_t volatile *)&pState->cReferences, v);
|
---|
565 | return true;
|
---|
566 | }
|
---|
567 | return false;
|
---|
568 | }
|
---|
569 |
|
---|
570 | #ifndef VBOXNETADP
|
---|
571 | DECLINLINE(bool) vboxNetFltWinDoIncReferenceDevices(PVBOXNETFLT_WINIF_DEVICE pState1, PVBOXNETFLT_WINIF_DEVICE pState2, uint32_t v)
|
---|
572 | {
|
---|
573 | if (vboxNetFltWinGetPowerState(pState1) == NdisDeviceStateD0
|
---|
574 | && vboxNetFltWinGetOpState(pState1) == kVBoxNetDevOpState_Initialized
|
---|
575 | && vboxNetFltWinGetPowerState(pState2) == NdisDeviceStateD0
|
---|
576 | && vboxNetFltWinGetOpState(pState2) == kVBoxNetDevOpState_Initialized)
|
---|
577 | {
|
---|
578 | ASMAtomicAddU32((uint32_t volatile *)&pState1->cReferences, v);
|
---|
579 | ASMAtomicAddU32((uint32_t volatile *)&pState2->cReferences, v);
|
---|
580 | return true;
|
---|
581 | }
|
---|
582 | return false;
|
---|
583 | }
|
---|
584 | #endif
|
---|
585 |
|
---|
586 |
|
---|
587 | DECLINLINE(bool) vboxNetFltWinReferenceWinIfNetFlt(PVBOXNETFLTINS pNetFlt, bool * pbNetFltActive)
|
---|
588 | {
|
---|
589 | RTSpinlockAcquire((pNetFlt)->hSpinlock);
|
---|
590 | #ifndef VBOXNETADP
|
---|
591 | if(!vboxNetFltWinDoReferenceDevices(&pNetFlt->u.s.WinIf.MpState, &pNetFlt->u.s.WinIf.PtState))
|
---|
592 | #else
|
---|
593 | if(!vboxNetFltWinDoReferenceDevice(&pNetFlt->u.s.WinIf.MpState))
|
---|
594 | #endif
|
---|
595 | {
|
---|
596 | RTSpinlockReleaseNoInts((pNetFlt)->hSpinlock);
|
---|
597 | *pbNetFltActive = false;
|
---|
598 | return false;
|
---|
599 | }
|
---|
600 |
|
---|
601 | if(pNetFlt->enmTrunkState != INTNETTRUNKIFSTATE_ACTIVE)
|
---|
602 | {
|
---|
603 | vboxNetFltWinReferenceModePassThru(pNetFlt);
|
---|
604 | RTSpinlockReleaseNoInts((pNetFlt)->hSpinlock);
|
---|
605 | *pbNetFltActive = false;
|
---|
606 | return true;
|
---|
607 | }
|
---|
608 |
|
---|
609 | vboxNetFltRetain((pNetFlt), true /* fBusy */);
|
---|
610 | vboxNetFltWinReferenceModeNetFlt(pNetFlt);
|
---|
611 | RTSpinlockReleaseNoInts((pNetFlt)->hSpinlock);
|
---|
612 |
|
---|
613 | *pbNetFltActive = true;
|
---|
614 | return true;
|
---|
615 | }
|
---|
616 |
|
---|
617 | DECLINLINE(bool) vboxNetFltWinIncReferenceWinIfNetFlt(PVBOXNETFLTINS pNetFlt, uint32_t v, bool *pbNetFltActive)
|
---|
618 | {
|
---|
619 | uint32_t i;
|
---|
620 |
|
---|
621 | Assert(v);
|
---|
622 | if(!v)
|
---|
623 | {
|
---|
624 | *pbNetFltActive = false;
|
---|
625 | return false;
|
---|
626 | }
|
---|
627 |
|
---|
628 | RTSpinlockAcquire((pNetFlt)->hSpinlock);
|
---|
629 | #ifndef VBOXNETADP
|
---|
630 | if(!vboxNetFltWinDoIncReferenceDevices(&pNetFlt->u.s.WinIf.MpState, &pNetFlt->u.s.WinIf.PtState, v))
|
---|
631 | #else
|
---|
632 | if(!vboxNetFltWinDoIncReferenceDevice(&pNetFlt->u.s.WinIf.MpState, v))
|
---|
633 | #endif
|
---|
634 | {
|
---|
635 | RTSpinlockReleaseNoInts(pNetFlt->hSpinlock);
|
---|
636 | *pbNetFltActive = false;
|
---|
637 | return false;
|
---|
638 | }
|
---|
639 |
|
---|
640 | if(pNetFlt->enmTrunkState != INTNETTRUNKIFSTATE_ACTIVE)
|
---|
641 | {
|
---|
642 | vboxNetFltWinIncReferenceModePassThru(pNetFlt, v);
|
---|
643 |
|
---|
644 | RTSpinlockReleaseNoInts((pNetFlt)->hSpinlock);
|
---|
645 | *pbNetFltActive = false;
|
---|
646 | return true;
|
---|
647 | }
|
---|
648 |
|
---|
649 | vboxNetFltRetain(pNetFlt, true /* fBusy */);
|
---|
650 |
|
---|
651 | vboxNetFltWinIncReferenceModeNetFlt(pNetFlt, v);
|
---|
652 |
|
---|
653 | RTSpinlockReleaseNoInts(pNetFlt->hSpinlock);
|
---|
654 |
|
---|
655 | /* we have marked it as busy, so can do the res references outside the lock */
|
---|
656 | for(i = 0; i < v-1; i++)
|
---|
657 | {
|
---|
658 | vboxNetFltRetain(pNetFlt, true /* fBusy */);
|
---|
659 | }
|
---|
660 |
|
---|
661 | *pbNetFltActive = true;
|
---|
662 |
|
---|
663 | return true;
|
---|
664 | }
|
---|
665 |
|
---|
666 | DECLINLINE(void) vboxNetFltWinDecReferenceNetFlt(PVBOXNETFLTINS pNetFlt, uint32_t n)
|
---|
667 | {
|
---|
668 | uint32_t i;
|
---|
669 | for(i = 0; i < n; i++)
|
---|
670 | {
|
---|
671 | vboxNetFltRelease(pNetFlt, true);
|
---|
672 | }
|
---|
673 |
|
---|
674 | vboxNetFltWinDecReferenceModeNetFlt(pNetFlt, n);
|
---|
675 | }
|
---|
676 |
|
---|
677 | DECLINLINE(void) vboxNetFltWinDereferenceNetFlt(PVBOXNETFLTINS pNetFlt)
|
---|
678 | {
|
---|
679 | vboxNetFltRelease(pNetFlt, true);
|
---|
680 |
|
---|
681 | vboxNetFltWinDereferenceModeNetFlt(pNetFlt);
|
---|
682 | }
|
---|
683 |
|
---|
684 | DECLINLINE(void) vboxNetFltWinDecReferenceWinIf(PVBOXNETFLTINS pNetFlt, uint32_t v)
|
---|
685 | {
|
---|
686 | #ifdef VBOXNETADP
|
---|
687 | vboxNetFltWinDecReferenceDevice(&pNetFlt->u.s.WinIf.MpState, v);
|
---|
688 | #else
|
---|
689 | vboxNetFltWinDecReferenceDevices(&pNetFlt->u.s.WinIf.MpState, &pNetFlt->u.s.WinIf.PtState, v);
|
---|
690 | #endif
|
---|
691 | }
|
---|
692 |
|
---|
693 | DECLINLINE(void) vboxNetFltWinDereferenceWinIf(PVBOXNETFLTINS pNetFlt)
|
---|
694 | {
|
---|
695 | #ifdef VBOXNETADP
|
---|
696 | vboxNetFltWinDereferenceDevice(&pNetFlt->u.s.WinIf.MpState);
|
---|
697 | #else
|
---|
698 | vboxNetFltWinDereferenceDevices(&pNetFlt->u.s.WinIf.MpState, &pNetFlt->u.s.WinIf.PtState);
|
---|
699 | #endif
|
---|
700 | }
|
---|
701 |
|
---|
702 | DECLINLINE(bool) vboxNetFltWinIncReferenceWinIf(PVBOXNETFLTINS pNetFlt, uint32_t v)
|
---|
703 | {
|
---|
704 | Assert(v);
|
---|
705 | if(!v)
|
---|
706 | {
|
---|
707 | return false;
|
---|
708 | }
|
---|
709 |
|
---|
710 | RTSpinlockAcquire(pNetFlt->hSpinlock);
|
---|
711 | #ifdef VBOXNETADP
|
---|
712 | if(vboxNetFltWinDoIncReferenceDevice(&pNetFlt->u.s.WinIf.MpState, v))
|
---|
713 | #else
|
---|
714 | if(vboxNetFltWinDoIncReferenceDevices(&pNetFlt->u.s.WinIf.MpState, &pNetFlt->u.s.WinIf.PtState, v))
|
---|
715 | #endif
|
---|
716 | {
|
---|
717 | RTSpinlockReleaseNoInts(pNetFlt->hSpinlock);
|
---|
718 | return true;
|
---|
719 | }
|
---|
720 |
|
---|
721 | RTSpinlockReleaseNoInts(pNetFlt->hSpinlock);
|
---|
722 | return false;
|
---|
723 | }
|
---|
724 |
|
---|
725 | DECLINLINE(bool) vboxNetFltWinReferenceWinIf(PVBOXNETFLTINS pNetFlt)
|
---|
726 | {
|
---|
727 | RTSpinlockAcquire(pNetFlt->hSpinlock);
|
---|
728 | #ifdef VBOXNETADP
|
---|
729 | if(vboxNetFltWinDoReferenceDevice(&pNetFlt->u.s.WinIf.MpState))
|
---|
730 | #else
|
---|
731 | if(vboxNetFltWinDoReferenceDevices(&pNetFlt->u.s.WinIf.MpState, &pNetFlt->u.s.WinIf.PtState))
|
---|
732 | #endif
|
---|
733 | {
|
---|
734 | RTSpinlockReleaseNoInts(pNetFlt->hSpinlock);
|
---|
735 | return true;
|
---|
736 | }
|
---|
737 |
|
---|
738 | RTSpinlockReleaseNoInts(pNetFlt->hSpinlock);
|
---|
739 | return false;
|
---|
740 | }
|
---|
741 |
|
---|
742 | /***********************************************
|
---|
743 | * methods for accessing the network card info *
|
---|
744 | ***********************************************/
|
---|
745 |
|
---|
746 | DECLHIDDEN(NDIS_STATUS) vboxNetFltWinGetMacAddress(PVBOXNETFLTINS pNetFlt, PRTMAC pMac);
|
---|
747 | DECLHIDDEN(bool) vboxNetFltWinIsPromiscuous(PVBOXNETFLTINS pNetFlt);
|
---|
748 | DECLHIDDEN(NDIS_STATUS) vboxNetFltWinSetPromiscuous(PVBOXNETFLTINS pNetFlt, bool bYes);
|
---|
749 | DECLHIDDEN(NDIS_STATUS) vboxNetFltWinQueryPhysicalMedium(PVBOXNETFLTINS pNetFlt, NDIS_PHYSICAL_MEDIUM * pMedium);
|
---|
750 |
|
---|
751 | /*********************
|
---|
752 | * mem alloc API *
|
---|
753 | *********************/
|
---|
754 |
|
---|
755 | DECLHIDDEN(NDIS_STATUS) vboxNetFltWinMemAlloc(PVOID* ppMemBuf, UINT cbLength);
|
---|
756 |
|
---|
757 | DECLHIDDEN(void) vboxNetFltWinMemFree(PVOID pMemBuf);
|
---|
758 |
|
---|
759 | /* convenience method used which allocates and initializes the PINTNETSG containing one
|
---|
760 | * segment referring the buffer of size cbBufSize
|
---|
761 | * the allocated PINTNETSG should be freed with the vboxNetFltWinMemFree.
|
---|
762 | *
|
---|
763 | * This is used when our ProtocolReceive callback is called and we have to return the indicated NDIS_PACKET
|
---|
764 | * on a callback exit. This is why we allocate the PINTNETSG and put the packet info there and enqueue it
|
---|
765 | * for the packet queue */
|
---|
766 | DECLHIDDEN(NDIS_STATUS) vboxNetFltWinAllocSG(UINT cbBufSize, PINTNETSG *ppSG);
|
---|
767 |
|
---|
768 | /************************
|
---|
769 | * WinIf init/fini API *
|
---|
770 | ************************/
|
---|
771 | #if defined(VBOXNETADP)
|
---|
772 | DECLHIDDEN(NDIS_STATUS) vboxNetFltWinPtInitBind(PVBOXNETFLTINS *ppNetFlt, NDIS_HANDLE hMiniportAdapter, PNDIS_STRING pBindToMiniportName /* actually this is our miniport name*/, NDIS_HANDLE hWrapperConfigurationContext);
|
---|
773 | DECLHIDDEN(NDIS_STATUS) vboxNetFltWinPtInitWinIf(PVBOXNETFLTWIN pWinIf);
|
---|
774 | #else
|
---|
775 | DECLHIDDEN(NDIS_STATUS) vboxNetFltWinPtInitBind(PVBOXNETFLTINS *ppNetFlt, PNDIS_STRING pOurMiniportName, PNDIS_STRING pBindToMiniportName);
|
---|
776 | DECLHIDDEN(NDIS_STATUS) vboxNetFltWinPtInitWinIf(PVBOXNETFLTWIN pWinIf, PNDIS_STRING pOurDeviceName);
|
---|
777 | #endif
|
---|
778 |
|
---|
779 | DECLHIDDEN(VOID) vboxNetFltWinPtFiniWinIf(PVBOXNETFLTWIN pWinIf);
|
---|
780 |
|
---|
781 | /************************************
|
---|
782 | * Execute Job at passive level API *
|
---|
783 | ************************************/
|
---|
784 |
|
---|
785 | typedef VOID (*PFNVBOXNETFLT_JOB_ROUTINE) (PVOID pContext);
|
---|
786 |
|
---|
787 | DECLHIDDEN(VOID) vboxNetFltWinJobSynchExecAtPassive(PFNVBOXNETFLT_JOB_ROUTINE pfnRoutine, PVOID pContext);
|
---|
788 |
|
---|
789 | /*******************************
|
---|
790 | * Ndis Packets processing API *
|
---|
791 | *******************************/
|
---|
792 | DECLHIDDEN(PNDIS_PACKET) vboxNetFltWinNdisPacketFromSG(PVBOXNETFLTINS pNetFlt, PINTNETSG pSG, PVOID pBufToFree, bool bToWire, bool bCopyMemory);
|
---|
793 |
|
---|
794 | DECLHIDDEN(void) vboxNetFltWinFreeSGNdisPacket(PNDIS_PACKET pPacket, bool bFreeMem);
|
---|
795 |
|
---|
796 | #ifdef DEBUG_NETFLT_PACKETS
|
---|
797 | #define DBG_CHECK_PACKETS(_p1, _p2) \
|
---|
798 | { \
|
---|
799 | bool _b = vboxNetFltWinMatchPackets(_p1, _p2, -1); \
|
---|
800 | Assert(_b); \
|
---|
801 | }
|
---|
802 |
|
---|
803 | #define DBG_CHECK_PACKET_AND_SG(_p, _sg) \
|
---|
804 | { \
|
---|
805 | bool _b = vboxNetFltWinMatchPacketAndSG(_p, _sg, -1); \
|
---|
806 | Assert(_b); \
|
---|
807 | }
|
---|
808 |
|
---|
809 | #define DBG_CHECK_SGS(_sg1, _sg2) \
|
---|
810 | { \
|
---|
811 | bool _b = vboxNetFltWinMatchSGs(_sg1, _sg2, -1); \
|
---|
812 | Assert(_b); \
|
---|
813 | }
|
---|
814 |
|
---|
815 | #else
|
---|
816 | #define DBG_CHECK_PACKETS(_p1, _p2)
|
---|
817 | #define DBG_CHECK_PACKET_AND_SG(_p, _sg)
|
---|
818 | #define DBG_CHECK_SGS(_sg1, _sg2)
|
---|
819 | #endif
|
---|
820 |
|
---|
821 | /**
|
---|
822 | * Ndis loops back broadcast packets posted to the wire by IntNet
|
---|
823 | * This routine is used in the mechanism of preventing this looping
|
---|
824 | *
|
---|
825 | * @param pAdapt
|
---|
826 | * @param pPacket
|
---|
827 | * @param bOnRecv true is we are receiving the packet from the wire
|
---|
828 | * false otherwise (i.e. the packet is from the host)
|
---|
829 | *
|
---|
830 | * @return true if the packet is a looped back one, false otherwise
|
---|
831 | */
|
---|
832 | #ifdef VBOX_LOOPBACK_USEFLAGS
|
---|
833 | DECLINLINE(bool) vboxNetFltWinIsLoopedBackPacket(PNDIS_PACKET pPacket)
|
---|
834 | {
|
---|
835 | return (NdisGetPacketFlags(pPacket) & g_fPacketIsLoopedBack) == g_fPacketIsLoopedBack;
|
---|
836 | }
|
---|
837 | #endif
|
---|
838 |
|
---|
839 | /**************************************************************
|
---|
840 | * utility methods for ndis packet creation/initialization *
|
---|
841 | **************************************************************/
|
---|
842 |
|
---|
843 | #define VBOXNETFLT_OOB_INIT(_p) \
|
---|
844 | { \
|
---|
845 | NdisZeroMemory(NDIS_OOB_DATA_FROM_PACKET(_p), sizeof(NDIS_PACKET_OOB_DATA)); \
|
---|
846 | NDIS_SET_PACKET_HEADER_SIZE(_p, VBOXNETFLT_PACKET_ETHEADER_SIZE); \
|
---|
847 | }
|
---|
848 |
|
---|
849 | #ifndef VBOXNETADP
|
---|
850 |
|
---|
851 | DECLINLINE(NDIS_STATUS) vboxNetFltWinCopyPacketInfoOnRecv(PNDIS_PACKET pDstPacket, PNDIS_PACKET pSrcPacket, bool bForceStatusResources)
|
---|
852 | {
|
---|
853 | NDIS_STATUS Status = bForceStatusResources ? NDIS_STATUS_RESOURCES : NDIS_GET_PACKET_STATUS(pSrcPacket);
|
---|
854 | NDIS_SET_PACKET_STATUS(pDstPacket, Status);
|
---|
855 |
|
---|
856 | NDIS_PACKET_FIRST_NDIS_BUFFER(pDstPacket) = NDIS_PACKET_FIRST_NDIS_BUFFER(pSrcPacket);
|
---|
857 | NDIS_PACKET_LAST_NDIS_BUFFER(pDstPacket) = NDIS_PACKET_LAST_NDIS_BUFFER(pSrcPacket);
|
---|
858 |
|
---|
859 | NdisGetPacketFlags(pDstPacket) = NdisGetPacketFlags(pSrcPacket);
|
---|
860 |
|
---|
861 | NDIS_SET_ORIGINAL_PACKET(pDstPacket, NDIS_GET_ORIGINAL_PACKET(pSrcPacket));
|
---|
862 | NDIS_SET_PACKET_HEADER_SIZE(pDstPacket, NDIS_GET_PACKET_HEADER_SIZE(pSrcPacket));
|
---|
863 |
|
---|
864 | return Status;
|
---|
865 | }
|
---|
866 |
|
---|
867 | DECLINLINE(void) vboxNetFltWinCopyPacketInfoOnSend(PNDIS_PACKET pDstPacket, PNDIS_PACKET pSrcPacket)
|
---|
868 | {
|
---|
869 | NDIS_PACKET_FIRST_NDIS_BUFFER(pDstPacket) = NDIS_PACKET_FIRST_NDIS_BUFFER(pSrcPacket);
|
---|
870 | NDIS_PACKET_LAST_NDIS_BUFFER(pDstPacket) = NDIS_PACKET_LAST_NDIS_BUFFER(pSrcPacket);
|
---|
871 |
|
---|
872 | NdisGetPacketFlags(pDstPacket) = NdisGetPacketFlags(pSrcPacket);
|
---|
873 |
|
---|
874 | NdisMoveMemory(NDIS_OOB_DATA_FROM_PACKET(pDstPacket),
|
---|
875 | NDIS_OOB_DATA_FROM_PACKET(pSrcPacket),
|
---|
876 | sizeof (NDIS_PACKET_OOB_DATA));
|
---|
877 |
|
---|
878 | NdisIMCopySendPerPacketInfo(pDstPacket, pSrcPacket);
|
---|
879 |
|
---|
880 | PVOID pMediaSpecificInfo = NULL;
|
---|
881 | UINT fMediaSpecificInfoSize = 0;
|
---|
882 |
|
---|
883 | NDIS_GET_PACKET_MEDIA_SPECIFIC_INFO(pSrcPacket, &pMediaSpecificInfo, &fMediaSpecificInfoSize);
|
---|
884 |
|
---|
885 | if (pMediaSpecificInfo || fMediaSpecificInfoSize)
|
---|
886 | {
|
---|
887 | NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO(pDstPacket, pMediaSpecificInfo, fMediaSpecificInfoSize);
|
---|
888 | }
|
---|
889 | }
|
---|
890 |
|
---|
891 | DECLHIDDEN(NDIS_STATUS) vboxNetFltWinPrepareSendPacket(PVBOXNETFLTINS pNetFlt, PNDIS_PACKET pPacket, PNDIS_PACKET *ppMyPacket);
|
---|
892 | DECLHIDDEN(NDIS_STATUS) vboxNetFltWinPrepareRecvPacket(PVBOXNETFLTINS pNetFlt, PNDIS_PACKET pPacket, PNDIS_PACKET *ppMyPacket, bool bDpr);
|
---|
893 | #endif
|
---|
894 |
|
---|
895 | DECLHIDDEN(void) vboxNetFltWinSleep(ULONG milis);
|
---|
896 |
|
---|
897 | #define MACS_EQUAL(_m1, _m2) \
|
---|
898 | ((_m1).au16[0] == (_m2).au16[0] \
|
---|
899 | && (_m1).au16[1] == (_m2).au16[1] \
|
---|
900 | && (_m1).au16[2] == (_m2).au16[2])
|
---|
901 |
|
---|
902 |
|
---|
903 | DECLHIDDEN(NDIS_STATUS) vboxNetFltWinDetachFromInterface(PVBOXNETFLTINS pNetFlt, bool bOnUnbind);
|
---|
904 | DECLHIDDEN(NDIS_STATUS) vboxNetFltWinCopyString(PNDIS_STRING pDst, PNDIS_STRING pSrc);
|
---|
905 |
|
---|
906 |
|
---|
907 | /**
|
---|
908 | * Sets the enmState member atomically.
|
---|
909 | *
|
---|
910 | * Used for all updates.
|
---|
911 | *
|
---|
912 | * @param pThis The instance.
|
---|
913 | * @param enmNewState The new value.
|
---|
914 | */
|
---|
915 | DECLINLINE(void) vboxNetFltWinSetWinIfState(PVBOXNETFLTINS pNetFlt, VBOXNETFLT_WINIFSTATE enmNewState)
|
---|
916 | {
|
---|
917 | ASMAtomicWriteU32((uint32_t volatile *)&pNetFlt->u.s.WinIf.enmState, enmNewState);
|
---|
918 | }
|
---|
919 |
|
---|
920 | /**
|
---|
921 | * Gets the enmState member atomically.
|
---|
922 | *
|
---|
923 | * Used for all reads.
|
---|
924 | *
|
---|
925 | * @returns The enmState value.
|
---|
926 | * @param pThis The instance.
|
---|
927 | */
|
---|
928 | DECLINLINE(VBOXNETFLT_WINIFSTATE) vboxNetFltWinGetWinIfState(PVBOXNETFLTINS pNetFlt)
|
---|
929 | {
|
---|
930 | return (VBOXNETFLT_WINIFSTATE)ASMAtomicUoReadU32((uint32_t volatile *)&pNetFlt->u.s.WinIf.enmState);
|
---|
931 | }
|
---|
932 |
|
---|
933 | /* reference the driver module to prevent driver unload */
|
---|
934 | DECLHIDDEN(void) vboxNetFltWinDrvReference();
|
---|
935 | /* dereference the driver module to prevent driver unload */
|
---|
936 | DECLHIDDEN(void) vboxNetFltWinDrvDereference();
|
---|
937 |
|
---|
938 |
|
---|
939 | #ifndef VBOXNETADP
|
---|
940 | # define VBOXNETFLT_PROMISCUOUS_SUPPORTED(_pNetFlt) (!(_pNetFlt)->fDisablePromiscuous)
|
---|
941 | #else
|
---|
942 | # define STATISTIC_INCREASE(_s) ASMAtomicIncU32((uint32_t volatile *)&(_s));
|
---|
943 |
|
---|
944 | DECLHIDDEN(void) vboxNetFltWinGenerateMACAddress(RTMAC *pMac);
|
---|
945 | DECLHIDDEN(int) vboxNetFltWinMAC2NdisString(RTMAC *pMac, PNDIS_STRING pNdisString);
|
---|
946 | DECLHIDDEN(int) vboxNetFltWinMACFromNdisString(RTMAC *pMac, PNDIS_STRING pNdisString);
|
---|
947 |
|
---|
948 | #endif
|
---|
949 | #endif /* #ifndef ___VBoxNetFltRt_win_h___ */
|
---|