一个内核模块,总是死机,请给看看,谢谢。
时间:2010-10-13
来源:互联网
这是我在网上找到的一个内核模块,功能是记录PING,并显示出来。
原来程序是针对老内核的,后来我上网查到,新的内核SKBUFF定义有所变化,便改了改后,MAKE,但是总是死机,请高手给看看,谢谢了。
改动的两处我已经注明。
复制代码
原来程序是针对老内核的,后来我上网查到,新的内核SKBUFF定义有所变化,便改了改后,MAKE,但是总是死机,请高手给看看,谢谢了。
改动的两处我已经注明。
- #include <linux/init.h>
- #include <linux/types.h>
- #include <linux/netdevice.h>
- #include <linux/skbuff.h>
- #include <linux/netfilter_ipv4.h>
- #include <linux/inet.h>
- #include <linux/in.h>
- #include <linux/ip.h>
-
- static unsigned int icmp_srv(unsigned int hook,
- struct sk_buff **pskb,
- const struct net_device *in,
- const struct net_device *out,
- int (*okfn)(struct sk_buff *)
- )
- {
- //printk(KERN_INFO"hook_icmp::icmp_srv()\n");
- struct iphdr *iph = (*pskb)->network_header; //这块我改动过原来是 nh.iph
-
- if(iph->protocol == IPPROTO_ICMP)
- {
- printk(KERN_INFO"hook_icmp::icmp_srv: receive ICMP packet\n");
- printk(KERN_INFO"src: ");
- }
-
- return NF_ACCEPT;
- }
-
- static struct nf_hook_ops icmpsrv_ops =
- {
- .hook = icmp_srv,
- .pf = PF_INET,
- .hooknum = NF_INET_PRE_ROUTING, //这块我改动过,原来那个是用户态的,不支持了,改成新的了。
- .priority = NF_IP_PRI_FILTER -1,
- };
-
- static int __init init_hook_icmp(void)
- {
- return nf_register_hook(&icmpsrv_ops);
- }
-
- static void __exit fini_hook_icmp(void)
- {
- nf_unregister_hook(&icmpsrv_ops);
- }
-
- MODULE_LICENSE("GPL");
-
- module_init(init_hook_icmp);
- module_exit(fini_hook_icmp);
作者: 程序c 发布时间: 2010-10-13
内核版本是多少,确定一下 hook 函数的接口形式是否正确
作者: Godbach 发布时间: 2010-10-13
主要就是第二个参数
struct sk_buff **pskb,
在你的内核版本中是否仍旧是二级指针
struct sk_buff **pskb,
在你的内核版本中是否仍旧是二级指针
作者: Godbach 发布时间: 2010-10-13
我的内核版本是2.6.31
如何查是否是二级指针麻烦给指点一下
源码地址是 http://lxr.linux.no/#linux+v2.6.31/include/linux/skbuff.h#L1196
如何查是否是二级指针麻烦给指点一下
源码地址是 http://lxr.linux.no/#linux+v2.6.31/include/linux/skbuff.h#L1196
作者: 程序c 发布时间: 2010-10-13
static struct nf_hook_ops
这个结构体中的一个成员是函数指针,也就是定义的 hook 函数。看一下函数的参数形式。
这个结构体中的一个成员是函数指针,也就是定义的 hook 函数。看一下函数的参数形式。
作者: Godbach 发布时间: 2010-10-13
实在抱歉。这个我找到了,不过我还是有点看不明白。可能我基础不太好吧。
96struct nf_hook_ops
97{
98 struct list_head list;
99
100 /* User fills in from here down. */
101 nf_hookfn *hook;
102 struct module *owner;
103 u_int8_t pf;
104 unsigned int hooknum;
105 /* Hooks are ordered in ascending priority. */
106 int priority;
107};
96struct nf_hook_ops
97{
98 struct list_head list;
99
100 /* User fills in from here down. */
101 nf_hookfn *hook;
102 struct module *owner;
103 u_int8_t pf;
104 unsigned int hooknum;
105 /* Hooks are ordered in ascending priority. */
106 int priority;
107};
作者: 程序c 发布时间: 2010-10-13
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28