Skip to content

Commit 92b449b

Browse files
author
Joel 'Aaron' Cohen
committed
Fix whitespace
1 parent 25ae322 commit 92b449b

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

netfilterqueue.pxd

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ cdef extern from "libnetfilter_queue/linux_nfnetlink_queue.h":
7878
u_int32_t packet_id
7979
u_int16_t hw_protocol
8080
u_int8_t hook
81-
81+
8282
cdef extern from "libnetfilter_queue/libnetfilter_queue.h":
8383
struct nfq_handle:
8484
pass
@@ -88,10 +88,10 @@ cdef extern from "libnetfilter_queue/libnetfilter_queue.h":
8888
pass
8989
struct nfqnl_msg_packet_hw:
9090
u_int8_t hw_addr[8]
91-
91+
9292
nfq_handle *nfq_open()
9393
int nfq_close(nfq_handle *h)
94-
94+
9595
int nfq_bind_pf(nfq_handle *h, u_int16_t pf)
9696
int nfq_unbind_pf(nfq_handle *h, u_int16_t pf)
9797
ctypedef int *nfq_callback(nfq_q_handle *gh, nfgenmsg *nfmsg,
@@ -101,21 +101,21 @@ cdef extern from "libnetfilter_queue/libnetfilter_queue.h":
101101
nfq_callback *cb,
102102
void *data)
103103
int nfq_destroy_queue(nfq_q_handle *qh)
104-
104+
105105
int nfq_handle_packet(nfq_handle *h, char *buf, int len)
106-
106+
107107
int nfq_set_mode(nfq_q_handle *qh,
108108
u_int8_t mode, unsigned int len)
109-
109+
110110
q_set_queue_maxlen(nfq_q_handle *qh,
111111
u_int32_t queuelen)
112-
112+
113113
int nfq_set_verdict(nfq_q_handle *qh,
114114
u_int32_t id,
115115
u_int32_t verdict,
116116
u_int32_t data_len,
117117
unsigned char *buf) nogil
118-
118+
119119
int nfq_set_verdict_mark(nfq_q_handle *qh,
120120
u_int32_t id,
121121
u_int32_t verdict,
@@ -130,15 +130,15 @@ cdef extern from "libnetfilter_queue/libnetfilter_queue.h":
130130
int nfq_get_timestamp(nfq_data *nfad, timeval *tv)
131131
nfqnl_msg_packet_hw *nfq_get_packet_hw(nfq_data *nfad)
132132
int nfq_get_nfmark (nfq_data *nfad)
133-
133+
134134
# Dummy defines from linux/socket.h:
135135
cdef enum: # Protocol families, same as address families.
136136
PF_INET = 2
137137
PF_INET6 = 10
138138

139139
cdef extern from "sys/socket.h":
140140
ssize_t recv(int __fd, void *__buf, size_t __n, int __flags) nogil
141-
141+
142142
# Dummy defines from linux/netfilter.h
143143
cdef enum:
144144
NF_DROP
@@ -153,18 +153,18 @@ cdef class Packet:
153153
cdef nfq_q_handle *_qh
154154
cdef nfq_data *_nfa
155155
cdef nfqnl_msg_packet_hdr *_hdr
156-
cdef bint _verdict_is_set # True if verdict has been issued,
156+
cdef bint _verdict_is_set # True if verdict has been issued,
157157
# false otherwise
158158
cdef bint _mark_is_set # True if a mark has been given, false otherwise
159159
cdef u_int32_t _given_mark # Mark given to packet
160160
cdef bytes _given_payload # New payload of packet, or null
161-
161+
162162
# From NFQ packet header:
163163
cdef readonly u_int32_t id
164164
cdef readonly u_int16_t hw_protocol
165165
cdef readonly u_int8_t hook
166166
cdef readonly u_int32_t mark
167-
167+
168168
# Packet details:
169169
cdef Py_ssize_t payload_len
170170
cdef readonly char *payload
@@ -176,7 +176,7 @@ cdef class Packet:
176176
#cdef readonly u_int32_t physindev
177177
#cdef readonly u_int32_t outdev
178178
#cdef readonly u_int32_t physoutdev
179-
179+
180180
cdef set_nfq_data(self, nfq_q_handle *qh, nfq_data *nfa)
181181
cdef void verdict(self, u_int8_t verdict)
182182
cpdef Py_ssize_t get_payload_len(self)
@@ -187,12 +187,12 @@ cdef class Packet:
187187
cpdef accept(self)
188188
cpdef drop(self)
189189
cpdef repeat(self)
190-
190+
191191
cdef class NetfilterQueue:
192192
cdef object user_callback # User callback
193193
cdef nfq_handle *h # Handle to NFQueue library
194194
cdef nfq_q_handle *qh # A handle to the queue
195195
cdef u_int16_t af # Address family
196196
cdef packet_copy_size # Amount of packet metadata + data copied to buffer
197197
cpdef run2(self)
198-
198+

netfilterqueue.pyx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Bind to a Linux netfilter queue. Send packets to a user-specified callback
2+
Bind to a Linux netfilter queue. Send packets to a user-specified callback
33
function.
44
55
Copyright: (c) 2011, Kerkhoff Technologies Inc.
@@ -20,7 +20,7 @@ DEF BufferSize = 4096
2020
DEF MetadataSize = 80
2121
DEF MaxCopySize = BufferSize - MetadataSize
2222

23-
cdef int global_callback(nfq_q_handle *qh, nfgenmsg *nfmsg,
23+
cdef int global_callback(nfq_q_handle *qh, nfgenmsg *nfmsg,
2424
nfq_data *nfa, void *data) with gil:
2525
"""Create a Packet and pass it to appropriate callback."""
2626
cdef NetfilterQueue nfqueue = <NetfilterQueue>data
@@ -37,29 +37,29 @@ cdef class Packet:
3737
self._verdict_is_set = False
3838
self._mark_is_set = False
3939
self._given_payload = None
40-
40+
4141
def __str__(self):
4242
cdef iphdr *hdr = <iphdr*>self.payload
4343
protocol = PROTOCOLS.get(hdr.protocol, "Unknown protocol")
4444
return "%s packet, %s bytes" % (protocol, self.payload_len)
45-
45+
4646
cdef set_nfq_data(self, nfq_q_handle *qh, nfq_data *nfa):
4747
"""
48-
Assign a packet from NFQ to this object. Parse the header and load
48+
Assign a packet from NFQ to this object. Parse the header and load
4949
local values.
5050
"""
5151
self._qh = qh
5252
self._nfa = nfa
5353
self._hdr = nfq_get_msg_packet_hdr(nfa)
54-
54+
5555
self.id = ntohl(self._hdr.packet_id)
5656
self.hw_protocol = ntohs(self._hdr.hw_protocol)
5757
self.hook = self._hdr.hook
58-
58+
5959
self.payload_len = nfq_get_payload(self._nfa, &self.payload)
6060
if self.payload_len < 0:
6161
raise OSError("Failed to get payload of packet.")
62-
62+
6363
nfq_get_timestamp(self._nfa, &self.timestamp)
6464
self.mark = nfq_get_nfmark(nfa)
6565

@@ -69,7 +69,7 @@ cdef class Packet:
6969
raise RuntimeWarning("Verdict already given for this packet.")
7070

7171
cdef u_int32_t modified_payload_len = 0
72-
cdef unsigned char *modified_payload = NULL
72+
cdef unsigned char *modified_payload = NULL
7373
if self._given_payload:
7474
modified_payload_len = len(self._given_payload)
7575
modified_payload = self._given_payload
@@ -90,21 +90,21 @@ cdef class Packet:
9090
modified_payload)
9191

9292
self._verdict_is_set = True
93-
93+
9494
def get_payload(self):
9595
"""Return payload as Python string."""
9696
return self.payload[:self.payload_len]
9797

9898
cpdef Py_ssize_t get_payload_len(self):
9999
return self.payload_len
100-
100+
101101
cpdef double get_timestamp(self):
102102
return self.timestamp.tv_sec + (self.timestamp.tv_usec/1000000.0)
103-
103+
104104
cpdef set_payload(self, bytes payload):
105105
"""Set the new payload of this packet."""
106106
self._given_payload = payload
107-
107+
108108
cpdef set_mark(self, u_int32_t mark):
109109
self._given_mark = mark
110110
self._mark_is_set = True
@@ -113,11 +113,11 @@ cdef class Packet:
113113
if self._mark_is_set:
114114
return self._given_mark
115115
return self.mark
116-
116+
117117
cpdef accept(self):
118118
"""Accept the packet."""
119119
self.verdict(NF_ACCEPT)
120-
120+
121121
cpdef drop(self):
122122
"""Drop the packet."""
123123
self.verdict(NF_DROP)
@@ -134,21 +134,21 @@ cdef class NetfilterQueue:
134134
self.h = nfq_open()
135135
if self.h == NULL:
136136
raise OSError("Failed to open NFQueue.")
137-
nfq_unbind_pf(self.h, self.af) # This does NOT kick out previous
137+
nfq_unbind_pf(self.h, self.af) # This does NOT kick out previous
138138
# running queues
139139
if nfq_bind_pf(self.h, self.af) < 0:
140140
raise OSError("Failed to bind family %s. Are you root?" % self.af)
141-
141+
142142
def __dealloc__(self):
143143
if self.qh != NULL:
144144
nfq_destroy_queue(self.qh)
145145
self.qh = NULL
146-
# Don't call nfq_unbind_pf unless you want to disconnect any other
146+
# Don't call nfq_unbind_pf unless you want to disconnect any other
147147
# processes using this libnetfilter_queue on this protocol family!
148148
nfq_close(self.h)
149149

150150
def bind(self, int queue_num, object user_callback,
151-
u_int32_t max_len=DEFAULT_MAX_QUEUELEN,
151+
u_int32_t max_len=DEFAULT_MAX_QUEUELEN,
152152
u_int8_t mode=NFQNL_COPY_PACKET,
153153
u_int32_t range=MaxPacketSize):
154154
"""Create and bind to a new queue."""
@@ -157,21 +157,21 @@ cdef class NetfilterQueue:
157157
<nfq_callback*>global_callback, <void*>self)
158158
if self.qh == NULL:
159159
raise OSError("Failed to create queue %s." % queue_num)
160-
160+
161161
if range > MaxCopySize:
162162
range = MaxCopySize
163163
if nfq_set_mode(self.qh, mode, range) < 0:
164164
raise OSError("Failed to set packet copy mode.")
165-
165+
166166
nfq_set_queue_maxlen(self.qh, max_len)
167-
167+
168168
def unbind(self):
169169
"""Destroy the queue."""
170170
if self.qh != NULL:
171171
nfq_destroy_queue(self.qh)
172172
self.qh = NULL
173173
# See warning about nfq_unbind_pf in __dealloc__ above.
174-
174+
175175
def run(self):
176176
"""Begin accepting packets."""
177177
cdef int fd = nfq_fd(self.h)

0 commit comments

Comments
 (0)