0

I have written a pre route hook function in my LKM. When I try to compile it, it gives me below warning

/home/sample/kmod-sample/kernel/kmod_sample.h:159:9: warning: initialization from incompatible pointer type [enabled by default]
         .hook           = sample_prerouting_hook,
         ^
/home/sample/kmod-sample/kernel/kmod_sample.h:159:9: warning: (near initialization for ‘sample_prerouting_ops.hook’) [enabled by default]

Below is my code in module header file named sample.h

static unsigned int sample_prerouting_hook (
        unsigned int hook,
        struct sk_buff *pskb,
        const struct net_device *in,
        const struct net_device *out,
        int (*okfn)(struct sk_buff*)
);

static struct nf_hook_ops sample_prerouting_ops = {
        .hook           = sample_prerouting_hook,
        .owner          = THIS_MODULE,
        .pf             = PF_INET,
        .hooknum        = NF_INET_PRE_ROUTING,
        .priority       = NF_IP_PRI_LAST,
};

What can I do to resolve this warning ??

Vandan
  • 1
  • 3
  • "What can I do to resolve this warning ??" - You need to initialize `.hook` field with the function of **proper type** (signature), which is compatible with the type of the field. Without **your code** it is impossible to be more specific. It is a **requirement** of the Stack Overflow to provide the code in the question post. – Tsyvarev Apr 18 '22 at 08:10
  • i have added code now – Vandan Apr 18 '22 at 08:20
  • Does this answer your question? [Compilation error when creating a Netfilter kernel module](https://stackoverflow.com/questions/55106789/compilation-error-when-creating-a-netfilter-kernel-module) – Tsyvarev Apr 18 '22 at 08:28
  • yes my friend, it did. thanks. – Vandan Apr 18 '22 at 09:32

0 Answers0