* Why I can't compile a simple netfilter hook module?
@ 2012-05-08 4:07 Chir0n
2012-05-08 4:19 ` rohan puri
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Chir0n @ 2012-05-08 4:07 UTC (permalink / raw)
To: 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 <linux/kernel.h>
#include <linux/module.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
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/20120508/209e801c/attachment.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Why I can't compile a simple netfilter hook module?
2012-05-08 4:07 Why I can't compile a simple netfilter hook module? Chir0n
@ 2012-05-08 4:19 ` rohan puri
2012-05-08 13:40 ` Dexter
2012-05-08 14:01 ` rohan puri
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: rohan puri @ 2012-05-08 4:19 UTC (permalink / raw)
To: kernelnewbies
On Tue, May 8, 2012 at 9:37 AM, Chir0n <io.chir0n@gmail.com> wrote:
> 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 <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/netfilter.h>
> #include <linux/netfilter_ipv4.h>
>
> 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*
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> Hi,
You need to include header which defines "*NF_IP_PRE_ROUTING"*
*
*
*- *Rohan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120508/22e71820/attachment.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Why I can't compile a simple netfilter hook module?
2012-05-08 4:19 ` rohan puri
@ 2012-05-08 13:40 ` Dexter
0 siblings, 0 replies; 6+ messages in thread
From: Dexter @ 2012-05-08 13:40 UTC (permalink / raw)
To: kernelnewbies
On Tue, 2012-05-08 at 09:49 +0530, rohan puri wrote:
>
>
> On Tue, May 8, 2012 at 9:37 AM, Chir0n <io.chir0n@gmail.com> wrote:
> 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 <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/netfilter.h>
> #include <linux/netfilter_ipv4.h>
>
> 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
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> Hi,
>
>
> You need to include header which defines "NF_IP_PRE_ROUTING"
>
>
> - Rohan
Hi,
But I have declared this header:
#include <linux/netfilter_ipv4.h>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Why I can't compile a simple netfilter hook module?
2012-05-08 4:07 Why I can't compile a simple netfilter hook module? Chir0n
2012-05-08 4:19 ` rohan puri
@ 2012-05-08 14:01 ` rohan puri
2012-05-22 4:38 ` 回复: " c265n46
2012-05-22 15:08 ` Jonathan Neuschäfer
3 siblings, 0 replies; 6+ messages in thread
From: rohan puri @ 2012-05-08 14:01 UTC (permalink / raw)
To: kernelnewbies
On Tue, May 8, 2012 at 9:37 AM, Chir0n <io.chir0n@gmail.com> wrote:
> 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 <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/netfilter.h>
> #include <linux/netfilter_ipv4.h>
>
> 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]
> *
you may have declared the header, thn check whether the path is correct or
the symbol name spelling.
> * /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*
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> Also dont delete previous mail thread contents.
- Rohan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120508/2c5913da/attachment-0001.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* 回复: Why I can't compile a simple netfilter hook module?
2012-05-08 4:07 Why I can't compile a simple netfilter hook module? Chir0n
2012-05-08 4:19 ` rohan puri
2012-05-08 14:01 ` rohan puri
@ 2012-05-22 4:38 ` c265n46
2012-05-22 15:08 ` Jonathan Neuschäfer
3 siblings, 0 replies; 6+ messages in thread
From: c265n46 @ 2012-05-22 4:38 UTC (permalink / raw)
To: kernelnewbies
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"<kernelnewbies@kernelnewbies.org>
???
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 <linux/kernel.h>
#include <linux/module.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Why I can't compile a simple netfilter hook module?
2012-05-08 4:07 Why I can't compile a simple netfilter hook module? Chir0n
` (2 preceding siblings ...)
2012-05-22 4:38 ` 回复: " c265n46
@ 2012-05-22 15:08 ` Jonathan Neuschäfer
3 siblings, 0 replies; 6+ messages in thread
From: Jonathan Neuschäfer @ 2012-05-22 15:08 UTC (permalink / raw)
To: kernelnewbies
On Tue, May 08, 2012 at 01:07:43AM -0300, Chir0n wrote:
> /home/fabio/Desktop/modules/hello.c:19:18: error: ?NF_IP_PRE_ROUTING?
> undeclared (first use in this function)
This symbol is declared in a section that's "only for userspace
compatibility" (netfilter_ipv4.h, line 10).
HTH,
Jonathan Neusch?fer
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-05-22 15:08 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-08 4:07 Why I can't compile a simple netfilter hook module? Chir0n
2012-05-08 4:19 ` rohan puri
2012-05-08 13:40 ` Dexter
2012-05-08 14:01 ` rohan puri
2012-05-22 4:38 ` 回复: " c265n46
2012-05-22 15:08 ` Jonathan Neuschäfer
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.