VirtualBox

Changeset 81883 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Nov 15, 2019 4:31:00 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134678
Message:

Main/DHCPServer+NatNetwork+VirtualBox+Console: Remove old DHCP methods, attributes and interfaces, plus eliminate useless parameters from NATNetwork and DHCPServer Start methods. Additionally a few fixes to the DTD (and correcting some XML goofs in VirtualBox.xidl). More reserved attributes for the not yet implemented ICloudNetwork.

Location:
trunk/src/VBox/Main/src-server
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/DHCPServerImpl.cpp

    r79866 r81883  
    8383    /** weak VirtualBox parent */
    8484    VirtualBox * const  pVirtualBox;
    85     /** The DHCP server name (network).
    86      * @todo Kind of duplicated by networkName, if I understand it correctly.  */
     85    /** The DHCP server name (network). */
    8786    Utf8Str const       strName;
    8887
     
    9897    com::Utf8Str strLogFilename;
    9998
    100     com::Utf8Str networkName;
    10199    com::Utf8Str trunkName;
    102100    com::Utf8Str trunkType;
     
    573571        hrc = i_doSaveSettings();
    574572    return hrc;
    575 }
    576 
    577 
    578 /**
    579  * Used by the legacy 6.0 IDHCPServer::GetVmSlotOptions() and
    580  * IDHCPServer::GetGlobalOptions() implementations.
    581  *
    582  * New interfaces have the option number and option encoding separate from the
    583  * value.
    584  */
    585 HRESULT DHCPServer::i_encode60Option(com::Utf8Str &strEncoded, DHCPOption_T enmOption,
    586                                      DHCPOptionEncoding_T enmEncoding, const com::Utf8Str &strValue)
    587 {
    588     int vrc;
    589     switch (enmEncoding)
    590     {
    591         case DHCPOptionEncoding_Normal:
    592         {
    593             /*
    594              * This is original encoding which assumed that for each
    595              * option we know its format and so we know how option
    596              * "value" text is to be interpreted.
    597              *
    598              *   "2:10800"           # integer 32
    599              *   "6:1.2.3.4 8.8.8.8" # array of ip-address
    600              */
    601             vrc = strEncoded.printfNoThrow("%d:%s", (int)enmOption, strValue.c_str());
    602             break;
    603         }
    604 
    605         case DHCPOptionEncoding_Hex:
    606         {
    607             /*
    608              * This is a bypass for any option - preformatted value as
    609              * hex string with no semantic involved in formatting the
    610              * value for the DHCP reply.
    611              *
    612              *   234=68:65:6c:6c:6f:2c:20:77:6f:72:6c:64
    613              */
    614             vrc = strEncoded.printfNoThrow("%d=%s", (int)enmOption, strValue.c_str());
    615             break;
    616         }
    617 
    618         default:
    619         {
    620             /*
    621              * Try to be forward compatible.
    622              *
    623              *   "254@42=i hope you know what this means"
    624              */
    625             vrc = strEncoded.printfNoThrow("%d@%d=%s", (int)enmOption, (int)enmEncoding, strValue.c_str());
    626             break;
    627         }
    628     }
    629     return RT_SUCCESS(vrc) ? S_OK : E_OUTOFMEMORY;
    630 }
    631 
    632 
    633 /**
    634  * worker for IDHCPServer::GetGlobalOptions.
    635  */
    636 HRESULT DHCPServer::i_getAllOptions60(DHCPConfig &aSourceConfig, std::vector<com::Utf8Str> &aValues)
    637 {
    638     /* Get the values using the new getter: */
    639     std::vector<DHCPOption_T>           Options;
    640     std::vector<DHCPOptionEncoding_T>   Encodings;
    641     std::vector<com::Utf8Str>           Values;
    642     HRESULT hrc = aSourceConfig.i_getAllOptions(Options, Encodings, Values);
    643     if (SUCCEEDED(hrc))
    644     {
    645         /* Encoding them using in the 6.0 style: */
    646         size_t const cValues = Values.size();
    647         aValues.resize(cValues);
    648         for (size_t i = 0; i < cValues && SUCCEEDED(hrc); i++)
    649             hrc = i_encode60Option(aValues[i], Options[i], Encodings[i], Values[i]);
    650     }
    651     return hrc;
    652 }
    653 
    654 
    655 /**
    656  * Worker for legacy <=6.0 interfaces for adding options.
    657  *
    658  * @throws std::bad_alloc
    659  */
    660 HRESULT DHCPServer::i_add60Option(DHCPConfig &aTargetConfig, DhcpOpt_T aOption, const com::Utf8Str &aValue)
    661 {
    662     if (aOption != 0)
    663         return aTargetConfig.i_setOption((DHCPOption_T)aOption, DHCPOptionEncoding_Normal, aValue);
    664 
    665     /*
    666      * This is a kludge to sneak in option encoding information
    667      * through existing API.  We use option 0 and supply the real
    668      * option/value in the same format that i_encode60Option() above
    669      * produces for getter methods.
    670      */
    671     uint8_t u8Code;
    672     char    *pszNext;
    673     int vrc = RTStrToUInt8Ex(aValue.c_str(), &pszNext, 10, &u8Code);
    674     if (RT_FAILURE(vrc))
    675         return setErrorBoth(E_INVALIDARG, VERR_PARSE_ERROR);
    676 
    677     DHCPOptionEncoding_T enmEncoding;
    678     switch (*pszNext)
    679     {
    680         case ':':           /* support legacy format too */
    681         {
    682             enmEncoding = DHCPOptionEncoding_Normal;
    683             break;
    684         }
    685 
    686         case '=':
    687         {
    688             enmEncoding = DHCPOptionEncoding_Hex;
    689             break;
    690         }
    691 
    692         case '@':
    693         {
    694             uint32_t u32Enc = 0;
    695             vrc = RTStrToUInt32Ex(pszNext + 1, &pszNext, 10, &u32Enc);
    696             if (RT_FAILURE(vrc))
    697                 return setErrorBoth(E_INVALIDARG, VERR_PARSE_ERROR);
    698             if (*pszNext != '=')
    699                 return setErrorBoth(E_INVALIDARG, VERR_PARSE_ERROR);
    700             enmEncoding = (DHCPOptionEncoding_T)u32Enc;
    701             break;
    702         }
    703 
    704         default:
    705             return VERR_PARSE_ERROR;
    706     }
    707 
    708     return aTargetConfig.i_setOption((DHCPOption_T)aOption, enmEncoding, com::Utf8Str(pszNext + 1));
    709 }
    710 
    711 
    712 HRESULT DHCPServer::addGlobalOption(DhcpOpt_T aOption, const com::Utf8Str &aValue)
    713 {
    714     return i_add60Option(*m->globalConfig, aOption, aValue);
    715 }
    716 
    717 
    718 HRESULT DHCPServer::removeGlobalOption(DhcpOpt_T aOption)
    719 {
    720     return m->globalConfig->i_removeOption((DHCPOption_T)aOption);
    721 }
    722 
    723 
    724 HRESULT DHCPServer::removeGlobalOptions()
    725 {
    726     return m->globalConfig->i_removeAllOptions();
    727 }
    728 
    729 
    730 HRESULT DHCPServer::getGlobalOptions(std::vector<com::Utf8Str> &aValues)
    731 {
    732     return i_getAllOptions60(*m->globalConfig, aValues);
    733 }
    734 
    735 
    736 HRESULT DHCPServer::getVmConfigs(std::vector<com::Utf8Str> &aValues)
    737 {
    738     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    739 
    740     try
    741     {
    742         aValues.resize(m->individualConfigs.size());
    743         size_t i = 0;
    744         for (Data::IndividualConfigIterator it = m->individualConfigs.begin(); it != m->individualConfigs.end(); ++it, i++)
    745             if (it->second->i_getScope() != DHCPConfigScope_MAC)
    746                 aValues[i].printf("[%RTuuid]:%d", it->second->i_getMachineId().raw(), it->second->i_getSlot());
    747             else
    748                 aValues[i].printf("[%RTmac]", it->second->i_getMACAddress());
    749     }
    750     catch (std::bad_alloc &)
    751     {
    752         return E_OUTOFMEMORY;
    753     }
    754 
    755     return S_OK;
    756573}
    757574
     
    876693
    877694
    878 HRESULT DHCPServer::addVmSlotOption(const com::Utf8Str &aVmName, LONG aSlot, DhcpOpt_T aOption, const com::Utf8Str &aValue)
    879 {
    880     ComObjPtr<DHCPIndividualConfig> ptrConfig;
    881     HRESULT hrc = i_vmNameAndSlotToConfig(aVmName, aSlot, true, ptrConfig);
    882     if (SUCCEEDED(hrc))
    883         hrc = i_add60Option(*ptrConfig, aOption, aValue);
    884     return hrc;
    885 }
    886 
    887 
    888 HRESULT DHCPServer::removeVmSlotOption(const com::Utf8Str &aVmName, LONG aSlot, DhcpOpt_T aOption)
    889 {
    890     ComObjPtr<DHCPIndividualConfig> ptrConfig;
    891     HRESULT hrc = i_vmNameAndSlotToConfig(aVmName, aSlot, false, ptrConfig);
    892     if (SUCCEEDED(hrc))
    893         hrc = ptrConfig->i_removeOption((DHCPOption_T)aOption);
    894     return hrc;
    895 }
    896 
    897 
    898 HRESULT DHCPServer::removeVmSlotOptions(const com::Utf8Str &aVmName, LONG aSlot)
    899 {
    900     ComObjPtr<DHCPIndividualConfig> ptrConfig;
    901     HRESULT hrc = i_vmNameAndSlotToConfig(aVmName, aSlot, false, ptrConfig);
    902     if (SUCCEEDED(hrc))
    903         hrc = ptrConfig->i_removeAllOptions();
    904     return hrc;
    905 }
    906 
    907 
    908 HRESULT DHCPServer::getVmSlotOptions(const com::Utf8Str &aVmName, LONG aSlot, std::vector<com::Utf8Str> &aValues)
    909 {
    910     ComObjPtr<DHCPIndividualConfig> ptrConfig;
    911     HRESULT hrc = i_vmNameAndSlotToConfig(aVmName, aSlot, false, ptrConfig);
    912     if (SUCCEEDED(hrc))
    913         hrc = i_getAllOptions60(*ptrConfig, aValues);
    914     else if (hrc == VBOX_E_OBJECT_NOT_FOUND)
    915     {
    916         aValues.resize(0);
    917         hrc = S_OK;
    918     }
    919     return hrc;
    920 }
    921 
    922 
    923 HRESULT DHCPServer::getMacOptions(const com::Utf8Str &aMAC, std::vector<com::Utf8Str> &aOption)
    924 {
    925     RT_NOREF(aMAC, aOption);
    926     AssertFailed();
    927     return setError(E_NOTIMPL, tr("The GetMacOptions method has been discontinued as it was only supposed to be used by the DHCP server and it does not need it any more. sorry"));
    928 }
    929 
    930 
    931695HRESULT DHCPServer::getEventSource(ComPtr<IEventSource> &aEventSource)
    932696{
     
    1008772    HRESULT hrc = stop();
    1009773    if (SUCCEEDED(hrc))
    1010         hrc = start(m->networkName, m->trunkName, m->trunkType);
     774        hrc = start(m->trunkName, m->trunkType);
    1011775    return hrc;
    1012776}
     
    1025789    {
    1026790        xml::ElementNode *pElmRoot = doc.createRootElement("DHCPServer");
    1027         pElmRoot->setAttribute("networkName", m->networkName);
     791        pElmRoot->setAttribute("networkName", m->strName);
    1028792        if (m->trunkName.isNotEmpty())
    1029793            pElmRoot->setAttribute("trunkName", m->trunkName);
     
    1081845
    1082846
    1083 /** @todo r=bird: why do we get the network name passed in here?  it's the same
    1084  *        as m->strName, isn't it? */
    1085 HRESULT DHCPServer::start(const com::Utf8Str &aNetworkName, const com::Utf8Str &aTrunkName, const com::Utf8Str &aTrunkType)
     847HRESULT DHCPServer::start(const com::Utf8Str &aTrunkName, const com::Utf8Str &aTrunkType)
    1086848{
    1087849    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    1137899     * Copy the startup parameters.
    1138900     */
    1139     m->networkName = aNetworkName;
    1140901    m->trunkName   = aTrunkName;
    1141902    m->trunkType   = aTrunkType;
    1142     HRESULT hrc = i_calcLeasesConfigAndLogFilenames(aNetworkName);
     903    HRESULT hrc = i_calcLeasesConfigAndLogFilenames(m->strName);
    1143904    if (SUCCEEDED(hrc))
    1144905    {
     
    1153914             */
    1154915            m->dhcp.resetArguments();
    1155             int vrc = m->dhcp.addArgPair("--comment", m->networkName.c_str());
     916            int vrc = m->dhcp.addArgPair("--comment", m->strName.c_str());
    1156917            if (RT_SUCCESS(vrc))
    1157918                vrc = m->dhcp.addArgPair("--config", m->strConfigFilename.c_str());
     
    1213974    if (m->strLeasesFilename.isEmpty())
    1214975    {
    1215         HRESULT hrc = i_calcLeasesConfigAndLogFilenames(m->networkName.isEmpty() ? m->strName : m->networkName);
     976        HRESULT hrc = i_calcLeasesConfigAndLogFilenames(m->strName);
    1216977        if (FAILED(hrc))
    1217978            return hrc;
  • trunk/src/VBox/Main/src-server/NATNetworkImpl.cpp

    r79644 r81883  
    648648    if (FAILED(host->COMGETTER(DomainName)(domain.asOutParam())))
    649649        LogRel(("NATNetwork: Failed to get host's domain name\n"));
     650    ComPtr<IDHCPGlobalConfig> pDHCPConfig;
     651    HRESULT hrc = m->dhcpServer->COMGETTER(GlobalConfig)(pDHCPConfig.asOutParam());
     652    if (FAILED(hrc))
     653    {
     654        LogRel(("NATNetwork: Failed to get global DHCP config when updating domain name option with %Rhrc\n", hrc));
     655        return;
     656    }
    650657    if (domain.isNotEmpty())
    651658    {
    652         HRESULT hrc = m->dhcpServer->AddGlobalOption(DhcpOpt_DomainName, domain.raw());
     659        hrc = pDHCPConfig->SetOption(DHCPOption_DomainName, DHCPOptionEncoding_Normal, domain.raw());
    653660        if (FAILED(hrc))
    654661            LogRel(("NATNetwork: Failed to add domain name option with %Rhrc\n", hrc));
    655662    }
    656663    else
    657         m->dhcpServer->RemoveGlobalOption(DhcpOpt_DomainName);
     664        pDHCPConfig->RemoveOption(DHCPOption_DomainName);
    658665}
    659666
     
    678685    {
    679686        LogRel(("NATNetwork: Failed to get name servers from host with %Rhrc\n", hrc));
     687        return;
     688    }
     689    ComPtr<IDHCPGlobalConfig> pDHCPConfig;
     690    hrc = m->dhcpServer->COMGETTER(GlobalConfig)(pDHCPConfig.asOutParam());
     691    if (FAILED(hrc))
     692    {
     693        LogRel(("NATNetwork: Failed to get global DHCP config when updating domain name server option with %Rhrc\n", hrc));
    680694        return;
    681695    }
     
    735749            lstServers.append(RTCStringFmt("%RTnaipv4", networkid.u | RT_H2N_U32_C(1U))); /* proxy */
    736750
    737         hrc = m->dhcpServer->AddGlobalOption(DhcpOpt_DomainNameServer, Bstr(RTCString::join(lstServers, " ")).raw());
     751        hrc = pDHCPConfig->SetOption(DHCPOption_DomainNameServers, DHCPOptionEncoding_Normal, Bstr(RTCString::join(lstServers, " ")).raw());
    738752        if (FAILED(hrc))
    739753            LogRel(("NATNetwork: Failed to add domain name server option '%s' with %Rhrc\n", RTCString::join(lstServers, " ").c_str(), hrc));
    740754    }
    741755    else
    742         m->dhcpServer->RemoveGlobalOption(DhcpOpt_DomainNameServer);
     756        pDHCPConfig->RemoveOption(DHCPOption_DomainNameServers);
    743757}
    744758
     
    754768
    755769
    756 HRESULT  NATNetwork::start(const com::Utf8Str &aTrunkType)
     770HRESULT  NATNetwork::start()
    757771{
    758772#ifdef VBOX_WITH_NAT_SERVICE
     
    761775
    762776    m->NATRunner.addArgPair(NetworkServiceRunner::kpszKeyNetwork, Utf8Str(m->s.strNetworkName).c_str());
    763     m->NATRunner.addArgPair(NetworkServiceRunner::kpszKeyTrunkType, Utf8Str(aTrunkType).c_str());
     777    m->NATRunner.addArgPair(NetworkServiceRunner::kpszKeyTrunkType, Utf8Str(TRUNKTYPE_WHATEVER).c_str());
    764778    m->NATRunner.addArgPair(NetworkServiceRunner::kpszIpAddress, Utf8Str(m->IPv4Gateway).c_str());
    765779    m->NATRunner.addArgPair(NetworkServiceRunner::kpszIpNetmask, Utf8Str(m->IPv4NetworkMask).c_str());
     
    820834#endif /* VBOX_WITH_DHCPD */
    821835        /* XXX: AddGlobalOption(DhcpOpt_Router,) - enables attachement of DhcpServer to Main (no longer true with VBoxNetDhcpd). */
    822         m->dhcpServer->AddGlobalOption(DhcpOpt_Router, Bstr(m->IPv4Gateway).raw());
    823 
    824         hrc = m->dhcpServer->Start(Bstr(m->s.strNetworkName).raw(), Bstr("").raw(), Bstr(aTrunkType).raw());
     836        ComPtr<IDHCPGlobalConfig> pDHCPConfig;
     837        hrc = m->dhcpServer->COMGETTER(GlobalConfig)(pDHCPConfig.asOutParam());
     838        if (FAILED(hrc))
     839        {
     840            LogRel(("NATNetwork: Failed to get global DHCP config when updating IPv4 gateway option with %Rhrc\n", hrc));
     841            m->dhcpServer.setNull();
     842            return E_FAIL;
     843        }
     844        pDHCPConfig->SetOption(DHCPOption_Routers, DHCPOptionEncoding_Normal, Bstr(m->IPv4Gateway).raw());
     845
     846        hrc = m->dhcpServer->Start(Bstr::Empty.raw(), Bstr(TRUNKTYPE_WHATEVER).raw());
    825847        if (FAILED(hrc))
    826848        {
     
    838860    return E_FAIL;
    839861#else
    840     NOREF(aTrunkType);
    841862    ReturnComNotImplemented();
    842863#endif
  • trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp

    r81710 r81883  
    19611961            strNewCreateFlags += ",directoryIncludesUUID=1";
    19621962
    1963         com::Utf8Str blstr = "";
     1963        com::Utf8Str blstr;
    19641964        rc = composeMachineFilename(aName,
    19651965                                    llGroups.front(),
     
    38913891        if (FAILED(rc)) return -1;
    38923892
    3893         rc = nat->Start(Bstr("whatever").raw());
     3893        rc = nat->Start();
    38943894        if (SUCCEEDED(rc))
    38953895            LogRel(("Started NAT network '%s'\n", aNetworkName.c_str()));
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