Changeset 77804 in vbox for trunk/src/VBox
- Timestamp:
- Mar 20, 2019 8:05:37 AM (6 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp
r76553 r77804 2580 2580 } 2581 2581 2582 static bool vboxNetCfgWinDetectStaleConnection(PCWSTR pName) 2583 { 2584 HKEY hkeyConnection, hkeyAdapter, hkeyAdapters; 2585 WCHAR wszAdaptersKeyName[] = L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"; 2586 WCHAR wszAdapterSubKeyName[MAX_PATH]; 2587 LSTATUS status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, wszAdaptersKeyName, 0, KEY_ALL_ACCESS, &hkeyAdapters); 2588 if (status != ERROR_SUCCESS) 2589 return false; 2590 2591 bool fFailureImminent = false; 2592 for (DWORD i = 0; !fFailureImminent; ++i) 2593 { 2594 DWORD cbName = MAX_PATH; 2595 status = RegEnumKeyEx(hkeyAdapters, i, wszAdapterSubKeyName, &cbName, NULL, NULL, NULL, NULL); 2596 // if (status == ERROR_NO_MORE_ITEMS) 2597 // break; 2598 if (status != ERROR_SUCCESS) 2599 break; 2600 2601 status = RegOpenKeyEx(hkeyAdapters, wszAdapterSubKeyName, 0, KEY_ALL_ACCESS, &hkeyAdapter); 2602 if (status == ERROR_SUCCESS) 2603 { 2604 status = RegOpenKeyEx(hkeyAdapter, L"Connection", 0, KEY_ALL_ACCESS, &hkeyConnection); 2605 if (status == ERROR_SUCCESS) 2606 { 2607 WCHAR wszName[MAX_PATH]; 2608 cbName = MAX_PATH; 2609 status = RegQueryValueEx(hkeyConnection, L"Name", NULL, NULL, (LPBYTE)wszName, &cbName); 2610 if (status == ERROR_SUCCESS) 2611 if (wcsicmp(wszName, pName) == 0) 2612 fFailureImminent = true; 2613 RegCloseKey(hkeyConnection); 2614 } 2615 RegCloseKey(hkeyAdapter); 2616 } 2617 } 2618 RegCloseKey(hkeyAdapters); 2619 2620 return fFailureImminent; 2621 } 2622 2582 2623 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinRenameConnection (LPWSTR pGuid, PCWSTR NewName) 2583 2624 { … … 2586 2627 HRESULT status; 2587 2628 2629 /* 2630 * Before attempting to rename the connection, check if there is a stale 2631 * connection with the same name. We must return ok, so the rest of 2632 * configuration process proceeds normally. 2633 */ 2634 if (vboxNetCfgWinDetectStaleConnection(NewName)) 2635 return S_OK; 2588 2636 /* First try the IShellFolder interface, which was unimplemented 2589 2637 * for the network connections folder before XP. */ … … 2881 2929 } 2882 2930 2883 static HRESULT vboxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile, 2931 typedef struct { 2932 BSTR bstrName; 2933 GUID *pGuid; 2934 HRESULT hr; 2935 } RENAMING_CONTEXT; 2936 2937 static BOOL vboxNetCfgWinRenameHostOnlyNetworkInterface(IN INetCfg *pNc, IN INetCfgComponent *pNcc, PVOID pContext) 2938 { 2939 RT_NOREF1(pNc); 2940 RENAMING_CONTEXT *pParams = (RENAMING_CONTEXT *)pContext; 2941 2942 GUID guid; 2943 pParams->hr = pNcc->GetInstanceGuid(&guid); 2944 if ( pParams->hr == S_OK && guid == *pParams->pGuid) 2945 { 2946 /* Located our component, rename it */ 2947 pParams->hr = pNcc->SetDisplayName(pParams->bstrName); 2948 return FALSE; 2949 } 2950 return TRUE; 2951 } 2952 2953 static HRESULT vboxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile, IN BSTR bstrDesiredName, 2884 2954 OUT GUID *pGuid, OUT BSTR *lppszName, OUT BSTR *pErrMsg) 2885 2955 { … … 3326 3396 INetCfg *pNetCfg = NULL; 3327 3397 LPWSTR lpszApp = NULL; 3398 3399 RENAMING_CONTEXT context; 3400 context.hr = E_FAIL; 3401 3402 if (pGuid) 3403 { 3404 hrc = CLSIDFromString(pWCfgGuidString, (LPCLSID)pGuid); 3405 if (FAILED(hrc)) 3406 NonStandardLogFlow(("CLSIDFromString failed, hrc (0x%x)\n", hrc)); 3407 } 3408 3409 hr = VBoxNetCfgWinQueryINetCfg(&pNetCfg, TRUE, L"VirtualBox Host-Only Creation", 3410 30 * 1000, /* on Vista we often get 6to4svc.dll holding the lock, wait for 30 sec. */ 3411 /** @todo special handling for 6to4svc.dll ???, i.e. several retrieves */ 3412 &lpszApp); 3413 if (hr == S_OK) 3414 { 3415 if (SysStringLen(bstrDesiredName) != 0) 3416 { 3417 /* Rename only if the desired name has been provided */ 3418 context.bstrName = bstrDesiredName; 3419 context.pGuid = pGuid; 3420 hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg, 3421 &GUID_DEVCLASS_NET, 3422 vboxNetCfgWinRenameHostOnlyNetworkInterface, 3423 &context); 3424 } 3425 if (SUCCEEDED(hr)) 3426 hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg, 3427 &GUID_DEVCLASS_NETSERVICE, 3428 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority, 3429 pGuid); 3430 if (SUCCEEDED(hr)) 3431 hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg, 3432 &GUID_DEVCLASS_NETTRANS, 3433 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority, 3434 pGuid); 3435 if (SUCCEEDED(hr)) 3436 hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg, 3437 &GUID_DEVCLASS_NETCLIENT, 3438 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority, 3439 pGuid); 3440 if (SUCCEEDED(hr)) 3441 { 3442 hr = pNetCfg->Apply(); 3443 } 3444 else 3445 NonStandardLogFlow(("Enumeration failed, hr 0x%x\n", hr)); 3446 VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE); 3447 } 3448 else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszApp) 3449 { 3450 NonStandardLogFlow(("Application %ws is holding the lock, failed\n", lpszApp)); 3451 CoTaskMemFree(lpszApp); 3452 } 3453 else 3454 NonStandardLogFlow(("VBoxNetCfgWinQueryINetCfg failed, hr 0x%x\n", hr)); 3455 3328 3456 #ifndef VBOXNETCFG_DELAYEDRENAME 3457 if (SUCCEEDED(hr) && SUCCEEDED(context.hr)) 3458 { 3459 /* The device has been successfully renamed, replace the name now. */ 3460 wcscpy_s(DevName, RT_ELEMENTS(DevName), bstrDesiredName); 3461 } 3462 3329 3463 WCHAR ConnectionName[128]; 3330 3464 ULONG cbName = sizeof(ConnectionName); … … 3343 3477 } 3344 3478 } 3345 3346 if (pGuid)3347 {3348 hrc = CLSIDFromString(pWCfgGuidString, (LPCLSID)pGuid);3349 if (FAILED(hrc))3350 NonStandardLogFlow(("CLSIDFromString failed, hrc (0x%x)\n", hrc));3351 }3352 3353 hr = VBoxNetCfgWinQueryINetCfg(&pNetCfg, TRUE, L"VirtualBox Host-Only Creation",3354 30 * 1000, /* on Vista we often get 6to4svc.dll holding the lock, wait for 30 sec. */3355 /** @todo special handling for 6to4svc.dll ???, i.e. several retrieves */3356 &lpszApp);3357 if (hr == S_OK)3358 {3359 hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg,3360 &GUID_DEVCLASS_NETSERVICE,3361 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,3362 pGuid);3363 if (SUCCEEDED(hr))3364 {3365 hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg,3366 &GUID_DEVCLASS_NETTRANS,3367 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,3368 pGuid);3369 if (SUCCEEDED(hr))3370 hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg,3371 &GUID_DEVCLASS_NETCLIENT,3372 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,3373 pGuid);3374 }3375 3376 if (SUCCEEDED(hr))3377 {3378 hr = pNetCfg->Apply();3379 }3380 else3381 NonStandardLogFlow(("Enumeration failed, hr 0x%x\n", hr));3382 VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);3383 }3384 else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszApp)3385 {3386 NonStandardLogFlow(("Application %ws is holding the lock, failed\n", lpszApp));3387 CoTaskMemFree(lpszApp);3388 }3389 else3390 NonStandardLogFlow(("VBoxNetCfgWinQueryINetCfg failed, hr 0x%x\n", hr));3391 3479 } 3392 3480 … … 3397 3485 } 3398 3486 3399 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile, 3487 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile, IN BSTR pwsDesiredName, 3400 3488 OUT GUID *pGuid, OUT BSTR *lppszName, OUT BSTR *pErrMsg) 3401 3489 { 3402 HRESULT hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, p Guid, lppszName, pErrMsg);3490 HRESULT hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, pwsDesiredName, pGuid, lppszName, pErrMsg); 3403 3491 if (hrc == E_ABORT) 3404 3492 { … … 3412 3500 * See @bugref{7973} for details. 3413 3501 */ 3414 hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, p Guid, lppszName, pErrMsg);3502 hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, pwsDesiredName, pGuid, lppszName, pErrMsg); 3415 3503 if (hrc == E_ABORT) 3416 3504 { … … 3435 3523 Sleep(1000); 3436 3524 CloseServiceHandle(hService); 3437 hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, p Guid, lppszName, pErrMsg);3525 hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, pwsDesiredName, pGuid, lppszName, pErrMsg); 3438 3526 } 3439 3527 else -
trunk/src/VBox/Installer/win/InstallHelper/VBoxInstallHelper.cpp
r76553 r77804 1072 1072 #ifdef VBOXNETCFG_DELAYEDRENAME 1073 1073 BSTR devId; 1074 hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface(pwszInfPath, fIsFile, &guid, &devId, NULL);1074 hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface(pwszInfPath, fIsFile, NULL, &guid, &devId, NULL); 1075 1075 #else /* !VBOXNETCFG_DELAYEDRENAME */ 1076 hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface(pwszInfPath, fIsFile, &guid, NULL, NULL);1076 hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface(pwszInfPath, fIsFile, NULL, &guid, NULL, NULL); 1077 1077 #endif /* !VBOXNETCFG_DELAYEDRENAME */ 1078 1078 logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface returns 0x%x", hr); -
trunk/src/VBox/Main/include/HostImpl.h
r76562 r77804 85 85 86 86 static void i_generateMACAddress(Utf8Str &mac); 87 88 #ifdef RT_OS_WINDOWS 89 HRESULT i_updatePersistentConfigForHostOnlyAdapters(void); 90 HRESULT i_removePersistentConfig(const Bstr &bstrGuid); 91 #endif /* RT_OS_WINDOWS */ 92 87 93 88 94 private: -
trunk/src/VBox/Main/include/HostNetworkInterfaceImpl.h
r77436 r77804 50 50 51 51 HRESULT i_setVirtualBox(VirtualBox *pVirtualBox); 52 #ifdef RT_OS_WINDOWS 53 HRESULT i_updatePersistentConfig(); 54 #endif /* RT_OS_WINDOWS */ 52 55 53 56 #ifdef VBOX_WITH_RESOURCE_USAGE_API … … 84 87 85 88 Utf8Str i_composeNetworkName(const Utf8Str szShortName); 89 90 #if defined(RT_OS_WINDOWS) 91 HRESULT eraseAdapterConfigParameter(const char *szParamName); 92 HRESULT saveAdapterConfigParameter(const char *szParamName, const Utf8Str& strValue); 93 HRESULT saveAdapterConfigIPv4Dhcp(); 94 HRESULT saveAdapterConfigIPv4(ULONG addr, ULONG mask); 95 HRESULT saveAdapterConfigIPv6(const Utf8Str& addr, ULONG prefix); 96 HRESULT saveAdapterConfig(); 97 bool isInConfigFile(); 98 #endif /* defined(RT_OS_WINDOWS) */ 86 99 87 100 const Utf8Str mInterfaceName; -
trunk/src/VBox/Main/include/netif.h
r77436 r77804 97 97 int NetIfEnableStaticIpConfigV6(VirtualBox *pVBox, HostNetworkInterface *pIf, const Utf8Str &aOldIPV6Address, const Utf8Str &aIPV6Address, ULONG aIPV6MaskPrefixLength); 98 98 int NetIfEnableDynamicIpConfig(VirtualBox *pVBox, HostNetworkInterface * pIf); 99 #if defined(RT_OS_WINDOWS) 100 int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress, IN_BSTR bstrName = NULL); 101 #else /* !defined(RT_OS_WINDOWS) */ 99 102 int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress, const char *pszName = NULL); 103 #endif /* !defined(RT_OS_WINDOWS) */ 100 104 int NetIfRemoveHostOnlyNetworkInterface(VirtualBox *pVBox, const Guid &aId, IProgress **aProgress); 101 105 int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *); -
trunk/src/VBox/Main/src-server/HostImpl.cpp
r77506 r77804 54 54 #endif 55 55 56 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) 57 # include <set> 58 #endif 56 #include <set> 59 57 60 58 #ifdef VBOX_WITH_RESOURCE_USAGE_API … … 186 184 : 187 185 fDVDDrivesListBuilt(false), 188 fFloppyDrivesListBuilt(false) 186 fFloppyDrivesListBuilt(false), 187 fPersistentConfigUpToDate(false) 189 188 {}; 190 189 … … 231 230 /** Host's DNS informaton fetching */ 232 231 HostDnsMonitorProxy hostDnsMonitorProxy; 232 233 /** Startup syncing of persistent config in extra data */ 234 bool fPersistentConfigUpToDate; 233 235 }; 234 236 … … 644 646 #endif /* defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT) */ 645 647 648 #if defined(RT_OS_WINDOWS) 649 struct HostOnlyInfo 650 { 651 HostOnlyInfo() : fDhcpEnabled(false), uIPv6PrefixLength(0) {}; 652 653 Bstr bstrName; 654 bool fDhcpEnabled; 655 Bstr strIPv4Address; 656 Bstr strIPv4NetMask; 657 Bstr strIPv6Address; 658 ULONG uIPv6PrefixLength; 659 }; 660 661 typedef std::map<Utf8Str, HostOnlyInfo*> GUID_TO_HOST_ONLY_INFO; 662 663 HRESULT Host::i_updatePersistentConfigForHostOnlyAdapters(void) 664 { 665 /* No need to do the sync twice */ 666 if (m->fPersistentConfigUpToDate) 667 return S_OK; 668 m->fPersistentConfigUpToDate = true; 669 bool fChangesMade = false; 670 671 /* Extract the list of configured host-only interfaces */ 672 GUID_TO_HOST_ONLY_INFO aSavedAdapters; 673 SafeArray<BSTR> aGlobalExtraDataKeys; 674 HRESULT hrc = m->pParent->GetExtraDataKeys(ComSafeArrayAsOutParam(aGlobalExtraDataKeys)); 675 AssertMsg(SUCCEEDED(hrc), ("VirtualBox::GetExtraDataKeys failed with %Rhrc\n", hrc)); 676 for (size_t i = 0; i < aGlobalExtraDataKeys.size(); ++i) 677 { 678 Utf8Str strKey = aGlobalExtraDataKeys[i]; 679 680 if (strKey.startsWith("HostOnly/{")) 681 { 682 Bstr bstrValue; 683 HRESULT hrc = m->pParent->GetExtraData(aGlobalExtraDataKeys[i], bstrValue.asOutParam()); 684 if (hrc != S_OK) 685 continue; 686 687 Utf8Str strGuid = strKey.substr(10, 36); /* Skip "HostOnly/{" */ 688 if (aSavedAdapters.find(strGuid) == aSavedAdapters.end()) 689 aSavedAdapters[strGuid] = new HostOnlyInfo(); 690 691 if (strKey.endsWith("}/Name")) 692 aSavedAdapters[strGuid]->bstrName = bstrValue; 693 else if (strKey.endsWith("}/IPAddress")) 694 { 695 if (bstrValue == "DHCP") 696 aSavedAdapters[strGuid]->fDhcpEnabled = true; 697 else 698 aSavedAdapters[strGuid]->strIPv4Address = bstrValue; 699 } 700 else if (strKey.endsWith("}/IPNetMask")) 701 aSavedAdapters[strGuid]->strIPv4NetMask = bstrValue; 702 else if (strKey.endsWith("}/IPV6Address")) 703 aSavedAdapters[strGuid]->strIPv6Address = bstrValue; 704 else if (strKey.endsWith("}/IPV6PrefixLen")) 705 aSavedAdapters[strGuid]->uIPv6PrefixLength = Utf8Str(bstrValue).toUInt32(); 706 } 707 } 708 709 /* Go over the list of existing adapters and update configs saved in extra data */ 710 std::set<Bstr> aKnownNames; 711 for (HostNetworkInterfaceList::iterator it = m->llNetIfs.begin(); it != m->llNetIfs.end(); ++it) 712 { 713 /* Get type */ 714 HostNetworkInterfaceType_T t; 715 hrc = (*it)->COMGETTER(InterfaceType)(&t); 716 if (FAILED(hrc) || t != HostNetworkInterfaceType_HostOnly) 717 continue; 718 /* Get id */ 719 Bstr bstrGuid; 720 hrc = (*it)->COMGETTER(Id)(bstrGuid.asOutParam()); 721 if (FAILED(hrc)) 722 continue; 723 /* Get name */ 724 Bstr bstrName; 725 hrc = (*it)->COMGETTER(Name)(bstrName.asOutParam()); 726 if (FAILED(hrc)) 727 continue; 728 729 /* Remove adapter from map as it does not need any further processing */ 730 aSavedAdapters.erase(Utf8Str(bstrGuid)); 731 /* Add adapter name to the list of known names, so we won't attempt to create adapters with the same name */ 732 aKnownNames.insert(bstrName); 733 /* Make sure our extra data contains the latest config */ 734 hrc = (*it)->i_updatePersistentConfig(); 735 if (hrc != S_OK) 736 break; 737 } 738 739 /* The following loop not only creates missing adapters, it destroys HostOnlyInfo objects contained in the map as well */ 740 for (GUID_TO_HOST_ONLY_INFO::iterator it = aSavedAdapters.begin(); it != aSavedAdapters.end(); ++it) 741 { 742 Utf8Str strGuid = (*it).first; 743 HostOnlyInfo *pInfo = (*it).second; 744 /* We create adapters only if we haven't seen one with the same name */ 745 if (aKnownNames.find(pInfo->bstrName) == aKnownNames.end()) 746 { 747 /* There is no adapter with such name yet, create it */ 748 ComPtr<IHostNetworkInterface> hif; 749 ComPtr<IProgress> progress; 750 751 int rc = NetIfCreateHostOnlyNetworkInterface(m->pParent, hif.asOutParam(), progress.asOutParam(), pInfo->bstrName.raw()); 752 if (RT_FAILURE(rc)) 753 { 754 LogRel(("Failed to create host-only adapter (%d)\n", rc)); 755 hrc = E_UNEXPECTED; 756 break; 757 } 758 /* Wait for the adapter to get configured completely, before we modify IP addresses. */ 759 progress->WaitForCompletion(-1); 760 fChangesMade = true; 761 if (pInfo->fDhcpEnabled) 762 { 763 hrc = hif->EnableDynamicIPConfig(); 764 LogRel(("EnableDynamicIPConfig returned 0x%x\n", hrc)); 765 } 766 else 767 { 768 hrc = hif->EnableStaticIPConfig(pInfo->strIPv4Address.raw(), pInfo->strIPv4NetMask.raw()); 769 LogRel(("EnableStaticIpConfig returned 0x%x\n", hrc)); 770 } 771 # if 0 772 /* Somehow HostNetworkInterface::EnableStaticIPConfigV6 is not implemented yet. */ 773 if (SUCCEEDED(hrc)) 774 { 775 hrc = hif->EnableStaticIPConfigV6(pInfo->strIPv6Address.raw(), pInfo->uIPv6PrefixLength); 776 LogRel(("EnableStaticIPConfigV6 returned 0x%x\n", hrc)); 777 } 778 # endif 779 /* Now we have seen this name */ 780 aKnownNames.insert(pInfo->bstrName); 781 /* Drop the old config as the newly created adapter has different GUID */ 782 i_removePersistentConfig(strGuid); 783 } 784 delete pInfo; 785 } 786 /* Update the list again if we have created some adapters */ 787 if (SUCCEEDED(hrc) && fChangesMade) 788 hrc = i_updateNetIfList(); 789 790 return hrc; 791 } 792 #endif /* defined(RT_OS_WINDOWS) */ 793 646 794 /** 647 795 * Returns a list of host network interfaces. … … 660 808 return rc; 661 809 } 810 #if defined(RT_OS_WINDOWS) 811 rc = i_updatePersistentConfigForHostOnlyAdapters(); 812 if (FAILED(rc)) 813 { 814 LogRel(("Failed to update persistent config for host-only adapters with rc=%Rhrc\n", rc)); 815 return rc; 816 } 817 #endif /* defined(RT_OS_WINDOWS) */ 662 818 663 819 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); … … 1334 1490 tmpMask.raw()); 1335 1491 ComAssertComRCRet(hrc, hrc); 1336 #endif 1492 #endif /* !defined(RT_OS_WINDOWS) */ 1337 1493 } 1338 1494 … … 1342 1498 #endif 1343 1499 } 1500 1501 1502 #ifdef RT_OS_WINDOWS 1503 HRESULT Host::i_removePersistentConfig(const Bstr &bstrGuid) 1504 { 1505 HRESULT hrc = m->pParent->SetExtraData(BstrFmt("HostOnly/{%ls}/Name", bstrGuid.raw()).raw(), NULL); 1506 if (SUCCEEDED(hrc)) hrc = m->pParent->SetExtraData(BstrFmt("HostOnly/{%ls}/IPAddress", bstrGuid.raw()).raw(), NULL); 1507 if (SUCCEEDED(hrc)) hrc = m->pParent->SetExtraData(BstrFmt("HostOnly/{%ls}/IPNetMask", bstrGuid.raw()).raw(), NULL); 1508 if (SUCCEEDED(hrc)) hrc = m->pParent->SetExtraData(BstrFmt("HostOnly/{%ls}/IPV6Address", bstrGuid.raw()).raw(), NULL); 1509 if (SUCCEEDED(hrc)) hrc = m->pParent->SetExtraData(BstrFmt("HostOnly/{%ls}/IPV6PrefixLen", bstrGuid.raw()).raw(), NULL); 1510 return hrc; 1511 } 1512 #endif /* RT_OS_WINDOWS */ 1344 1513 1345 1514 HRESULT Host::removeHostOnlyNetworkInterface(const com::Guid &aId, … … 1371 1540 { 1372 1541 /* Drop configuration parameters for removed interface */ 1542 #ifdef RT_OS_WINDOWS 1543 rc = i_removePersistentConfig(Utf8StrFmt("%RTuuid", &aId)); 1544 LogRel(("i_removePersistentConfig(%RTuuid) returned %d\n", &aId, r)); 1545 #else /* !RT_OS_WINDOWS */ 1373 1546 rc = m->pParent->SetExtraData(BstrFmt("HostOnly/%ls/IPAddress", name.raw()).raw(), NULL); 1374 1547 rc = m->pParent->SetExtraData(BstrFmt("HostOnly/%ls/IPNetMask", name.raw()).raw(), NULL); 1375 1548 rc = m->pParent->SetExtraData(BstrFmt("HostOnly/%ls/IPV6Address", name.raw()).raw(), NULL); 1376 1549 rc = m->pParent->SetExtraData(BstrFmt("HostOnly/%ls/IPV6NetMask", name.raw()).raw(), NULL); 1550 #endif /* !RT_OS_WINDOWS */ 1377 1551 1378 1552 return S_OK; … … 1563 1737 return rc; 1564 1738 } 1739 #if defined(RT_OS_WINDOWS) 1740 rc = i_updatePersistentConfigForHostOnlyAdapters(); 1741 if (FAILED(rc)) 1742 { 1743 LogRel(("Failed to update persistent config for host-only adapters with rc=%Rhrc\n", rc)); 1744 return rc; 1745 } 1746 #endif /* defined(RT_OS_WINDOWS) */ 1565 1747 1566 1748 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); … … 1598 1780 return rc; 1599 1781 } 1782 #if defined(RT_OS_WINDOWS) 1783 rc = i_updatePersistentConfigForHostOnlyAdapters(); 1784 if (FAILED(rc)) 1785 { 1786 LogRel(("Failed to update persistent config for host-only adapters with rc=%Rhrc\n", rc)); 1787 return rc; 1788 } 1789 #endif /* defined(RT_OS_WINDOWS) */ 1600 1790 1601 1791 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); … … 1628 1818 return rc; 1629 1819 } 1820 #if defined(RT_OS_WINDOWS) 1821 rc = i_updatePersistentConfigForHostOnlyAdapters(); 1822 if (FAILED(rc)) 1823 { 1824 LogRel(("Failed to update persistent config for host-only adapters with rc=%Rhrc\n", rc)); 1825 return rc; 1826 } 1827 #endif /* defined(RT_OS_WINDOWS) */ 1630 1828 1631 1829 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); -
trunk/src/VBox/Main/src-server/HostNetworkInterfaceImpl.cpp
r77436 r77804 156 156 157 157 #ifdef VBOX_WITH_HOSTNETIF_API 158 159 #if defined(RT_OS_WINDOWS) 160 HRESULT HostNetworkInterface::saveAdapterConfigParameter(const char *szParamName, const Utf8Str &strValue) 161 { 162 AssertReturn(mVirtualBox != NULL, E_POINTER); 163 return mVirtualBox->SetExtraData(Bstr(Utf8StrFmt("HostOnly/{%RTuuid}/%s", mGuid, szParamName)).raw(), Bstr(strValue).raw()); 164 } 165 166 HRESULT HostNetworkInterface::eraseAdapterConfigParameter(const char *szParamName) 167 { 168 AssertReturn(mVirtualBox != NULL, E_POINTER); 169 return mVirtualBox->SetExtraData(Bstr(Utf8StrFmt("HostOnly/{%RTuuid}/%s", mGuid, szParamName)).raw(), NULL); 170 } 171 172 HRESULT HostNetworkInterface::saveAdapterConfigIPv4Dhcp() 173 { 174 HRESULT hrc = saveAdapterConfigParameter("IPAddress", "DHCP"); 175 if (hrc == S_OK) 176 hrc = eraseAdapterConfigParameter("IPNetMask"); 177 return hrc; 178 } 179 180 HRESULT HostNetworkInterface::saveAdapterConfigIPv4(ULONG addr, ULONG mask) 181 { 182 HRESULT hrc = saveAdapterConfigParameter("IPAddress", Utf8StrFmt("%RTnaipv4", addr)); 183 if (hrc == S_OK) 184 hrc = saveAdapterConfigParameter("IPNetMask", Utf8StrFmt("%RTnaipv4", mask)); 185 return hrc; 186 } 187 188 HRESULT HostNetworkInterface::saveAdapterConfigIPv6(const Utf8Str& addr, ULONG prefix) 189 { 190 HRESULT hrc = saveAdapterConfigParameter("IPV6Address", addr); 191 if (hrc == S_OK) 192 hrc = saveAdapterConfigParameter("IPV6PrefixLen", Utf8StrFmt("%u", prefix)); 193 return hrc; 194 } 195 196 bool HostNetworkInterface::isInConfigFile(void) 197 { 198 /* We care about host-only adapters only */ 199 if (mIfType != HostNetworkInterfaceType_HostOnly) 200 return true; 201 202 Assert(mVirtualBox != NULL); 203 if (mVirtualBox == NULL) 204 return false; /* Trigger config update, which will fail with proper return code */ 205 Bstr tmpName; 206 mVirtualBox->GetExtraData(Bstr(Utf8StrFmt("HostOnly/{%RTuuid}/Name", mGuid)).raw(), tmpName.asOutParam()); 207 return (tmpName.isNotEmpty() && tmpName == mInterfaceName); 208 209 } 210 211 HRESULT HostNetworkInterface::saveAdapterConfig(void) 212 { 213 /* We care about host-only adapters only */ 214 if (mIfType != HostNetworkInterfaceType_HostOnly) 215 return true; 216 217 HRESULT hrc = saveAdapterConfigParameter("Name", mInterfaceName.c_str()); 218 if (FAILED(hrc)) 219 return hrc; 220 if (m.dhcpEnabled) 221 hrc = saveAdapterConfigIPv4Dhcp(); 222 else 223 hrc = saveAdapterConfigIPv4(m.IPAddress, m.networkMask); 224 if (SUCCEEDED(hrc)) 225 hrc = saveAdapterConfigIPv6(m.IPV6Address.c_str(), m.IPV6NetworkMaskPrefixLength); 226 return hrc; 227 } 228 229 HRESULT HostNetworkInterface::i_updatePersistentConfig(void) 230 { 231 if (mVirtualBox == NULL) 232 return E_POINTER; 233 234 HRESULT hrc = S_OK; 235 if (!isInConfigFile()) 236 { 237 hrc = saveAdapterConfig(); 238 } 239 return hrc; 240 } 241 #endif /* defined(RT_OS_WINDOWS) */ 158 242 159 243 HRESULT HostNetworkInterface::updateConfig() … … 465 549 { 466 550 m.realIPAddress = 0; 551 #if defined(RT_OS_WINDOWS) 552 eraseAdapterConfigParameter("IPAddress"); 553 eraseAdapterConfigParameter("IPNetMask"); 554 #else /* !defined(RT_OS_WINDOWS) */ 467 555 if (FAILED(mVirtualBox->SetExtraData(BstrFmt("HostOnly/%s/IPAddress", 468 556 mInterfaceName.c_str()).raw(), NULL))) … … 471 559 mInterfaceName.c_str()).raw(), NULL))) 472 560 return E_FAIL; 561 #endif /* !defined(RT_OS_WINDOWS) */ 473 562 return S_OK; 474 563 } … … 495 584 m.realIPAddress = ip; 496 585 m.realNetworkMask = mask; 586 #if defined(RT_OS_WINDOWS) 587 saveAdapterConfigIPv4(ip, mask); 588 #else /* !defined(RT_OS_WINDOWS) */ 497 589 if (FAILED(mVirtualBox->SetExtraData(BstrFmt("HostOnly/%s/IPAddress", 498 590 mInterfaceName.c_str()).raw(), … … 503 595 Bstr(aNetworkMask).raw()))) 504 596 return E_FAIL; 597 #endif /* !defined(RT_OS_WINDOWS) */ 505 598 return S_OK; 506 599 } … … 566 659 m.realIPV6Address = aIPV6Address; 567 660 m.realIPV6PrefixLength = aIPV6NetworkMaskPrefixLength; 661 #if defined(RT_OS_WINDOWS) 662 saveAdapterConfigIPv6(Bstr(aIPV6Address).raw(), aIPV6NetworkMaskPrefixLength); 663 #else /* !defined(RT_OS_WINDOWS) */ 568 664 if (FAILED(mVirtualBox->SetExtraData(BstrFmt("HostOnly/%s/IPV6Address", 569 665 mInterfaceName.c_str()).raw(), … … 573 669 mInterfaceName.c_str()).raw(), 574 670 BstrFmt("%u", aIPV6NetworkMaskPrefixLength).raw()))) 671 #endif /* !defined(RT_OS_WINDOWS) */ 575 672 return E_FAIL; 576 673 } -
trunk/src/VBox/Main/src-server/win/NetIf-win.cpp
r77440 r77804 302 302 vrc = aClient->write(d->msgCode); 303 303 if (RT_FAILURE(vrc)) break; 304 //vrc = aClient->write(Utf8Str(d->name));305 //if (RT_FAILURE(vrc)) break;304 vrc = aClient->write(Utf8Str(d->name)); 305 if (RT_FAILURE(vrc)) break; 306 306 307 307 /* wait for a reply */ … … 337 337 { 338 338 rc = d->iface->updateConfig(); 339 if (SUCCEEDED(rc)) 340 rc = d->iface->i_updatePersistentConfig(); 339 341 } 340 342 } … … 678 680 LogFlowFunc(("CreateHostOnlyNetworkInterface:\n")); 679 681 680 // Utf8Str name;681 // vrc = aClient->read(name);682 //if (RT_FAILURE(vrc)) break;682 Utf8Str desiredName; 683 vrc = aClient->read(desiredName); 684 if (RT_FAILURE(vrc)) break; 683 685 684 686 Guid guid; … … 689 691 #ifdef VBOXNETCFG_DELAYEDRENAME 690 692 Bstr devId; 691 hrc = VBoxNetCfgWinCreateHostOnlyNetworkInterface(NULL, false, guid.asOutParam(), devId.asOutParam(),693 hrc = VBoxNetCfgWinCreateHostOnlyNetworkInterface(NULL, false, Bstr(desiredName).raw(), guid.asOutParam(), devId.asOutParam(), 692 694 bstrErr.asOutParam()); 693 695 #else /* !VBOXNETCFG_DELAYEDRENAME */ 694 hrc = VBoxNetCfgWinCreateHostOnlyNetworkInterface(NULL, false, guid.asOutParam(), name.asOutParam(),696 hrc = VBoxNetCfgWinCreateHostOnlyNetworkInterface(NULL, false, Bstr(desiredName).raw(), guid.asOutParam(), name.asOutParam(), 695 697 bstrErr.asOutParam()); 696 698 #endif /* !VBOXNETCFG_DELAYEDRENAME */ … … 1146 1148 IHostNetworkInterface **aHostNetworkInterface, 1147 1149 IProgress **aProgress, 1148 const char *pszName) 1149 { 1150 RT_NOREF(pszName); 1150 IN_BSTR aName) 1151 { 1151 1152 #ifndef VBOX_WITH_NETFLT 1152 1153 return VERR_NOT_IMPLEMENTED; … … 1177 1178 1178 1179 d->msgCode = SVCHlpMsg::CreateHostOnlyNetworkInterface; 1179 //d->name = aName;1180 d->name = aName; 1180 1181 d->iface = iface; 1181 1182 d->vBox = pVirtualBox;
Note:
See TracChangeset
for help on using the changeset viewer.