VirtualBox

Changeset 54106 in vbox


Ignore:
Timestamp:
Feb 8, 2015 12:43:35 AM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
98104
Message:

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

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/pdmnetifs.h

    r35361 r54106  
    426426                                                       bool fUdp, const char *pHostIp, uint16_t u16HostPort,
    427427                                                       const char *pGuestIp, uint16_t u16GuestPort));
     428    /**
     429     * Inform NAT about host DNS settings change.
     430     *
     431     * IHostNameResolutionConfigurationChangeEvent.
     432     */
     433    DECLR3CALLBACKMEMBER(void, pfnNotifyDnsChanged, (PPDMINETWORKNATCONFIG pInterface));
    428434
    429435} PDMINETWORKNATCONFIG;
    430436/** PDMINETWORKNATCONFIG interface ID. */
    431 #define PDMINETWORKNATCONFIG_IID                "0f001d62-4d2f-11df-93b3-2fd0b3a36a6b"
     437#define PDMINETWORKNATCONFIG_IID                "dc961028-3523-4b52-a93b-e38168a4a9fa"
    432438/** @} */
    433439
  • trunk/src/VBox/Devices/Network/DrvNAT.cpp

    r53399 r54106  
    14021402    /* NAT engine configuration */
    14031403    pThis->INetworkNATCfg.pfnRedirectRuleCommand = drvNATNetworkNatConfig_RedirectRuleCommand;
     1404    pThis->INetworkNATCfg.pfnNotifyDnsChanged = NULL;
    14041405
    14051406    /*
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r54060 r54106  
    262262    HRESULT i_onNATRedirectRuleChange(ULONG ulInstance, BOOL aNatRuleRemove,
    263263                                      NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
     264    HRESULT i_onNATDnsChanged();
    264265
    265266    // Mouse interface
     
    350351                     ULONG aMaxDowntime,
    351352                     ComPtr<IProgress> &aProgress);
     353
     354    void notifyNatDnsChange(PUVM pUVM, const char *pszDevice, ULONG ulInstanceMax);
    352355
    353356    /**
  • 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()
Note: See TracChangeset for help on using the changeset viewer.

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