diff --git a/pkg/btf/validation.go b/pkg/btf/validation.go index d53b4577b98..cb9aeb06d38 100644 --- a/pkg/btf/validation.go +++ b/pkg/btf/validation.go @@ -163,6 +163,24 @@ func getKernelType(arg btf.Type) string { return "union " + union.Name + suffix } + enum, ok := arg.(*btf.Enum) + if ok { + prefix := "u" + if enum.Signed { + prefix = "s" + } + switch enum.Size { + case 1: + case 2: + case 4: + case 8: + default: + // Not sure what to do here, so just dump the type name + return arg.TypeName() + suffix + } + return fmt.Sprintf("%s%d%s", prefix, 8*enum.Size, suffix) + } + cnst, ok := arg.(*btf.Const) if ok { // NB: ignore const diff --git a/pkg/btf/validation_test.go b/pkg/btf/validation_test.go index fa785044665..007d4159bab 100644 --- a/pkg/btf/validation_test.go +++ b/pkg/btf/validation_test.go @@ -12,6 +12,7 @@ import ( "github.com/cilium/ebpf/btf" "github.com/cilium/tetragon/pkg/tracingpolicy" + "github.com/stretchr/testify/require" ) func expectError(t *testing.T, err error) error { @@ -79,3 +80,16 @@ func TestSpecs(t *testing.T) { }) } } + +func TestEnum(t *testing.T) { + require.Equal(t, + getKernelType(&btf.Enum{ + Size: 2, + Signed: false, + }), "u16") + require.Equal(t, + getKernelType(&btf.Enum{ + Size: 4, + Signed: true, + }), "s32") +}