Skip to main content

Fast python library encapsulating the nfqueue netlink interface.

Project description

fnfqueue

Build Status Python Versions PyPI - License

Fast netfilter nfqueue python and C interface. Gets the speed from

  • avoiding memory allocation
  • batching reads (uses recv_mmsg)

It also does not use the callback-like interface of libnetfilter-queue and provides a more python like iterator interface. Additionally, it doesn't assume anything and therefore doesn't automatically set verdicts on packets (unlike python-nfqueue in debian which accepts everything after you return from the callback...)

It can handle ping -f (even iperf if the moon is in the right spot) to localhost from within python.

Focus is on a python like interface.

Short example for mangling packets:

iptables -A OUTPUT <filter here> -j NFQUEUE --queue-num 1
import fnfqueue

queue = 1
conn = fnfqueue.Connection()

try:
    q = conn.bind(queue)
    q.set_mode(0xffff, fnfqueue.COPY_PACKET)
except PermissionError:
    print("Access denied; Do I have root rights or the needed capabilities?")
    sys.exit(-1)

while True:
    try:
        for packet in conn:
            packet.payload = packet.payload # modify the packet here
            packet.mangle()
    except fnfqueue.BufferOverflowException:
        print("buffer error")
        pass

conn.close() # this can be called concurrently to cancel the above for loop

Help is provided as python docs.

No C libraries are needed. Needs cffi for building. Kernel and libc must be recent enough to support nfqueue and recvmmsg (linux 2.6.33, glibc 2.12 - more recent kernels provide better performance).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fnfqueue-1.1.2.tar.gz (14.5 kB view hashes)

Uploaded Source

Built Distributions

fnfqueue-1.1.2-pp39-pypy39_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_28_x86_64.whl (16.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.28+ x86-64

fnfqueue-1.1.2-pp38-pypy38_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_28_x86_64.whl (16.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.28+ x86-64

fnfqueue-1.1.2-pp37-pypy37_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_28_x86_64.whl (16.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.28+ x86-64

fnfqueue-1.1.2-cp311-cp311-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_28_x86_64.whl (46.7 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.28+ x86-64

fnfqueue-1.1.2-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_28_x86_64.whl (46.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.28+ x86-64

fnfqueue-1.1.2-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_28_x86_64.whl (46.7 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.28+ x86-64

fnfqueue-1.1.2-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_28_x86_64.whl (46.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.28+ x86-64

fnfqueue-1.1.2-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_28_x86_64.whl (46.6 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.28+ x86-64

fnfqueue-1.1.2-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_28_x86_64.whl (46.6 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.28+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page