VBoxNetFltNobj.cpp revision 7e9ca60730092c625220814121c54a593ad20997
/* $Id$ */
/** @file
* VBoxNetFltNobj.cpp - Notify Object for Bridged Networking Driver.
* Used to filter Bridged Networking Driver bindings
*/
/*
* Copyright (C) 2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "VBoxNetFltNobj.h"
#include <Ntddndis.h>
#include <assert.h>
#include <stdio.h>
#include <VBoxNetFltNobjT_i.c>
//# define VBOXNETFLTNOTIFY_DEBUG_BIND
#ifdef DEBUG
# define NonStandardAssert(a) assert(a)
# define NonStandardAssertBreakpoint() assert(0)
#else
# define NonStandardAssert(a) do{}while (0)
# define NonStandardAssertBreakpoint() do{}while (0)
#endif
{
}
{
cleanup();
}
void VBoxNetFltNobj::cleanup()
{
if (mpNetCfg)
{
}
if (mpNetCfgComponent)
{
}
}
void VBoxNetFltNobj::init(IN INetCfgComponent *pNetCfgComponent, IN INetCfg *pNetCfg, IN BOOL bInstalling)
{
cleanup();
if (pNetCfg)
{
}
if (pNetCfgComponent)
{
}
}
/* INetCfgComponentControl methods */
STDMETHODIMP VBoxNetFltNobj::Initialize(IN INetCfgComponent *pNetCfgComponent, IN INetCfg *pNetCfg, IN BOOL bInstalling)
{
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
{
0, /*__reserved DWORD ulOptions*/
KEY_READ, /*__in REGSAM samDesired*/
phKey);
if (winEr != ERROR_SUCCESS)
{
}
}
else
{
}
return hr;
}
{
L"Driver", /*__in_opt LPCTSTR lpValueName*/
0, /*__reserved LPDWORD lpReserved*/
&Type, /*__out_opt LPDWORD lpType*/
&cbValue/*__inout_opt LPDWORD lpcbData*/
);
if (winEr == ERROR_SUCCESS)
{
0, /*__reserved DWORD ulOptions*/
KEY_READ, /*__in REGSAM samDesired*/
phKey);
if (winEr != ERROR_SUCCESS)
{
}
}
else
{
}
return hr;
}
{
{
{
}
}
else
{
}
return hr;
}
static HRESULT vboxNetFltWinNotifyCheckNetAdp(IN INetCfgComponent *pComponent, OUT bool * pbShouldBind)
{
{
{
*pbShouldBind = false;
}
else
{
}
}
else
{
}
return hr;
}
static HRESULT vboxNetFltWinNotifyCheckMsLoop(IN INetCfgComponent *pComponent, OUT bool * pbShouldBind)
{
{
{
/* we need to detect the medium the adapter is presenting
* to do that we could examine in the registry the *msloop params */
{
L"Medium", /*__in_opt LPCTSTR lpValueName*/
0, /*__reserved LPDWORD lpReserved*/
&Type, /*__out_opt LPDWORD lpType*/
&cbValue/*__inout_opt LPDWORD lpcbData*/
);
if (winEr == ERROR_SUCCESS)
{
&endPrt,
0 /* base*/);
if (winEr == ERROR_SUCCESS)
{
if (enmMedium == 0) /* 0 is Ethernet */
{
*pbShouldBind = true;
}
else
{
*pbShouldBind = false;
}
}
else
{
*pbShouldBind = true;
}
}
else
{
/* TODO: we should check the default medium in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\<driver_id>\Ndi\Params\Medium, REG_SZ "Default" value */
*pbShouldBind = true;
}
}
else
{
}
}
else
{
}
}
else
{
}
return hr;
}
static HRESULT vboxNetFltWinNotifyCheckLowerRange(IN INetCfgComponent *pComponent, OUT bool * pbShouldBind)
{
{
0, /*__reserved DWORD ulOptions*/
KEY_READ, /*__in REGSAM samDesired*/
if (winEr == ERROR_SUCCESS)
{
L"LowerRange", /*__in_opt LPCTSTR lpValueName*/
0, /*__reserved LPDWORD lpReserved*/
&Type, /*__out_opt LPDWORD lpType*/
&cbValue/*__inout_opt LPDWORD lpcbData*/
);
if (winEr == ERROR_SUCCESS)
{
{
*pbShouldBind = true;
}
else
{
*pbShouldBind = false;
}
}
else
{
/* do not set err status to it */
*pbShouldBind = false;
}
}
else
{
}
}
else
{
}
return hr;
}
static HRESULT vboxNetFltWinNotifyShouldBind(IN INetCfgComponent *pComponent, OUT bool *pbShouldBind)
{
do
{
/* filter out only physical adapters */
{
break;
}
if (fCharacteristics & NCF_HIDDEN)
{
/* we are not binding to hidden adapters */
*pbShouldBind = false;
break;
}
{
/* this is a loopback adapter,
* the pbShouldBind already contains the result */
break;
}
{
/* error occurred */
break;
}
{
/* this is a VBoxNetAdp adapter,
* the pbShouldBind already contains the result */
break;
}
{
/* error occurred */
break;
}
/* hr == S_FALSE means this is not a loopback adpater, set it to S_OK */
// if (!(fCharacteristics & NCF_PHYSICAL))
// {
// /* we are binding to physical adapters only */
// *pbShouldBind = false;
// break;
// }
{
/* the vboxNetFltWinNotifyCheckLowerRange ccucceeded,
* the pbShouldBind already contains the result */
break;
}
/* we are here because of the fail, nothing else to do */
} while (0);
return hr;
}
static HRESULT vboxNetFltWinNotifyShouldBind(IN INetCfgBindingInterface *pIf, OUT bool *pbShouldBind)
{
{
}
else
{
}
return hr;
}
{
{
{
do
{
{
pBindingIf->Release();
{
if (!(*pbDoBind))
{
break;
}
}
else
{
/* break on failure */
break;
}
}
{
/* no more elements */
break;
}
else
{
/* break on falure */
break;
}
} while (true);
}
else
{
}
}
else
{
}
return hr;
}
{
#ifdef VBOXNETFLTNOTIFY_DEBUG_BIND
return VBOXNETFLTNOTIFY_DEBUG_BIND;
#else
bool bShouldBind;
{
}
return bShouldBind;
#endif
}
/* INetCfgComponentNotifyBinding methods */
STDMETHODIMP VBoxNetFltNobj::NotifyBindingPath(IN DWORD dwChangeFlag, IN INetCfgBindingPath *pNetCfgBP)
{
if (!(dwChangeFlag & NCN_ENABLE) || (dwChangeFlag & NCN_REMOVE) || vboxNetFltWinNotifyShouldBind(pNetCfgBP))
return S_OK;
return NETCFG_S_DISABLE_QUERY;
}
STDMETHODIMP VBoxNetFltNobj::QueryBindingPath(IN DWORD dwChangeFlag, IN INetCfgBindingPath *pNetCfgBP)
{
return S_OK;
return NETCFG_S_DISABLE_QUERY;
}
extern "C"
{
if (dwReason == DLL_PROCESS_ATTACH)
{
}
else if (dwReason == DLL_PROCESS_DETACH)
{
}
return TRUE;
}
{
}
{
}
{
}
{
}