Exemplo n.º 1
0
/**
创建需要用到的proc文件

@return 成功返回 RR_OK,失败返回 RR_FAIL。
*/
int create_proc_file(void)
{
	int ret = ADV_KILL_OK;
	//web config
	advkillconfdata = (char *)ADVKILL_CALLOC(1, MAX_ADVKILL_CONF_LEN);
	if (advkillconfdata == NULL)
		return ADV_KILL_FAIL;
	
	proc_dir = proc_mkdir(ADV_KILL_PROC_DIRECTORY, NULL);
	if (proc_dir == NULL) 
	{
		ret = -ENOMEM;
		printk(KERN_ERR "Couldn't create proc dir[/proc/%s]\n", ADV_KILL_PROC_DIRECTORY);
		goto exit_fail;
	}
	else
	{
#if (LINUX_VERSION_CODE < KERNEL_VERSION (3, 10, 0))
		proc_advkill_conf = create_proc_entry(ADV_KILL_PROC_FILE, 0644, proc_dir);
		if (proc_advkill_conf == NULL)
		{
			printk(KERN_ERR "Couldn't create proc entry[/proc/%s/%s]\n", ADV_KILL_PROC_DIRECTORY, ADV_KILL_PROC_FILE);
			ret = -ENOMEM;
			goto exit_fail;
		}
		proc_advkill_conf->read_proc = advkill_conf_read;
		proc_advkill_conf->write_proc = advkill_conf_write;
#else
		proc_advkill_conf = proc_create(ADV_KILL_PROC_FILE, 0644, proc_dir, &advkill_fops);
		if (proc_advkill_conf == NULL)
		{
			printk(KERN_ERR "Couldn't create proc entry[/proc/%s/%s]\n", ADV_KILL_PROC_DIRECTORY, ADV_KILL_PROC_FILE);
			ret = -ENOMEM;
			goto exit_fail;
		}
#endif
	}

	return ret;

exit_fail:
	if (advkillconfdata != NULL)
	{
		ADVKILL_FREE(advkillconfdata, MAX_ADVKILL_CONF_LEN);
		advkillconfdata = NULL;
	}
	if (proc_dir != NULL)
	{
		remove_proc_entry(ADV_KILL_PROC_FILE, proc_dir);
		proc_dir = NULL;
	}
	return ret;	
}
Exemplo n.º 2
0
/**
根据location发送302消息

@param skb 原始的sk_buff结构地址
@param location 需要发送的location内容
@return 成功返回 ADV_KILL_OK,失败返回 ADV_KILL_FAIL。
*/
int send_client_location(struct sk_buff *skb, char *location)
{
	char *tcpdata = NULL;
	int tcpdatalen = 0;

	if(!location || !skb)
		return ADV_KILL_FAIL;
	tcpdata = http_location_str_generate(&tcpdatalen, location);
	if (tcpdata == NULL)
	{
		return ADV_KILL_FAIL;
	}
	pkg_skbuff_dev_xmit(skb, tcpdata, tcpdatalen);
	
	ADVKILL_FREE(tcpdata, tcpdatalen+1);
	return ADV_KILL_OK;
}
Exemplo n.º 3
0
/*
 发送伪造的HTTP200响应
 @param skb 原始的sk_buff结构地址 CType Content-Type Cont 网页内容
 @return 成功返回 ADV_KILL_OK,失败返回 ADV_KILL_FAIL。
HTTP/1.1 200 OK\r\n
Server: QWS\r\n
Content-Type: text/xml\r\n
Content-Length: 125\r\n
Connection: close\r\n
Accept-Ranges: bytes\r\n\r\n
*/
int send_client_fake_message(struct sk_buff *skb, const char * CType, const char * Cont)
{
	char *new_data = NULL;
	int retval = 0, datlen = 0;

	if(!skb)
		return ADV_KILL_FAIL;

	datlen = strlen(CType)+strlen(Cont)+120;
	new_data = (char *)ADVKILL_CALLOC(1, datlen);
	if(new_data==NULL)
		return ADV_KILL_FAIL;
	sprintf(new_data,"HTTP/1.1 200 OK\r\nServer: QWS\r\nContent-Type: %s\r\nContent-Length: %d\r\nConnection: close\r\nAccept-Ranges: bytes\r\n\r\n%s",CType,strlen(Cont),Cont);
	retval=pkg_skbuff_dev_xmit(skb, new_data, strlen(new_data));
	ADVKILL_FREE(new_data, datlen);
	return retval;
}
Exemplo n.º 4
0
/**
删除proc文件
*/
void destroy_proc_file(void)
{
	if (proc_advkill_conf != NULL)
	{
		remove_proc_entry(ADV_KILL_PROC_FILE, proc_dir);
		proc_advkill_conf = NULL;
	}
	if (proc_dir != NULL)
	{
		remove_proc_entry(ADV_KILL_PROC_DIRECTORY, NULL);
		proc_dir = NULL;
	}
	if (advkillconfdata != NULL)
	{
		ADVKILL_FREE(advkillconfdata, MAX_ADVKILL_CONF_LEN);
		advkillconfdata = NULL;
	}
}