Use an actual warning, and avoid it in CI

This commit is contained in:
Joshua Oreman 2022-01-11 21:45:58 -07:00
parent 5d1d123be0
commit e7d451098b
2 changed files with 15 additions and 3 deletions

View File

@ -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."""

View File

@ -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: