- Timestamp:
- Jul 29, 2016 9:14:25 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltRt-win.cpp
r62709 r62711 1 1 /* $Id$ */ 2 2 /** @file 3 * VBoxNetFltRt-win.cpp - Bridged Networking Driver, Windows Specific Code.4 * NetFlt Runtime5 */ 3 * VBoxNetFltRt-win.cpp - Bridged Networking Driver, Windows Specific Runtime Code. 4 */ 5 6 6 /* 7 7 * Copyright (C) 2011-2016 Oracle Corporation … … 15 15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 16 16 */ 17 18 /********************************************************************************************************************************* 19 * Header Files * 20 *********************************************************************************************************************************/ 17 21 #include "VBoxNetFltCmn-win.h" 18 22 #include <VBox/intnetinline.h> 19 23 #include <iprt/thread.h> 20 24 21 RT_C_DECLS_BEGIN 22 #include <tdikrnl.h> 23 RT_C_DECLS_END 25 #include <iprt/nt/tdikrnl.h> 24 26 #include <mstcpip.h> 25 27 28 29 /********************************************************************************************************************************* 30 * Structures and Typedefs * 31 *********************************************************************************************************************************/ 26 32 /** represents the job element of the job queue 27 33 * see comments for VBOXNETFLT_JOB_QUEUE */ … … 71 77 #endif 72 78 NDIS_STATUS Status; 73 } CREATE_INSTANCE_CONTEXT, *PCREATE_INSTANCE_CONTEXT;79 } CREATE_INSTANCE_CONTEXT, *PCREATE_INSTANCE_CONTEXT; 74 80 75 81 /*contexts used for our jobs */ … … 81 87 bool fRediscovery; 82 88 int Status; 83 } ATTACH_INFO, *PATTACH_INFO;89 } ATTACH_INFO, *PATTACH_INFO; 84 90 85 91 /* general worker context */ … … 88 94 PVBOXNETFLTINS pNetFltIf; 89 95 int Status; 90 } WORKER_INFO, *PWORKER_INFO;96 } WORKER_INFO, *PWORKER_INFO; 91 97 92 98 /* idc initialization */ … … 98 104 volatile int rc; 99 105 KEVENT hCompletionEvent; 100 }INIT_IDC_INFO, *PINIT_IDC_INFO; 101 102 103 /** globals */ 106 } INIT_IDC_INFO, *PINIT_IDC_INFO; 107 108 109 /********************************************************************************************************************************* 110 * Global Variables * 111 *********************************************************************************************************************************/ 104 112 /** global job queue. some operations are required to be done at passive level, e.g. thread creation, adapter bind/unbind initiation, 105 113 * while IntNet typically calls us APC_LEVEL, so we just create a system thread in our DriverEntry and enqueue the jobs to that thread */ … … 107 115 volatile static bool g_bVBoxIdcInitialized; 108 116 INIT_IDC_INFO g_VBoxInitIdcInfo; 117 109 118 /** 110 119 * The (common) global data. … … 114 123 VBOXNETFLTGLOBALS_WIN g_VBoxNetFltGlobalsWin = {0}; 115 124 125 126 /********************************************************************************************************************************* 127 * Defined Constants And Macros * 128 *********************************************************************************************************************************/ 116 129 #define LIST_ENTRY_2_JOB(pListEntry) \ 117 130 ( (PVBOXNETFLT_JOB)((uint8_t *)(pListEntry) - RT_OFFSETOF(VBOXNETFLT_JOB, ListEntry)) ) 118 131 132 133 /********************************************************************************************************************************* 134 * Internal Functions * 135 *********************************************************************************************************************************/ 119 136 static int vboxNetFltWinAttachToInterface(PVBOXNETFLTINS pThis, void * pContext, bool fRediscovery); 120 137 static int vboxNetFltWinConnectIt(PVBOXNETFLTINS pThis); … … 126 143 static int vboxNetFltWinStopInitIdcProbing(); 127 144 145 146 128 147 /** makes the current thread to sleep for the given number of miliseconds */ 129 148 DECLHIDDEN(void) vboxNetFltWinSleep(ULONG milis) … … 160 179 */ 161 180 /* allocates and zeroes the nonpaged memory of a given size */ 162 DECLHIDDEN(NDIS_STATUS) vboxNetFltWinMemAlloc(PVOID * ppMemBuf, UINT cbLength)181 DECLHIDDEN(NDIS_STATUS) vboxNetFltWinMemAlloc(PVOID *ppvMemBuf, UINT cbLength) 163 182 { 164 183 #ifdef DEBUG_NETFLT_USE_EXALLOC 165 *pp MemBuf = ExAllocatePoolWithTag(NonPagedPool, cbLength, VBOXNETFLT_MEM_TAG);166 if (*pp MemBuf)167 { 168 NdisZeroMemory(*pp MemBuf, cbLength);184 *ppvMemBuf = ExAllocatePoolWithTag(NonPagedPool, cbLength, VBOXNETFLT_MEM_TAG); 185 if (*ppvMemBuf) 186 { 187 NdisZeroMemory(*ppvMemBuf, cbLength); 169 188 return NDIS_STATUS_SUCCESS; 170 189 } 171 190 return NDIS_STATUS_FAILURE; 172 191 #else 173 NDIS_STATUS fStatus = NdisAllocateMemoryWithTag(pp MemBuf, cbLength, VBOXNETFLT_MEM_TAG);192 NDIS_STATUS fStatus = NdisAllocateMemoryWithTag(ppvMemBuf, cbLength, VBOXNETFLT_MEM_TAG); 174 193 if (fStatus == NDIS_STATUS_SUCCESS) 175 { 176 NdisZeroMemory(*ppMemBuf, cbLength); 177 } 194 NdisZeroMemory(*ppvMemBuf, cbLength); 178 195 return fStatus; 179 196 #endif … … 273 290 static NDIS_STATUS vboxNetFltWinNdisBufferMoveToSG0(PNDIS_BUFFER pBuffer, PINTNETSG pSG) 274 291 { 275 UINT cSegs = 0;276 292 PINTNETSEG paSeg; 277 293 uint8_t * ptr; … … 547 563 PNDIS_BUFFER pCurrentBuffer = NULL; 548 564 UINT cBufferCount; 549 UINT uBytesCopied = 0;550 565 UINT cbPacketLength; 551 566 … … 1399 1414 return NDIS_STATUS_NOT_SUPPORTED; 1400 1415 } 1401 #else /* if defined VBOXNETADP */ 1416 1417 #else /* VBOXNETADP */ 1402 1418 1403 1419 /** … … 1442 1458 } 1443 1459 1444 static int vboxNetFltWinWchar2 Int(WCHAR c, uint8_t * pv)1460 static int vboxNetFltWinWchar2Byte(WCHAR c, uint8_t *pb) 1445 1461 { 1446 1462 if (c >= L'A' && c <= L'F') 1447 { 1448 *pv = (c - L'A') + 10; 1449 } 1463 *pb = (c - L'A') + 10; 1450 1464 else if (c >= L'a' && c <= L'f') 1451 { 1452 *pv = (c - L'a') + 10; 1453 } 1465 *pb = (c - L'a') + 10; 1454 1466 else if (c >= L'0' && c <= L'9') 1455 { 1456 *pv = (c - L'0'); 1457 } 1467 *pb = (c - L'0'); 1458 1468 else 1459 {1460 1469 return VERR_INVALID_PARAMETER; 1461 }1462 1470 return VINF_SUCCESS; 1463 1471 } … … 1465 1473 DECLHIDDEN(int) vboxNetFltWinMACFromNdisString(RTMAC *pMac, PNDIS_STRING pNdisString) 1466 1474 { 1467 int i, rc;1468 PWSTR pString;1469 1475 1470 1476 /* validate parameters */ … … 1473 1479 AssertReturn(pNdisString->Length >= 12*sizeof(pNdisString->Buffer[0]), VERR_INVALID_PARAMETER); 1474 1480 1475 pString = pNdisString->Buffer;1476 1477 for (i = 0; i < 6; i++)1481 int rc = VINF_SUCCESS; 1482 PWSTR pString = pNdisString->Buffer; 1483 for (int i = 0; i < 6; i++) 1478 1484 { 1479 1485 uint8_t v1, v2; 1480 rc = vboxNetFltWinWchar2 Int(pString[0], &v1);1486 rc = vboxNetFltWinWchar2Byte(pString[0], &v1); 1481 1487 if (RT_FAILURE(rc)) 1482 {1483 1488 break; 1484 } 1485 1486 rc = vboxNetFltWinWchar2Int(pString[1], &v2); 1489 1490 rc = vboxNetFltWinWchar2Byte(pString[1], &v2); 1487 1491 if (RT_FAILURE(rc)) 1488 {1489 1492 break; 1490 }1491 1493 1492 1494 pMac->au8[i] = (v1 << 4) | v2; … … 1498 1500 } 1499 1501 1500 #endif 1502 #endif /* VBOXNETADP */ 1503 1501 1504 /** 1502 1505 * creates a NDIS_PACKET from the PINTNETSG … … 1762 1765 //#endif 1763 1766 } 1767 #ifndef VBOXNETADP /* unreachable for VBOXNETADP because of the above return */ 1764 1768 vboxNetFltWinMpDeregister(&g_VBoxNetFltGlobalsWin.Mp); 1765 # ifndef VBOXNETADP1769 # ifndef VBOXNETADP 1766 1770 NdisFreeSpinLock(&g_VBoxNetFltGlobalsWin.lockFilters); 1767 #endif /* VBOXNETADP */ 1771 # endif 1772 #endif 1768 1773 } 1769 1774 vboxNetFltWinJobFiniQueue(&g_VBoxJobQueue); … … 1961 1966 int rc; 1962 1967 #endif 1963 BOOLEAN bCallFiniOnFail = FALSE;1964 1968 1965 1969 LogFlowFunc(("ENTER: pWinIf 0x%p\n", pWinIf)); … … 2024 2028 return NDIS_STATUS_SUCCESS; 2025 2029 #ifndef VBOXNETADP 2026 vboxNetFltWinMemFree(pWinIf->MpDeviceName.Buffer);2030 // unreachable: vboxNetFltWinMemFree(pWinIf->MpDeviceName.Buffer); 2027 2031 } 2028 2032 RTSemFastMutexDestroy(pWinIf->hSynchRequestMutex); 2029 2033 } 2030 2034 else 2031 {2032 2035 Status = NDIS_STATUS_FAILURE; 2033 }2034 2036 NdisFreePacketPool(pWinIf->hSendPacketPool); 2035 2037 } 2036 2038 NdisFreeBufferPool(pWinIf->hSendBufferPool); 2037 2039 } 2038 #endif2039 2040 NdisFreeBufferPool(pWinIf->hRecvBufferPool); 2041 #endif 2040 2042 } 2041 2043 NdisFreePacketPool(pWinIf->hRecvPacketPool); … … 2148 2150 PNDIS_BUFFER pBuffer1; 2149 2151 UINT uTotalPacketLength1; 2150 uint8_t * pMemBuf1;2152 uint8_t *pbMemBuf1 = NULL; 2151 2153 UINT cbLength1 = 0; 2152 2154 … … 2154 2156 PNDIS_BUFFER pBuffer2; 2155 2157 UINT uTotalPacketLength2; 2156 uint8_t * pMemBuf2;2158 uint8_t *pbMemBuf2 = NULL; 2157 2159 UINT cbLength2 = 0; 2158 2160 bool bMatch = true; … … 2193 2195 if (!cbLength1) 2194 2196 { 2195 NdisQueryBufferSafe(pBuffer1, &p MemBuf1, &cbLength1, NormalPagePriority);2197 NdisQueryBufferSafe(pBuffer1, &pbMemBuf1, &cbLength1, NormalPagePriority); 2196 2198 NdisGetNextBuffer(pBuffer1, &pBuffer1); 2197 2199 } 2198 2200 else 2199 2201 { 2200 Assert(p MemBuf1);2202 Assert(pbMemBuf1); 2201 2203 Assert(ucbLength2Match); 2202 p MemBuf1 += ucbLength2Match;2204 pbMemBuf1 += ucbLength2Match; 2203 2205 } 2204 2206 2205 2207 if (!cbLength2) 2206 2208 { 2207 NdisQueryBufferSafe(pBuffer2, &p MemBuf2, &cbLength2, NormalPagePriority);2209 NdisQueryBufferSafe(pBuffer2, &pbMemBuf2, &cbLength2, NormalPagePriority); 2208 2210 NdisGetNextBuffer(pBuffer2, &pBuffer2); 2209 2211 } 2210 2212 else 2211 2213 { 2212 Assert(p MemBuf2);2214 Assert(pbMemBuf2); 2213 2215 Assert(ucbLength2Match); 2214 p MemBuf2 += ucbLength2Match;2216 pbMemBuf2 += ucbLength2Match; 2215 2217 } 2216 2218 … … 2218 2220 ucbLength2Match = MIN(ucbLength2Match, cbLength2); 2219 2221 2220 if (memcmp( (PVOID*)pMemBuf1, (PVOID*)pMemBuf2, ucbLength2Match))2222 if (memcmp(pbMemBuf1, pbMemBuf2, ucbLength2Match)) 2221 2223 { 2222 2224 bMatch = false; … … 2253 2255 PNDIS_BUFFER pBuffer1; 2254 2256 UINT uTotalPacketLength1; 2255 uint8_t * pMemBuf1;2257 uint8_t *pbMemBuf1 = NULL; 2256 2258 UINT cbLength1 = 0; 2257 2259 UINT uTotalPacketLength2 = pSG->cbTotal; 2258 uint8_t * pMemBuf2;2260 uint8_t *pbMemBuf2 = NULL; 2259 2261 UINT cbLength2 = 0; 2260 2262 bool bMatch = true; … … 2293 2295 if (!cbLength1) 2294 2296 { 2295 NdisQueryBufferSafe(pBuffer1, &p MemBuf1, &cbLength1, NormalPagePriority);2297 NdisQueryBufferSafe(pBuffer1, &pbMemBuf1, &cbLength1, NormalPagePriority); 2296 2298 NdisGetNextBuffer(pBuffer1, &pBuffer1); 2297 2299 } 2298 2300 else 2299 2301 { 2300 Assert(p MemBuf1);2302 Assert(pbMemBuf1); 2301 2303 Assert(ucbLength2Match); 2302 p MemBuf1 += ucbLength2Match;2304 pbMemBuf1 += ucbLength2Match; 2303 2305 } 2304 2306 … … 2306 2308 { 2307 2309 Assert(i < pSG->cSegsUsed); 2308 p MemBuf2 = (uint8_t*)pSG->aSegs[i].pv;2310 pbMemBuf2 = (uint8_t*)pSG->aSegs[i].pv; 2309 2311 cbLength2 = pSG->aSegs[i].cb; 2310 2312 i++; … … 2312 2314 else 2313 2315 { 2314 Assert(p MemBuf2);2316 Assert(pbMemBuf2); 2315 2317 Assert(ucbLength2Match); 2316 p MemBuf2 += ucbLength2Match;2318 pbMemBuf2 += ucbLength2Match; 2317 2319 } 2318 2320 … … 2320 2322 ucbLength2Match = MIN(ucbLength2Match, cbLength2); 2321 2323 2322 if (memcmp( (PVOID*)pMemBuf1, (PVOID*)pMemBuf2, ucbLength2Match))2324 if (memcmp(pbMemBuf1, pbMemBuf2, ucbLength2Match)) 2323 2325 { 2324 2326 bMatch = false; … … 2352 2354 { 2353 2355 UINT uTotalPacketLength1 = pSG1->cbTotal; 2354 PVOID p MemBuf1;2356 PVOID pbMemBuf1 = NULL; 2355 2357 UINT cbLength1 = 0; 2356 2358 UINT i1 = 0; 2357 2359 UINT uTotalPacketLength2 = pSG2->cbTotal; 2358 PVOID p MemBuf2;2360 PVOID pbMemBuf2 = NULL; 2359 2361 UINT cbLength2 = 0; 2360 2362 … … 2393 2395 { 2394 2396 Assert(i1 < pSG1->cSegsUsed); 2395 p MemBuf1 = pSG1->aSegs[i1].pv;2397 pbMemBuf1 = pSG1->aSegs[i1].pv; 2396 2398 cbLength1 = pSG1->aSegs[i1].cb; 2397 2399 i1++; … … 2401 2403 { 2402 2404 Assert(i2 < pSG2->cSegsUsed); 2403 p MemBuf2 = pSG2->aSegs[i2].pv;2405 pbMemBuf2 = pSG2->aSegs[i2].pv; 2404 2406 cbLength2 = pSG2->aSegs[i2].cb; 2405 2407 i2++; … … 2409 2411 ucbLength2Match = MIN(ucbLength2Match, cbLength2); 2410 2412 2411 if (memcmp(p MemBuf1, pMemBuf2, ucbLength2Match))2413 if (memcmp(pbMemBuf1, pbMemBuf2, ucbLength2Match)) 2412 2414 { 2413 2415 bMatch = false; … … 2677 2679 #ifndef VBOXNETFLT_NO_PACKET_QUEUE 2678 2680 vboxNetFltWinQuFiniPacketQueue(pInstance); 2681 #else 2682 RT_NOREF1(pInstance); 2679 2683 #endif 2680 2684 return NDIS_STATUS_SUCCESS; … … 2776 2780 return false; 2777 2781 #else 2782 RT_NOREF1(pThis); 2778 2783 return true; 2779 2784 #endif … … 2837 2842 /* rediscovery means adaptor bind is performed while intnet is already using it 2838 2843 * i.e. adaptor was unbound while being used by intnet and now being bound back again */ 2839 Assert(((VBOXNETFTLINSSTATE)ASMAtomicUoReadU32((uint32_t volatile *)&pThis->enmState)) == kVBoxNetFltInsState_Connected); 2844 Assert( ((VBOXNETFTLINSSTATE)ASMAtomicUoReadU32((uint32_t volatile *)&pThis->enmState)) 2845 == kVBoxNetFltInsState_Connected); 2840 2846 } 2841 2847 #ifndef VBOXNETADP … … 2856 2862 { 2857 2863 if (!pAttachInfo->fRediscovery) 2858 {2859 2864 vboxNetFltWinDrvReference(); 2860 }2861 2865 #ifndef VBOXNETADP 2862 2866 if (pThis->u.s.WinIf.OpenCloseStatus == NDIS_STATUS_SUCCESS) … … 2884 2888 return; 2885 2889 } 2890 #ifndef VBOXNETADP /* unreachable for VBOXNETADP because of the return above */ 2886 2891 AssertBreakpoint(); 2887 2892 … … 2890 2895 vboxNetFltWinDrvDereference(); 2891 2896 } 2892 # ifndef VBOXNETADP2897 # ifndef VBOXNETADP 2893 2898 vboxNetFltWinPtDoUnbinding(pThis, true); 2894 #else 2895 vboxNetFltWinMpDoDeinitialization(pThis); 2899 /*# else - unreachable 2900 vboxNetFltWinMpDoDeinitialization(pThis); */ 2901 # endif 2896 2902 #endif 2897 2903 } … … 2945 2951 static NTSTATUS vboxNetFltWinPtDevDispatch(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp) 2946 2952 { 2953 RT_NOREF1(pDevObj); 2947 2954 PIO_STACK_LOCATION pIrpSl = IoGetCurrentIrpStackLocation(pIrp);; 2948 2955 NTSTATUS Status = STATUS_SUCCESS; … … 3092 3099 int vboxNetFltPortOsXmit(PVBOXNETFLTINS pThis, void *pvIfData, PINTNETSG pSG, uint32_t fDst) 3093 3100 { 3101 RT_NOREF1(pvIfData); 3094 3102 int rc = VINF_SUCCESS; 3095 3103 uint32_t cRefs = 0; 3096 3104 #ifndef VBOXNETADP 3097 3105 if (fDst & INTNETTRUNKDIR_WIRE) 3098 {3099 3106 cRefs++; 3100 }3101 3107 if (fDst & INTNETTRUNKDIR_HOST) 3102 {3103 3108 cRefs++; 3104 }3105 3109 #else 3106 if (fDst & INTNETTRUNKDIR_WIRE || fDst & INTNETTRUNKDIR_HOST) 3107 { 3110 if ((fDst & INTNETTRUNKDIR_WIRE) || (fDst & INTNETTRUNKDIR_HOST)) 3108 3111 cRefs = 1; 3109 }3110 3112 #endif 3111 3113 … … 3144 3146 #if defined(DEBUG_NETFLT_PACKETS) || !defined(VBOX_LOOPBACK_USEFLAGS) 3145 3147 /* the status is NOT pending, complete the packet */ 3146 bool bTmp = vboxNetFltWinLbRemoveSendPacket(pThis, pPacket);3147 Assert( bTmp);3148 bool fTmp = vboxNetFltWinLbRemoveSendPacket(pThis, pPacket); 3149 Assert(fTmp); NOREF(fTmp); 3148 3150 #endif 3149 3151 if (!NT_SUCCESS(fStatus)) 3150 { 3151 /* TODO: convert status to VERR_xxx */ 3152 rc = VERR_GENERAL_FAILURE; 3153 } 3152 rc = VERR_GENERAL_FAILURE; /** @todo convert status to VERR_xxx */ 3154 3153 3155 3154 vboxNetFltWinFreeSGNdisPacket(pPacket, true); … … 3411 3410 PTDI_PNP_CONTEXT Context) 3412 3411 { 3412 RT_NOREF2(DeviceName, Context); 3413 3413 vboxNetFltWinNotifyHostAddress(Address, true); 3414 3414 } … … 3418 3418 PTDI_PNP_CONTEXT Context) 3419 3419 { 3420 RT_NOREF2(DeviceName, Context); 3420 3421 vboxNetFltWinNotifyHostAddress(Address, false); 3421 3422 } … … 3444 3445 Assert(!g_VBoxNetFltGlobalsWin.hNotifier); 3445 3446 NTSTATUS Status = TdiRegisterPnPHandlers(&Info, sizeof(Info), &g_VBoxNetFltGlobalsWin.hNotifier); 3446 Log2(("vboxNetFltWinRegisterIpAddrNotifier: TdiRegisterPnPHandlers returned %d\n", Status)); 3447 Log2(("vboxNetFltWinRegisterIpAddrNotifier: TdiRegisterPnPHandlers returned %d\n", Status)); NOREF(Status); 3447 3448 } 3448 3449 else … … 3487 3488 NTSTATUS Status = TdiDeregisterPnPHandlers(hNotifier); 3488 3489 Log2(("vboxNetFltWinUnregisterIpAddrNotifier: TdiDeregisterPnPHandlers(%p) returned %d\n", 3489 hNotifier, Status)); 3490 hNotifier, Status)); NOREF(Status); 3490 3491 } 3491 3492 else … … 3612 3613 void vboxNetFltPortOsNotifyMacAddress(PVBOXNETFLTINS pThis, void *pvIfData, PCRTMAC pMac) 3613 3614 { 3615 RT_NOREF3(pThis, pvIfData, pMac); 3614 3616 } 3615 3617 … … 3617 3619 { 3618 3620 /* Nothing to do */ 3621 RT_NOREF3(pThis, pvIf, ppvIfData); 3619 3622 return VINF_SUCCESS; 3620 3623 } … … 3623 3626 { 3624 3627 /* Nothing to do */ 3628 RT_NOREF2(pThis, pvIfData); 3625 3629 return VINF_SUCCESS; 3626 3630 }
Note:
See TracChangeset
for help on using the changeset viewer.