cilium / ebpf

ebpf-go is a pure-Go library to read, modify and load eBPF programs and attach them to various hooks in the Linux kernel.
https://ebpf-go.dev
MIT License
6.38k stars 699 forks source link

add Program.Run to allow passing all parameters to BPF_PROG_RUN #576

Closed lmb closed 2 years ago

lmb commented 2 years ago

Some recent kernel version introduced BPF_PROG_RUN. It's just an alias for BPF_PROG_TEST_RUN but it shows that upstream considers RUN to be a basic primitive on programs. Another thing that has become apparent is that the input required by different types of programs differs wildly.

Instead of TestWithContext I would add a method Program.Run(RunOptions) (RunResult, error). Names TBD. RunOptions contains all the possible fields like Data, Context, etc. RunResult contains data output, context output, etc. Test and Benchmark keep the same API but are wrappers around Run.

cc @ti-mo

Originally posted by @lmb in https://github.com/cilium/ebpf/pull/511#pullrequestreview-823817507

lmb commented 2 years ago

See #537 for some discussion on what the default argument for input should be.

lmb commented 2 years ago

RunOptions should also include Reset, so that program interruption can be handled by the caller.

dxuuu commented 2 years ago

Run(RunOptions) sounds reasonable to me. Adding a reset callback also sounds good. Just lmk on #647 and I'll send an update

lmb commented 2 years ago

This is now in master!