读书人

请问:2.6编译netfilter后运行死机

发布时间: 2012-03-12 12:45:33 作者: rapoo

请教:2.6编译netfilter后运行死机
请教下:运行到ip_nat_setup_info的时候就死机了,那位兄弟知道什么原因阿,谢谢

static unsigned int
trigger_dnat(struct sk_buff **pskb,
unsigned int hooknum,
const struct net_device *in,
const struct net_device *out,
const void *targinfo,
void *userinfo)
{
struct ipt_trigger *found;
const struct iphdr *iph = (*pskb)-> nh.iph;
struct tcphdr *tcph = (void *)iph + iph-> ihl*4;/* Might be TCP, UDP */
struct ip_conntrack *ct;
enum ip_conntrack_info ctinfo;
struct ip_nat_multi_range newrange;

int ret;

IP_NF_ASSERT(hooknum == NF_IP_PRE_ROUTING);
/* Check if the trigger-ed range has already existed in 'trigger_list '. */
found = LIST_FIND(&trigger_list, trigger_in_matched,
struct ipt_trigger *, iph-> protocol, ntohs(tcph-> dest));
printk( "ntohs:%d\n ",ntohs(tcph-> dest));

if (!found || !found-> srcip)
{
printk( "no match in the list\n ");
return IPT_CONTINUE;/* We don 't block any packet. */
}
printk( "############# %s ############\n ", __FUNCTION__);
printk( "ip:%u\n ",found-> srcip);
found-> reply = 1;/* Confirm there has been a reply connection. */
ct = ip_conntrack_get(*pskb, &ctinfo);
IP_NF_ASSERT(ct && (ctinfo == IP_CT_NEW));

printk( "%s: got ", __FUNCTION__);
DUMP_TUPLE(&ct-> tuplehash[IP_CT_DIR_ORIGINAL].tuple);

/* Alter the destination of imcoming packet. */
printk( "Alter the destination of imcoming packet\n ");

newrange = ((struct ip_nat_multi_range)
{ 1, { { IP_NAT_RANGE_MAP_IPS,
found-> srcip, found-> srcip,
{0} , {0}
} } });

/* Hand modified range to generic setup. */
printk( "Hand modified range to generic setup ");
ret = ip_nat_setup_info(ct, &newrange, hooknum);



printk( "ret:%d\n ",ret);

return ret;
}

[解决办法]
const struct iphdr *iph = (*pskb)-> nh.iph;
iph后来有被读过没??
应该是指针的问题...
[解决办法]
肯定是指针的问题,这几天我也在做这方面的东西,就是因为指针的问题!楼主我建议你不要直接操作传过来的skb,我用的时候就出错了!因为在sk_buff结构中有些成员是只读的(如数据区),你可以这样在程序中这样做
struct sk_buff *skb = NULL;
skb = skb_copy(pskb);
然后你再对skb进行措作就比较安全了!
不知道有没有帮助!

读书人网 >UNIXLINUX

热点推荐