svinota / pyroute2

Python Netlink and PF_ROUTE library — network configuration and monitoring
https://pyroute2.org/
Other
962 stars 249 forks source link

add skbprio (ipset) #718

Open fefelka opened 4 years ago

fefelka commented 4 years ago

Hi! When I add only ip address, all good. But when I add skbprio field, get errors and address not added to set ALLOW. What format of field "skbprio" is should be?

!/usr/bin/python3

from pyroute2 import IPSet ipset = IPSet()

ipset.create("ALLOW", skbinfo=True)

ipset.add("ALLOW","1.1.1.1", skbprio="1:2") ipset.close()

root@test:~/fwrules# ./test.py Traceback (most recent call last): File "./test.py", line 8, in ipset.add("ALLOW","1.1.1.1",skbprio="1:2") File "/usr/local/lib/python3.4/dist-packages/pyroute2-0.5.12.post17-py3.4.egg/pyroute2/ipset.py", line 419, in add *kwargs) File "/usr/local/lib/python3.4/dist-packages/pyroute2-0.5.12.post17-py3.4.egg/pyroute2/ipset.py", line 370, in _add_delete_test terminate=_nlmsg_error) File "/usr/local/lib/python3.4/dist-packages/pyroute2-0.5.12.post17-py3.4.egg/pyroute2/ipset.py", line 141, in request msg_flags, terminate=terminate) File "/usr/local/lib/python3.4/dist-packages/pyroute2-0.5.12.post17-py3.4.egg/pyroute2/netlink/nlsocket.py", line 375, in nlm_request return tuple(self._genlm_request(argv, **kwarg)) File "/usr/local/lib/python3.4/dist-packages/pyroute2-0.5.12.post17-py3.4.egg/pyroute2/netlink/nlsocket.py", line 865, in nlm_request self.put(msg, msg_type, msg_flags, msg_seq=msg_seq) File "/usr/local/lib/python3.4/dist-packages/pyroute2-0.5.12.post17-py3.4.egg/pyroute2/netlink/nlsocket.py", line 614, in put self.sendto_gate(msg, addr) File "/usr/local/lib/python3.4/dist-packages/pyroute2-0.5.12.post17-py3.4.egg/pyroute2/netlink/nlsocket.py", line 1001, in _gate msg.encode() File "/usr/local/lib/python3.4/dist-packages/pyroute2-0.5.12.post17-py3.4.egg/pyroute2/netlink/init.py", line 1110, in encode offset = self.encode_nlas(offset) File "/usr/local/lib/python3.4/dist-packages/pyroute2-0.5.12.post17-py3.4.egg/pyroute2/netlink/init.py", line 1451, in encode_nlas nla.encode() File "/usr/local/lib/python3.4/dist-packages/pyroute2-0.5.12.post17-py3.4.egg/pyroute2/netlink/init.py", line 1110, in encode offset = self.encode_nlas(offset) File "/usr/local/lib/python3.4/dist-packages/pyroute2-0.5.12.post17-py3.4.egg/pyroute2/netlink/init.py", line 1451, in encode_nlas nla.encode() File "/usr/local/lib/python3.4/dist-packages/pyroute2-0.5.12.post17-py3.4.egg/pyroute2/netlink/init.py", line 1095, in encode struct.pack_into(efmt, self.data, offset, value) struct.error: pack_into expected 2 items for packing (got 1)

ffourcot commented 4 years ago

Hello,

We have to improve documentation on this part. Currently, only tuple is allowed in skbprio. You can see an exemple in test file:

https://github.com/svinota/pyroute2/blob/master/tests/general/test_ipset.py#L215

It could be a great feature to support strings like you tried as well

fefelka commented 4 years ago

thank!