VirtualBox

忽略:
時間撮記:
2015-2-8 上午12:43:35 (10 年 以前)
作者:
vboxsync
訊息:

NAT: Introduce PDMINETWORKNATCONFIG::pfnNotifyDnsChanged and call it
on IHostNameResolutionConfigurationChangeEvent. This is just the
plumbing so far, there's no actual callback yet.

檔案:
修改 1 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r54060 r54106  
    350350            }
    351351            break;
     352
     353            case VBoxEventType_OnHostNameResolutionConfigurationChange:
     354            {
     355                mConsole->i_onNATDnsChanged();
     356                break;
     357            }
    352358
    353359            case VBoxEventType_OnHostPCIDevicePlug:
     
    630636            com::SafeArray<VBoxEventType_T> eventTypes;
    631637            eventTypes.push_back(VBoxEventType_OnNATRedirect);
     638            eventTypes.push_back(VBoxEventType_OnHostNameResolutionConfigurationChange);
    632639            eventTypes.push_back(VBoxEventType_OnHostPCIDevicePlug);
    633640            eventTypes.push_back(VBoxEventType_OnExtraDataChanged);
     
    42924299    return rc;
    42934300}
     4301
     4302
     4303/*
     4304 * IHostNameResolutionConfigurationChangeEvent
     4305 *
     4306 * Currently this event doesn't carry actual resolver configuration,
     4307 * so we have to go back to VBoxSVC and ask...  This is not ideal.
     4308 */
     4309HRESULT Console::i_onNATDnsChanged()
     4310{
     4311    HRESULT hrc;
     4312
     4313    AutoCaller autoCaller(this);
     4314    AssertComRCReturnRC(autoCaller.rc());
     4315
     4316    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     4317
     4318    ComPtr<IVirtualBox> pVirtualBox;
     4319    hrc = mMachine->COMGETTER(Parent)(pVirtualBox.asOutParam());
     4320    if (FAILED(hrc))
     4321        return S_OK;
     4322
     4323    ComPtr<IHost> pHost;
     4324    hrc = pVirtualBox->COMGETTER(Host)(pHost.asOutParam());
     4325    if (FAILED(hrc))
     4326        return S_OK;
     4327
     4328    SafeArray<BSTR> aNameServers;
     4329    hrc = pHost->COMGETTER(NameServers)(ComSafeArrayAsOutParam(aNameServers));
     4330    if (FAILED(hrc))
     4331        return S_OK;
     4332
     4333    const size_t cNameServers = aNameServers.size();
     4334    Log(("DNS change - %zu nameservers\n", cNameServers));
     4335
     4336    for (size_t i = 0; i < cNameServers; ++i)
     4337    {
     4338        com::Utf8Str strNameServer(aNameServers[i]);
     4339        Log(("- nameserver[%zu] = \"%s\"\n", i, strNameServer.c_str()));
     4340    }
     4341
     4342    com::Bstr domain;
     4343    pHost->COMGETTER(DomainName)(domain.asOutParam());
     4344    Log(("domain name = \"%s\"\n", com::Utf8Str(domain).c_str()));
     4345
     4346
     4347    ChipsetType_T enmChipsetType;
     4348    hrc = mMachine->COMGETTER(ChipsetType)(&enmChipsetType);
     4349    if (!FAILED(hrc))
     4350    {
     4351        SafeVMPtrQuiet ptrVM(this);
     4352        if (ptrVM.isOk())
     4353        {
     4354            ULONG ulInstanceMax = (ULONG)Global::getMaxNetworkAdapters(enmChipsetType);
     4355
     4356            notifyNatDnsChange(ptrVM.rawUVM(), "pcnet", ulInstanceMax);
     4357            notifyNatDnsChange(ptrVM.rawUVM(), "e1000", ulInstanceMax);
     4358            notifyNatDnsChange(ptrVM.rawUVM(), "virtio-net", ulInstanceMax);
     4359        }
     4360    }
     4361
     4362    return S_OK;
     4363}
     4364
     4365
     4366/*
     4367 * This routine walks over all network device instances, checking if
     4368 * device instance has DrvNAT attachment and triggering DrvNAT DNS
     4369 * change callback.
     4370 */
     4371void Console::notifyNatDnsChange(PUVM pUVM, const char *pszDevice, ULONG ulInstanceMax)
     4372{
     4373    Log(("notifyNatDnsChange: looking for DrvNAT attachment on %s device instances\n", pszDevice));
     4374    for (ULONG ulInstance = 0; ulInstance < ulInstanceMax; ulInstance++)
     4375    {
     4376        PPDMIBASE pBase;
     4377        int rc = PDMR3QueryDriverOnLun(pUVM, pszDevice, ulInstance, 0 /* iLun */, "NAT", &pBase);
     4378        if (RT_FAILURE(rc))
     4379            continue;
     4380
     4381        Log(("Instance %s#%d has DrvNAT attachment; do actual notify\n", pszDevice, ulInstance));
     4382        if (pBase)
     4383        {
     4384            PPDMINETWORKNATCONFIG pNetNatCfg = NULL;
     4385            pNetNatCfg = (PPDMINETWORKNATCONFIG)pBase->pfnQueryInterface(pBase, PDMINETWORKNATCONFIG_IID);
     4386            if (pNetNatCfg && pNetNatCfg->pfnNotifyDnsChanged)
     4387                pNetNatCfg->pfnNotifyDnsChanged(pNetNatCfg);
     4388        }
     4389    }
     4390}
     4391
    42944392
    42954393VMMDevMouseInterface *Console::i_getVMMDevMouseInterface()
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette