BPF Tools – packet analyst toolkit
github.com
github.com
tcpdump -i eth0 -d dst 127.0.0.1
(000) ldh [12]
(001) jeq #0x800 jt 2 jf 4
(002) ld [30]
(003) jeq #0x7f000001 jt 8 jf 9
(004) jeq #0x806 jt 6 jf 5
(005) jeq #0x8035 jt 6 jf 9
(006) ld [38]
(007) jeq #0x7f000001 jt 8 jf 9
(008) ret #65535
(009) ret #0I would say that BPF is closer to iptables rules then tcpdump.
Quote from the README: .... The aim of this tool is to help creating BPF rules that will match (and drop) malicious traffic.
I haven't used BPF before, because I haven't had a need to yet. But I have been very interested in BPF for some time now. I hope more tools are made to make it easier to use BPF.
This is very different from iptables, where everything has to be expressed as a rule ("policy") with a set of fixed parameters that match a packet. iptables has a way to jump around in the rule set ("chains"), but it's not quite Turing-complete.
In Linux, BPF has been generalized (as eBPF, "extended BPF") to work not just with networking, but the kernel as a whole, though I'm not sure how extensive the set of available tracepoints is at the moment.
(I once wanted a pcap filter that matched SYN packets with a wscale option set; it ended up being a 8kB long filter due to needing to handle different ordering of variable sized TCP options. It would have been pretty trivial to do in raw BPF).
The examples here seem to be for doing pattern matching (with wildcards) on portions of DNS query packets. That's definitely in the range of things you can't coerce the pcap filter language to do an even adequate job on.
Ah-ha, thanks! I've written quite a bit of BPF but haven't dug too deeply into pcap filters. Based on the examples it looked redundant with the pcap language.