Skip to content

Commit

Permalink
Fix haveProgTestRun on kernel version 5.15.65
Browse files Browse the repository at this point in the history
A recent patch[0] to the kernel prevents bpf_prog_test_run_skb() from running
the bpf program with with an empty skb.  This makes the existing feature check
fail, so to fix it an additional byte of input data is needed.

[0]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fd1894224407c484f652ad456e1ce423e89bb3eb
  • Loading branch information
player-two authored and lmb committed Sep 14, 2022
1 parent c5668cf commit a38fb6b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions prog.go
Expand Up @@ -624,8 +624,12 @@ var haveProgTestRun = internal.FeatureTest("BPF_PROG_TEST_RUN", "4.12", func() e
}
defer prog.Close()

// Programs require at least 14 bytes input
in := make([]byte, 14)
// Programs require at least 15 bytes input
// Looking in net/bpf/test_run.c, bpf_test_init() requires that the input is
// at least ETH_HLEN (14) bytes. A recent patch[0] also ensures that the skb
// is not empty after the layer 2 header is removed.
// [0]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fd1894224407c484f652ad456e1ce423e89bb3eb
in := make([]byte, 15)
attr := sys.ProgRunAttr{
ProgFd: uint32(prog.FD()),
DataSizeIn: uint32(len(in)),
Expand Down

0 comments on commit a38fb6b

Please sign in to comment.