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>