- 论坛徽章:
- 3
|
This problem has been resolved
修改后的代码如下:
1 #include <linux/module.h>
2 #include <linux/skbuff.h>
3 #include <linux/ip.h>
4 #include <linux/udp.h>
5 #include <linux/icmp.h>
6 #include <net/icmp.h>
7 #include <net/ip.h>
8 #include <net/tcp.h>
9 #include <net/route.h>
10 #include <net/dst.h>
11 #include <net/net_namespace.h>
12 #include <linux/netfilter/x_tables.h>
13 #include <linux/netfilter_ipv4/ip_tables.h>
14 #ifdef CONFIG_BRIDGE_NETFILTER
15 #include <linux/netfilter_bridge.h>
16 #endif
17
18 MODULE_LICENSE("GPL");
19 MODULE_AUTHOR("zj");
20 MODULE_DESCRIPTION("Xtables: packet \"winnuke\" target for IPv4");
21
22 static unsigned int
23 /*
24 reject_tg(unsigned int hooknum,
25 struct sk_buff *skb,
26 const struct net_device *in,
27 const struct net_device *out,
28 int (*okfn)(struct sk_buff *))
29 */
30 reject_tg(struct sk_buff *skb,
31 const struct net_device *in,
32 const struct net_device *out,
33 unsigned int hooknum,
34 const struct xt_target *target,
35 const void *targinfo)
36 {
37 const struct iphdr *oiph;
38 const struct tcphdr *oth;
39 struct tcphdr _otcph;
40
41 oiph = ip_hdr(skb);
42 if (oiph->frag_off & htons(IP_OFFSET))
43 return NF_DROP;
44 switch (oiph->protocol)
45 {
46 case IPPROTO_TCP:
47 printk("TCP PACKET!!!\n");
48 break;
49 case IPPROTO_UDP:
50 printk("UDP PACKET!!!\n");
51 break;
52 case IPPROTO_ICMP:
53 break;
54 default:
55 return NF_ACCEPT;
56 }
57 oth = skb_header_pointer(skb, ip_hdrlen(skb),
58 sizeof(_otcph), &_otcph);
59 if (oth == NULL)
60 return NF_DROP;
61
62 if (oth->urg)
63 return NF_DROP;
64 else
65 {
66 printk("urg ok!!!!!");
67 printk("s_port:%d,d_port:%d",oth->source,oth->dest);
68 }
69 return NF_ACCEPT;
70 }
71
72 static struct xt_target reject_tg_reg __read_mostly = {
73 .name = "reject",
74 .family = PF_INET,
75 .target = reject_tg,
76 .hooks = (1 << NF_INET_LOCAL_IN) | (1 << NF_INET_FORWARD) |
77 (1 << NF_INET_LOCAL_OUT),
78 .me = THIS_MODULE,
79 };
80
81 extern int
82 xt_register_target(struct xt_target *target);
83 extern void
84 xt_unregister_target(struct xt_target *target);
85 static int __init reject_tg_init(void)
86 {
87 return xt_register_target(&reject_tg_reg);
88 }
89
90 static void __exit reject_tg_exit(void)
91 {
92 xt_unregister_target(&reject_tg_reg);
93 }
94
95 module_init(reject_tg_init);
96 module_exit(reject_tg_exit);
|
Makefile我没有改你的。
编译后不会再有warning,当你执行insmod ipt_REJECT.ko(ipt_REJECT是我给这个target的命名)的时候,dmesg会看到如下信息:
ipt_REJECT: Unknown symbol xt_register_target
ipt_REJECT: Unknown symbol xt_unregister_target
于是,问题很明显了,就是xt_register_target和xt_unregister_target这两个符号没有找到,所以加载失败。
分析一下失败的原因:既然编译都通过了,那么头文件什么的应该没有问题;问题很可能就是实现这两个函数的模块没有加载。我们在源码中找到,这两个函数实在x_tables这个模块中实现的,lsmod | grep x_tables 确实没有找到,于是手动加载:modprobe x_tables
ok,继续执行insmod ipt_REJECT.ko
ok,这下成功了,哈哈,大功告成。 |
评分
-
查看全部评分
|