VirtualBox

Changeset 92133 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Oct 28, 2021 10:43:36 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
147952
Message:

Main,FE/VBoxManage: Allow changing the localhost reachable flag for the NAT attachment type, bugref:9896

Location:
trunk/src/VBox
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp

    r91416 r92133  
    153153    MODIFYVM_NATDNSPROXY,
    154154    MODIFYVM_NATDNSHOSTRESOLVER,
     155    MODIFYVM_NATLOCALHOSTREACHABLE,
    155156    MODIFYVM_MACADDRESS,
    156157    MODIFYVM_HIDPTR,
     
    359360    { "--natdnsproxy",              MODIFYVM_NATDNSPROXY,               RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
    360361    { "--natdnshostresolver",       MODIFYVM_NATDNSHOSTRESOLVER,        RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
     362    { "--natlocalhostreachable",    MODIFYVM_NATLOCALHOSTREACHABLE,     RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
    361363    { "--macaddress",               MODIFYVM_MACADDRESS,                RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
    362364    { "--mouse",                    MODIFYVM_HIDPTR,                    RTGETOPT_REQ_STRING },
     
    21282130                break;
    21292131            }
     2132
     2133            case MODIFYVM_NATLOCALHOSTREACHABLE:
     2134            {
     2135                if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
     2136                    break;
     2137
     2138                ComPtr<INetworkAdapter> nic;
     2139                CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
     2140                ASSERT(nic);
     2141
     2142                ComPtr<INATEngine> engine;
     2143                CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
     2144
     2145                CHECK_ERROR(engine, COMSETTER(LocalhostReachable)(ValueUnion.f));
     2146                break;
     2147            }
     2148
    21302149            case MODIFYVM_MACADDRESS:
    21312150            {
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r92056 r92133  
    2430724307  <interface
    2430824308    name="INATEngine" extends="$unknown"
    24309     uuid="8faef61e-6e15-4f71-a6a5-94e707fafbcc"
     24309    uuid="a06253a7-dcd2-44e3-8689-9c9c4b6b6234"
    2431024310    wsmap="managed"
    2431124311    reservedMethods="4" reservedAttributes="8"
     
    2435424354      <desc>Array of NAT port-forwarding rules in string representation, in the following
    2435524355        format: "name,protocol id,host ip,host port,guest ip,guest port".</desc>
     24356    </attribute>
     24357    <attribute name="LocalhostReachable" type="boolean">
     24358      <desc>Whether traffic from the guest directed to 10.0.2.2 will reach the
     24359        host's loopback interface, i.e. localhost or 127.0.0.1.</desc>
    2435624360    </attribute>
    2435724361    <method name="setNetworkSettings">
  • trunk/src/VBox/Main/include/MachineImpl.h

    r91743 r92133  
    548548    Utf8Str i_getDefaultNVRAMFilename();
    549549    Utf8Str i_getSnapshotNVRAMFilename();
     550    SettingsVersion_T i_getSettingsVersion(void);
    550551
    551552    void i_composeSavedStateFilename(Utf8Str &strStateFilePath);
  • trunk/src/VBox/Main/include/NATEngineImpl.h

    r90828 r92133  
    6363    HRESULT setHostIP(const com::Utf8Str &aHostIP);
    6464    HRESULT getHostIP(com::Utf8Str &aBindIP);
     65    HRESULT setLocalhostReachable(BOOL fLocalhostReachable);
     66    HRESULT getLocalhostReachable(BOOL *pfLocalhostReachable);
    6567    /* TFTP properties */
    6668    HRESULT setTFTPPrefix(const com::Utf8Str &aTFTPPrefix);
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r91503 r92133  
    55145514                hrc = natEngine->COMGETTER(AliasMode)(&aliasMode);                          H();
    55155515                InsertConfigInteger(pCfg, "AliasMode", aliasMode);
     5516
     5517                BOOL fLocalhostReachable;
     5518                hrc = natEngine->COMGETTER(LocalhostReachable)(&fLocalhostReachable);       H();
     5519                InsertConfigInteger(pCfg, "LocalhostReachable", fLocalhostReachable);
    55165520
    55175521                /* port-forwarding */
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r92040 r92133  
    73117311
    73127312    return strNVRAMFilePath;
     7313}
     7314
     7315/**
     7316 * Returns the version of the settings file.
     7317 */
     7318SettingsVersion_T Machine::i_getSettingsVersion(void)
     7319{
     7320    AutoCaller autoCaller(this);
     7321    AssertComRCReturn(autoCaller.rc(), SettingsVersion_Null);
     7322
     7323    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     7324
     7325    return mData->pMachineConfigFile->getSettingsVersion();
    73137326}
    73147327
  • trunk/src/VBox/Main/src-server/NATEngineImpl.cpp

    r85309 r92133  
    188188    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    189189
    190     /* so far nothing to do */
     190    mData->m->fLocalhostReachable = false; /* Applies to new VMs only, see @bugref{9896} */
    191191}
    192192
     
    199199    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    200200
    201     return mData->m->areDefaultSettings();
     201    return mData->m->areDefaultSettings(mParent->i_getSettingsVersion());
    202202}
    203203
     
    434434}
    435435
     436HRESULT NATEngine::setLocalhostReachable(BOOL fLocalhostReachable)
     437{
     438    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     439
     440    if (mData->m->fLocalhostReachable != RT_BOOL(fLocalhostReachable))
     441    {
     442        mData->m.backup();
     443        mData->m->fLocalhostReachable = RT_BOOL(fLocalhostReachable);
     444        mParent->i_setModified(Machine::IsModified_NetworkAdapters);
     445    }
     446    return S_OK;
     447}
     448
     449HRESULT NATEngine::getLocalhostReachable(BOOL *pfLocalhostReachable)
     450{
     451    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     452    *pfLocalhostReachable = mData->m->fLocalhostReachable;
     453    return S_OK;
     454}
     455
    436456HRESULT NATEngine::setTFTPPrefix(const com::Utf8Str &aTFTPPrefix)
    437457{
  • trunk/src/VBox/Main/xml/Settings.cpp

    r91416 r92133  
    14721472    return m->fFileExists;
    14731473}
     1474
     1475/**
     1476 * Returns the settings file version
     1477 *
     1478 * @returns Settings file version enum.
     1479 */
     1480SettingsVersion_T ConfigFileBase::getSettingsVersion()
     1481{
     1482    return m->sv;
     1483}
     1484
    14741485
    14751486/**
     
    30303041    fAliasLog(false),
    30313042    fAliasProxyOnly(false),
    3032     fAliasUseSamePorts(false)
     3043    fAliasUseSamePorts(false),
     3044    fLocalhostReachable(true) /* Historically this value is true. */
    30333045{
    30343046}
     
    30613073
    30623074/**
     3075 * Check whether the localhost-reachable setting is the default for the given settings version.
     3076 */
     3077bool NAT::areLocalhostReachableDefaultSettings(SettingsVersion_T sv) const
     3078{
     3079    return    (   fLocalhostReachable
     3080                && sv < SettingsVersion_v1_19)
     3081           || (   !fLocalhostReachable
     3082                && sv >= SettingsVersion_v1_19);
     3083}
     3084
     3085/**
    30633086 * Check if all settings have default values.
    30643087 */
    3065 bool NAT::areDefaultSettings() const
    3066 {
     3088bool NAT::areDefaultSettings(SettingsVersion_T sv) const
     3089{
     3090    /*
     3091     * Before settings version 1.19 localhost was reachable by default
     3092     * when using NAT which was changed with version 1.19+, see @bugref{9896}
     3093     * for more information.
     3094     */
    30673095    return strNetwork.isEmpty()
    30683096        && strBindIP.isEmpty()
     
    30753103        && areAliasDefaultSettings()
    30763104        && areTFTPDefaultSettings()
    3077         && mapRules.size() == 0;
     3105        && mapRules.size() == 0
     3106        && areLocalhostReachableDefaultSettings(sv);
    30783107}
    30793108
     
    31023131            && fAliasProxyOnly     == n.fAliasProxyOnly
    31033132            && fAliasUseSamePorts  == n.fAliasUseSamePorts
     3133            && fLocalhostReachable == n.fLocalhostReachable
    31043134            && mapRules            == n.mapRules);
    31053135}
     
    31453175        && enmPromiscModePolicy == NetworkAdapterPromiscModePolicy_Deny
    31463176        && mode == NetworkAttachmentType_Null
    3147         && nat.areDefaultSettings()
     3177        && nat.areDefaultSettings(sv)
    31483178        && strBridgedName.isEmpty()
    31493179        && strInternalNetworkName.isEmpty()
     
    31623192 * Special check if settings of the non-current attachment type have default values.
    31633193 */
    3164 bool NetworkAdapter::areDisabledDefaultSettings() const
    3165 {
    3166     return (mode != NetworkAttachmentType_NAT ? nat.areDefaultSettings() : true)
     3194bool NetworkAdapter::areDisabledDefaultSettings(SettingsVersion_T sv) const
     3195{
     3196    return (mode != NetworkAttachmentType_NAT ? nat.areDefaultSettings(sv) : true)
    31673197        && (mode != NetworkAttachmentType_Bridged ? strBridgedName.isEmpty() : true)
    31683198        && (mode != NetworkAttachmentType_Internal ? strInternalNetworkName.isEmpty() : true)
     
    41774207        elmMode.getAttributeValue("tcprcv", nic.nat.u32TcpRcv);
    41784208        elmMode.getAttributeValue("tcpsnd", nic.nat.u32TcpSnd);
     4209        elmMode.getAttributeValue("localhost-reachable", nic.nat.fLocalhostReachable);
    41794210        const xml::ElementNode *pelmDNS;
    41804211        if ((pelmDNS = elmMode.findChildElement("DNS")))
     
    68636894                {
    68646895                    /* m->sv >= SettingsVersion_v1_10 */
    6865                     if (!nic.areDisabledDefaultSettings())
     6896                    if (!nic.areDisabledDefaultSettings(m->sv))
    68666897                    {
    68676898                        xml::ElementNode *pelmDisabledNode = pelmAdapter->createChild("DisabledModes");
     
    72517282            // For the currently active network attachment type we have to
    72527283            // generate the tag, otherwise the attachment type is lost.
    7253             if (fEnabled || !nic.nat.areDefaultSettings())
     7284            if (fEnabled || !nic.nat.areDefaultSettings(m->sv))
    72547285            {
    72557286                xml::ElementNode *pelmNAT = elmParent.createChild("NAT");
    72567287
    7257                 if (!nic.nat.areDefaultSettings())
     7288                if (!nic.nat.areDefaultSettings(m->sv))
    72587289                {
    72597290                    if (nic.nat.strNetwork.length())
     
    72717302                    if (nic.nat.u32TcpSnd)
    72727303                        pelmNAT->setAttribute("tcpsnd", nic.nat.u32TcpSnd);
     7304                    if (!nic.nat.areLocalhostReachableDefaultSettings(m->sv))
     7305                        pelmNAT->setAttribute("localhost-reachable", nic.nat.fLocalhostReachable);
    72737306                    if (!nic.nat.areDNSDefaultSettings())
    72747307                    {
     
    79627995            return;
    79637996        }
     7997
     7998        NetworkAdaptersList::const_iterator netit;
     7999        for (netit = hardwareMachine.llNetworkAdapters.begin();
     8000             netit != hardwareMachine.llNetworkAdapters.end();
     8001             ++netit)
     8002        {
     8003            if (   netit->fEnabled
     8004                && netit->mode == NetworkAttachmentType_NAT
     8005                && !netit->nat.fLocalhostReachable)
     8006            {
     8007                m->sv = SettingsVersion_v1_19;
     8008                break;
     8009            }
     8010        }
    79648011    }
    79658012
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