PF byte count and packet counts are not reported
karlism opened this issue · 1 comments
Hello,
py-pf PFStatus.bytes
and PFStatus.packets
objects seem to always return zero value. Following python script example (taken from documentation here: http://www.kernel-panic.it/programming/py-pf/pf3.html):
#!/usr/bin/env python
import pf
filter = pf.PacketFilter()
status = filter.get_status()
print(status.states)
print """Bytes in
IPv4: {0[0]}
IPv6: {0[1]}""".format(status.bytes["in"])
print """Bytes out
IPv4: {0[0]}
IPv6: {0[1]}""".format(status.bytes["out"])
print """Packets in
Passed
IPv4: {0[0]}
IPv6: {0[1]}
Blocked
IPv4: {1[0]}
IPv6: {1[1]}""".format(status.packets["in"][pf.PF_PASS],
status.packets["in"][pf.PF_DROP])
Returns following output during large file download:
3
Bytes in
IPv4: 0
IPv6: 0
Bytes out
IPv4: 0
IPv6: 0
Packets in
Passed
IPv4: 0
IPv6: 0
Blocked
IPv4: 0
IPv6: 0
As can be seen, state count is reported properly, but byte and packet counts are always zero.
I'm using py-pf 0.1.9 installed from OpenBSD 6.4 packages for amd64 architecture.
Hi,
I'm still working on updating py-pf to OpenBSD 6.4, but the statistics appear to already work.
The problem is that you did not set the status interface in your script; just call filter.set_status_if(<interface>)
before you call filter.get_status()
.
For example:
filter = pf.PacketFilter()
filter.set_status_if("vio0")
status = filter.get_status()
[ ... ]
My output looks like:
46
Bytes in
IPv4: 154894
IPv6: 40915
Bytes out
IPv4: 93275
IPv6: 736
Packets in
Passed
IPv4: 1748
IPv6: 511
Blocked
IPv4: 139
IPv6: 43
Hope this helps!
Cheers,
Daniele