- 论坛徽章:
- 0
|
本帖最后由 morfast 于 2011-05-05 22:28 编辑
试了下NF hook, 按照这篇文章http://bbs.chinaunix.net/thread-2177913-1-1.html写的
但在hook function里多写几句,比如调用skb_copy一下什么的,insmod后就kernel panic死机了。如果只是返回一个NF_ACCEPT或是NF_DROP,就没问题
看不出代码里有什么问题,还是有其它原因?
代码如下:- #include <linux/init.h>
- #include <linux/module.h>
- #include <linux/netfilter_ipv4.h>
- #include <linux/if_ether.h>
- #include <linux/ip.h>
- MODULE_LICENSE("Dual BSD/GPL");
- /* This is the structure we shall use to register our function */
- static struct nf_hook_ops nfho;
- /* This is the hook function itself */
- static 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 *))
- {
- //如果没有下面这两行,则不会发生kernel panic
- struct sk_buff *sb;
- sb = skb_copy(*skb, GFP_ATOMIC);
- return NF_DROP;
- }
- /* Initialisation routine */
- static int init_dropall(void)
- {
- /* Fill in our hook structure */
- nfho.hook = (nf_hookfn *)hook_func;
- nfho.hooknum = NF_INET_PRE_ROUTING;
- nfho.pf = PF_INET;
- nfho.priority = NF_IP_PRI_FIRST;
- nf_register_hook(&nfho);
- return 0;
- }
- /* Cleanup routine */
- static void exit_dropall(void)
- {
- nf_unregister_hook(&nfho);
- }
- module_init(init_dropall);
- module_exit(exit_dropall);
复制代码 |
|