免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4280 | 回复: 4
打印 上一主题 下一主题

加载内核模块死机!求解! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-04-07 15:51 |只看该作者 |倒序浏览
我在Ubuntu8.04 (内核2.6.24)下加载netfilter模块,代码是网上的,编译也通过了,但是加载模块后机器就死了,怎么回事?
代码如下:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>

static struct nf_hook_ops nfho;
static unsigned char *drop_ip = "\x7f\x00\x00\x01";

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 *))
{
       struct sk_buff *sb = *skb;
       struct iphdr     *iph ;
   
       iph = ip_hdr(sb);
       pr_info("Packet from %d.%d.%d.%d\n",NIPQUAD(iph->saddr));
       if ( iph->saddr == *(__be32 *) drop_ip)
       {
             pr_info("Dropped packet from ... %d.%d.%d.%d\n",*drop_ip, *(drop_ip+1), *(drop_ip+2), *(drop_ip+3) );
             return NF_DROP;
       }else {
           
             return NF_ACCEPT;
       }
}

int init_module()
{
       pr_info("i'm now in the kernel space!\n");
       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);
    pr_info("module removed from kernel!\n");
}
Makefile如下:
obj-m +=simpFilter.o

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
    rm Module.symvers

论坛徽章:
0
2 [报告]
发表于 2009-11-25 09:35 |只看该作者
把struct sk_buff *sb = *skb;改为struct sk_buff *sb;sb=skb;试一下

论坛徽章:
0
3 [报告]
发表于 2009-11-25 10:24 |只看该作者
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 *))
{
       struct sk_buff *sb = skb;              还有这里

论坛徽章:
0
4 [报告]
发表于 2009-11-26 00:50 |只看该作者
try:

iph = ip_hdr(sb); == > iph = ipip_hdr(sb);

论坛徽章:
0
5 [报告]
发表于 2009-12-07 22:45 |只看该作者

回复 #2 interlcan 的帖子

2楼正解,2.6.24后kernel中的network貌似变动较大..
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP