<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<STYLE type=text/css> <!--@import url(scrollbar.css); --></STYLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<STYLE>                        body{FONT-SIZE:12pt; FONT-FAMILY:宋体,serif;}                </STYLE>
<META content="MSHTML 6.00.2900.6182" name=GENERATOR><BASE target=_blank></HEAD>
<BODY
style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; MARGIN: 12px; LINE-HEIGHT: 1.3; BORDER-RIGHT-WIDTH: 0px"
marginheight="0" marginwidth="0">
<DIV><FONT face=宋体 color=#000000 size=3>what is your kernel
version?</FONT></DIV>
<DIV>maybe you should use NF_INET_PRE_ROUTING instead.</DIV>
<DIV> </DIV>
<DIV align=left><FONT face=Verdana color=#c0c0c0 size=2>2012-05-22</FONT></DIV>
<DIV align=left><FONT face=Verdana size=2>
<HR id=SignNameHR style="WIDTH: 122px; HEIGHT: 2px" align=left SIZE=2>
</FONT></DIV>
<DIV align=left><FONT face=Verdana color=#c0c0c0 size=2><SPAN
id=_FlashSignName>c265n46</SPAN></FONT></DIV>
<DIV><FONT face=Verdana size=2>
<HR>
</FONT></DIV>
<DIV><FONT face=Verdana size=2><STRONG>发件人:</STRONG>Chir0n</FONT></DIV>
<DIV><FONT face=Verdana
size=2><STRONG>发送时间:</STRONG>2012-05-08 12:14</FONT></DIV>
<DIV><FONT face=Verdana size=2><STRONG>主题:</STRONG>Why I can't compile a simple
netfilter hook module?</FONT></DIV>
<DIV><FONT face=Verdana
size=2><STRONG>收件人:</STRONG>"kernelnewbies"<kernelnewbies@kernelnewbies.org></FONT></DIV>
<DIV><FONT face=Verdana size=2><STRONG>抄送:</STRONG></FONT></DIV>
<DIV><FONT face=Verdana size=2></FONT> </DIV>
<DIV><FONT face=Verdana size=2>I'm using this Makefile:<BR><BR><FONT
size=1><I>obj-m += hello.o<BR><BR>all:<BR> make -C
/lib/modules/$(shell uname -r)/build M=$(PWD) modules<BR><BR>clean:<BR>
make -C /lib/modules/$(shell uname -r)/build M=$(PWD)
clean</I></FONT><BR><BR><BR>The hello.c is this:<BR><BR><FONT size=1><I>#include
<linux/kernel.h><BR>#include <linux/module.h><BR>#include
<linux/netfilter.h><BR>#include
<linux/netfilter_ipv4.h><BR><BR>static struct nf_hook_ops nfho;
//struct holding set of hook function
options<BR><BR>//function to be called by hook<BR>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
*))<BR>{<BR> printk(KERN_INFO "packet dropped\n");
//log to
var/log/messages<BR> return NF_DROP;
//drops the
packet<BR>}<BR><BR>//Called when module loaded using 'insmod'<BR>int
init_module()<BR>{<BR> nfho.hook = hook_func;
//function to call when
conditions below met<BR> nfho.hooknum = NF_IP_PRE_ROUTING;
//called right after packet recieved, first hook in
Netfilter<BR> <A href="http://nfho.pf">nfho.pf</A> = PF_INET;
//IPV4 packets<BR> nfho.priority = NF_IP_PRI_FIRST;
//set to highest priority over all other hook
functions<BR> nf_register_hook(&nfho);
//register hook<BR><BR> return 0;
//return 0 for
success<BR>}<BR><BR>//Called when module unloaded using 'rmmod'<BR>void
cleanup_module()<BR>{<BR> nf_unregister_hook(&nfho);
//cleanup – unregister
hook<BR>}</I></FONT><BR><BR><BR>Here are the error message:<BR><BR><FONT
size=1><I>$ make<BR>make -C /lib/modules/3.3.2-6.fc16.x86_64/build
M=/home/fabio/Desktop/modules modules<BR>make[1]: Entering directory
`/usr/src/kernels/3.3.2-6.fc16.x86_64'<BR> CC [M]
/home/fabio/Desktop/modules/hello.o<BR>/home/fabio/Desktop/modules/hello.c:
In function ‘init_module’:<BR>/home/fabio/Desktop/modules/hello.c:18:13:
warning: assignment from incompatible pointer type [enabled by
default]<BR>/home/fabio/Desktop/modules/hello.c:19:18: error:
‘NF_IP_PRE_ROUTING’ undeclared (first use in this
function)<BR>/home/fabio/Desktop/modules/hello.c:19:18: note: each undeclared
identifier is reported only once for each function it appears in<BR>make[2]: ***
[/home/fabio/Desktop/modules/hello.o] Error 1<BR>make[1]: ***
[_module_/home/fabio/Desktop/modules] Error 2<BR>make[1]: Leaving directory
`/usr/src/kernels/3.3.2-6.fc16.x86_64'<BR>make: *** [all] Error
2</I></FONT><BR></FONT></DIV></BODY></HTML>