Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nfhook (netfilter) error: assignment from incompatible pointer type

I have seen this page with similar error message: Nf_hook_ops returns incompatible pointer when assigning to hook_func -C -Linux -Netfilter

However, it didn't give a clear answer to how to solve the issue. The author for that question says that he found out his netfilter.h is located elsewhere which caused the trouble, but for me I found out that all the four files included are in the correct directory (usr/src/linux-headers-4.8.0-22-generic/include/linux in my case).

Following is my code which should help clarify better.

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>

static struct nf_hook_ops nfho;

unsigned int hook_func_incoming(unsigned int hooknum, struct sk_buff *sskb, 
const struct net_device *in, const struct net_device *out, int (*okfn)
(struct sk_buff *)){
    return NF_DROP;
}

int init_module(){
    nfho.hook = hook_func_incoming;
    nfho.hooknum = NF_INET_PRE_ROUTING;
    nfho.pf = PF_INET;
    nfho.priority = NF_IP_PRI_FIRST;
    nf_register_hook(&nfho);
    printk(KERN_INFO "SIMPLE FIREWALL LOADED\n");
    return 0;
}

The exact error message is this:

error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types] nfho.hook = hook_func_incoming; ^ cc1: some warnings being treated as errors

Please let me know what I should do to be able to compile my netfilter, any help is appreciated!

like image 371
DataScienceExplorer Avatar asked May 24 '17 05:05

DataScienceExplorer


1 Answers

In the (IMHO) latest (released) netfilter version, nf_hookfn (the base type of nf_hook_ops.hook) is defined as follows:

typedef unsigned int nf_hookfn(void *priv,
                   struct sk_buff *skb,
                   const struct nf_hook_state *state);

Your function hook_func_incoming does not match this signature, you should adopt it.

like image 113
Matthias Avatar answered Oct 23 '22 05:10

Matthias