读书人

菜人netfilter有关问题请高手帮忙

发布时间: 2012-03-04 11:13:34 作者: rapoo

菜人netfilter问题,急急急,请高手帮忙 急急急急急急急急急急急急
#define MODULE
#include <linux/module.h>
#define __KERNEL__
#include <linux/kernel.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>

static struct nf_hook_ops nfho;

/* 注册的hook函数的实现 */
unsigned int hook_func(unsigned int hooknum,
struct sk_buff **skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
return 0; /* NF_DROP丢弃所有的数据包 */
}


int init_module()
{


nfho.list={NULL,NULL};
nfho.hook = hook_func;
nfho.hooknum =NF_IP_PRE_ROUTING;
nfho.pf =PF_INET;
nfho.priority = NF_IP_PRI_FIRST;

nf_register_hook(&nfho);



return 0;
}


void cleanup_module()
{
nf_unregister_hook(&nfho);
}

编译出现如下错误:

undefine reference to "nf_register_hook "

[解决办法]
是在kernel源码里编的么?
另外kernel配置时要打开NETFILTER支持
[解决办法]
写netfilter模块需要在kernel空间,也就是说需要和kernel源码一起编译。

不过也可以在用户空间实现,只要使用libipq。

libipq需要iptables的源代码包,解压后make, make install-devel就可以了
这里有一篇介绍文章:
http://www.yuanma.org/data/2006/0829/article_1426.htm

读书人网 >UNIXLINUX

热点推荐