Changeset 60318 in vbox for trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg
- Timestamp:
- Apr 4, 2016 8:45:21 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp
r59077 r60318 19 19 #define _WIN32_DCOM 20 20 21 #include <iphlpapi.h>22 21 23 22 #include <devguid.h> … … 35 34 #include <Wbemidl.h> 36 35 #include <comdef.h> 36 37 #include <winsock2.h> 37 38 #include <Ws2tcpip.h> 39 #include <ws2ipdef.h> 40 #include <netioapi.h> 41 #include <iphlpapi.h> 38 42 39 43 … … 57 61 #define VBOX_NETCFG_LOCK_TIME_OUT 5000 /** @todo r=bird: What does this do? */ 58 62 63 /* 64 * Forward declaration for using vboxNetCfgWinSetupMetric() 65 */ 66 HRESULT vboxNetCfgWinSetupMetric(IN HKEY hKey); 67 HRESULT vboxNetCfgWinGetInterfaceLUID(IN HKEY hKey, OUT NET_LUID* pLUID); 59 68 60 69 /* … … 276 285 ZeroMemory(&Token, sizeof (Token)); 277 286 Token.Type = OBO_USER; 287 INetCfgComponent* pTempComponent = NULL; 278 288 279 289 hr = pSetup->Install(pszwComponentId, &Token, … … 282 292 NULL, /* IN LPCWSTR pszwAnswerFile */ 283 293 NULL, /* IN LPCWSTR pszwAnswerSections */ 284 ppComponent);294 &pTempComponent); 285 295 if (SUCCEEDED(hr)) 286 296 { 297 if (pTempComponent != NULL) 298 { 299 HKEY hkey; 300 NET_LUID luid; 301 HRESULT res; 302 303 /* 304 * Set default metric value of interface to fix multicast issue 305 * See @bugref{6379} for details. 306 */ 307 res = pTempComponent->OpenParamKey(&hkey); 308 if(SUCCEEDED(res) && hkey != NULL) 309 res = vboxNetCfgWinSetupMetric(hkey); 310 if (FAILED(res)) 311 { 312 /* 313 * The setting of Metric is not very important functionality, 314 * So we will not break installation process due to this error. 315 */ 316 NonStandardLogFlow(("VBoxNetCfgWinInstallComponent Warning! " 317 "vboxNetCfgWinSetupMetric failed, default metric " 318 "for new interface will not be set, hr (0x%x)\n", res)); 319 } 320 if (ppComponent != NULL) 321 *ppComponent = pTempComponent; 322 else 323 pTempComponent->Release(); 324 } 325 287 326 /* ignore the apply failure */ 288 327 HRESULT tmpHr = pNetCfg->Apply(); … … 3100 3139 SetErrBreak(("Querying NetCfgInstanceId failed (0x%08X)", ret)); 3101 3140 3141 /* 3142 * Set default metric value of interface to fix multicast issue 3143 * See @bugref{6379} for details. 3144 */ 3145 HRESULT hSMRes = vboxNetCfgWinSetupMetric(hkey); 3146 if (FAILED(hSMRes)) 3147 { 3148 /* 3149 * The setting of Metric is not very important functionality, 3150 * So we will not break installation process due to this error. 3151 */ 3152 NonStandardLogFlow(("vboxNetCfgWinCreateHostOnlyNetworkInterface Warning! " 3153 "vboxNetCfgWinSetupMetric failed, default metric " 3154 "for new interface will not be set, hr (0x%x)\n", hSMRes)); 3155 } 3156 3102 3157 #ifndef VBOXNETCFG_DELAYEDRENAME 3103 3158 /* … … 3300 3355 return hrc; 3301 3356 } 3357 3358 3359 HRESULT vboxNetCfgWinGetLoopbackMetric(OUT int* Metric) 3360 { 3361 HRESULT status = S_OK; 3362 MIB_IPINTERFACE_ROW row; 3363 3364 InitializeIpInterfaceEntry(&row); 3365 row.Family = AF_INET; 3366 row.InterfaceLuid.Info.IfType = IF_TYPE_SOFTWARE_LOOPBACK; 3367 3368 status = GetIpInterfaceEntry(&row); 3369 if (status != 0) 3370 return E_FAIL; 3371 3372 *Metric = row.Metric; 3373 3374 return status; 3375 } 3376 3377 3378 HRESULT vboxNetCfgWinSetInterfaceMetric( 3379 IN NET_LUID* pInterfaceLuid, 3380 IN DWORD metric) 3381 { 3382 MIB_IPINTERFACE_ROW newRow; 3383 InitializeIpInterfaceEntry(&newRow); 3384 // identificate the interface to change 3385 newRow.InterfaceLuid = *pInterfaceLuid; 3386 newRow.Family = AF_INET; 3387 // changed settings 3388 newRow.UseAutomaticMetric = false; 3389 newRow.Metric = metric; 3390 3391 // change settings 3392 return SetIpInterfaceEntry(&newRow); 3393 } 3394 3395 3396 HRESULT vboxNetCfgWinGetInterfaceLUID(IN HKEY hKey, OUT NET_LUID* pLUID) 3397 { 3398 HRESULT res = S_OK; 3399 DWORD luidIndex = 0; 3400 DWORD ifType = 0; 3401 DWORD cbSize = sizeof(luidIndex); 3402 DWORD dwValueType = REG_DWORD; 3403 3404 if (pLUID == NULL) 3405 return E_INVALIDARG; 3406 3407 res = RegQueryValueExW(hKey, L"NetLuidIndex", NULL, 3408 &dwValueType, (LPBYTE)&luidIndex, &cbSize); 3409 if (FAILED(res)) 3410 return res; 3411 3412 cbSize = sizeof(ifType); 3413 dwValueType = REG_DWORD; 3414 res = RegQueryValueExW(hKey, L"*IfType", NULL, 3415 &dwValueType, (LPBYTE)&ifType, &cbSize); 3416 if (FAILED(res)) 3417 return res; 3418 3419 ZeroMemory(pLUID, sizeof(NET_LUID)); 3420 pLUID->Info.IfType = ifType; 3421 pLUID->Info.NetLuidIndex = luidIndex; 3422 3423 return res; 3424 } 3425 3426 3427 HRESULT vboxNetCfgWinSetupMetric(IN HKEY hKey) 3428 { 3429 HRESULT status = S_OK; 3430 NET_LUID luid; 3431 int loopbackMetric; 3432 3433 status = vboxNetCfgWinGetInterfaceLUID(hKey, &luid); 3434 if (FAILED(status)) 3435 return status; 3436 3437 status = vboxNetCfgWinGetLoopbackMetric(&loopbackMetric); 3438 if (FAILED(status)) 3439 return status; 3440 3441 status = vboxNetCfgWinSetInterfaceMetric(&luid, loopbackMetric - 1); 3442 3443 return status; 3444 } 3445 3302 3446 3303 3447 #ifdef VBOXNETCFG_DELAYEDRENAME
Note:
See TracChangeset
for help on using the changeset viewer.