HRESULT VBoxNetDhcp::HandleEvent(VBoxEventType_T aEventType, IEvent *pEvent)
{
    switch(aEventType)
    {
        case VBoxEventType_OnHostNameResolutionConfigurationChange:
            fetchAndUpdateDnsInfo();
            break;

        case VBoxEventType_OnNATNetworkStartStop:
        {
            ComPtr <INATNetworkStartStopEvent> pStartStopEvent = pEvent;

            com::Bstr networkName;
            HRESULT hrc = pStartStopEvent->COMGETTER(NetworkName)(networkName.asOutParam());
            AssertComRCReturn(hrc, hrc);
            if (networkName.compare(getNetworkName().c_str()))
                break; /* change not for our network */

            BOOL fStart = TRUE;
            hrc = pStartStopEvent->COMGETTER(StartEvent)(&fStart);
            AssertComRCReturn(hrc, hrc);
            if (!fStart)
                shutdown();
            break;
        }

        case VBoxEventType_OnVBoxSVCAvailabilityChanged:
        {
            shutdown();
            break;
        }
    }

    return S_OK;
}
Esempio n. 2
0
HRESULT VBoxNetDhcp::HandleEvent(VBoxEventType_T aEventType, IEvent *pEvent)
{
    switch(aEventType)
    {
        case VBoxEventType_OnHostNameResolutionConfigurationChange:
            fetchAndUpdateDnsInfo();
            break;
    }

    return S_OK;
}
Esempio n. 3
0
int VBoxNetDhcp::initWithMain()
{
    /* ok, here we should initiate instance of dhcp server
     * and listener for Dhcp configuration events
     */
    AssertRCReturn(virtualbox.isNull(), VERR_INTERNAL_ERROR);
    std::string networkName = getNetwork();

    int rc = findDhcpServer(virtualbox, networkName, m_DhcpServer);
    AssertRCReturn(rc, rc);

    rc = findNatNetwork(virtualbox, networkName, m_NATNetwork);
    AssertRCReturn(rc, rc);

    BOOL fNeedDhcpServer = isDhcpRequired(m_NATNetwork);
    if (!fNeedDhcpServer)
        return VERR_CANCELLED;

    RTNETADDRIPV4 gateway;
    com::Bstr strGateway;
    HRESULT hrc = m_NATNetwork->COMGETTER(Gateway)(strGateway.asOutParam());
    AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
    RTNetStrToIPv4Addr(com::Utf8Str(strGateway).c_str(), &gateway);

    ConfigurationManager *confManager = ConfigurationManager::getConfigurationManager();
    AssertPtrReturn(confManager, VERR_INTERNAL_ERROR);
    confManager->addToAddressList(RTNET_DHCP_OPT_ROUTERS, gateway);

    rc = fetchAndUpdateDnsInfo();
    AssertMsgRCReturn(rc, ("Wasn't able to fetch Dns info"), rc);

    ComEventTypeArray aVBoxEvents;
    aVBoxEvents.push_back(VBoxEventType_OnHostNameResolutionConfigurationChange);
    rc = createNatListener(m_vboxListener, virtualbox, this, aVBoxEvents);
    AssertRCReturn(rc, rc);

    RTNETADDRIPV4 LowerAddress;
    rc = configGetBoundryAddress(m_DhcpServer, false, LowerAddress);
    AssertMsgRCReturn(rc, ("can't get lower boundrary adderss'"),rc);

    RTNETADDRIPV4 UpperAddress;
    rc = configGetBoundryAddress(m_DhcpServer, true, UpperAddress);
    AssertMsgRCReturn(rc, ("can't get upper boundrary adderss'"),rc);

    RTNETADDRIPV4 address = getIpv4Address();
    RTNETADDRIPV4 netmask = getIpv4Netmask();
    RTNETADDRIPV4 networkId = networkid(address, netmask);
    std::string name = std::string("default");

    confManager->addNetwork(unconst(g_RootConfig),
                            networkId,
                            netmask,
                            LowerAddress,
                            UpperAddress);

    com::Bstr bstr;
    hrc = virtualbox->COMGETTER(HomeFolder)(bstr.asOutParam());
    com::Utf8StrFmt strXmlLeaseFile("%ls%c%s.leases",
                                    bstr.raw(), RTPATH_DELIMITER, networkName.c_str());
    confManager->loadFromFile(strXmlLeaseFile);

    return VINF_SUCCESS;
}