Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-15-2006, 11:04 PM   #1
LQ Newbie
Registered: Feb 2006
Posts: 6

Rep: Reputation: 0
Post 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!

Old 03-16-2006, 05:04 AM   #2
Senior Member
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 55
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:

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

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

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);
Old 03-16-2006, 01:22 PM   #3
LQ Newbie
Registered: Feb 2006
Posts: 6

Original Poster
Rep: Reputation: 0

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!



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Keyboard hooks icemanind Programming 3 07-19-2006 06:01 AM
Can't remove sendmail hooks sixerjman Linux - Software 1 01-27-2006 07:10 PM
about mac layer lsm hooks chandakumesh Linux - Wireless Networking 2 08-26-2005 04:09 PM
about mac layer hooks chandakumesh Linux - Networking 1 08-26-2005 03:47 PM
mutt hooks cbb Linux - Software 2 08-14-2005 02:51 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:47 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration