Skip to content

Commit

Permalink
syscalls: omit AttachType field in haveProgAttach
Browse files Browse the repository at this point in the history
Discovered while running the test suite on kernel 4.14.

With the addition BPF_PROG_ATTACH tests in package link, the haveProgAttach
feature test was added, gated on 4.10. This helper uses the AttachType field,
which sets the bpf_attr expected_attach_type field, which is only available
as of 4.17. As probing CGroupSKB is sufficient, omit setting AttachType.

This patch fixes the tests on kernels between 4.10 and 4.17.

Signed-off-by: Timo Beckers <timo@isovalent.com>
  • Loading branch information
ti-mo committed May 3, 2022
1 parent 96aa1a7 commit 754a2e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 2 additions & 3 deletions link/syscalls.go
Expand Up @@ -27,9 +27,8 @@ const (

var haveProgAttach = internal.FeatureTest("BPF_PROG_ATTACH", "4.10", func() error {
prog, err := ebpf.NewProgram(&ebpf.ProgramSpec{
Type: ebpf.CGroupSKB,
AttachType: ebpf.AttachCGroupInetIngress,
License: "MIT",
Type: ebpf.CGroupSKB,
License: "MIT",
Instructions: asm.Instructions{
asm.Mov.Imm(asm.R0, 0),
asm.Return(),
Expand Down
7 changes: 6 additions & 1 deletion prog.go
Expand Up @@ -58,7 +58,12 @@ type ProgramSpec struct {
Name string

// Type determines at which hook in the kernel a program will run.
Type ProgramType
Type ProgramType

// AttachType of the program, needed to differentiate allowed context
// accesses in some newer program types like CGroupSockAddr.
//
// Available on kernels 4.17 and later.
AttachType AttachType

// Name of a kernel data structure or function to attach to. Its
Expand Down

0 comments on commit 754a2e2

Please sign in to comment.