Skip to contentSkip to conversation

How to register conntrack notifier

DISCUSSION Nils Rennebarth 3 participants 7 messages Oct 27, 2009 – Nov 13, 2009 netfilter

lore
Share & tools
lore
#0 lore raw

Hi,

The help text for NF_CONNTRACK_EVENTS reads:
If this option is enabled, the connection tracking code will provide a notifier chain that can be used by other kernel code to get notified about changes in the connection tracking state.
which sounds just like what I need: I want to execute a callback whenever a conntrack gets destroyed. However studying nf_conntrack_netlink.c, nf_conntrack_ecache.c and related header files for quite a while now, i am still unable to figure out how to do that.

Can someone enlighten me?

______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT! Jetzt freischalten unter http://movieflat.web.de

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#1 lore raw
Quoted 11 lines · Nils Rennebarth

Hi,

The help text for NF_CONNTRACK_EVENTS reads:
If this option is enabled, the connection tracking code will provide a notifier chain that can be used by other kernel code to get notified about changes in the connection tracking state.
which sounds just like what I need: I want to execute a callback whenever a conntrack gets destroyed. However studying nf_conntrack_netlink.c, nf_conntrack_ecache.c and related header files for quite a while now, i am still unable to figure out how to do that.

Quoted 1 line

Can someone enlighten me?

You have to register a structure nf_ct_event_notifier with the callback function, you have to look at nf_conntrack_ecache.c and nf_conntrack_netlink.c. There one problem though since you can only register one callback and that one is usually used by nf_conntrack_netlink.c

You can also catch events from user-space by means of libnetfilter_conntrack, have a look at utils/, it includes some examples.

#2 lore raw

Hi Pablo,
I was looking at conntrack events callbacks and conntrack tools too.
As you said in your mail, only one callback can be registered, so if nf_conntrack_netlink module is loaded, no other modules can register a callback for events.

If I correctly undertand the code, it seems that in the past kernels this limitation was not there. For example, 2.6.21.5 version had a notifier chain declared in nf_conntrack_ecache.c:

ATOMIC_NOTIFIER_HEAD(nf_conntrack_chain);

and nf_conntrack_register_notifier() simply adds an entry (callback block) to the chain, so many callbacks could be registered for conntrack events. Am I right?
Why has this been changed nowadays?

Thanks!
Luca

Quoted 19 lines · Pablo Neira Ayuso
Quoted 11 lines · Nils Rennebarth

Hi,

The help text for NF_CONNTRACK_EVENTS reads:
  If this option is enabled, the connection tracking code will provide a notifier chain that can be used by other kernel code to get notified about changes in the connection tracking state. which sounds just like what I need: I want to execute a callback whenever a conntrack gets destroyed. However studying nf_conntrack_netlink.c, nf_conntrack_ecache.c and related header files for quite a while now, i am still unable to figure out how to do that.

Quoted 1 line

Can someone enlighten me?

You have to register a structure nf_ct_event_notifier with the callback function, you have to look at nf_conntrack_ecache.c and nf_conntrack_netlink.c. There one problem though since you can only register one callback and that one is usually used by nf_conntrack_netlink.c

Quoted 7 lines

You can also catch events from user-space by means of libnetfilter_conntrack, have a look at utils/, it includes some examples. --
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 8 lines · Luca Pesce

Hi Pablo,
I was looking at conntrack events callbacks and conntrack tools too.
As you said in your mail, only one callback can be registered, so if nf_conntrack_netlink module is loaded, no other modules can register a callback for events.

If I correctly undertand the code, it seems that in the past kernels this limitation was not there.

Indeed. This limitation was introduced recently

Quoted 8 lines

For example, 2.6.21.5 version had a
notifier chain declared in nf_conntrack_ecache.c:

ATOMIC_NOTIFIER_HEAD(nf_conntrack_chain);

and nf_conntrack_register_notifier() simply adds an entry (callback block) to the chain, so many callbacks could be registered for conntrack events. Am I right?

Yes.

Quoted 1 line

Why has this been changed nowadays?

Because the notifier chain added too much overhead for the only single client (nf_conntrack_netlink) in the kernel code.

#4 lore raw

Ok, so newer kernels opted for performance, giving that on 99% of the time only nf_conntrack_netlink uses event notifier callbacks, which is usually the case...
But I am curious...what if another kernel module needs to receive conntrack events? Are there any way to keep track of events in kernel space while nf_conntrack_netlink is holding the one and only callback hook?
Thanks Pablo!
Luca

Quoted 22 lines · Pablo Neira Ayuso
Quoted 9 lines · Luca Pesce

Hi Pablo,
  I was looking at conntrack events callbacks and conntrack tools too. As you said in your mail, only one callback can be registered, so if nf_conntrack_netlink module is loaded, no other modules can register a callback for events.

If I correctly undertand the code, it seems that in the past kernels this limitation was not there.

Indeed. This limitation was introduced recently

Quoted 8 lines

For example, 2.6.21.5 version had a
notifier chain declared in nf_conntrack_ecache.c:

ATOMIC_NOTIFIER_HEAD(nf_conntrack_chain);

and nf_conntrack_register_notifier() simply adds an entry (callback block) to the chain, so many callbacks could be registered for conntrack events. Am I right?

Quoted 7 lines

Yes.

Quoted 1 line

Why has this been changed nowadays?

Because the notifier chain added too much overhead for the only single client (nf_conntrack_netlink) in the kernel code.

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 3 lines · Luca Pesce

Ok, so newer kernels opted for performance, giving that on 99% of the time only nf_conntrack_netlink uses event notifier callbacks, which is usually the case...

Looking at the kernel code, there's no other client of that notifier chain that ctnetlink.

Quoted 4 lines

But I am curious...what if another kernel module needs to receive conntrack events? Are there any way to keep track of events in kernel space while nf_conntrack_netlink is holding the one and only callback hook?

Then, that new module would need to be submitted to mainline. Of course it should be something that proves to be useful for the general public. Sorry, we won't introduce the notifier chain again for an out-of-tree module.

#6 lore raw

Ok, perfectly clear.
Thanks Pablo!
Luca

Quoted 18 lines · Pablo Neira Ayuso
Quoted 4 lines · Luca Pesce

Ok, so newer kernels opted for performance, giving that on 99% of the time only nf_conntrack_netlink uses event notifier callbacks, which is usually the case...

Looking at the kernel code, there's no other client of that notifier chain that ctnetlink.

Quoted 4 lines

But I am curious...what if another kernel module needs to receive conntrack events? Are there any way to keep track of events in kernel space while nf_conntrack_netlink is holding the one and only callback hook?

Then, that new module would need to be submitted to mainline. Of course it should be something that proves to be useful for the general public. Sorry, we won't introduce the notifier chain again for an out-of-tree module.