From mboxrd@z Thu Jan 1 00:00:00 1970 From: c265n46@163.com (c265n46) Date: Tue, 22 May 2012 12:38:00 +0800 Subject: =?UTF-8?Q?=E5=9B=9E=E5=A4=8D:=20=20Why=20I=20can't=20compile=20a=20simple=20netfilter=20hook=20module=3F?= In-Reply-To: References: Message-ID: <2d50ad54.2d8607.13772d66a06.Coremail.c265n46@163.com> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org what is your kernel version? maybe you should use NF_INET_PRE_ROUTING instead. 2012-05-22 c265n46 ????Chir0n ?????2012-05-08 12:14 ???Why I can't compile a simple netfilter hook module? ????"kernelnewbies" ??? I'm using this Makefile: obj-m += hello.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 The hello.c is this: #include #include #include #include static struct nf_hook_ops nfho; //struct holding set of hook function options //function to be called by 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 *)) { printk(KERN_INFO "packet dropped\n"); //log to var/log/messages return NF_DROP; //drops the packet } //Called when module loaded using 'insmod' int init_module() { nfho.hook = hook_func; //function to call when conditions below met nfho.hooknum = NF_IP_PRE_ROUTING; //called right after packet recieved, first hook in Netfilter nfho.pf = PF_INET; //IPV4 packets nfho.priority = NF_IP_PRI_FIRST; //set to highest priority over all other hook functions nf_register_hook(&nfho); //register hook return 0; //return 0 for success } //Called when module unloaded using 'rmmod' void cleanup_module() { nf_unregister_hook(&nfho); //cleanup ? unregister hook } Here are the error message: $ make make -C /lib/modules/3.3.2-6.fc16.x86_64/build M=/home/fabio/Desktop/modules modules make[1]: Entering directory `/usr/src/kernels/3.3.2-6.fc16.x86_64' CC [M] /home/fabio/Desktop/modules/hello.o /home/fabio/Desktop/modules/hello.c: In function ?init_module?: /home/fabio/Desktop/modules/hello.c:18:13: warning: assignment from incompatible pointer type [enabled by default] /home/fabio/Desktop/modules/hello.c:19:18: error: ?NF_IP_PRE_ROUTING? undeclared (first use in this function) /home/fabio/Desktop/modules/hello.c:19:18: note: each undeclared identifier is reported only once for each function it appears in make[2]: *** [/home/fabio/Desktop/modules/hello.o] Error 1 make[1]: *** [_module_/home/fabio/Desktop/modules] Error 2 make[1]: Leaving directory `/usr/src/kernels/3.3.2-6.fc16.x86_64' make: *** [all] Error 2 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120522/c37e1dee/attachment.html