Exemplo n.º 1
0
BOOL IMSetRules(PPassthruFilter pRules, int nRuleCount)
{
	BOOL bRet = TRUE;
	HANDLE hControlDevice = PtOpenControlDevice();
	CIMAdapters adapters;
	if(!adapters.EnumAdapters(hControlDevice))
		return FALSE;

	HANDLE hAdapter;
	int i, j;
	for(i=0; i<adapters.m_nAdapters; i++)
	{
		hAdapter = PtOpenAdapter(adapters.m_pwszAdapterName[i]);
		if(hAdapter == INVALID_HANDLE_VALUE)
		{
			bRet = FALSE;
			break;
		}
		else
		{
			for(j=0; i<nRuleCount; j++)
			{
				if(!PtAddFilter(hAdapter, &pRules[j]))
				{
					bRet = FALSE;
					break;
				}
			}
			::CloseHandle(hAdapter);
		}
	}
	::CloseHandle(hControlDevice);
	return bRet;
}
Exemplo n.º 2
0
BOOL IMClearRules()
{
	BOOL bRet = TRUE;
	HANDLE hControlDevice = PtOpenControlDevice();
	CIMAdapters adapters;
	if(!adapters.EnumAdapters(hControlDevice))
		return FALSE;

	HANDLE hAdapter;
	for(int i=0; i<adapters.m_nAdapters; i++)
	{
		hAdapter = PtOpenAdapter(adapters.m_pwszAdapterName[i]);
		if(hAdapter != INVALID_HANDLE_VALUE)
		{
			PtClearFilter(hAdapter);
			::CloseHandle(hAdapter);
		}
		else
		{
			bRet = FALSE;
			break;
		}
	}
	return bRet;
}
Exemplo n.º 3
0
/*
* Calls the packet blocking function of the device
* driver to remove all filtering done
*/
void ClearFilter()
{
	HANDLE	LowerHandle;
	LPTSTR	TmpAdapterName;
	BOOL Rtn;

	// hold PT Driver lock to read a packet
	EnterCriticalSection(pPtDriverLock);

	//TmpAdapterName = _tcsdup( ParaIfaceName );
	TmpAdapterName = _tcsdup( (wchar_t *)&ParaIfaceName );
	LowerHandle = PtOpenAdapter(TmpAdapterName);

	if( LowerHandle != INVALID_HANDLE_VALUE )
	{
		Rtn = PtSetIPv4BlockingFilter(LowerHandle, NULL);

		PtCloseAdapter(LowerHandle);
	}

	// release lock
	LeaveCriticalSection(pPtDriverLock);
}
Exemplo n.º 4
0
/*
* Calls the packet blocking function of the device
* driver to let the packets of existing routes, to
* go through
*/
void SetFilter(PIPv4BlockAddrArray  pARFilter)
{
	HANDLE	LowerHandle;
	LPTSTR	TmpAdapterName;
	BOOL	Success, CallSetFilter;
	UINT	CheckSize;

	CallSetFilter = TRUE;

	// check if it is an attempt to set the same old filter
	if(pOldARFilter != NULL)
	{
		if(pOldARFilter->NumberElements != pARFilter->NumberElements) 
		{
			CallSetFilter = TRUE;
		}
		else
		{
			CheckSize = sizeof(IPv4BlockAddrArray) 
							+ (sizeof(IPAddrInfo) * (pARFilter->NumberElements - 1));
			if(memcmp(pOldARFilter, pARFilter, CheckSize) == 0)
			{
				CallSetFilter = FALSE;
			}
		}
		free(pOldARFilter);
	}

	pOldARFilter = pARFilter;

	// if same old filter, then dont set
	if(CallSetFilter)
	{

		// hold PT Driver lock to read a packet
		EnterCriticalSection(pPtDriverLock);

		TmpAdapterName = _tcsdup( ( wchar_t *)&ParaIfaceName );
		LowerHandle = PtOpenAdapter(TmpAdapterName);

		if( LowerHandle != INVALID_HANDLE_VALUE )
		{
			Success = PtSetIPv4BlockingFilter(LowerHandle, pARFilter);

			if(!Success) 
			{
				EnterCriticalSection(pLoggingLock);
				LogMessage(LOGGING_SEVERAITY_ERROR,
						"FilterSetter : PT set filter has failed");
				LeaveCriticalSection(pLoggingLock);

				// if there was an error in setting th filter,
				// make it set the filter next time also
				free(pOldARFilter);
				pOldARFilter = NULL;
			}

			PtCloseAdapter(LowerHandle);
		} 
		else
		{
			EnterCriticalSection(pLoggingLock);
			LogMessage(LOGGING_SEVERAITY_ERROR,
						"FilterSetter : Unable to open PT device to set filter");
			LeaveCriticalSection(pLoggingLock);

			// if there was an error in opening the handle,
			// make it set the filter next time also
			free(pOldARFilter);
			pOldARFilter = NULL;
		}

		// release lock
		LeaveCriticalSection(pPtDriverLock);
	}
}