From 754a2e238d8f9dafa8b974ab1aad57b309f151d1 Mon Sep 17 00:00:00 2001 From: Timo Beckers Date: Mon, 2 May 2022 15:55:56 +0200 Subject: [PATCH] syscalls: omit AttachType field in haveProgAttach 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 --- link/syscalls.go | 5 ++--- prog.go | 7 ++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/link/syscalls.go b/link/syscalls.go index 5802f8927..a661395b3 100644 --- a/link/syscalls.go +++ b/link/syscalls.go @@ -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(), diff --git a/prog.go b/prog.go index 5e990af7f..353123512 100644 --- a/prog.go +++ b/prog.go @@ -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