Skip to content

Commit 305b258

Browse files
committed
Fix CI, make COPY_META mode work
1 parent 62da18e commit 305b258

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

netfilterqueue.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ cdef enum:
169169
NF_MAX_VERDICT = NF_STOP
170170

171171
cdef class NetfilterQueue:
172+
cdef object __weakref__
172173
cdef object user_callback # User callback
173174
cdef nfq_handle *h # Handle to NFQueue library
174175
cdef nfq_q_handle *qh # A handle to the queue

netfilterqueue.pyx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ cdef class Packet:
8282

8383
self.payload_len = nfq_get_payload(nfa, &self.payload)
8484
if self.payload_len < 0:
85-
raise OSError("Failed to get payload of packet.")
85+
# Probably using a mode that doesn't provide the payload
86+
self.payload = NULL
87+
self.payload_len = 0
8688

8789
nfq_get_timestamp(nfa, &self.timestamp)
8890
self.mark = nfq_get_nfmark(nfa)
@@ -142,6 +144,10 @@ cdef class Packet:
142144
return self._owned_payload
143145
elif self.payload != NULL:
144146
return self.payload[:self.payload_len]
147+
elif self.payload_len == 0:
148+
raise RuntimeError(
149+
"Packet has no payload -- perhaps you're using COPY_META mode?"
150+
)
145151
else:
146152
raise RuntimeError(
147153
"Payload data is no longer available. You must call "
@@ -191,7 +197,6 @@ cdef class NetfilterQueue:
191197
cdef u_int16_t af # Address family
192198
af = kwargs.get("af", PF_INET)
193199

194-
self.unbinding = False
195200
self.h = nfq_open()
196201
if self.h == NULL:
197202
raise OSError("Failed to open NFQueue.")

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

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

6+
setup_requires = []
67
try:
78
# Use Cython
89
from Cython.Build import cythonize
910

10-
setup_requires = []
1111
ext_modules = cythonize(
1212
Extension(
1313
"netfilterqueue", ["netfilterqueue.pyx"], libraries=["netfilter_queue"]

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ async def run(self):
191191
# Tell each peer about the other one's port
192192
for idx in (1, 2):
193193
self.dest_addr[idx] = (
194-
PEER_IP[idx], int(await self._received[idx].receive())
194+
PEER_IP[idx],
195+
int(await self._received[idx].receive()),
195196
)
196197
await self._conn[3 - idx].send(b"%d" % self.dest_addr[idx][1])
197198
yield

tests/test_basic.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import time
1010
import weakref
1111

12-
from netfilterqueue import NetfilterQueue
12+
from netfilterqueue import NetfilterQueue, COPY_META
1313

1414

1515
async def test_comms_without_queue(harness):
@@ -94,6 +94,8 @@ async def test_mark_repeat(harness):
9494

9595
def cb(chan, pkt):
9696
nonlocal counter
97+
with pytest.raises(RuntimeError, match="Packet has no payload"):
98+
pkt.get_payload()
9799
assert pkt.get_mark() == counter
98100
timestamps.append(pkt.get_timestamp())
99101
if counter < 5:
@@ -104,7 +106,7 @@ def cb(chan, pkt):
104106
else:
105107
pkt.accept()
106108

107-
async with harness.capture_packets_to(2, cb):
109+
async with harness.capture_packets_to(2, cb, mode=COPY_META):
108110
t0 = time.time()
109111
await harness.send(2, b"testing")
110112
await harness.expect(2, b"testing")
@@ -155,7 +157,7 @@ async def listen_for_packets():
155157
(mac1, FORWARD, b"one"),
156158
(mac1, FORWARD, b"two"),
157159
(None, OUTPUT, b"three"),
158-
(None, OUTPUT, b"four")
160+
(None, OUTPUT, b"four"),
159161
]
160162

161163

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy