From e7d451098ba132e4696049ea3cea285536a1213b Mon Sep 17 00:00:00 2001 From: Joshua Oreman Date: Tue, 11 Jan 2022 21:45:58 -0700 Subject: [PATCH] Use an actual warning, and avoid it in CI --- netfilterqueue.pyx | 16 +++++++++++++--- tests/conftest.py | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) 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: