VirtualBox

Changeset 66940 in vbox


Ignore:
Timestamp:
May 17, 2017 4:44:04 PM (8 years ago)
Author:
vboxsync
Message:

Main/NetworkAdapter+NATEngine: Improve default handling (deal with NULL guest OS type), and also add a check if the current settings are default. Note that the API defaults are not the same as the Settings defaults, and that's intentional as the API defaults apply to NICs which the settings didn't read from the config at all.

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

Legend:

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

    r61170 r66940  
    4848    void i_commit();
    4949    void i_copyFrom(NATEngine *aThat);
     50    void i_applyDefaults();
     51    bool i_hasDefaults();
    5052    HRESULT i_loadSettings(const settings::NAT &data);
    5153    HRESULT i_saveSettings(settings::NAT &data);
  • trunk/src/VBox/Main/include/NetworkAdapterImpl.h

    r61170 r66940  
    5858    void i_copyFrom(NetworkAdapter *aThat);
    5959    void i_applyDefaults(GuestOSType *aOsType);
     60    bool i_hasDefaults();
    6061
    6162    ComObjPtr<NetworkAdapter> i_getPeer();
  • trunk/src/VBox/Main/src-server/NATEngineImpl.cpp

    r64193 r66940  
    178178    /* this will back up current data */
    179179    mData->m.assignCopy(aThat->mData->m);
     180}
     181
     182void NATEngine::i_applyDefaults()
     183{
     184    /* sanity */
     185    AutoCaller autoCaller(this);
     186    AssertComRCReturnVoid(autoCaller.rc());
     187
     188    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     189
     190    /* so far nothing to do */
     191}
     192
     193bool NATEngine::i_hasDefaults()
     194{
     195   /* sanity */
     196    AutoCaller autoCaller(this);
     197    AssertComRCReturn(autoCaller.rc(), true);
     198
     199    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     200
     201    return mData->m->areDefaultSettings();
    180202}
    181203
  • trunk/src/VBox/Main/src-server/NetworkAdapterImpl.cpp

    r65103 r66940  
    11811181}
    11821182
     1183/**
     1184 * Applies the defaults for this network adapter.
     1185 *
     1186 * @note This method currently assumes that the object is in the state after
     1187 * calling init(), it does not set defaults from an arbitrary state.
     1188 */
    11831189void NetworkAdapter::i_applyDefaults(GuestOSType *aOsType)
    11841190{
    1185     AssertReturnVoid(aOsType != NULL);
    1186 
    11871191    /* sanity */
    11881192    AutoCaller autoCaller(this);
    11891193    AssertComRCReturnVoid(autoCaller.rc());
     1194
     1195    mNATEngine->i_applyDefaults();
    11901196
    11911197    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    11961202#endif // VBOX_WITH_E1000
    11971203
    1198     NetworkAdapterType_T defaultType = aOsType->i_networkAdapterType();
     1204    NetworkAdapterType_T defaultType = NetworkAdapterType_Am79C973;
     1205    if (aOsType)
     1206        defaultType = aOsType->i_networkAdapterType();
    11991207
    12001208    /* Set default network adapter for this OS type */
     
    12031211        defaultType == NetworkAdapterType_I82545EM)
    12041212    {
    1205         if (e1000enabled) mData->type = defaultType;
    1206     }
    1207     else mData->type = defaultType;
    1208 
    1209     /* Enable the first one adapter to the NAT */
    1210     if (mData->ulSlot == 0)
     1213        if (e1000enabled)
     1214            mData->type = defaultType;
     1215    }
     1216    else
     1217        mData->type = defaultType;
     1218
     1219    /* Enable the first one adapter and set it to NAT */
     1220    /** @todo r=klaus remove this long term, since a newly created VM should
     1221     * have no additional hardware components unless configured either
     1222     * explicitly or through Machine::applyDefaults. */
     1223    if (aOsType && mData->ulSlot == 0)
    12111224    {
    12121225        mData->fEnabled = true;
     
    12161229    }
    12171230    mData->fCableConnected = true;
     1231}
     1232
     1233bool NetworkAdapter::i_hasDefaults()
     1234{
     1235    /* sanity */
     1236    AutoCaller autoCaller(this);
     1237    AssertComRCReturn(autoCaller.rc(), true);
     1238
     1239    ComObjPtr<GuestOSType> pGuestOSType;
     1240    HRESULT rc = mParent->i_getVirtualBox()->i_findGuestOSType(mParent->i_getOSTypeId(),
     1241                                                               pGuestOSType);
     1242    if (FAILED(rc))
     1243        return false;
     1244
     1245    NetworkAdapterType_T defaultType = pGuestOSType->i_networkAdapterType();
     1246
     1247    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     1248
     1249    if (   !mData->fEnabled
     1250        && mData->strMACAddress.isEmpty()
     1251        && mData->type == defaultType
     1252        && mData->fCableConnected
     1253        && mData->ulLineSpeed == 0
     1254        && mData->enmPromiscModePolicy == NetworkAdapterPromiscModePolicy_Deny
     1255        && mData->mode == NetworkAttachmentType_Null
     1256        && mData->strBridgedName.isEmpty()
     1257        && mData->strInternalNetworkName.isEmpty()
     1258        && mData->strHostOnlyName.isEmpty()
     1259        && mData->strNATNetworkName.isEmpty()
     1260        && mData->strGenericDriver.isEmpty()
     1261        && mData->genericProperties.size() == 0)
     1262    {
     1263        /* Could be default, check NAT defaults. */
     1264        return mNATEngine->i_hasDefaults();
     1265    }
     1266
     1267    return false;
    12181268}
    12191269
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