How to register conntrack notifier
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
Pablo Neira Ayuso
maintainerQuoted 11 lines · Nils Rennebarth
Hi,
The help text for
NF_CONNTRACK_EVENTSreads:
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 studyingnf_conntrack_netlink.c,nf_conntrack_ecache.cand 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.
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_EVENTSreads:
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 studyingnf_conntrack_netlink.c,nf_conntrack_ecache.cand 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_notifierwith the callback function, you have to look atnf_conntrack_ecache.candnf_conntrack_netlink.c. There one problem though since you can only register one callback and that one is usually used bynf_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
Pablo Neira Ayuso
maintainerQuoted 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 ifnf_conntrack_netlinkmodule 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 innf_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.
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 ifnf_conntrack_netlinkmodule 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 innf_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
Pablo Neira Ayuso
maintainerQuoted 3 lines · Luca Pesce
Ok, so newer kernels opted for performance, giving that on 99% of the time only
nf_conntrack_netlinkuses 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_netlinkis 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.
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_netlinkuses 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_netlinkis 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.