Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
v0.9.0, unreleased
v0.9.0, 12 Jan 2021
Improve usability when Packet objects are retained past the callback
Add Packet.retain() to save the packet contents in such cases
Eliminate warnings during build on py3
Add CI and basic test suite
Raise a warning, not an error, if we don't get the bufsize we want
Don't allow bind() more than once on the same NetfilterQueue, since
that would leak the old queue handle
Don't allow bind() more than once on the same NetfilterQueue, since that would leak the old queue handle
** This will be the last version with support for Python 2.7. **

v0.8.1, 30 Jan 2017
Fix bug #25- crashing when used in OUTPUT or POSTROUTING chains
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ include *.rst
include *.c
include *.pyx
include *.pxd
recursive-include tests/ *.py
5 changes: 5 additions & 0 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ set -ex -o pipefail
pip install -U pip setuptools wheel
sudo apt-get install libnetfilter-queue-dev

# Cython is required to build the sdist...
pip install cython
python setup.py sdist --formats=zip

# ... but not to install it
pip uninstall -y cython
pip install dist/*.zip

if python --version 2>&1 | fgrep -q "Python 2.7"; then
Expand Down
18 changes: 6 additions & 12 deletions netfilterqueue.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function.
Copyright: (c) 2011, Kerkhoff Technologies Inc.
License: MIT; see LICENSE.txt
"""
VERSION = (0, 8, 1)
VERSION = (0, 9, 0)

# Constants for module users
COPY_NONE = 0
Expand All @@ -24,21 +24,13 @@ DEF SockCopySize = MaxCopySize + SockOverhead
# Socket queue should hold max number of packets of copysize bytes
DEF SockRcvSize = DEFAULT_MAX_QUEUELEN * SockCopySize // 2

cdef extern from "Python.h":
const char* __FILE__
int __LINE__

cdef extern from *:
"""
#if PY_MAJOR_VERSION < 3
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
#endif
"""

import socket
import warnings
cimport cpython.version

cdef int global_callback(nfq_q_handle *qh, nfgenmsg *nfmsg,
nfq_data *nfa, void *data) with gil:
"""Create a Packet and pass it to appropriate callback."""
Expand Down Expand Up @@ -227,11 +219,11 @@ cdef class NetfilterQueue:
newsiz = nfnl_rcvbufsiz(nfq_nfnlh(self.h), sock_len)
if newsiz != sock_len * 2:
try:
warnings.warn_explicit(
import warnings

warnings.warn(
"Socket rcvbuf limit is now %d, requested %d." % (newsiz, sock_len),
category=RuntimeWarning,
filename=bytes(__FILE__).decode("ascii"),
lineno=__LINE__,
)
except: # if warnings are being treated as errors
self.unbind()
Expand Down Expand Up @@ -267,6 +259,8 @@ cdef class NetfilterQueue:

def run_socket(self, s):
"""Accept packets using socket.recv so that, for example, gevent can monkeypatch it."""
import socket

while True:
try:
buf = s.recv(BufferSize)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools >= 42", "wheel", "cython"]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
11 changes: 10 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os, sys
from setuptools import setup, Extension

VERSION = "0.8.1" # Remember to change CHANGES.txt and netfilterqueue.pyx when version changes.
VERSION = "0.9.0" # Remember to change CHANGES.txt and netfilterqueue.pyx when version changes.

try:
# Use Cython
Expand All @@ -14,6 +15,14 @@
)
except ImportError:
# No Cython
if not os.path.exists(os.path.join(os.path.dirname(__file__), "netfilterqueue.c")):
sys.stderr.write(
"You must have Cython installed (`pip install cython`) to build this "
"package from source.\nIf you're receiving this error when installing from "
"PyPI, please file a bug report at "
"https://github.com/oremanj/python-netfilterqueue/issues/new\n"
)
sys.exit(1)
ext_modules = [
Extension("netfilterqueue", ["netfilterqueue.c"], libraries=["netfilter_queue"])
]
Expand Down
1 change: 0 additions & 1 deletion test-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ pytest
trio
pytest-trio
async_generator
cython
black
platformdirs <= 2.4.0 # needed by black; 2.4.1+ don't support py3.6
2 changes: 0 additions & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ black==21.12b0
# via -r test-requirements.in
click==8.0.3
# via black
cython==0.29.26
# via -r test-requirements.in
idna==3.3
# via trio
iniconfig==1.1.1
Expand Down
4 changes: 3 additions & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ def set_udp_payload(p, msg):


async def test_errors(harness):
with pytest.warns(RuntimeWarning, match="rcvbuf limit is"):
with pytest.warns(RuntimeWarning, match="rcvbuf limit is") as record:
async with harness.capture_packets_to(2, sock_len=2 ** 30):
pass

assert record[0].filename.endswith("conftest.py")

async with harness.capture_packets_to(2, queue_num=0):
with pytest.raises(OSError, match="Failed to create queue"):
async with harness.capture_packets_to(2, queue_num=0):
Expand Down