Имеется модуль, представляющий собой файервол на базе netfiltra.
Проблемма представляет собой зависание системы, как я пологаю из-за
сегфолта в модуле.
Приведу для начала тот код что имеет отношение к проблемме:
/************************************netfw-bace.h*******************************
*************/
...
struct netfw_chains_table;
//struct of table
struct netfw_table{
	struct netfw_table *prev;
	struct netfw_table *next;
	char *name;
	int id;
	int policy;
	int (* set_rule)(int action, struct netfw_chains_table *new);
	int (* ud_set_rule)(char *table, int action, int id, char *par, char *arg, int num_par);
};
//struct of module
struct netfw_module{
	struct netfw_module *prev;
	struct netfw_module *next;
	char *name;
	int id;
	char *match;
	int (* check)(int action, char *table_name, int id, char *arg, struct sk_buff **skb);
};
//struct of rule chain
struct netfw_rules_chain{
	struct netfw_rules_chain *prev;
	struct netfw_rules_chain *next;
	int it;
	struct netfw_module *m;
	int (* check)(int action, char *table_name, int id, char *arg, struct sk_buff **skb);
};
//struct of chain table
struct netfw_chains_table{
	struct netfw_chains_table *prev;
	struct netfw_chains_table *next;
	char *table;
	int num_rules;
	struct netfw_rules_chain *list;
};
...
/*******************************************************************************
*****************/
/************************************netfw-bace.c*******************************
*************/
#include "netfw-bace.h"
...
void fill(struct netfw_module *m, char *table, int id, char *arg)
{
	...
}
int netfw_add_rule(char *table, int id, int it, char *par[], char *arg[], int num)
{
	struct netfw_table *t = netfw_get_table_by_name(table);
	if(!t) return NETFW_ERR_NO_SUCH_TABLE;
	struct netfw_rules_chain *chain_cach = kmalloc(sizeof(struct netfw_rules_chain),GFP_DMA);
	if(!chain_cach) return -1;
	chain_cach->next = chain_cach->prev = chain_cach;
	
	struct netfw_module *m;
	
	struct netfw_chains_table *ct = kmalloc(sizeof(struct netfw_chains_table),GFP_DMA);
	if(!ct) return -1;
	ct->next = ct->prev = ct;
	int k;
	for(k = 0; k <= num - 1; k++)
	{
		m = netfw_get_module_by_name(par[k]);
		if(m)
		{
			fill(m,table,netfw_num_rules,arg[k]);
			struct netfw_rules_chain *new = kmalloc(sizeof(struct netfw_rules_chain),GFP_DMA);
			if(!new) return -1;
			new->it = it;			
			new->m = m;
			new->check = m->check;
			struct netfw_rules_chain *next = chain_cach->next;
			struct netfw_rules_chain *prev = chain_cach;
			next->prev = new;
			new->next = next;
			new->prev = prev;
			prev->next = new;
		}
	}
	ct->table = table;
	ct->list = chain_cach;
	ct->num_rules = num;
	t->set_rule(NETFW_ADD_RULE,ct);
	
	netfw_num_rules++;
	
	return 0;
}
void netfw_add_chains_table(struct netfw_chains_table *new, struct netfw_chains_table *old,int first)
{
	if(first)
	{
	    old->table = new->table;
	    old->num_rules = new->num_rules;
	    old->list = new->list;
	}
	else
	{
    	    struct netfw_chains_table *next = old->next;
	    struct netfw_chains_table *prev = old;
	    next->prev = new;
	    new->next = next;
	    new->prev = prev;
	    prev->next = new;
        }
	
	printk("Table name in add_chains old->table: ");
	printk(old->table);
	printk("\n");
}
...
int netfw_check_rules(struct netfw_chains_table *chains_table, struct sk_buff **skb)
{
	printk("packet check was start\n");
	table = chains_table;
	int k,i,mach,it;
	it = 0;
	for(k = 0; k < netfw_num_rules; k++)
	{
		printk("change rule chain\n");
		mach = 0;
		chain = table->list;
		mod = chain->next;
		int b = 0;
		int tb = 0;
		for(i = 0; i < table->num_rules; i++)
		{
			if(b)
			{
			    printk("block is set\n");
			    mod->check(NETFW_CHK_RULE, 0, 0, 0, 0);
			}
			else
			{
				printk("block not set\n");
				printk("Table name table->table: ");
				printk(table->table);
				printk("\n");
				tb = mod->check(NETFW_CHK_RULE, table->table, 0, 0, skb);
				if(!tb)
				{
				    printk("missed chain block have been set\n");
				    b = 1;
				}
				else
				{
					if(tb == 1)
					{
					    printk("was match\n");
					    mach++;
					}
					if(tb == 2)
					{
					    printk("wrong table\n");
//					    i--;
					}
				}
				if(!mod->next) return 0;
				mod = mod->next;
			}
		}
		if(mach == table->num_rules)
		{
			printk("check was finish with set\n");
			it = chain->it;
			if(it == NETFW_ACCEPT)
			{
			    printk("packet was pass\n");
			    return 1;
			}
			if(it == NETFW_DROP)
			{
			    printk("packet was drop\n");
			    return 0;
			}
		}
		if(!table->next) return 0;
		table = table->next;
	}
	printk("check was finish with default\n");
	return 1;
}
...
ssize_t netfw_write (struct file *f, const char *ch, size_t size, loff_t *loff)
{
	if(num > 0)if(n < num*2)
	{
		if(par_accept)
		{
			par[n_par] = kmalloc(sizeof(char[strlen(ch)]),GFP_DMA);
			par[n_par] = ch;
			par_accept = 0;
			n_par++;
		}
		else
		{
			arg[n_arg] = kmalloc(sizeof(char[strlen(ch)]),GFP_DMA);
			arg[n_arg] = ch;
			par_accept = 1;
			n_arg++;
		}
		n++;
	}
	if(!strcmp(ch,"$"))
	{
		step = -1;
		n = n_par = n_arg = 0;
		if(act > 0)
		{
			switch(act)
			{
				case NETFW_ADD_RULE:
					netfw_add_rule(to_table,0,it,par,arg,num);
					break;
				case NETFW_DEL_RULE:
					break;
			}
		}
		num = 0;
	}
	
	step++;
	switch(step)
	{
		//Action
		case 1:
			if(!strcmp(ch,"add"))
			{
				act = NETFW_ADD_RULE;
			}
			if(!strcmp(ch,"del"))
			{
				act = NETFW_DEL_RULE;
			}
			break;
		//Table name
		case 2:
			to_table = ch;				<----- вот здесь она и записывается
			break;
		//What to do ( aka "it" )
		case 3:
			if(!strcmp(ch,"accept"))
			{
				it = NETFW_ACCEPT;
			}
			if(!strcmp(ch,"drop"))
			{
				it = NETFW_DROP;
			}
			break;
		//Num of elements
		case 4:
			num = netfw_char_to_int(ch);
			kfree(par);
			kfree(arg);
			par = kmalloc(sizeof(char[num]),GFP_DMA);
			arg = kmalloc(sizeof(char[num]),GFP_DMA);
			par_accept = 1;
			break;
	}
	return 0;
}
...
/*******************************************************************************
*****************/

    
      Ответ на:
      
          комментарий
        от cyclon 
  
    
      Ответ на:
      
          комментарий
        от bd 
  
    
      Ответ на:
      
          комментарий
        от cyclon 
  
    
      Ответ на:
      
          комментарий
        от anonymous 
  
    
      Ответ на:
      
          комментарий
        от cyclon 
  
    
      Ответ на:
      
          комментарий
        от cyclon 
  
    
      Ответ на:
      
          комментарий
        от cyclon 
  
    
      Ответ на:
      
          комментарий
        от cyclon 
  
    
      Ответ на:
      
          комментарий
        от cyclon 
  
    
      Ответ на:
      
          комментарий
        от cyclon 
  
    
        Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.
      
Похожие темы
- Форум Выделение памяти в модуле. (2005)
 - Форум Что за бред с инициализией переменной???? (2005)
 - Форум Проблемма с выделением памяти. (2005)
 - Форум Переслать полученный пакет (2012)
 - Форум Проблема с деструктором класса (2002)
 
- Форум Обещаный код с ошибкой __int_malloc (2004)
 - Форум Всё ли нормально в символьном устройстве? (2017)
 - Форум Передача и вывод int в ядре. (2005)
 - Форум Производительность AF_PACKET RAW и AF_INET SOCK_STREAM сокетов в ядре. (2010)
 - Форум проблема с обработкой прерывания (2006)