- 论坛徽章:
- 0
|
- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/netfilter.h>
- #include <linux/netfilter_ipv4.h>
- #include <linux/ip.h>
- /* 用于注册我们的函数的数据结构 */
- static struct nf_hook_ops nfho;
- unsigned char *drop_ip="\xc0\xa8\x5\xad";
- /* 注册的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 *))
- {
- #if 1
- struct sk_buff *sb=*skb;
- //if(sb !=NULL)
- //{
- // printk("12313\n");
- struct iphdr *iph = ip_hdr(sb);
-
- if (iph->saddr == *(unsigned int *)drop_ip) {
- // if (sb->nh.iph->saddr == drop_ip) {
-
- printk("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;
- #else
- dump_stack();
- #endif
- }
- /* 初始化程序 */
- int init_module()
- {
- /* 填充我们的hook数据结构 */
- nfho.hook = hook_func; /* 处理函数 */
- nfho.hooknum = NF_INET_PRE_ROUTING; /* 使用IPv4的第一个hook */
- nfho.pf = PF_INET;
- nfho.priority = NF_IP_PRI_FIRST; /* 让我们的函数首先执行 */
- nf_register_hook(&nfho);
- return 0;
- }
- /* 清除程序 */
- void cleanup_module()
- {
- nf_unregister_hook(&nfho);
- }
- //module_init(init_module);
- //module_exit(cleanup_module);
- MODULE_LICENSE("GPL");
复制代码 编译成模块,在加载时出现内核崩溃,请对netfilter研究较深的专家们给菜鸟说明一下,为什么出现这种情况,谢谢!!
崩溃信息如下:
# insmod netfilter.ko
~ # [61527.556000] CPU 0 Unable to handle kernel paging request at virtual address 00000098, epc == 82f29078, ra == 8015ca44
[61527.568000] Oops[#1]:
[61527.568000] Cpu 0
[61527.568000] $ 0 : 00000000 00000000 82f30000 00000000
[61527.568000] $ 4 : 00000000 832b2200 83833c00 00000000
[61527.568000] $ 8 : 82f29130 800fc8e0 00000005 00000800
[61527.568000] $12 : 83221dfc 00000009 83221e70 2aaec39c
[61527.568000] $16 : 83221ae0 00000004 00000001 80000000
[61527.568000] $20 : 83833c00 80163740 00000000 00000000
[61527.568000] $24 : 00000000 80163a98
[61527.568000] $28 : 83220000 83221a60 832b2200 8015ca44
[61527.568000] Hi : 00006157
[61527.568000] Lo : 1a768aa1
[61527.568000] epc : 82f29078 hook_func+0x14/0x6c [netfilter]
[61527.568000] Tainted: P
[61527.568000] ra : 8015ca44 nf_iterate+0x84/0xf8
[61527.568000] Status: 1100ff03 KERNEL EXL IE
[61527.568000] Cause : 00800008
[61527.568000] BadVA : 00000098
[61527.568000] PrId : 0001974c (MIPS 74Kc)
[61527.568000] Modules linked in:
[61527.568000] [<82f29000>] netfilter
[61527.568000] [<82f34000>] ath_addon(P)
[61527.568000] [<82d78000>] ath_pktlog(P)
[61527.568000] [<83100000>] umac
[61527.568000] [<830c0000>] ath_dev(P)
[61527.568000] [<83e70000>] ath_dfs(P)
[61527.568000] [<83f20000>] ath_rate_atheros(P)
[61527.568000] [<83000000>] ath_hal(P)
[61527.568000] [<83e48000>] asf(P)
[61527.568000] [<83e5c000>] adf
[61527.568000] [<83e60000>] athrs_gmac
[61527.568000] [<83e11000>] athrs_tun_var(P)
[61527.568000] Process ap2snmpd (pid: 2052, threadinfo=83220000, task=82dabac8, tls=00000000)
[61527.568000] Stack : 83eb82c0 831218e0 800fc4c0 83eb8868 00000000 00000000 04000200 8015ca44
[61527.568000] 021b0000 83000448 00000018 830003f4 80163740 0000401c 832b2200 00000000
[61527.568000] 8029ce50 00000002 83833c00 80163740 00000000 00000003 00000005 8015cc48
[61527.568000] 8029ce50 f0010473 83eb0000 00000002 00000000 83221ae0 80163740 80000000
[61527.568000] 82f294f0 83eb82c0 00000001 832b2200 83833c00 802533ac 802533c4 80250000
[61527.568000] ...
[61527.568000] Call Trace:
[61527.568000] [<82f29078>] hook_func+0x14/0x6c [netfilter]
[61527.568000] [<8015ca44>] nf_iterate+0x84/0xf8
[61527.568000] [<8015cc48>] nf_hook_slow+0x94/0x130
[61527.568000] [<80163d90>] ip_rcv+0x2f8/0x35c
[61527.568000] [<80146874>] process_backlog+0xa8/0x108
[61527.568000] [<80146fd8>] net_rx_action+0x90/0x1b0
[61527.568000] [<8002ac98>] __do_softirq+0xb0/0x148
[61527.568000] [<8002ad78>] do_softirq+0x48/0x6c
[61527.568000] [<8002b000>] local_bh_enable+0x8c/0xcc
[61527.568000] [<80147d8c>] dev_queue_xmit+0x32c/0x378
[61527.568000] [<8016872c>] ip_push_pending_frames+0x2e8/0x37c
[61527.568000] [<80186528>] udp_push_pending_frames+0x2fc/0x368
[61527.568000] [<80187f4c>] udp_sendmsg+0x4c8/0x5e8
[61527.568000] [<80135598>] sock_sendmsg+0xa8/0xc0
[61527.568000] [<80136b3c>] sys_sendto+0xc0/0x100
[61527.568000] [<8000f984>] stack_done+0x20/0x3c
[61527.568000]
[61527.568000]
[61527.568000] Code: 8ca30000 3c0282f3 8c4893c0 <8c640098> 8d030000 8c82000c 10430005 24050001 8fbf001c
[61527.840000] Kernel panic - not syncing: Fatal exception in interrupt
U-Boot 1.1.4 (May 4 2013 - 14:58:21)
|
|