+ -
当前位置:首页 → 问答吧 → 为啥我这段netfilter的代码在2.6内核下没效果

为啥我这段netfilter的代码在2.6内核下没效果

时间:2006-04-07

来源:互联网

#define __KERNEL__
#define MODULE

#include <linux/kernel.h>
#include <linux/module.h>

#include <linux/init.h>

#include <linux/ip.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/skbuff.h>
#include <linux/udp.h>
#include <linux/tcp.h>
#include <net/tcp.h>
#include <linux/in.h>


MODULE_LICENSE("GPL");

//每经过一个数据包就会调用这个函数一次。
unsigned int pb_hook( unsigned int hooknum,
struct sk_buff **pskb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff*) )
{
printk("receive one pkt\n");
return NF_ACCEPT;
}


static struct nf_hook_ops nfo_ip_local_in = {
{NULL,NULL},
pb_hook,
PF_INET,
NF_IP_LOCAL_IN,
NF_IP_PRI_FIRST
};


static int __init pb_test_init(void)
{
return nf_register_hook(&nfo_ip_local_in);
}
module_init(pb_test_init);

static void __exit pb_test_exit(void)
{
nf_unregister_hook(&nfo_ip_local_in);
}
module_exit(pb_test_exit);


2.4下完全正常

作者: pink_tulip   发布时间: 2006-04-07

研究了

struct nf_hook_ops都变了。

成员加了一个struct module,有谁了解么?

作者: pink_tulip   发布时间: 2006-04-08

这样行不行?
。。。。
owner = THIS_MODULE,
。。。。

作者: 铁丝上的比目鱼   发布时间: 2006-04-13

初始化结构出错了,2.6中struct nf_hook_ops多了东西。
struct nf_hook_ops nfo_ip_local_in=
{
.list={ NULL, NULL},
.hook= pb_hook,
.pf=PF_INET,
.hooknum=NF_IP_LOCAL_IN,
.priority=NF_IP_PRI_FIRST
};
,新成员不用也行

作者: smallpeg   发布时间: 2006-04-19

请问那个新成员是干啥的?

作者: pink_tulip   发布时间: 2006-04-27