work on new packet

This commit is contained in:
dowright 2021-08-23 18:57:01 -07:00 committed by DOWRIGHT
parent 3e37a8aec8
commit 505f6daf2c
2 changed files with 34 additions and 33 deletions

View File

@ -66,8 +66,8 @@ cdef class CPacket:
cdef udphdr udp_header
cdef icmphdr icmp_header
cdef u_int16_t __queue_num
cdef bint threaded
# cdef u_int16_t __queue_num
# cdef bint threaded
cdef bint _verdict_is_set
cdef u_int32_t _mark
@ -80,4 +80,5 @@ cdef class CPacket:
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 _parse(self)
cdef void verdict(self, u_int32_t verdict)

View File

@ -66,6 +66,37 @@ cdef class CPacket:
return 0
cdef _parse(self):
'''Index tcp/ip packet layers 3 & 4 for use as instance objects.
the before_exit method will be called before returning, which can be used to create
subclass specific objects like namedtuples or application layer data.'''
cdef iphdr * ip_header = < iphdr * > self.data
cdef u_int8_t iphdr_len = iphdr.tos & 15 * 4
cdef tcphdr * tcp_header
cdef udphdr * udp_header
cdef icmphdr * icmp_header
if (iphdr.protocol == IPPROTO_TCP):
self.tcp_header = < tcphdr * > self.data[iphdr_len:]
return 0
if (iphdr.protocol == IPPROTO_UDP):
self.udp_header = < udphdr * > self.data[iphdr_len:]
return 0
if (iphdr.protocol == IPPROTO_ICMP):
self.icmp_header = < icmphdr * > self.data[iphdr_len:]
return 0
return 1
cdef void verdict(self, u_int32_t verdict):
'''Call appropriate set_verdict... function on packet.'''
@ -92,37 +123,6 @@ cdef class CPacket:
self._verdict_is_set = True
cdef parse(self):
'''Index tcp/ip packet layers 3 & 4 for use as instance objects.
the before_exit method will be called before returning, which can be used to create
subclass specific objects like namedtuples or application layer data.'''
cdef iphdr * ip_header = < iphdr * > self.payload
cdef u_int8_t iphdr_len = iphdr.tos & 15 * 4
cdef tcphdr * tcp_header
cdef udphdr * udp_header
cdef icmphdr * icmp_header
if (iphdr.protocol == IPPROTO_TCP):
self.tcp_header = < tcphdr * > self.payload[iphdr_len:]
return 0
if (iphdr.protocol == IPPROTO_UDP):
self.udp_header = < udphdr * > self.payload[iphdr_len:]
return 0
if (iphdr.protocol == IPPROTO_ICMP):
self.icmp_header = < icmphdr * > self.payload[iphdr_len:]
return 0
return 1
# def _before_exit(self):
# '''executes before returning from parse call.
# May be overridden.