A few month ago I needed python bindings for the nfqueue netfilter library (libnetfilter_queue).

I was going to write them myself since I found none, but then I stumbled across this on the netfilter mailing list.

I like this wrapper because it is simple and the code is clear. I was able to adapt my work to them very quickly.

There were some little problems though.


First of all the unchanged code cannot be used in multithreaded programs (see http://www.python.org/doc/api/threads.html).

So I wrote a little patch which adds the necessary Py_BEGIN_ALLOW_THREADS and a "stop" function to stop the queue.

The code can be found here:


The second problem appears only on Linux >=2.6.23 (see http://www.spinics.net/lists/netfilter/msg42063.html).

Here is the patch:


Special thanks to Mathieu Geli for this wrapper, it helped me a lot and saved time in my work.

By the way, I found new nfqueue bindings based on SWIG that look nice. They are brand new, but I haven't tested them yet.

Links: