LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 606|回复: 0

netfilter 内核扩展

[复制链接]
发表于 2007-1-13 02:06:41 | 显示全部楼层 |阅读模式
#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/netfilter_ipv4/ip_tables.h>
#include <linux/netfilter.h>
#include <linux/kernel.h>
#include <linux/netfilter_ipv4.h>

MODULE_LICENSE("Dual BSD/GPL");

static struct nf_hook_ops nfho;

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 *))
{
        printk("*********************** hook_func()\n");
        return NF_DROP;
}

int my_init_module(void)
{
        nfho.hook        = hook_func;
        nfho.hooknum        = NF_IP_PRE_ROUTING;
        nfho.pf                = PF_INET;
        nfho.priority        = NF_IP_PRI_FIRST;

        printk("********************** my_init_module()\n");
        nf_register_hook(&nfho);
        return 0;
}

void my_cleanup_module(void)
{
        printk("********************* my_cleanup_module()\n");
        nf_unregister_hook(&nfho);
}

module_init(my_init_module);
module_exit(my_cleanup_module);

我把代码编译成ko,然后insmod,接着在message里面输出了两条信息后,系统就一点反应也没有了,只能重启,有谁能告诉我是为什么吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表