- Timestamp:
- Sep 10, 2015 4:35:59 PM (9 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/NATEngineImpl.h
r49874 r57694 7 7 8 8 /* 9 * Copyright (C) 2006-201 3Oracle Corporation9 * Copyright (C) 2006-2015 Oracle Corporation 10 10 * 11 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 34 34 public NATEngineWrap 35 35 { 36 public: 37 typedef std::map<Utf8Str, settings::NATRule> NATRuleMap; 36 public: 38 37 39 38 DECLARE_EMPTY_CTOR_DTOR(NATEngine) … … 48 47 49 48 bool i_isModified(); 50 booli_rollback();49 void i_rollback(); 51 50 void i_commit(); 51 void i_copyFrom(NATEngine *aThat); 52 52 HRESULT i_loadSettings(const settings::NAT &data); 53 53 HRESULT i_saveSettings(settings::NAT &data); … … 103 103 struct Data; 104 104 Data *mData; 105 bool m_fModified;106 105 const ComObjPtr<NATEngine> mPeer; 107 106 Machine * const mParent; 108 NATRuleMap mNATRules;109 107 INetworkAdapter * const mAdapter; 110 108 }; -
trunk/src/VBox/Main/include/NetworkAdapterImpl.h
r49951 r57694 7 7 8 8 /* 9 * Copyright (C) 2006-201 3Oracle Corporation9 * Copyright (C) 2006-2015 Oracle Corporation 10 10 * 11 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 155 155 const ComObjPtr<NATEngine> mNATEngine; 156 156 157 bool m_fModified;158 157 Backupable<Data> mData; 159 158 }; -
trunk/src/VBox/Main/src-server/NATEngineImpl.cpp
r51498 r57694 5 5 6 6 /* 7 * Copyright (C) 2010-201 4Oracle Corporation7 * Copyright (C) 2010-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 28 28 #include <VBox/settings.h> 29 29 #include <VBox/com/array.h> 30 31 typedef std::map<Utf8Str, settings::NATRule> NATRuleMap; 30 32 31 33 struct NATEngineData … … 59 61 /* Alias service */ 60 62 ULONG mAliasMode; 63 /* Port forwarding rules */ 64 NATRuleMap mNATRules; 61 65 }; 62 66 … … 90 94 AssertReturn(autoInitSpan.isOk(), E_FAIL); 91 95 autoInitSpan.setSucceeded(); 92 m_fModified = false;93 96 mData = new Data(); 94 97 mData->m.allocate(); … … 113 116 mData = new Data(); 114 117 mData->m.share(aThat->mData->m); 115 NATRuleMap::iterator it;116 mNATRules.clear();117 for (it = aThat->mNATRules.begin(); it != aThat->mNATRules.end(); ++it)118 {119 mNATRules.insert(std::make_pair(it->first, it->second));120 }121 118 unconst(mParent) = aParent; 122 119 unconst(mAdapter) = aAdapter; … … 140 137 mData = new Data(); 141 138 mData->m.attachCopy(aThat->mData->m); 142 NATRuleMap::iterator it;143 mNATRules.clear();144 for (it = aThat->mNATRules.begin(); it != aThat->mNATRules.end(); ++it)145 {146 mNATRules.insert(std::make_pair(it->first, it->second));147 }148 139 unconst(mAdapter) = aAdapter; 149 140 unconst(mParent) = aParent; … … 159 150 return; 160 151 161 mNATRules.clear();162 152 mData->m.free(); 163 153 delete mData; … … 169 159 bool NATEngine::i_isModified() 170 160 { 171 Auto WriteLock alock(this COMMA_LOCKVAL_SRC_POS);172 bool fModified = m _fModified;161 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 162 bool fModified = mData->m.isBackedUp(); 173 163 return fModified; 174 164 } 175 165 176 boolNATEngine::i_rollback()166 void NATEngine::i_rollback() 177 167 { 178 168 AutoCaller autoCaller(this); 179 AssertComRCReturn(autoCaller.rc(), false); 180 181 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 182 bool fChanged = m_fModified; 183 184 if (m_fModified) 185 { 186 /* we need to check all data to see whether anything will be changed 187 * after rollback */ 188 mData->m.rollback(); 189 } 190 m_fModified = false; 191 return fChanged; 169 AssertComRCReturnVoid(autoCaller.rc()); 170 171 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 172 173 mData->m.rollback(); 192 174 } 193 175 … … 204 186 * first) */ 205 187 AutoMultiWriteLock2 alock(mPeer, this COMMA_LOCKVAL_SRC_POS); 206 if (m _fModified)188 if (mData->m.isBackedUp()) 207 189 { 208 190 mData->m.commit(); 209 191 if (mPeer) 210 {211 192 mPeer->mData->m.attach(mData->m); 212 mPeer->mNATRules.clear(); 213 NATRuleMap::iterator it; 214 for (it = mNATRules.begin(); it != mNATRules.end(); ++it) 215 { 216 mPeer->mNATRules.insert(std::make_pair(it->first, it->second)); 217 } 218 } 219 } 220 m_fModified = false; 193 } 194 } 195 196 void NATEngine::i_copyFrom(NATEngine *aThat) 197 { 198 AssertReturnVoid(aThat != NULL); 199 200 /* sanity */ 201 AutoCaller autoCaller(this); 202 AssertComRCReturnVoid(autoCaller.rc()); 203 204 /* sanity too */ 205 AutoCaller thatCaller(aThat); 206 AssertComRCReturnVoid(thatCaller.rc()); 207 208 /* peer is not modified, lock it for reading (aThat is "master" so locked 209 * first) */ 210 AutoReadLock rl(aThat COMMA_LOCKVAL_SRC_POS); 211 AutoWriteLock wl(this COMMA_LOCKVAL_SRC_POS); 212 213 /* this will back up current data */ 214 mData->m.assignCopy(aThat->mData->m); 221 215 } 222 216 … … 245 239 { 246 240 mData->m.backup(); 247 m _fModified = true;241 mParent->i_setModified(Machine::IsModified_NetworkAdapters); 248 242 } 249 243 if (aMtu) … … 258 252 mData->m->mTcpRcv = aTcpWndRcv; 259 253 260 if (m_fModified)261 mParent->i_setModified(Machine::IsModified_NetworkAdapters);262 254 return S_OK; 263 255 } … … 268 260 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 269 261 270 aRedirects.resize(m NATRules.size());262 aRedirects.resize(mData->m->mNATRules.size()); 271 263 size_t i = 0; 272 264 NATRuleMap::const_iterator it; 273 for (it = m NATRules.begin(); it !=mNATRules.end(); ++it, ++i)265 for (it = mData->m->mNATRules.begin(); it != mData->m->mNATRules.end(); ++it, ++i) 274 266 { 275 267 settings::NATRule r = it->second; … … 307 299 308 300 NATRuleMap::iterator it; 309 for (it = m NATRules.begin(); it !=mNATRules.end(); ++it)301 for (it = mData->m->mNATRules.begin(); it != mData->m->mNATRules.end(); ++it) 310 302 { 311 303 r = it->second; … … 320 312 } 321 313 314 mData->m.backup(); 322 315 r.strName = name.c_str(); 323 316 r.proto = aProto; … … 326 319 r.strGuestIP = aGuestIP; 327 320 r.u16GuestPort = aGuestPort; 328 m NATRules.insert(std::make_pair(name, r));321 mData->m->mNATRules.insert(std::make_pair(name, r)); 329 322 mParent->i_setModified(Machine::IsModified_NetworkAdapters); 330 m_fModified = true;331 323 332 324 ULONG ulSlot; … … 342 334 { 343 335 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 344 NATRuleMap::iterator it = m NATRules.find(aName);345 if (it == m NATRules.end())336 NATRuleMap::iterator it = mData->m->mNATRules.find(aName); 337 if (it == mData->m->mNATRules.end()) 346 338 return E_INVALIDARG; 347 339 mData->m.backup(); … … 355 347 mAdapter->COMGETTER(Slot)(&ulSlot); 356 348 357 m NATRules.erase(it);349 mData->m->mNATRules.erase(it); 358 350 mParent->i_setModified(Machine::IsModified_NetworkAdapters); 359 m_fModified = true;360 mData->m.commit();361 351 alock.release(); 362 352 mParent->i_onNATRedirectRuleChange(ulSlot, TRUE, Bstr(aName).raw(), proto, Bstr(strHostIP).raw(), … … 391 381 mData->m->mAliasMode |= (data.fAliasProxyOnly ? NATAliasMode_AliasProxyOnly : 0); 392 382 /* port forwarding */ 393 m NATRules.clear();383 mData->m->mNATRules.clear(); 394 384 for (settings::NATRuleList::const_iterator it = data.llRules.begin(); 395 385 it != data.llRules.end(); ++it) 396 386 { 397 mNATRules.insert(std::make_pair(it->strName, *it)); 398 } 399 m_fModified = false; 387 mData->m->mNATRules.insert(std::make_pair(it->strName, *it)); 388 } 400 389 return rc; 401 390 } … … 429 418 data.fAliasUseSamePorts = !!(mData->m->mAliasMode & NATAliasMode_AliasUseSamePorts); 430 419 431 for (NATRuleMap::iterator it = m NATRules.begin();432 it != m NATRules.end(); ++it)420 for (NATRuleMap::iterator it = mData->m->mNATRules.begin(); 421 it != mData->m->mNATRules.end(); ++it) 433 422 data.llRules.push_back(it->second); 434 m_fModified = false;435 423 return rc; 436 424 } … … 444 432 mData->m->mNetwork = aNetwork; 445 433 mParent->i_setModified(Machine::IsModified_NetworkAdapters); 446 m_fModified = true;447 434 } 448 435 return S_OK; … … 469 456 mData->m->mBindIP = aHostIP; 470 457 mParent->i_setModified(Machine::IsModified_NetworkAdapters); 471 m_fModified = true;472 458 } 473 459 return S_OK; … … 491 477 mData->m->mTFTPPrefix = aTFTPPrefix; 492 478 mParent->i_setModified(Machine::IsModified_NetworkAdapters); 493 m_fModified = true;494 479 } 495 480 return S_OK; … … 517 502 mData->m->mTFTPBootFile = aTFTPBootFile; 518 503 mParent->i_setModified(Machine::IsModified_NetworkAdapters); 519 m_fModified = true;520 504 } 521 505 return S_OK; … … 543 527 mData->m->mTFTPNextServer = aTFTPNextServer; 544 528 mParent->i_setModified(Machine::IsModified_NetworkAdapters); 545 m_fModified = true;546 529 } 547 530 return S_OK; … … 569 552 mData->m->mDNSPassDomain = aDNSPassDomain; 570 553 mParent->i_setModified(Machine::IsModified_NetworkAdapters); 571 m_fModified = true;572 554 } 573 555 return S_OK; … … 591 573 mData->m->mDNSProxy = aDNSProxy; 592 574 mParent->i_setModified(Machine::IsModified_NetworkAdapters); 593 m_fModified = true;594 575 } 595 576 return S_OK; … … 619 600 mData->m->mDNSUseHostResolver = aDNSUseHostResolver; 620 601 mParent->i_setModified(Machine::IsModified_NetworkAdapters); 621 m_fModified = true;622 602 } 623 603 return S_OK; … … 633 613 mData->m->mAliasMode = aAliasMode; 634 614 mParent->i_setModified(Machine::IsModified_NetworkAdapters); 635 m_fModified = true;636 615 } 637 616 return S_OK; -
trunk/src/VBox/Main/src-server/NetworkAdapterImpl.cpp
r56867 r57694 81 81 mNATEngine->init(aParent, this); 82 82 /* mPeer is left null */ 83 84 m_fModified = false;85 83 86 84 mData.allocate(); … … 129 127 130 128 unconst(mParent) = aParent; 129 /* mPeer is left null */ 130 131 131 unconst(mNATEngine).createObject(); 132 132 mNATEngine->init(aParent, this, aThat->mNATEngine); … … 180 180 mNATEngine->initCopy(aParent, this, aThat->mNATEngine); 181 181 182 /* sanity */ 182 183 AutoCaller thatCaller(aThat); 183 184 AssertComRCReturnRC(thatCaller.rc()); … … 256 257 mData->mAdapterType = aAdapterType; 257 258 258 m_fModified = true;259 259 // leave the lock before informing callbacks 260 260 alock.release(); … … 304 304 mData->mEnabled = aEnabled; 305 305 306 m_fModified = true;307 306 // leave the lock before informing callbacks 308 307 alock.release(); … … 394 393 if (SUCCEEDED(rc)) 395 394 { 396 m_fModified = true;397 395 // leave the lock before informing callbacks 398 396 alock.release(); 399 400 397 401 398 AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS); // mParent is const, no need to lock … … 449 446 mData->mAttachmentType = aAttachmentType; 450 447 451 m_fModified = true;452 448 // leave the lock before informing callbacks 453 449 alock.release(); … … 501 497 mData->mBridgedInterface = aBridgedInterface; 502 498 503 m_fModified = true;504 499 // leave the lock before informing callbacks 505 500 alock.release(); … … 548 543 mData.backup(); 549 544 mData->mHostOnlyInterface = aHostOnlyInterface; 550 551 m_fModified = true;552 545 553 546 // leave the lock before informing callbacks … … 597 590 mData->mInternalNetwork = aInternalNetwork; 598 591 599 m_fModified = true;600 592 // leave the lock before informing callbacks 601 593 alock.release(); … … 646 638 mData->mNATNetwork = aNATNetwork; 647 639 648 m_fModified = true;649 640 // leave the lock before informing callbacks 650 641 alock.release(); … … 720 711 mData->mCableConnected = aConnected; 721 712 722 m_fModified = true;723 713 // leave the lock before informing callbacks 724 714 alock.release(); … … 758 748 mData->mLineSpeed = aSpeed; 759 749 760 m_fModified = true;761 750 // leave the lock before informing callbacks 762 751 alock.release(); … … 808 797 mData.backup(); 809 798 mData->mPromiscModePolicy = aPromiscModePolicy; 810 m_fModified = true;811 799 812 800 alock.release(); … … 843 831 mData->mTraceEnabled = aEnabled; 844 832 845 m_fModified = true;846 833 // leave the lock before informing callbacks 847 834 alock.release(); … … 881 868 mData->mTraceFile = aTraceFile; 882 869 883 m_fModified = true;884 870 // leave the lock before informing callbacks 885 871 alock.release(); … … 927 913 mData->mBootPriority = aBootPriority; 928 914 929 m_fModified = true;930 915 // leave the lock before informing callbacks 931 916 alock.release(); … … 1093 1078 if (FAILED(rc)) return rc; 1094 1079 1095 // after loading settings, we are no longer different from the XML on disk1096 m_fModified = false;1097 1098 1080 return S_OK; 1099 1081 } … … 1134 1116 data.mode = mData->mAttachmentType; 1135 1117 1136 mNATEngine->i_commit();1137 1118 mNATEngine->i_saveSettings(data.nat); 1138 1119 … … 1147 1128 1148 1129 data.strNATNetworkName = mData->mNATNetwork; 1149 1150 // after saving settings, we are no longer different from the XML on disk1151 m_fModified = false;1152 1130 1153 1131 return S_OK; … … 1162 1140 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1163 1141 1164 bool fChanged = m _fModified;1142 bool fChanged = mData.isBackedUp(); 1165 1143 fChanged |= (mData->mAdapterType == NetworkAttachmentType_NAT? mNATEngine->i_isModified() : false); 1166 1144 return fChanged; … … 1177 1155 1178 1156 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1157 1158 mNATEngine->i_rollback(); 1179 1159 1180 1160 mData.rollback(); … … 1198 1178 * first) */ 1199 1179 AutoMultiWriteLock2 alock(mPeer, this COMMA_LOCKVAL_SRC_POS); 1180 1181 mNATEngine->i_commit(); 1200 1182 1201 1183 if (mData.isBackedUp()) … … 1225 1207 AutoCaller thatCaller(aThat); 1226 1208 AssertComRCReturnVoid(thatCaller.rc()); 1209 1210 mNATEngine->i_copyFrom(aThat->mNATEngine); 1227 1211 1228 1212 /* peer is not modified, lock it for reading (aThat is "master" so locked … … 1345 1329 i_updateBandwidthGroup(pBwGroup); 1346 1330 1347 m_fModified = true;1348 1331 // leave the lock before informing callbacks 1349 1332 alock.release();
Note:
See TracChangeset
for help on using the changeset viewer.