Changeset 65365 in vbox for trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg
- Timestamp:
- Jan 18, 2017 3:44:07 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp
r63564 r65365 82 82 * Forward declaration for using vboxNetCfgWinSetupMetric() 83 83 */ 84 HRESULT vboxNetCfgWinSetupMetric(IN HKEY hKey);84 HRESULT vboxNetCfgWinSetupMetric(IN NET_LUID* pLuid); 85 85 HRESULT vboxNetCfgWinGetInterfaceLUID(IN HKEY hKey, OUT NET_LUID* pLUID); 86 86 … … 316 316 if (pTempComponent != NULL) 317 317 { 318 HKEY hkey ;318 HKEY hkey = (HKEY)INVALID_HANDLE_VALUE; 319 319 HRESULT res; 320 320 … … 326 326 327 327 /* Set default metric value for host-only interface only */ 328 if (SUCCEEDED(res) && hkey != NULL && wcsnicmp(pszwComponentId, VBOXNETCFGWIN_NETADP_ID, 256) == 0) 329 { 330 res = vboxNetCfgWinSetupMetric(hkey); 328 if ( SUCCEEDED(res) 329 && hkey != INVALID_HANDLE_VALUE 330 && wcsnicmp(pszwComponentId, VBOXNETCFGWIN_NETADP_ID, 256) == 0) 331 { 332 NET_LUID luid; 333 res = vboxNetCfgWinGetInterfaceLUID(hkey, &luid); 334 335 /* Close the key as soon as possible. See @bugref{7973}. */ 336 RegCloseKey (hkey); 337 hkey = (HKEY)INVALID_HANDLE_VALUE; 338 331 339 if (FAILED(res)) 332 340 { … … 336 344 */ 337 345 NonStandardLogFlow(("VBoxNetCfgWinInstallComponent Warning! " 338 "vboxNetCfgWinSetupMetric failed, default metric " 339 "for new interface will not be set, hr (0x%x)\n", res)); 340 } 346 "vboxNetCfgWinGetInterfaceLUID failed, default metric " 347 "for new interface will not be set, hr (0x%x)\n", res)); 348 } 349 else 350 { 351 res = vboxNetCfgWinSetupMetric(&luid); 352 if (FAILED(res)) 353 { 354 /* 355 * The setting of Metric is not very important functionality, 356 * So we will not break installation process due to this error. 357 */ 358 NonStandardLogFlow(("VBoxNetCfgWinInstallComponent Warning! " 359 "vboxNetCfgWinSetupMetric failed, default metric " 360 "for new interface will not be set, hr (0x%x)\n", res)); 361 } 362 } 363 } 364 if (hkey != INVALID_HANDLE_VALUE) 365 { 366 RegCloseKey (hkey); 367 hkey = (HKEY)INVALID_HANDLE_VALUE; 341 368 } 342 369 if (ppComponent != NULL) … … 3134 3161 GetLastError())); 3135 3162 3136 /* Figure out NetCfgInstanceId */3137 hkey = SetupDiOpenDevRegKey(hDeviceInfo,3138 &DeviceInfoData,3139 DICS_FLAG_GLOBAL,3140 0,3141 DIREG_DRV,3142 KEY_READ);3143 if (hkey == INVALID_HANDLE_VALUE)3144 SetErrBreak(("SetupDiOpenDevRegKey failed (0x%08X)", GetLastError()));3145 3146 3163 /* Query the instance ID; on Windows 10, the registry key may take a short 3147 3164 * while to appear. Microsoft recommends waiting for up to 5 seconds, but … … 3152 3169 for (int retries = 0; retries < 2 * 20; ++retries) 3153 3170 { 3171 Sleep(500); /* half second */ 3172 3173 /* Figure out NetCfgInstanceId */ 3174 hkey = SetupDiOpenDevRegKey(hDeviceInfo, 3175 &DeviceInfoData, 3176 DICS_FLAG_GLOBAL, 3177 0, 3178 DIREG_DRV, 3179 KEY_READ); 3180 if (hkey == INVALID_HANDLE_VALUE) 3181 break; 3182 3154 3183 cbSize = sizeof(pWCfgGuidString); 3155 3184 ret = RegQueryValueExW (hkey, L"NetCfgInstanceId", NULL, 3156 3185 &dwValueType, (LPBYTE) pWCfgGuidString, &cbSize); 3157 3186 /* As long as the return code is FILE_NOT_FOUND, sleep and retry. */ 3158 if (ret == ERROR_FILE_NOT_FOUND) 3159 Sleep(500); /* half second */ 3160 else 3187 if (ret != ERROR_FILE_NOT_FOUND) 3161 3188 break; 3189 3190 RegCloseKey (hkey); 3191 hkey = (HKEY)INVALID_HANDLE_VALUE; 3162 3192 } 3163 3193 … … 3168 3198 } 3169 3199 3200 /* 3201 * We need to check 'hkey' after we check 'ret' to distinguish the case 3202 * of failed SetupDiOpenDevRegKey from the case when we timed out. 3203 */ 3204 if (hkey == INVALID_HANDLE_VALUE) 3205 SetErrBreak(("SetupDiOpenDevRegKey failed (0x%08X)", GetLastError())); 3206 3170 3207 if (ret != ERROR_SUCCESS) 3171 3208 SetErrBreak(("Querying NetCfgInstanceId failed (0x%08X)", ret)); 3172 3209 3173 /* 3174 * Set default metric value of interface to fix multicast issue 3175 * See @bugref{6379} for details. 3176 */ 3177 HRESULT hSMRes = vboxNetCfgWinSetupMetric(hkey); 3210 NET_LUID luid; 3211 HRESULT hSMRes = vboxNetCfgWinGetInterfaceLUID(hkey, &luid); 3212 3213 /* Close the key as soon as possible. See @bugref{7973}. */ 3214 RegCloseKey (hkey); 3215 hkey = (HKEY)INVALID_HANDLE_VALUE; 3216 3178 3217 if (FAILED(hSMRes)) 3179 3218 { … … 3183 3222 */ 3184 3223 NonStandardLogFlow(("vboxNetCfgWinCreateHostOnlyNetworkInterface Warning! " 3185 "vboxNetCfgWinSetupMetric failed, default metric " 3186 "for new interface will not be set, hr (0x%x)\n", hSMRes)); 3187 } 3224 "vboxNetCfgWinGetInterfaceLUID failed, default metric " 3225 "for new interface will not be set, hr (0x%x)\n", hSMRes)); 3226 } 3227 else 3228 { 3229 /* 3230 * Set default metric value of interface to fix multicast issue 3231 * See @bugref{6379} for details. 3232 */ 3233 hSMRes = vboxNetCfgWinSetupMetric(&luid); 3234 if (FAILED(hSMRes)) 3235 { 3236 /* 3237 * The setting of Metric is not very important functionality, 3238 * So we will not break installation process due to this error. 3239 */ 3240 NonStandardLogFlow(("vboxNetCfgWinCreateHostOnlyNetworkInterface Warning! " 3241 "vboxNetCfgWinSetupMetric failed, default metric " 3242 "for new interface will not be set, hr (0x%x)\n", hSMRes)); 3243 } 3244 } 3245 3188 3246 3189 3247 #ifndef VBOXNETCFG_DELAYEDRENAME … … 3501 3559 3502 3560 3503 HRESULT vboxNetCfgWinSetupMetric(IN HKEY hKey)3561 HRESULT vboxNetCfgWinSetupMetric(IN NET_LUID* pLuid) 3504 3562 { 3505 3563 HINSTANCE hModule = NULL; … … 3507 3565 if (SUCCEEDED(rc)) 3508 3566 { 3509 NET_LUID luid;3510 rc = vboxNetCfgWinGet InterfaceLUID(hKey, &luid);3567 int loopbackMetric; 3568 rc = vboxNetCfgWinGetLoopbackMetric(&loopbackMetric); 3511 3569 if (SUCCEEDED(rc)) 3512 { 3513 int loopbackMetric; 3514 rc = vboxNetCfgWinGetLoopbackMetric(&loopbackMetric); 3515 if (SUCCEEDED(rc)) 3516 rc = vboxNetCfgWinSetInterfaceMetric(&luid, loopbackMetric - 1); 3517 } 3570 rc = vboxNetCfgWinSetInterfaceMetric(pLuid, loopbackMetric - 1); 3518 3571 } 3519 3572
Note:
See TracChangeset
for help on using the changeset viewer.