From d1556391272e3df9e4e4fbec9d1abee3ab4b7980 Mon Sep 17 00:00:00 2001 From: dowright Date: Mon, 23 Aug 2021 20:00:29 -0700 Subject: [PATCH] work on new packet --- new_packet.pxd | 6 +++--- new_packet.pyx | 22 +++++++--------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/new_packet.pxd b/new_packet.pxd index e44d0e6..4f7a8dc 100644 --- a/new_packet.pxd +++ b/new_packet.pxd @@ -187,11 +187,11 @@ cdef class CPacket: # Packet details: cdef Py_ssize_t payload_len - cdef readonly unsigned char *payload + cdef readonly unsigned char *data cdef timeval timestamp cdef u_int8_t hw_addr[8] - cdef nf_callback(self, nfq_q_handle * qh, nfgenmsg * nfmsg, nfq_data * nfa, void * data) nogil - cdef parse(self, nfq_q_handle * qh, nfq_data * nfa) + cdef nf_callback(self, nfq_q_handle *qh, nfgenmsg *nfmsg, nfq_data *nfa, void *data) + cdef parse(self, nfq_q_handle *qh, nfq_data *nfa) nogil cdef _parse(self) cdef void verdict(self, u_int32_t verdict) diff --git a/new_packet.pyx b/new_packet.pyx index 7e15c7f..906b1d7 100644 --- a/new_packet.pyx +++ b/new_packet.pyx @@ -42,7 +42,7 @@ cdef class CPacket: return "%s packet, %s bytes" % (protocol, self.payload_len) @staticmethod - cdef nf_callback(self, nfq_q_handle *qh, nfgenmsg *nfmsg, nfq_data *nfa, void *data) nogil: + cdef nf_callback(self, nfq_q_handle *qh, nfgenmsg *nfmsg, nfq_data *nfa, void *data): # cdef NetfilterQueue nfqueue = data # cdef object user_callback = nfqueue.user_callback @@ -51,7 +51,7 @@ cdef class CPacket: packet.parse(qh, nfa) # NOTE: this will be callback target for nfqueue - cdef parse(self, nfq_q_handle *qh, nfq_data *nfa): + cdef parse(self, nfq_q_handle *qh, nfq_data *nfa) nogil: '''Alternate constructor. Used to start listener/proxy instances using nfqueue bindings.''' '''Assign a packet from NFQ to this object. Parse the header and load local values.''' @@ -75,7 +75,7 @@ cdef class CPacket: self._mark = nfq_get_nfmark(nfa) # splitting packet by tcp/ip layers - cdef int error = self.parse() + cdef int error = self._parse() # if (self.continue_condition): # self._before_exit() @@ -93,30 +93,22 @@ cdef class CPacket: cdef iphdr *ip_header = self.data - cdef u_int8_t iphdr_len = iphdr.tos & 15 * 4 + cdef u_int8_t iphdr_len = ip_header.tos & 15 * 4 cdef tcphdr *tcp_header cdef udphdr *udp_header cdef icmphdr *icmp_header - if (iphdr.protocol == IPPROTO_TCP): + if (ip_header.protocol == IPPROTO_TCP): self.tcp_header = self.data[iphdr_len:] - return 0 - - if (iphdr.protocol == IPPROTO_UDP): + if (ip_header.protocol == IPPROTO_UDP): self.udp_header = self.data[iphdr_len:] - return 0 - - if (iphdr.protocol == IPPROTO_ICMP): + if (ip_header.protocol == IPPROTO_ICMP): self.icmp_header = self.data[iphdr_len:] - return 0 - - return 1 - cdef void verdict(self, u_int32_t verdict): '''Call appropriate set_verdict... function on packet.'''