File tree Expand file tree Collapse file tree 5 files changed +16
-7
lines changed Expand file tree Collapse file tree 5 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -169,6 +169,7 @@ cdef enum:
169
169
NF_MAX_VERDICT = NF_STOP
170
170
171
171
cdef class NetfilterQueue:
172
+ cdef object __weakref__
172
173
cdef object user_callback # User callback
173
174
cdef nfq_handle * h # Handle to NFQueue library
174
175
cdef nfq_q_handle * qh # A handle to the queue
Original file line number Diff line number Diff line change @@ -82,7 +82,9 @@ cdef class Packet:
82
82
83
83
self .payload_len = nfq_get_payload(nfa, & self .payload)
84
84
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
86
88
87
89
nfq_get_timestamp(nfa, & self .timestamp)
88
90
self .mark = nfq_get_nfmark(nfa)
@@ -142,6 +144,10 @@ cdef class Packet:
142
144
return self ._owned_payload
143
145
elif self .payload != NULL :
144
146
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
+ )
145
151
else :
146
152
raise RuntimeError (
147
153
" Payload data is no longer available. You must call "
@@ -191,7 +197,6 @@ cdef class NetfilterQueue:
191
197
cdef u_int16_t af # Address family
192
198
af = kwargs.get(" af" , PF_INET)
193
199
194
- self .unbinding = False
195
200
self .h = nfq_open()
196
201
if self .h == NULL :
197
202
raise OSError (" Failed to open NFQueue." )
Original file line number Diff line number Diff line change 3
3
4
4
VERSION = "0.9.0" # Remember to change CHANGES.txt and netfilterqueue.pyx when version changes.
5
5
6
+ setup_requires = []
6
7
try :
7
8
# Use Cython
8
9
from Cython .Build import cythonize
9
10
10
- setup_requires = []
11
11
ext_modules = cythonize (
12
12
Extension (
13
13
"netfilterqueue" , ["netfilterqueue.pyx" ], libraries = ["netfilter_queue" ]
Original file line number Diff line number Diff line change @@ -191,7 +191,8 @@ async def run(self):
191
191
# Tell each peer about the other one's port
192
192
for idx in (1 , 2 ):
193
193
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 ()),
195
196
)
196
197
await self ._conn [3 - idx ].send (b"%d" % self .dest_addr [idx ][1 ])
197
198
yield
Original file line number Diff line number Diff line change 9
9
import time
10
10
import weakref
11
11
12
- from netfilterqueue import NetfilterQueue
12
+ from netfilterqueue import NetfilterQueue , COPY_META
13
13
14
14
15
15
async def test_comms_without_queue (harness ):
@@ -94,6 +94,8 @@ async def test_mark_repeat(harness):
94
94
95
95
def cb (chan , pkt ):
96
96
nonlocal counter
97
+ with pytest .raises (RuntimeError , match = "Packet has no payload" ):
98
+ pkt .get_payload ()
97
99
assert pkt .get_mark () == counter
98
100
timestamps .append (pkt .get_timestamp ())
99
101
if counter < 5 :
@@ -104,7 +106,7 @@ def cb(chan, pkt):
104
106
else :
105
107
pkt .accept ()
106
108
107
- async with harness .capture_packets_to (2 , cb ):
109
+ async with harness .capture_packets_to (2 , cb , mode = COPY_META ):
108
110
t0 = time .time ()
109
111
await harness .send (2 , b"testing" )
110
112
await harness .expect (2 , b"testing" )
@@ -155,7 +157,7 @@ async def listen_for_packets():
155
157
(mac1 , FORWARD , b"one" ),
156
158
(mac1 , FORWARD , b"two" ),
157
159
(None , OUTPUT , b"three" ),
158
- (None , OUTPUT , b"four" )
160
+ (None , OUTPUT , b"four" ),
159
161
]
160
162
161
163
You can’t perform that action at this time.
0 commit comments