⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ruleop.c

📁 Linux下面截获以态网数据包!是在内核态下面运行的驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
	p = strstr( host+1, WEB_MAIL_HOST_SEQ );
	while( p )
	{
		*pDot = (UCHAR)( ( (UCHAR *)p - pDot ) - 1 );
		pDot = p;
		p = strstr( p + 1, WEB_MAIL_HOST_SEQ );
	}
	
	*pDot = (UCHAR)( ( (UCHAR * )pEnd - pDot ) - 1 );		
	InvalidateDomain( host);
	printk("delete post domain:%s\r\n", pRule->key );
	DeleteRuleIPByID( pRule->ruleID );
}

void DeleteYahooRule( RULE *pRule )
{
	RULE		*pPre,*pTemp = NULL;
	UINT		iHash;
	UINT		sip = 0;
	
	if( pRule->keyLen== 0 )
	{
		return;
	}
	printk("delete yahoo:%s\r\n", pRule->key );
	iHash = StrLowerCaseHash( pRule->key, pRule->keyLen);
	iHash = iHash%YAHOO_HASH_LEN;
	
	down_interruptible( &gVar.ruleHash.yahoo[iHash].fastMutex );
	pPre =  gVar.ruleHash.yahoo[iHash].pRule;
	while( pPre )
	{
		if( pPre->ruleID == pRule->ruleID )
			break;
		
		pTemp = pPre;
		pPre = pPre->pNext;
	}
	
	if( pPre )
	{
		if( pTemp )
			pTemp->pNext = pPre->pNext;
		else
			gVar.ruleHash.yahoo[iHash].pRule = pPre->pNext;
		
		sip = pPre->sip;
		kfree( pPre );
	}
	up( &gVar.ruleHash.yahoo[iHash].fastMutex );
	
	if( 0 != sip )
		DeleteRuleIP( sip );
}

void DeleteMailRule( RULE *pRule )
{
	RULE		*pPre,*pTemp = NULL;
	UINT		iHash;
	UINT 		sip = 0;
	
	if( pRule->keyLen == 0 )
	{
		return;
	}
	
	printk("delete mail:%s\r\n", pRule->key );
	iHash = StrLowerCaseHash( pRule->key, pRule->keyLen);
	iHash = iHash%MAIL_HASH_LEN;
	
	down_interruptible( &gVar.ruleHash.mail[iHash].fastMutex );
	pPre =  gVar.ruleHash.mail[iHash].pRule;
	while( pPre )
	{
		if( pPre->ruleID == pRule->ruleID )
			break;
			
		pTemp = pPre;
		pPre = pPre->pNext;
	}
	
	if( pPre )
	{
		if( pTemp )
			pTemp->pNext = pPre->pNext;
		else
			gVar.ruleHash.mail[iHash].pRule = pPre->pNext;
		
		sip = pPre->sip;
		kfree( pPre );
	}
	up( &gVar.ruleHash.mail[iHash].fastMutex );
	
	if( 0 != sip )
	DeleteRuleIP( sip );
}




void DeletePpRule( RULE *pRule )
{
	RULE		*pPre,*pTemp = NULL;
	UINT		iHash;
	UINT		sip = 0;
	
	iHash = (pRule->iKey)%PP_HASH_LEN;
	
	down_interruptible( &gVar.ruleHash.pp[iHash].fastMutex );
	pPre =  gVar.ruleHash.pp[iHash].pRule;
	while( pPre )
	{
		if( pPre->ruleID == pRule->ruleID )
			break;
		
		pTemp = pPre;
		pPre = pPre->pNext;
	}
	
	if( pPre )
	{
		if( pTemp )
			pTemp->pNext = pPre->pNext;
		else
			gVar.ruleHash.pp[iHash].pRule = pPre->pNext;
		
		sip = pPre->sip;
		kfree( pPre );
	}
	up( &gVar.ruleHash.pp[iHash].fastMutex );
	
	if( 0 != sip )
		DeleteRuleIP( sip );
}



void DeleteAolRule( RULE *pRule )
{
	RULE		*pPre,*pTemp = NULL;
	UINT		iHash;
	UINT		sip = 0;
	
	if( pRule->keyLen== 0 )
		return;
		
	printk("delete aol:%s\r\n", pRule->key );
	iHash = StrLowerCaseHash( pRule->key, pRule->keyLen);
	iHash = iHash%AOL_HASH_LEN;
	
	down_interruptible( &gVar.ruleHash.aol[iHash].fastMutex );
	pPre =  gVar.ruleHash.aol[iHash].pRule;
	while( pPre )
	{
		if( pPre->ruleID == pRule->ruleID )
			break;
			
		pTemp = pPre;
		pPre = pPre->pNext;
	}
	if( pPre )
	{
		if( pTemp )
			pTemp->pNext = pPre->pNext;
		else
			gVar.ruleHash.aol[iHash].pRule = pPre->pNext;
		
		sip = pPre->sip;
		kfree( pPre );
	}
	up( &gVar.ruleHash.aol[iHash].fastMutex );
	
	if( 0 != sip )
		DeleteRuleIP( sip );
}



void DeleteIrcRule( RULE *pRule )
{
	RULE		*pPre,*pTemp = NULL;
	UINT		iHash;
	UINT		sip = 0;
	
	if( pRule->keyLen== 0 )
		return;
		
	printk("delete irc:%s\r\n", pRule->key );
	iHash = StrLowerCaseHash( pRule->key, pRule->keyLen);
	iHash = iHash%IRC_HASH_LEN;
	
	down_interruptible( &gVar.ruleHash.irc[iHash].fastMutex );
	pPre =  gVar.ruleHash.irc[iHash].pRule;
	while( pPre )
	{
		if( pPre->ruleID == pRule->ruleID )
			break;
		
		pTemp = pPre;
		pPre = pPre->pNext;
	}
	
	if( pPre )
	{
		if( pTemp )
			pTemp->pNext = pPre->pNext;
		else
			gVar.ruleHash.irc[iHash].pRule = pPre->pNext;
		
		sip = pPre->sip;
		kfree( pPre );
	}
	up( &gVar.ruleHash.irc[iHash].fastMutex );
	
	if( 0 != sip )
		DeleteRuleIP( sip );
}

void DeleteGtalkRule( RULE *pRule )
{
	RULE		*pPre,*pTemp = NULL;
	UINT		iHash;
	UINT 		sip = 0;
	
	if( pRule->keyLen == 0 )
	{
		return;
	}
	
	printk("delete gtalk:%s\r\n", pRule->key );
	iHash = StrLowerCaseHash( pRule->key, pRule->keyLen);
	iHash = iHash%MAIL_HASH_LEN;
	
	down_interruptible( &gVar.ruleHash.gtalk[iHash].fastMutex );
	pPre =  gVar.ruleHash.gtalk[iHash].pRule;
	while( pPre )
	{
		if( pPre->ruleID == pRule->ruleID )
			break;
		
		pTemp = pPre;
		pPre = pPre->pNext;
	}
	
	if( pPre )
	{
		if( pTemp )
			pTemp->pNext = pPre->pNext;
		else
			gVar.ruleHash.gtalk[iHash].pRule = pPre->pNext;
		
		sip = pPre->sip;
		kfree( pPre );
	}
	up( &gVar.ruleHash.gtalk[iHash].fastMutex );
	
	if( 0 != sip )
		DeleteRuleIP( sip );
}



UINT MatchRule( void *pKey, UINT keyLen, UINT protocolType, UINT sip, char bDy )
{
	UINT				iHash = 0;
	UINT				ruleID = 0;
	RULE				*pRule = NULL;
	
	switch( protocolType )
	{
	case RULE_PROTOCOL_IP:
		break;
	
	case RULE_PROTOCOL_ICQ:
		iHash = (*(UINT *)pKey)%ICQ_HASH_LEN;
		pRule = gVar.ruleHash.icq[iHash].pRule;
		
		while( pRule )
		{
			if( pRule->iKey == *(UINT *)pKey )
				break;
			
			pRule = pRule->pNext;
		}			
		break;
		
	case RULE_PROTOCOL_QQ:
		iHash = (*(UINT *)pKey)%QQ_HASH_LEN;
		pRule = gVar.ruleHash.qq[iHash].pRule;
		while( pRule )
		{
			if( pRule->iKey == *(UINT *)pKey )
				break;
				
			pRule = pRule->pNext;
		}
		break;
		
	case RULE_PROTOCOL_MSN:
		iHash = StrLowerCaseHash( pKey, keyLen);
		iHash = iHash%MSN_HASH_LEN;
		pRule = gVar.ruleHash.msn[iHash].pRule;
		while( pRule )
		{
			if( strstr( pRule->key, pKey) )
			{
				printk( "msn:%s\r\n", (char *)pKey );
				break;
			}
			pRule = pRule->pNext;
		}			
		break;
					
	case RULE_PROTOCOL_MAIL:			
		iHash = StrLowerCaseHash( pKey, keyLen);
		iHash = iHash%MAIL_HASH_LEN;
		pRule = gVar.ruleHash.mail[iHash].pRule;
		
		while( pRule )
		{
			if( strstr( pRule->key, pKey) )
				break;
			
			pRule = pRule->pNext;
		}			
		break;
		
	case RULE_PROTOCOL_YAHOO:			
		iHash = StrLowerCaseHash( pKey, keyLen);
		iHash = iHash%YAHOO_HASH_LEN;
		pRule = gVar.ruleHash.yahoo[iHash].pRule;
		
		while( pRule )
		{
			if( strstr( pRule->key, pKey) )
				break;
			pRule = pRule->pNext;
		}			
		break;
				
	case RULE_PROTOCOL_PP:
		iHash = (*(UINT *)pKey)%PP_HASH_LEN;
		pRule = gVar.ruleHash.pp[iHash].pRule;
		while( pRule )
		{
			if( pRule->iKey == *(UINT *)pKey )
				break;
			
			pRule = pRule->pNext;
		}
		break;
		
	case RULE_PROTOCOL_AOL:
		iHash = StrLowerCaseHash( pKey, keyLen);
		iHash = iHash%AOL_HASH_LEN;
		pRule = gVar.ruleHash.aol[iHash].pRule;
		
		while( pRule )
		{
			if( strstr( pRule->key, pKey) )
			{
				printk( "aol:%s\r\n", (char *)pKey );
				break;
			}
			pRule = pRule->pNext;
		}			
		break;
					
	case RULE_PROTOCOL_IRC:
		iHash = StrLowerCaseHash( pKey, keyLen);
		iHash = iHash%IRC_HASH_LEN;
		pRule = gVar.ruleHash.irc[iHash].pRule;
		
		while( pRule )
		{
			if( strstr( pRule->key, pKey) )
			{
				printk( "irc:%s\r\n", (char *)pKey );
				break;
			}
			pRule = pRule->pNext;
		}			
		break;
				
	case RULE_PROTOCOL_GTALK:
		iHash = StrLowerCaseHash( pKey, keyLen);
		iHash = iHash%GTALK_HASH_LEN;
		pRule = gVar.ruleHash.gtalk[iHash].pRule;
		
		while( pRule )
		{
			if( strstr( pRule->key, pKey) )
			{
				printk( "gtalk:%s\r\n", (char *)pKey );
				break;
			}
			
			pRule = pRule->pNext;
		}			
		break;					
	default:
		break;
	}
	
	if( pRule )
	{	
		pRule->sip = sip;
		
		//匹配的规则可能是白名单
		ruleID = (pRule->ruleID) |( pRule->ruleType);
		
		if( !( pRule->ruleType ) && bDy )
		{
			//只是匹中黑名单的IP才记录
			AddRuleIP(sip, ruleID, false, 0);
		}
	}
	
	return ruleID;
}

RULE * FindRuleByID( RULE *pRule )
{
	switch( pRule->protocolType )
	{
	case RULE_PROTOCOL_IP:
		break;
	case RULE_PROTOCOL_QQ:
		break;
	case RULE_PROTOCOL_MSN:
		break;
	case RULE_PROTOCOL_MAIL:
		break;
	default:
		break;
	}
	
	return NULL;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -