diff --git a/netfilterqueue.pyx b/netfilterqueue.pyx index 683d9fc..8240a76 100644 --- a/netfilterqueue.pyx +++ b/netfilterqueue.pyx @@ -24,6 +24,10 @@ 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 @@ -32,6 +36,7 @@ cdef extern from *: """ import socket +import warnings cimport cpython.version cdef int global_callback(nfq_q_handle *qh, nfgenmsg *nfmsg, @@ -215,9 +220,14 @@ cdef class NetfilterQueue: nfq_set_queue_maxlen(self.qh, max_len) - newsiz = nfnl_rcvbufsiz(nfq_nfnlh(self.h),sock_len) - if newsiz != sock_len*2: - raise RuntimeWarning("Socket rcvbuf limit is now %d, requested %d." % (newsiz,sock_len)) + newsiz = nfnl_rcvbufsiz(nfq_nfnlh(self.h), sock_len) + if newsiz != sock_len * 2: + warnings.warn_explicit( + "Socket rcvbuf limit is now %d, requested %d." % (newsiz, sock_len), + category=RuntimeWarning, + filename=__FILE__, + lineno=__LINE__, + ) def unbind(self): """Destroy the queue.""" diff --git a/tests/conftest.py b/tests/conftest.py index 02feb59..8cf71fd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -206,6 +206,8 @@ class Harness: packets_w.send_nowait(p) nfq = netfilterqueue.NetfilterQueue() + # Use a smaller socket buffer to avoid a warning in CI + options.setdefault("sock_len", 131072) if queue_num >= 0: nfq.bind(queue_num, stash_packet, **options) else: