VBoxNetFltNotify.cpp revision 065adffee82ccc6f7d6f1dcc2815c03a098cff3e
/*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* Sun Microsystems, Inc. confidential
* All rights reserved
*/
/*
* Based in part on Microsoft DDK sample code for Sample Notify Object
*+---------------------------------------------------------------------------
*
* Microsoft Windows
* Copyright (C) Microsoft Corporation, 1992-2001.
*
* Author: Alok Sinha
*
*----------------------------------------------------------------------------
*/
#include "VBoxNetFltNotify.h"
#include <Ntddndis.h>
#include <assert.h>
#include <stdio.h>
#include <VBoxNetFltNotifyn_i.c>
#define ReleaseObj( x ) if ( x ) \
//# define VBOXNETFLTNOTIFY_DEBUG_BIND true
#ifdef DEBUG
# define AssertBreakpoint() assert(0)
# define TraceMsg DbgTraceMsg
#else
# define Assert(a) do{}while(0)
# define AssertBreakpoint() do{}while(0)
# define TraceMsg
#endif
{
}
/*,
m_eApplyAction(eActUnknown),
m_pUnkContext(NULL)*/
{
TraceMsg(L"VBoxNetFltNotify\n");
}
{
TraceMsg(L"-->~VBoxNetFltNotify (destructor)\n");
ReleaseObj( m_pncc );
ReleaseObj( m_pnc );
TraceMsg(L"<--~VBoxNetFltNotify (destructor)\n");
}
/*
* NOTIFY OBJECT FUNCTIONS
*/
/*
* INetCfgComponentControl
*
* The following functions provide the INetCfgComponentControl interface.
*/
/**
* Initialize the notify object
*
* @param pnccItem Pointer to INetCfgComponent object
* @param pnc Pointer to INetCfg object
* @param fInstalling TRUE if we are being installed
* @return S_OK on success, otherwise an error code
*/
{
TraceMsg(L"-->Initialize\n");
if (m_pncc)
{
}
if (m_pnc)
{
}
TraceMsg(L"<--Initialize\n");
return hr;
}
/**
* Cancel any changes made to internal data
* @return S_OK on success, otherwise an error code
*/
{
TraceMsg(L"CancelChanges\n");
return S_OK;
}
/*
* Apply changes. We can make changes to registry etc. here.
* @return S_OK on success, otherwise an error code
*/
{
TraceMsg(L"ApplyRegistryChanges\n");
return S_OK;
}
/**
* Apply changes.
* @param pfCallback PnPConfigCallback interface.
* @return S_OK on success, otherwise an error code
*/
{
TraceMsg(L"ApplyPnpChanges\n");
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
{
TraceMsg(L"vboxNetFltWinQueryDriverKey from instance key: RegQueryValueExW error, hr (0x%x)\n", hr);
}
return hr;
}
{
{
{
TraceMsg(L"vboxNetFltWinQueryDriverKey from Component: vboxNetFltWinQueryDriverKey error, hr (0x%x)\n", hr);
}
}
else
{
TraceMsg(L"vboxNetFltWinQueryDriverKey from Component: vboxNetFltWinQueryInstanceKey error, hr (0x%x)\n", hr);
}
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
{
TraceMsg(L"vboxNetFltWinNotifyCheckMsLoop: loopback is configured as NOT ethernet, NOT binding\n", winEr);
*pbShouldBind = false;
}
}
else
{
TraceMsg(L"vboxNetFltWinNotifyCheckMsLoop: wcstoul error, winEr (%d), ignoring and binding\n", winEr);
*pbShouldBind = true;
}
}
else
{
TraceMsg(L"vboxNetFltWinNotifyCheckMsLoop: RegQueryValueExW failed, winEr (%d), ignoring, binding\n", hr);
/* 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
{
TraceMsg(L"vboxNetFltWinNotifyCheckMsLoop: vboxNetFltWinQueryDriverKey for msloop failed, hr (0x%x)\n", hr);
}
}
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;
TraceMsg(L"vboxNetFltWinNotifyCheckLowerRange: RegQueryValueExW for LowerRange error, winEr (%d), not binding\n", winEr);
}
}
else
{
}
}
else
{
TraceMsg(L"vboxNetFltWinNotifyShouldBind for INetCfgComponen: vboxNetFltWinQueryDriverKey failed, hr (0x%x)\n", hr);
}
return hr;
}
static HRESULT vboxNetFltWinNotifyShouldBind(IN INetCfgComponent *pComponent, OUT bool *pbShouldBind)
{
TraceMsg(L"-->vboxNetFltWinNotifyShouldBind for INetCfgComponent\n");
do
{
/* filter out only physical adapters */
{
TraceMsg(L"vboxNetFltWinNotifyShouldBind for INetCfgComponen: GetCharacteristics failed, hr (0x%x)\n", hr);
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)
{
TraceMsg(L"-->vboxNetFltWinNotifyShouldBind for INetCfgBindingInterface\n");
{
}
else
{
}
return hr;
}
{
TraceMsg(L"-->vboxNetFltWinNotifyShouldBind for INetCfgBindingPath\n");
{
{
do
{
&ulCount );
{
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;
TraceMsg( L"-->vboxNetFltWinNotifyShouldBind\n");
{
TraceMsg( L"vboxNetFltWinNotifyShouldBind: vboxNetFltWinNotifyShouldBind failed, hr (0x%x)\n", hr );
}
return bShouldBind;
#endif
}
/*
* INetCfgComponentNotifyBinding
* The following functions provide the INetCfgComponentNotifyBinding interface.
*/
/**
* This is specific to the component being installed. This will
* ask us if we want to bind to the Item being passed into
* this routine. We can disable the binding by returning
* NETCFG_S_DISABLE_QUERY
*
* @param dwChangeFlag Type of binding change
* @param pncbpItem Pointer to INetCfgBindingPath object
* @return S_OK on success, otherwise an error code.
*/
{
{
TraceMsg( L"QueryBindingPath: we are NOT supporting the current component\n");
}
else
{
TraceMsg( L"QueryBindingPath: we are supporting the current component\n");
}
return hr;
}
/**
* bind to the component passed to us.
* @param dwChangeFlag Type of system change
* @param pncc Pointer to INetCfgComponent object
* @return S_OK on success, otherwise an error code
*/
{
/* NCN_ADD | NCN_ENABLE
* NCN_REMOVE | NCN_ENABLE
* NCN_ADD | NCN_DISABLE
* NCN_REMOVE | NCN_DISABLE
* */
{
{
TraceMsg( L"NotifyBindingPath: binding enabled for the component we are not supporting\n");
}
}
return hr;
}
/*
* DLL Entry Point
*/
extern "C"
LPVOID /*lpReserved*/)
{
TraceMsg( L"-->DllMain.\n");
if (dwReason == DLL_PROCESS_ATTACH) {
TraceMsg( L" Reason: Attach.\n");
}
else if (dwReason == DLL_PROCESS_DETACH) {
TraceMsg( L" Reason: Detach.\n");
}
TraceMsg( L"<--DllMain.\n");
return TRUE;
}
/*
* Used to determine whether the DLL can be unloaded by OLE
*/
STDAPI DllCanUnloadNow(void)
{
TraceMsg( L"-->DllCanUnloadNow.\n");
TraceMsg( L"<--DllCanUnloadNow, hr (0x%x).\n",
hr );
return hr;
}
/*
* Returns a class factory to create an object of the requested type
*/
{
TraceMsg( L"DllGetClassObject.\n");
}
/*
* DllRegisterServer - Adds entries to the system registry
*/
STDAPI DllRegisterServer(void)
{
/* Registers object, typelib and all interfaces in typelib */
TraceMsg( L"DllRegisterServer.\n");
}
/*
* DllUnregisterServer - Removes entries from the system registry
*/
STDAPI DllUnregisterServer(void)
{
TraceMsg( L"DllUnregisterServer.\n");
return S_OK;
}