From 5a15325f1a46b14c1bfd5f9f0ce5f465ad321031 Mon Sep 17 00:00:00 2001 From: dowright Date: Mon, 23 Aug 2021 19:32:21 -0700 Subject: [PATCH] work on new packet --- new_packet.pxd | 4 ++-- new_packet.pyx | 20 ++++++++++++++++++++ setup2.py | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/new_packet.pxd b/new_packet.pxd index abea666..e44d0e6 100644 --- a/new_packet.pxd +++ b/new_packet.pxd @@ -27,8 +27,8 @@ cdef extern from "netinet/tcp.h": u_int32_t th_seq u_int32_t th_ack - u_int8_t th_x2:4 - u_int8_t th_off:4 + u_int8_t th_x2 + u_int8_t th_off u_int8_t th_flags diff --git a/new_packet.pyx b/new_packet.pyx index f70efc1..7e15c7f 100644 --- a/new_packet.pyx +++ b/new_packet.pyx @@ -1,3 +1,23 @@ +#!/usr/bin/env python3 + +import socket + +# Constants for module users +cdef int COPY_NONE = 0 +cdef int COPY_META = 1 +cdef int COPY_PACKET = 2 + +cdef u_int16_t DEFAULT_MAX_QUEUELEN = 1024 +cdef u_int16_t MaxPacketSize = 0xFFFF + +# buffer size - metadata size +cdef u_int16_t MaxCopySize = 4096 - 80 + +# Socket queue should hold max number of packets of copy size bytes +# formula: DEF_MAX_QUEUELEN * (MaxCopySize+SockOverhead) / 2 +cdef u_int32_t SockRcvSize = 1024 * 4796 // 2 + + cdef class CPacket: '''parent class designed to index/parse full tcp/ip packets (including ethernet). two alternate constructors are supplied to support nfqueue or raw sockets. diff --git a/setup2.py b/setup2.py index 88e65c0..c471657 100644 --- a/setup2.py +++ b/setup2.py @@ -6,7 +6,7 @@ from Cython.Distutils import build_ext cmd = {'build_ext': build_ext} ext = Extension( - 'dnx_nfqueue', sources=['new_packet.pyx'], libraries=['netfilter_queue']) + 'new_packet', sources=['new_packet.pyx'], libraries=['netfilter_queue']) setup( name='DNX-NFQUEUE', cmdclass=cmd, ext_modules=cythonize(ext, language_level='3')