Skip to content

Commit e7d4510

Browse files
committed
Use an actual warning, and avoid it in CI
1 parent 5d1d123 commit e7d4510

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

netfilterqueue.pyx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ DEF SockCopySize = MaxCopySize + SockOverhead
2424
# Socket queue should hold max number of packets of copysize bytes
2525
DEF SockRcvSize = DEFAULT_MAX_QUEUELEN * SockCopySize // 2
2626

27+
cdef extern from "Python.h":
28+
const char* __FILE__
29+
int __LINE__
30+
2731
cdef extern from *:
2832
"""
2933
#if PY_MAJOR_VERSION < 3
@@ -32,6 +36,7 @@ cdef extern from *:
3236
"""
3337

3438
import socket
39+
import warnings
3540
cimport cpython.version
3641

3742
cdef int global_callback(nfq_q_handle *qh, nfgenmsg *nfmsg,
@@ -215,9 +220,14 @@ cdef class NetfilterQueue:
215220

216221
nfq_set_queue_maxlen(self.qh, max_len)
217222

218-
newsiz = nfnl_rcvbufsiz(nfq_nfnlh(self.h),sock_len)
219-
if newsiz != sock_len*2:
220-
raise RuntimeWarning("Socket rcvbuf limit is now %d, requested %d." % (newsiz,sock_len))
223+
newsiz = nfnl_rcvbufsiz(nfq_nfnlh(self.h), sock_len)
224+
if newsiz != sock_len * 2:
225+
warnings.warn_explicit(
226+
"Socket rcvbuf limit is now %d, requested %d." % (newsiz, sock_len),
227+
category=RuntimeWarning,
228+
filename=__FILE__,
229+
lineno=__LINE__,
230+
)
221231

222232
def unbind(self):
223233
"""Destroy the queue."""

tests/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ def stash_packet(p):
206206
packets_w.send_nowait(p)
207207

208208
nfq = netfilterqueue.NetfilterQueue()
209+
# Use a smaller socket buffer to avoid a warning in CI
210+
options.setdefault("sock_len", 131072)
209211
if queue_num >= 0:
210212
nfq.bind(queue_num, stash_packet, **options)
211213
else:

0 commit comments

Comments
 (0)