VirtualBox

Changeset 92133 in vbox for trunk/src/VBox/Main/xml


Ignore:
Timestamp:
Oct 28, 2021 10:43:36 AM (3 years ago)
Author:
vboxsync
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.

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