Skip to content

Commit a31c9a6

Browse files
committed
cleanup trailing whitespace
1 parent a008498 commit a31c9a6

File tree

3 files changed

+41
-41
lines changed

3 files changed

+41
-41
lines changed

netfilterqueue.c

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netfilterqueue.pxd

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ cdef extern from "libnetfilter_queue/linux_nfnetlink_queue.h":
7979
u_int32_t packet_id
8080
u_int16_t hw_protocol
8181
u_int8_t hook
82-
82+
8383
cdef extern from "libnetfilter_queue/libnetfilter_queue.h":
8484
struct nfq_handle:
8585
pass
@@ -89,10 +89,10 @@ cdef extern from "libnetfilter_queue/libnetfilter_queue.h":
8989
pass
9090
struct nfqnl_msg_packet_hw:
9191
u_int8_t hw_addr[8]
92-
92+
9393
nfq_handle *nfq_open()
9494
int nfq_close(nfq_handle *h)
95-
95+
9696
int nfq_bind_pf(nfq_handle *h, u_int16_t pf)
9797
int nfq_unbind_pf(nfq_handle *h, u_int16_t pf)
9898
ctypedef int *nfq_callback(nfq_q_handle *gh, nfgenmsg *nfmsg,
@@ -102,21 +102,21 @@ cdef extern from "libnetfilter_queue/libnetfilter_queue.h":
102102
nfq_callback *cb,
103103
void *data)
104104
int nfq_destroy_queue(nfq_q_handle *qh)
105-
105+
106106
int nfq_handle_packet(nfq_handle *h, char *buf, int len)
107-
107+
108108
int nfq_set_mode(nfq_q_handle *qh,
109109
u_int8_t mode, unsigned int len)
110-
110+
111111
q_set_queue_maxlen(nfq_q_handle *qh,
112112
u_int32_t queuelen)
113-
113+
114114
int nfq_set_verdict(nfq_q_handle *qh,
115115
u_int32_t id,
116116
u_int32_t verdict,
117117
u_int32_t data_len,
118118
unsigned char *buf) nogil
119-
119+
120120
int nfq_set_verdict_mark(nfq_q_handle *qh,
121121
u_int32_t id,
122122
u_int32_t verdict,
@@ -131,15 +131,15 @@ cdef extern from "libnetfilter_queue/libnetfilter_queue.h":
131131
int nfq_get_timestamp(nfq_data *nfad, timeval *tv)
132132
nfqnl_msg_packet_hw *nfq_get_packet_hw(nfq_data *nfad)
133133
int nfq_get_nfmark (nfq_data *nfad)
134-
134+
135135
# Dummy defines from linux/socket.h:
136136
cdef enum: # Protocol families, same as address families.
137137
PF_INET = 2
138138
PF_INET6 = 10
139139

140140
cdef extern from "sys/socket.h":
141141
ssize_t recv(int __fd, void *__buf, size_t __n, int __flags) nogil
142-
142+
143143
# Dummy defines from linux/netfilter.h
144144
cdef enum:
145145
NF_DROP
@@ -154,18 +154,18 @@ cdef class Packet:
154154
cdef nfq_q_handle *_qh
155155
cdef nfq_data *_nfa
156156
cdef nfqnl_msg_packet_hdr *_hdr
157-
cdef bint _verdict_is_set # True if verdict has been issued,
157+
cdef bint _verdict_is_set # True if verdict has been issued,
158158
# false otherwise
159159
cdef bint _mark_is_set # True if a mark has been given, false otherwise
160160
cdef u_int32_t _given_mark # Mark given to packet
161161
cdef bytes _given_payload # New payload of packet, or null
162-
162+
163163
# From NFQ packet header:
164164
cdef readonly u_int32_t id
165165
cdef readonly u_int16_t hw_protocol
166166
cdef readonly u_int8_t hook
167167
cdef readonly u_int32_t mark
168-
168+
169169
# Packet details:
170170
cdef Py_ssize_t payload_len
171171
cdef readonly char *payload
@@ -177,7 +177,7 @@ cdef class Packet:
177177
#cdef readonly u_int32_t physindev
178178
#cdef readonly u_int32_t outdev
179179
#cdef readonly u_int32_t physoutdev
180-
180+
181181
cdef set_nfq_data(self, nfq_q_handle *qh, nfq_data *nfa)
182182
cdef void verdict(self, u_int8_t verdict)
183183
cpdef Py_ssize_t get_payload_len(self)
@@ -188,11 +188,11 @@ cdef class Packet:
188188
cpdef accept(self)
189189
cpdef drop(self)
190190
cpdef repeat(self)
191-
191+
192192
cdef class NetfilterQueue:
193193
cdef object user_callback # User callback
194194
cdef nfq_handle *h # Handle to NFQueue library
195195
cdef nfq_q_handle *qh # A handle to the queue
196196
cdef u_int16_t af # Address family
197197
cdef packet_copy_size # Amount of packet metadata + data copied to buffer
198-
198+

netfilterqueue.pyx

Lines changed: 24 additions & 24 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.
@@ -22,7 +22,7 @@ DEF MaxCopySize = BufferSize - MetadataSize
2222

2323
cimport cpython.version
2424

25-
cdef int global_callback(nfq_q_handle *qh, nfgenmsg *nfmsg,
25+
cdef int global_callback(nfq_q_handle *qh, nfgenmsg *nfmsg,
2626
nfq_data *nfa, void *data) with gil:
2727
"""Create a Packet and pass it to appropriate callback."""
2828
cdef NetfilterQueue nfqueue = <NetfilterQueue>data
@@ -39,29 +39,29 @@ cdef class Packet:
3939
self._verdict_is_set = False
4040
self._mark_is_set = False
4141
self._given_payload = None
42-
42+
4343
def __str__(self):
4444
cdef iphdr *hdr = <iphdr*>self.payload
4545
protocol = PROTOCOLS.get(hdr.protocol, "Unknown protocol")
4646
return "%s packet, %s bytes" % (protocol, self.payload_len)
47-
47+
4848
cdef set_nfq_data(self, nfq_q_handle *qh, nfq_data *nfa):
4949
"""
50-
Assign a packet from NFQ to this object. Parse the header and load
50+
Assign a packet from NFQ to this object. Parse the header and load
5151
local values.
5252
"""
5353
self._qh = qh
5454
self._nfa = nfa
5555
self._hdr = nfq_get_msg_packet_hdr(nfa)
56-
56+
5757
self.id = ntohl(self._hdr.packet_id)
5858
self.hw_protocol = ntohs(self._hdr.hw_protocol)
5959
self.hook = self._hdr.hook
60-
60+
6161
self.payload_len = nfq_get_payload(self._nfa, &self.payload)
6262
if self.payload_len < 0:
6363
raise OSError("Failed to get payload of packet.")
64-
64+
6565
nfq_get_timestamp(self._nfa, &self.timestamp)
6666
self.mark = nfq_get_nfmark(nfa)
6767

@@ -71,7 +71,7 @@ cdef class Packet:
7171
raise RuntimeWarning("Verdict already given for this packet.")
7272

7373
cdef u_int32_t modified_payload_len = 0
74-
cdef unsigned char *modified_payload = NULL
74+
cdef unsigned char *modified_payload = NULL
7575
if self._given_payload:
7676
modified_payload_len = len(self._given_payload)
7777
modified_payload = self._given_payload
@@ -92,7 +92,7 @@ cdef class Packet:
9292
modified_payload)
9393

9494
self._verdict_is_set = True
95-
95+
9696
def get_payload(self):
9797
"""Return payload as Python string."""
9898
cdef object py_string
@@ -103,17 +103,17 @@ cdef class Packet:
103103
py_string = PyString_FromStringAndSize(
104104
self.payload, self.payload_len)
105105
return py_string
106-
106+
107107
cpdef Py_ssize_t get_payload_len(self):
108108
return self.payload_len
109-
109+
110110
cpdef double get_timestamp(self):
111111
return self.timestamp.tv_sec + (self.timestamp.tv_usec/1000000.0)
112-
112+
113113
cpdef set_payload(self, bytes payload):
114114
"""Set the new payload of this packet."""
115115
self._given_payload = payload
116-
116+
117117
cpdef set_mark(self, u_int32_t mark):
118118
self._given_mark = mark
119119
self._mark_is_set = True
@@ -122,11 +122,11 @@ cdef class Packet:
122122
if self._mark_is_set:
123123
return self._given_mark
124124
return self.mark
125-
125+
126126
cpdef accept(self):
127127
"""Accept the packet."""
128128
self.verdict(NF_ACCEPT)
129-
129+
130130
cpdef drop(self):
131131
"""Drop the packet."""
132132
self.verdict(NF_DROP)
@@ -143,20 +143,20 @@ cdef class NetfilterQueue:
143143
self.h = nfq_open()
144144
if self.h == NULL:
145145
raise OSError("Failed to open NFQueue.")
146-
nfq_unbind_pf(self.h, self.af) # This does NOT kick out previous
146+
nfq_unbind_pf(self.h, self.af) # This does NOT kick out previous
147147
# running queues
148148
if nfq_bind_pf(self.h, self.af) < 0:
149149
raise OSError("Failed to bind family %s. Are you root?" % self.af)
150-
150+
151151
def __dealloc__(self):
152152
if self.qh != NULL:
153153
nfq_destroy_queue(self.qh)
154-
# Don't call nfq_unbind_pf unless you want to disconnect any other
154+
# Don't call nfq_unbind_pf unless you want to disconnect any other
155155
# processes using this libnetfilter_queue on this protocol family!
156156
nfq_close(self.h)
157157

158158
def bind(self, int queue_num, object user_callback,
159-
u_int32_t max_len=DEFAULT_MAX_QUEUELEN,
159+
u_int32_t max_len=DEFAULT_MAX_QUEUELEN,
160160
u_int8_t mode=NFQNL_COPY_PACKET,
161161
u_int32_t range=MaxPacketSize):
162162
"""Create and bind to a new queue."""
@@ -165,20 +165,20 @@ cdef class NetfilterQueue:
165165
<nfq_callback*>global_callback, <void*>self)
166166
if self.qh == NULL:
167167
raise OSError("Failed to create queue %s." % queue_num)
168-
168+
169169
if range > MaxCopySize:
170170
range = MaxCopySize
171171
if nfq_set_mode(self.qh, mode, range) < 0:
172172
raise OSError("Failed to set packet copy mode.")
173-
173+
174174
nfq_set_queue_maxlen(self.qh, max_len)
175-
175+
176176
def unbind(self):
177177
"""Destroy the queue."""
178178
if self.qh != NULL:
179179
nfq_destroy_queue(self.qh)
180180
# See warning about nfq_unbind_pf in __dealloc__ above.
181-
181+
182182
def run(self):
183183
"""Begin accepting packets."""
184184
cdef int fd = nfq_fd(self.h)

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