- Timestamp:
- Mar 31, 2015 3:22:11 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/win/ndis6/VBoxNetLwf-win.cpp
r53624 r55041 187 187 /** MAC address of underlying adapter */ 188 188 RTMAC MacAddr; 189 /** Packet filter of underlying miniport */190 ULONG uPacketFilter;191 189 /** Saved offload configuration */ 192 190 NDIS_OFFLOAD SavedOffloadConfig; … … 197 195 /** true if the trunk expects data from us */ 198 196 bool fActive; 197 /** true if the host wants the adapter to be in promisc mode */ 198 bool fHostPromisc; 199 199 } VBOXNETLWF_MODULE; 200 200 typedef VBOXNETLWF_MODULE *PVBOXNETLWF_MODULE; … … 470 470 } 471 471 472 void inline vboxNetLwfWinOverridePacketFiltersUp(PVBOXNETLWF_MODULE pModuleCtx, ULONG *pFilters) 473 { 474 if (ASMAtomicReadBool(&pModuleCtx->fActive) && !ASMAtomicReadBool(&pModuleCtx->fHostPromisc)) 475 *pFilters &= ~NDIS_PACKET_TYPE_PROMISCUOUS; 476 } 477 472 478 NDIS_STATUS vboxNetLwfWinOidRequest(IN NDIS_HANDLE hModuleCtx, 473 479 IN PNDIS_OID_REQUEST pOidRequest) … … 494 500 && pOidRequest->DATA.SET_INFORMATION.Oid == OID_GEN_CURRENT_PACKET_FILTER) 495 501 { 496 ASMAtomicWriteU32((uint32_t*)&pModuleCtx->uPacketFilter, *(ULONG*)pOidRequest->DATA.SET_INFORMATION.InformationBuffer); 497 Log((__FUNCTION__": updated cached packet filter value to:\n")); 502 ASMAtomicWriteBool(&pModuleCtx->fHostPromisc, !!(*(ULONG*)pOidRequest->DATA.SET_INFORMATION.InformationBuffer & NDIS_PACKET_TYPE_PROMISCUOUS)); 503 Log((__FUNCTION__": host wanted to set packet filter value to:\n")); 504 vboxNetLwfWinDumpFilterTypes(*(ULONG*)pOidRequest->DATA.SET_INFORMATION.InformationBuffer); 505 /* Keep adapter in promisc mode as long as we are active. */ 506 if (ASMAtomicReadBool(&pModuleCtx->fActive)) 507 *(ULONG*)pClone->DATA.SET_INFORMATION.InformationBuffer |= NDIS_PACKET_TYPE_PROMISCUOUS; 508 Log5((__FUNCTION__": pass the following packet filters to miniport:\n")); 498 509 vboxNetLwfWinDumpFilterTypes(*(ULONG*)pOidRequest->DATA.SET_INFORMATION.InformationBuffer); 499 510 } … … 512 523 pPrev = ASMAtomicXchgPtrT(&pModuleCtx->pPendingRequest, NULL, PNDIS_OID_REQUEST); 513 524 Assert(pPrev == pClone); 525 Log5((__FUNCTION__": got the following packet filters from miniport:\n")); 526 vboxNetLwfWinDumpFilterTypes(*(ULONG*)pOidRequest->DATA.QUERY_INFORMATION.InformationBuffer); 527 /* 528 * The host does not expect the adapter to be in promisc mode, 529 * unless it enabled the mode. Let's not disillusion it. 530 */ 531 if ( pOidRequest->RequestType == NdisRequestQueryInformation 532 && pOidRequest->DATA.QUERY_INFORMATION.Oid == OID_GEN_CURRENT_PACKET_FILTER) 533 vboxNetLwfWinOverridePacketFiltersUp(pModuleCtx, (ULONG*)pOidRequest->DATA.QUERY_INFORMATION.InformationBuffer); 534 Log5((__FUNCTION__": reporting to the host the following packet filters:\n")); 535 vboxNetLwfWinDumpFilterTypes(*(ULONG*)pOidRequest->DATA.QUERY_INFORMATION.InformationBuffer); 514 536 vboxNetLwfWinCopyOidRequestResults(pClone, pOidRequest); 515 537 NdisFreeCloneOidRequest(pModuleCtx->hFilter, pClone); … … 538 560 Assert(pPrev == pRequest); 539 561 562 Log5((__FUNCTION__": completed rq type=%d oid=%x\n", pRequest->RequestType, pRequest->DATA.QUERY_INFORMATION.Oid)); 540 563 vboxNetLwfWinCopyOidRequestResults(pRequest, pOriginal); 564 if ( pRequest->RequestType == NdisRequestQueryInformation 565 && pRequest->DATA.QUERY_INFORMATION.Oid == OID_GEN_CURRENT_PACKET_FILTER) 566 { 567 Log5((__FUNCTION__": underlying miniport reports its packet filters:\n")); 568 vboxNetLwfWinDumpFilterTypes(*(ULONG*)pRequest->DATA.QUERY_INFORMATION.InformationBuffer); 569 vboxNetLwfWinOverridePacketFiltersUp(pModuleCtx, (ULONG*)pRequest->DATA.QUERY_INFORMATION.InformationBuffer); 570 Log5((__FUNCTION__": reporting the following packet filters to upper protocol:\n")); 571 vboxNetLwfWinDumpFilterTypes(*(ULONG*)pRequest->DATA.QUERY_INFORMATION.InformationBuffer); 572 } 541 573 NdisFreeCloneOidRequest(pModuleCtx->hFilter, pRequest); 542 574 NdisFOidRequestComplete(pModuleCtx->hFilter, pOriginal, Status); … … 556 588 static bool vboxNetLwfWinIsPromiscuous(PVBOXNETLWF_MODULE pModuleCtx) 557 589 { 558 return !!(pModuleCtx->uPacketFilter & NDIS_PACKET_TYPE_PROMISCUOUS);590 return ASMAtomicReadBool(&pModuleCtx->fHostPromisc); 559 591 } 560 592 … … 591 623 { 592 624 LogFlow(("==>"__FUNCTION__": module=%p %s\n", pModuleCtx, fPromisc ? "promiscuous" : "normal")); 625 ULONG uFilter = 0; 593 626 VBOXNETLWF_OIDREQ Rq; 594 627 vboxNetLwfWinInitOidRequest(&Rq); 595 ULONG uFilter = ASMAtomicReadU32((uint32_t*)&pModuleCtx->uPacketFilter); 628 Rq.Request.RequestType = NdisRequestQueryInformation; 629 Rq.Request.DATA.QUERY_INFORMATION.Oid = OID_GEN_CURRENT_PACKET_FILTER; 630 Rq.Request.DATA.QUERY_INFORMATION.InformationBuffer = &uFilter; 631 Rq.Request.DATA.QUERY_INFORMATION.InformationBufferLength = sizeof(uFilter); 632 NDIS_STATUS Status = vboxNetLwfWinSyncOidRequest(pModuleCtx, &Rq); 633 if (Status != NDIS_STATUS_SUCCESS) 634 { 635 Log((__FUNCTION__": vboxNetLwfWinSyncOidRequest(query, OID_GEN_CURRENT_PACKET_FILTER) failed with 0x%x\n", Status)); 636 return Status; 637 } 638 if (Rq.Request.DATA.QUERY_INFORMATION.BytesWritten != sizeof(uFilter)) 639 { 640 Log((__FUNCTION__": vboxNetLwfWinSyncOidRequest(query, OID_GEN_CURRENT_PACKET_FILTER) failed to write neccessary amount (%d bytes), actually written %d bytes\n", sizeof(uFilter), Rq.Request.DATA.QUERY_INFORMATION.BytesWritten)); 641 return NDIS_STATUS_FAILURE; 642 } 643 644 Log5((__FUNCTION__": OID_GEN_CURRENT_PACKET_FILTER query returned the following filters:\n")); 645 vboxNetLwfWinDumpFilterTypes(uFilter); 646 596 647 if (fPromisc) 648 { 649 /* If we about to go promiscuous, save the state before we change it. */ 650 ASMAtomicWriteBool(&pModuleCtx->fHostPromisc, !!(uFilter & NDIS_PACKET_TYPE_PROMISCUOUS)); 597 651 uFilter |= NDIS_PACKET_TYPE_PROMISCUOUS; 652 } 653 else 654 { 655 /* Reset promisc only if it was not enabled before we had changed it. */ 656 if (!ASMAtomicReadBool(&pModuleCtx->fHostPromisc)) 657 uFilter &= ~NDIS_PACKET_TYPE_PROMISCUOUS; 658 } 659 660 Log5((__FUNCTION__": OID_GEN_CURRENT_PACKET_FILTER about to set the following filters:\n")); 661 vboxNetLwfWinDumpFilterTypes(uFilter); 662 663 NdisResetEvent(&Rq.Event); /* need to reset as it has been set by query op */ 598 664 Rq.Request.RequestType = NdisRequestSetInformation; 599 665 Rq.Request.DATA.SET_INFORMATION.Oid = OID_GEN_CURRENT_PACKET_FILTER; 600 666 Rq.Request.DATA.SET_INFORMATION.InformationBuffer = &uFilter; 601 667 Rq.Request.DATA.SET_INFORMATION.InformationBufferLength = sizeof(uFilter); 602 NDIS_STATUSStatus = vboxNetLwfWinSyncOidRequest(pModuleCtx, &Rq);668 Status = vboxNetLwfWinSyncOidRequest(pModuleCtx, &Rq); 603 669 if (Status != NDIS_STATUS_SUCCESS) 604 670 { … … 1271 1337 { 1272 1338 LogFlow(("==>"__FUNCTION__": module=%p\n", hModuleCtx)); 1273 PVBOXNETLWF_MODULE pModule = (PVBOXNETLWF_MODULE)hModuleCtx;1274 Log((__FUNCTION__" Status indication: %s\n", vboxNetLwfWinStatusToText(pIndication->StatusCode)));1339 PVBOXNETLWF_MODULE pModuleCtx = (PVBOXNETLWF_MODULE)hModuleCtx; 1340 Log((__FUNCTION__"Got status indication: %s\n", vboxNetLwfWinStatusToText(pIndication->StatusCode))); 1275 1341 switch (pIndication->StatusCode) 1276 1342 { 1277 1343 case NDIS_STATUS_PACKET_FILTER: 1344 vboxNetLwfWinDumpFilterTypes(*(ULONG*)pIndication->StatusBuffer); 1345 vboxNetLwfWinOverridePacketFiltersUp(pModuleCtx, (ULONG*)pIndication->StatusBuffer); 1346 Log((__FUNCTION__"Reporting status: %s\n", vboxNetLwfWinStatusToText(pIndication->StatusCode))); 1278 1347 vboxNetLwfWinDumpFilterTypes(*(ULONG*)pIndication->StatusBuffer); 1279 1348 break; … … 1283 1352 break; 1284 1353 } 1285 NdisFIndicateStatus(pModule ->hFilter, pIndication);1354 NdisFIndicateStatus(pModuleCtx->hFilter, pIndication); 1286 1355 LogFlow(("<=="__FUNCTION__"\n")); 1287 1356 }
Note:
See TracChangeset
for help on using the changeset viewer.