LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Netfilter hooks (https://www.linuxquestions.org/questions/programming-9/netfilter-hooks-425236/)

mousars 03-15-2006 10:04 PM

Netfilter hooks
 
Hi folks,


I would like to register a module that I am writing to the NF_IP_FORWARD Hook in netfilter. The struct used for register is :


struct nf_hook_ops
{
struct list_head list;

/* User fills in from here down. */
nf_hookfn *hook;
int pf;
int hooknum;

/* Hooks are ordered in ascending priority. */
int priority;
};


And the hook function is a nf_hookfn, which is a typedef :


typedef unsigned int nf_hookfn(unsigned int hooknum,
struct sk_buff **skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *));


What is the parameter int (*okfn)(struct sk_buff *) which is passed to the hook ?

Any help would be greatly appreciated. Thank you so much for your time!

Ramirez

nx5000 03-16-2006 04:04 AM

Quote:

Originally Posted by mousars
What is the parameter int (*okfn)(struct sk_buff *) which is passed to the hook ?

Thats a C general question ( a pointer to a function that takes parameters )
Otherwise if its a netfilter question, have a look at this very simple example:
http://whatisthekernel.blogspot.com/...ter-hooks.html

How to obtain the declaration of a variable or a function:
    • Write on the left the natural description of the type
    • On the right, the identifier to declare (only one)
  1. While the left expression is not a base type, enum, struct or union, transform the two expressions like this:
    1. function returning an expl expr -> expl (expr)()
    2. array of expl expr -> expl (expr)[]
    3. pointer on expl expr -> expl *expr
As a side note, on rule (2.1) and (2.2) if expr is not of the form *exp, then parenthesis around expr can be ommited

Example:
int (*okfn)(struct sk_buff *)
Thats a pointer to a "function which takes as param a pointer to sk_buff , and returns int"

so:
left: the type , right the identifier (alone!)
  • Code:

    pointer to a func taking as param a pointer to sk_buff and returns int        okfn
  • Code:

    function which takes as param a pointer to sk_buff and returns int        *okfn
  • Code:

      int        (*okfn)(struct sk_buff*)
He have it.

As an exercise to the reader :)
void (*signal(int sig,int (*func)(int)))(int);

mousars 03-16-2006 12:22 PM

Hi,

Thanks for the link.

I went to the link, but it does not define the use of the (*okfn) function pointer.

Is it some pointer to a function that gets executed after the hook function returns? And if so, could I use this function for other purporses as well (instead of just after the hook function returns, like could i use it somewhere inside the hook function).

Thanks alot!

Ramirez


All times are GMT -5. The time now is 11:09 AM.