VirtualBox

Changeset 48710 in vbox for trunk


Ignore:
Timestamp:
Sep 26, 2013 1:44:36 PM (11 years ago)
Author:
vboxsync
Message:

NatNetworking/Main: do reference couting on network attachment switch.

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/NetworkAdapterImpl.h

    r42825 r48710  
    155155    HRESULT updateMacAddress(Utf8Str aMacAddress);
    156156    void updateBandwidthGroup(BandwidthGroup *aBwGroup);
     157    HRESULT checkAndSwitchFromNatNetworking();
     158    HRESULT switchToNatNetworking(IN_BSTR aNatNetworkName);
    157159
    158160    Machine * const     mParent;
  • trunk/src/VBox/Main/src-server/NetworkAdapterImpl.cpp

    r48538 r48710  
    2424#include "HostImpl.h"
    2525#include "SystemPropertiesImpl.h"
     26#include "VirtualBoxImpl.h"
    2627
    2728#include <iprt/string.h>
     
    542543        }
    543544
     545        alock.release();
     546
     547        HRESULT hrc = checkAndSwitchFromNatNetworking();
     548        if (FAILED(hrc))
     549            return hrc;
     550
     551        alock.acquire();
     552
    544553        mData.backup();
    545554        mData->mBridgedInterface = aBridgedInterface;
     
    602611        }
    603612
     613        alock.release();
     614
     615        HRESULT hrc = checkAndSwitchFromNatNetworking();
     616        if (FAILED(hrc))
     617            return hrc;
     618
     619        alock.acquire();
     620
    604621        mData.backup();
    605622        mData->mHostOnlyInterface = aHostOnlyInterface;
     
    658675        }
    659676
     677        alock.release();
     678
     679        HRESULT hrc = checkAndSwitchFromNatNetworking();
     680        if (FAILED(hrc))
     681            return hrc;
     682
     683        alock.acquire();
     684
    660685        mData.backup();
    661686        mData->mInternalNetwork = aInternalNetwork;
     
    709734    if (mData->mNATNetwork != aNATNetwork)
    710735    {
     736
     737        HRESULT hrc;
    711738        /* if an empty/null string is to be set, host only interface must be
    712739         * turned off */
     
    719746
    720747        mData.backup();
     748       
     749        alock.release();
     750
     751        hrc = checkAndSwitchFromNatNetworking();
     752        if (FAILED(hrc))
     753            return hrc;
     754
     755        hrc = switchToNatNetworking(aNATNetwork);
     756        if (FAILED(hrc))
     757            return hrc;
     758
     759        alock.acquire();
     760
    721761        mData->mNATNetwork = aNATNetwork;
    722762
     
    15501590    LogFlowThisFuncLeave();
    15511591}
     1592
     1593
     1594HRESULT NetworkAdapter::checkAndSwitchFromNatNetworking()
     1595{
     1596    HRESULT hrc;
     1597    MachineState_T state;
     1598
     1599    hrc = mParent->COMGETTER(State)(&state);
     1600    if (FAILED(hrc))
     1601        return hrc;
     1602
     1603    if (   mData->mAttachmentType == NetworkAttachmentType_NATNetwork
     1604        && state == MachineState_Running)
     1605    {
     1606        int natCount;
     1607
     1608        natCount = mParent->getVirtualBox()->natNetworkRefDec(mData->mNATNetwork.raw());
     1609        if (natCount == -1)
     1610            return E_INVALIDARG; /* no such network */
     1611    }
     1612   
     1613    return S_OK;
     1614}
     1615
     1616
     1617HRESULT NetworkAdapter::switchToNatNetworking(IN_BSTR aNatNetworkName)
     1618{
     1619    HRESULT hrc;
     1620    MachineState_T state;
     1621
     1622    hrc = mParent->COMGETTER(State)(&state);
     1623    if (FAILED(hrc))
     1624        return hrc;
     1625
     1626    if (state == MachineState_Running)
     1627    {
     1628        int natCount;
     1629
     1630        natCount = mParent->getVirtualBox()->natNetworkRefInc(aNatNetworkName);
     1631        if (natCount == -1)
     1632            return E_INVALIDARG; /* not found */
     1633    }
     1634
     1635    return S_OK;
     1636}
    15521637/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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