invalid pointer initialization

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ricardopf
    New Member
    • Mar 2009
    • 5

    invalid pointer initialization

    Hello all,

    I'm facing some problems to compile a new module for Linux Ubuntu 8.04, kernel version 2.6. Above are two pieces of code related to the problem.

    linux/netfilter.h
    Code:
    //begin netfilter
    ...
    typedef unsigned int nf_hookfn(unsigned int hooknum, struct sk_buff *skb, const struct net_devide *in, const struct net_device *out, int (*okfn)(struct sk_buff *));
    ...
    struct nf_hook_ops {
    struct list_head list;
    nf_hookfn *hook;
    struct module *owner;
    int pf;
    int hooknum;
    int priority;
    };
    ...
    // end netfilter
    myfile.h
    Code:
    // begin myfile
    ...
    #include <netfilter.h>
    ...
    unsigned int my_nf_hook(unsigned int hook, struct sk_buff **skb, const struct net_device *indev, const struct net_device *outdev, int (*okfn)(struct sk_buff *)); // It is a function that is further implemented
    ...
    static struct nf_hook_ops nfh_pre = {
    {NULL, NULL},
    my_nf_hook,
    THIS_MODULE,
    PF_INET,
    NF_IP_PRE_ROUTING,
    NF_IP_PRI_FILTER+1
    };
    ...
    // end myfile
    When I execute the 'make myfile.ko' to compile the module, it gives me the following warning:

    ... warning: initialization from incompatible pointer type

    This warning is pointing the line '9. my_nf_hook' inside the struct nfh_pre initialization.

    Well, after compiling, the ko file is generated. However, when I execute the command 'insmod myfile.ko' to load the module, it results in kernel panic. I believe that the warning is directed related to the problem.

    Finally, my question: does anybody know where is the problem in the code above? What could be missing?

    Thanks a lot in advance for repliers.
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    Is it struct sk_buff **skb or struct sk_buff *skb in function args ? ( number of *'s )

    Comment

    • ricardopf
      New Member
      • Mar 2009
      • 5

      #3
      That's right... it is **

      Comment

      • ricardopf
        New Member
        • Mar 2009
        • 5

        #4
        Problem solved

        Indeed, the pointer to pointer was the problem.
        However, who is implementing with netfilter.h needs to be careful about that. From kernel 2.6.20 (I guess) it is a pointer only to skb sk_buff structure. But, from 2.6.19 version and lesser ones it is a double pointer (**skb).
        Last edited by ricardopf; Mar 17 '09, 05:41 PM. Reason: Problem solved

        Comment

        Working...