Skip to content

Support eBPF live filtering on Linux #1234

Open
@ferrieux

Description

@ferrieux

On modern Linux, eBPF is available to do advanced filtering.
In some circumstances, the extra muscle brought by filtering early and in-kernel in zero-copy mode is critical.
One such use case is filtering of live a interface with a haystack of traffic and a needle matching a complex eBPF-expressed criterion.
As a simple example that currently has no efficient solution with tcpdump, is matching an IP address against a large hashtable (like is done in netfilter with ipset or nftables sets)

It would be cool, for this case, to be able to tell tcpdump to load a separately compiled eBPF object file, and attach it to its raw socket with SO_ATTACH_BPF.

Note I'm not advocating for deeper integration, like eBPF-filtering a pcap file, since that has none of the performance requirements above, and arbitrarily complex logic in full-fledged C in userspace can be used instead.

I'm also not proposing (alas) to replicate the beautifully self-contained inline cBPF; in eBPF the heavier ELF machinery makes it unlikely anybody would want to enter a program as a list of comma-separated integers (though I, for one, would love to do it for "return XDP_DROP")

I guess the implementation is straightforward (for sufficiently recent Linux). The only thing that needs thinking I guess is the command-line API. Among possibilities:

  • an extension to the pcap_filter language, like ebpf /path/to/program.o[+SEC], with the constraint that it must be alone (no mixing like "port 80 and ebpf /path/to/program.o")
  • an option, like -ebpf /path/to/program.o[+SEC]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions