oremanj / python-netfilterqueue

Python bindings for libnetfilter_queue
MIT License
248 stars 96 forks source link

netfilterqueue can not compile with python-3.9 because tp_print was removed #67

Closed standby24x7 closed 2 years ago

standby24x7 commented 3 years ago

OS: Fedora 33 python3-3.9.4-1.fc33.x86_64 libnetfilter_queue-devel-1.0.2-16.fc33.x86_64 libnetfilter_queue-1.0.2-16.fc33.x86_64
libnfnetlink-devel-1.0.1-18.fc33.x86_64

python-netfilterqueue version commit ec2ae290667b2d3f09d5ec1278d899db2f08c52f (HEAD -> master, origin/master, origin/HEAD)

Problem Description I failed to compile python-netfilterqueue on Fedora 33.

How reproducible Always

Step to reproduce (1) From source

python setup.py install

(2) From pip

pip install python-netfilterqueue --user

Actual Result In file included from netfilterqueue.c:440: /usr/include/libnetfilter_queue/libnetfilter_queue.h:119:67: note: expected ‘unsigned char ’ but argument is of type ‘char ’ 119 extern int nfq_get_payload(struct nfq_data *nfad, unsigned char **data); ~~~~^~~~ netfilterqueue.c: In function ‘__pyx_pf_14netfilterqueue_6Packet_4get_hw’: netfilterqueue.c:2533:17: warning: implicit declaration of function ‘PyString_FromStringAndSize’; did you mean ‘PyBytes_FromStringAndSize’? [-Wimplicit-function-declaration] 2533 pyx_t_3 = PyString_FromStringAndSize(((char *)__pyx_v_self->hw_addr), 8); if (unlikely(!pyx_t_3)) __PYX_ERR(0, 111, __pyx_L1_error) ^~~~~~ PyBytes_FromStringAndSize netfilterqueue.c:2533:15: warning: assignment to ‘PyObject ’ {aka ‘struct _object ’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 2533 pyx_t_3 = PyString_FromStringAndSize(((char *)__pyx_v_self->hw_addr), 8); if (unlikely(!pyx_t_3)) __PYX_ERR(0, 111, __pyx_L1_error) ^ netfilterqueue.c: In function ‘PyInit_netfilterqueue’: netfilterqueue.c:6111:37: error: ‘PyTypeObject’ {aka ‘struct _typeobject’} has no member named ‘tp_print’ 6111 __pyx_type_14netfilterqueue_Packet.tp_print = 0; ^ netfilterqueue.c:6116:45: error: ‘PyTypeObject’ {aka ‘struct _typeobject’} has no member named ‘tp_print’ 6116 __pyx_type_14netfilterqueue_NetfilterQueue.tp_print = 0;

Expected result The source is compiled and installed succesfully.

Additional information The code can be compiled on Fedora 31, which uses python3-3.7.9

Starting from python-3.9, tp_print was removed.

https://docs.python.org/3/whatsnew/3.9.html Removed The tp_print slot of PyTypeObject has been removed. It was used for printing objects to files in Python 2.7 and before. Since Python 3.0, it has been ignored and unused. (Contributed by Jeroen Demeyer in bpo-36974.)

standby24x7 commented 3 years ago

I understand what I need to do. If I build netfilterqueue from the source with python 3.9,
I need to remove netfilterqueue.c at first and then

python ./setup.py install

Then new netfilterqueue.c is created and it was build succesfully.

Example

python ./print_and_accept.py

python: can't open file '/home/iida/Repo/python-netfilterqueue/./print_and_accept.py': [Errno 2] No such file or directory [root@masabert python-netfilterqueue]# python ./setup.py install running install running build running build_ext skipping 'netfilterqueue.c' Cython extension (up-to-date) running install_lib running install_egg_info Removing /usr/local/lib64/python3.9/site-packages/NetfilterQueue-0.8.1-py3.9.egg-info Writing /usr/local/lib64/python3.9/site-packages/NetfilterQueue-0.8.1-py3.9.egg-info #

Cython 0.29.23

BMFI commented 3 years ago

I did not design netfilterque, but I did some research on Stackoverflow which suggests netfilterqueue can work with py3.6. I have not thoroughly tested it out, but when I ran my code with py3.6 my terminal stopped throwing errors which suggests it works. https://stackoverflow.com/search?q=netfilterqueue+python+3.6&s=42da880d-657a-44ed-b435-792c28d463c0

BMFI commented 3 years ago

The installation instructions are.

  1. apt-get install build-essential python-dev libnetfilter-queue-dev
  2. git clone git@github.com:kti/python-netfilterqueue.git cd python-netfilterqueue python setup.py install
oremanj commented 2 years ago

This is fixed on master and will be released to PyPI shortly. Note the Git repository address is now https://github.com/oremanj/python-netfilterqueue.