LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 03-15-2006, 10:04 PM   #1
mousars
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!

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

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

Original Poster
Rep: Reputation: 0
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
 
  


Reply


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 05:01 AM
Can't remove sendmail hooks sixerjman Linux - Software 1 01-27-2006 06:10 PM
about mac layer lsm hooks chandakumesh Linux - Wireless Networking 2 08-26-2005 03:09 PM
about mac layer hooks chandakumesh Linux - Networking 1 08-26-2005 02:47 PM
mutt hooks cbb Linux - Software 2 08-14-2005 01:51 PM


All times are GMT -5. The time now is 08:05 AM.

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