diff --git a/btf/format.go b/btf/format.go index 5e581b4a8..3e0dedaa2 100644 --- a/btf/format.go +++ b/btf/format.go @@ -161,6 +161,9 @@ func (gf *GoFormatter) writeTypeLit(typ Type, depth int) error { case *Datasec: err = gf.writeDatasecLit(v, depth) + case *Var: + err = gf.writeTypeLit(v.Type, depth) + default: return fmt.Errorf("type %T: %w", v, ErrNotSupported) } diff --git a/btf/format_test.go b/btf/format_test.go index c26e023df..4bf21c0fe 100644 --- a/btf/format_test.go +++ b/btf/format_test.go @@ -137,6 +137,7 @@ func TestGoTypeDeclaration(t *testing.T) { }, "type t struct { _ [4]byte; g uint32; _ [8]byte; }", }, + {&Var{Type: &Int{Size: 4}}, "type t uint32"}, } for _, test := range tests { diff --git a/btf/types.go b/btf/types.go index 44d393067..dbcdf9dd7 100644 --- a/btf/types.go +++ b/btf/types.go @@ -1291,6 +1291,20 @@ func UnderlyingType(typ Type) Type { return &cycle{typ} } +// QualifiedType returns the type with all qualifiers removed. +func QualifiedType(typ Type) Type { + result := typ + for depth := 0; depth <= maxResolveDepth; depth++ { + switch v := (result).(type) { + case qualifier: + result = v.qualify() + default: + return result + } + } + return &cycle{typ} +} + // As returns typ if is of type T. Otherwise it peels qualifiers and Typedefs // until it finds a T. // diff --git a/cmd/bpf2go/gen/output.go b/cmd/bpf2go/gen/output.go index 201683ed5..b8855c7ac 100644 --- a/cmd/bpf2go/gen/output.go +++ b/cmd/bpf2go/gen/output.go @@ -49,6 +49,10 @@ func (n templateName) MapSpecs() string { return string(n) + "MapSpecs" } +func (n templateName) VariableSpecs() string { + return string(n) + "VariableSpecs" +} + func (n templateName) Load() string { return n.maybeExport("load" + toUpperFirst(string(n))) } @@ -65,6 +69,10 @@ func (n templateName) Maps() string { return string(n) + "Maps" } +func (n templateName) Variables() string { + return string(n) + "Variables" +} + func (n templateName) Programs() string { return string(n) + "Programs" } @@ -82,6 +90,8 @@ type GenerateArgs struct { Constraints constraint.Expr // Maps to be emitted. Maps []string + // Variables to be emitted. + Variables []string // Programs to be emitted. Programs []string // Types to be emitted. @@ -121,6 +131,11 @@ func Generate(args GenerateArgs) error { maps[name] = args.Identifier(name) } + variables := make(map[string]string) + for _, name := range args.Variables { + variables[name] = args.Identifier(name) + } + programs := make(map[string]string) for _, name := range args.Programs { programs[name] = args.Identifier(name) @@ -151,6 +166,7 @@ func Generate(args GenerateArgs) error { Constraints constraint.Expr Name templateName Maps map[string]string + Variables map[string]string Programs map[string]string Types []btf.Type TypeNames map[btf.Type]string @@ -162,6 +178,7 @@ func Generate(args GenerateArgs) error { args.Constraints, templateName(args.Stem), maps, + variables, programs, types, typeNames, diff --git a/cmd/bpf2go/gen/output.tpl b/cmd/bpf2go/gen/output.tpl index 8d8047066..474c9c568 100644 --- a/cmd/bpf2go/gen/output.tpl +++ b/cmd/bpf2go/gen/output.tpl @@ -54,9 +54,10 @@ func {{ .Name.LoadObjects }}(obj interface{}, opts *ebpf.CollectionOptions) (err type {{ .Name.Specs }} struct { {{ .Name.ProgramSpecs }} {{ .Name.MapSpecs }} + {{ .Name.VariableSpecs }} } -// {{ .Name.Specs }} contains programs before they are loaded into the kernel. +// {{ .Name.ProgramSpecs }} contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type {{ .Name.ProgramSpecs }} struct { @@ -74,12 +75,22 @@ type {{ .Name.MapSpecs }} struct { {{- end }} } +// {{ .Name.VariableSpecs }} contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type {{ .Name.VariableSpecs }} struct { +{{- range $name, $id := .Variables }} + {{ $id }} *ebpf.VariableSpec `ebpf:"{{ $name }}"` +{{- end }} +} + // {{ .Name.Objects }} contains all objects after they have been loaded into the kernel. // // It can be passed to {{ .Name.LoadObjects }} or ebpf.CollectionSpec.LoadAndAssign. type {{ .Name.Objects }} struct { {{ .Name.Programs }} {{ .Name.Maps }} + {{ .Name.Variables }} } func (o *{{ .Name.Objects }}) Close() error { @@ -106,6 +117,15 @@ func (m *{{ .Name.Maps }}) Close() error { ) } +// {{ .Name.Variables }} contains all global variables after they have been loaded into the kernel. +// +// It can be passed to {{ .Name.LoadObjects }} or ebpf.CollectionSpec.LoadAndAssign. +type {{ .Name.Variables }} struct { +{{- range $name, $id := .Variables }} + {{ $id }} *ebpf.Variable `ebpf:"{{ $name }}"` +{{- end }} +} + // {{ .Name.Programs }} contains all programs after they have been loaded into the kernel. // // It can be passed to {{ .Name.LoadObjects }} or ebpf.CollectionSpec.LoadAndAssign. diff --git a/cmd/bpf2go/gen/output_test.go b/cmd/bpf2go/gen/output_test.go index 8d8b00744..75d12219b 100644 --- a/cmd/bpf2go/gen/output_test.go +++ b/cmd/bpf2go/gen/output_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/go-quicktest/qt" - "github.com/google/go-cmp/cmp" "github.com/cilium/ebpf/btf" "github.com/cilium/ebpf/cmd/bpf2go/internal" @@ -79,10 +78,6 @@ func TestPackageImport(t *testing.T) { qt.Assert(t, qt.StringContains(buf.String(), fmt.Sprintf(`"%s"`, internal.CurrentModule))) } -var typesEqualComparer = cmp.Comparer(func(a, b btf.Type) bool { - return a == b -}) - func TestCustomIdentifier(t *testing.T) { var buf bytes.Buffer args := GenerateArgs{ @@ -97,3 +92,27 @@ func TestCustomIdentifier(t *testing.T) { qt.Assert(t, qt.IsNil(err)) qt.Assert(t, qt.StringContains(buf.String(), "DO_THING")) } + +func TestObjects(t *testing.T) { + var buf bytes.Buffer + args := GenerateArgs{ + Package: "foo", + Stem: "bar", + Maps: []string{"map1"}, + Variables: []string{"var_1"}, + Programs: []string{"prog_foo_1"}, + Output: &buf, + } + err := Generate(args) + qt.Assert(t, qt.IsNil(err)) + + str := buf.String() + + qt.Assert(t, qt.StringContains(str, "Map1 *ebpf.MapSpec `ebpf:\"map1\"`")) + qt.Assert(t, qt.StringContains(str, "Var1 *ebpf.VariableSpec `ebpf:\"var_1\"`")) + qt.Assert(t, qt.StringContains(str, "ProgFoo1 *ebpf.ProgramSpec `ebpf:\"prog_foo_1\"`")) + + qt.Assert(t, qt.StringContains(str, "Map1 *ebpf.Map `ebpf:\"map1\"`")) + qt.Assert(t, qt.StringContains(str, "Var1 *ebpf.Variable `ebpf:\"var_1\"`")) + qt.Assert(t, qt.StringContains(str, "ProgFoo1 *ebpf.Program `ebpf:\"prog_foo_1\"`")) +} diff --git a/cmd/bpf2go/gen/types.go b/cmd/bpf2go/gen/types.go index 37dad0c76..115d73423 100644 --- a/cmd/bpf2go/gen/types.go +++ b/cmd/bpf2go/gen/types.go @@ -1,44 +1,95 @@ package gen import ( + "cmp" + "slices" + "github.com/cilium/ebpf" "github.com/cilium/ebpf/btf" ) // CollectGlobalTypes finds all types which are used in the global scope. // -// This currently includes the types of map keys and values. +// This currently includes the types of variables, map keys and values. func CollectGlobalTypes(spec *ebpf.CollectionSpec) []btf.Type { var types []btf.Type - for _, typ := range collectMapTypes(spec.Maps) { - switch btf.UnderlyingType(typ).(type) { - case *btf.Datasec: - // Avoid emitting .rodata, .bss, etc. for now. We might want to - // name these types differently, etc. - continue - case *btf.Int: - // Don't emit primitive types by default. - continue - } + types = collectMapTypes(types, spec.Maps) + types = collectVariableTypes(types, spec.Variables) - types = append(types, typ) - } + slices.SortStableFunc(types, func(a, b btf.Type) int { + return cmp.Compare(a.TypeName(), b.TypeName()) + }) return types } -// collectMapTypes returns a list of all types used as map keys or values. -func collectMapTypes(maps map[string]*ebpf.MapSpec) []btf.Type { - var result []btf.Type +// collectMapTypes collects all types used by MapSpecs. +func collectMapTypes(types []btf.Type, maps map[string]*ebpf.MapSpec) []btf.Type { for _, m := range maps { if m.Key != nil && m.Key.TypeName() != "" { - result = append(result, m.Key) + types = addType(types, m.Key) } if m.Value != nil && m.Value.TypeName() != "" { - result = append(result, m.Value) + types = addType(types, m.Value) } } - return result + + return types +} + +// collectVariableTypes collects all types used by VariableSpecs. +func collectVariableTypes(types []btf.Type, vars map[string]*ebpf.VariableSpec) []btf.Type { + for _, vs := range vars { + v := vs.Type() + if v == nil { + continue + } + + types = addType(types, v.Type) + } + + return types +} + +// addType adds a type to types if not already present. Types that don't need to +// be generated are not added to types. +func addType(types []btf.Type, incoming btf.Type) []btf.Type { + incoming = selectType(incoming) + if incoming == nil { + return types + } + + // Strip only the qualifiers (not typedefs) from the incoming type. Retain + // typedefs since they carry the name of the anonymous type they point to, + // without which we can't generate a named Go type. + incoming = btf.QualifiedType(incoming) + if incoming.TypeName() == "" { + return types + } + + exists := func(existing btf.Type) bool { + return existing.TypeName() == incoming.TypeName() + } + if !slices.ContainsFunc(types, exists) { + types = append(types, incoming) + } + return types +} + +func selectType(t btf.Type) btf.Type { + // Obtain a concrete type with qualifiers and typedefs stripped. + switch ut := btf.UnderlyingType(t).(type) { + case *btf.Struct, *btf.Union, *btf.Enum: + return t + + // Collect the array's element type. Note: qualifiers on array-type variables + // typically appear after the array, e.g. a const volatile int[4] is actually + // an array of const volatile ints. + case *btf.Array: + return selectType(ut.Type) + } + + return nil } diff --git a/cmd/bpf2go/gen/types_test.go b/cmd/bpf2go/gen/types_test.go index bb5866301..286705a98 100644 --- a/cmd/bpf2go/gen/types_test.go +++ b/cmd/bpf2go/gen/types_test.go @@ -8,19 +8,34 @@ import ( "github.com/cilium/ebpf/internal/testutils" "github.com/go-quicktest/qt" + "github.com/google/go-cmp/cmp" ) +func mustAnyTypeByName(t *testing.T, spec *ebpf.CollectionSpec, name string) btf.Type { + t.Helper() + + typ, err := spec.Types.AnyTypeByName(name) + qt.Assert(t, qt.IsNil(err)) + return typ +} + func TestCollectGlobalTypes(t *testing.T) { spec, err := ebpf.LoadCollectionSpec(testutils.NativeFile(t, "../testdata/minimal-%s.elf")) if err != nil { t.Fatal(err) } - map1 := spec.Maps["map1"] + bar := mustAnyTypeByName(t, spec, "bar") + barfoo := mustAnyTypeByName(t, spec, "barfoo") + baz := mustAnyTypeByName(t, spec, "baz") + e := mustAnyTypeByName(t, spec, "e") + ubar := mustAnyTypeByName(t, spec, "ubar") - types := CollectGlobalTypes(spec) - if err != nil { - t.Fatal(err) - } - qt.Assert(t, qt.CmpEquals(types, []btf.Type{map1.Key, map1.Value}, typesEqualComparer)) + got := CollectGlobalTypes(spec) + qt.Assert(t, qt.IsNil(err)) + + want := []btf.Type{bar, barfoo, baz, e, ubar} + qt.Assert(t, qt.CmpEquals(got, want, cmp.Comparer(func(a, b btf.Type) bool { + return a.TypeName() == b.TypeName() + }))) } diff --git a/cmd/bpf2go/main.go b/cmd/bpf2go/main.go index fb077e139..367246ba9 100644 --- a/cmd/bpf2go/main.go +++ b/cmd/bpf2go/main.go @@ -370,6 +370,11 @@ func (b2g *bpf2go) convert(tgt gen.Target, goarches gen.GoArches) (err error) { } } + var variables []string + for name := range spec.Variables { + variables = append(variables, name) + } + var programs []string for name := range spec.Programs { programs = append(programs, name) @@ -397,6 +402,7 @@ func (b2g *bpf2go) convert(tgt gen.Target, goarches gen.GoArches) (err error) { Stem: b2g.identStem, Constraints: constraints, Maps: maps, + Variables: variables, Programs: programs, Types: types, ObjectFile: filepath.Base(objFileName), diff --git a/cmd/bpf2go/test/api_test.go b/cmd/bpf2go/test/api_test.go index 76f57157e..72629125d 100644 --- a/cmd/bpf2go/test/api_test.go +++ b/cmd/bpf2go/test/api_test.go @@ -5,19 +5,20 @@ import ( "testing" "unsafe" + "github.com/go-quicktest/qt" + "github.com/cilium/ebpf/internal/testutils" ) func TestLoadingSpec(t *testing.T) { spec, err := loadTest() testutils.SkipIfNotSupported(t, err) - if err != nil { - t.Fatal("Can't load spec:", err) - } + qt.Assert(t, qt.IsNil(err)) - if spec == nil { - t.Fatal("Got a nil spec") - } + qt.Assert(t, qt.Not(qt.IsNil(spec))) + qt.Assert(t, qt.Not(qt.IsNil(spec.Programs))) + qt.Assert(t, qt.Not(qt.IsNil(spec.Maps))) + qt.Assert(t, qt.Not(qt.IsNil(spec.Variables))) } func TestLoadingObjects(t *testing.T) { @@ -29,13 +30,10 @@ func TestLoadingObjects(t *testing.T) { } defer objs.Close() - if objs.Filter == nil { - t.Error("Loading returns an object with nil programs") - } - - if objs.Map1 == nil { - t.Error("Loading returns an object with nil maps") - } + qt.Assert(t, qt.Not(qt.IsNil(objs.Filter))) + qt.Assert(t, qt.Not(qt.IsNil(objs.Map1))) + qt.Assert(t, qt.Not(qt.IsNil(objs.MyConstant))) + qt.Assert(t, qt.Not(qt.IsNil(objs.StructConst))) } func TestTypes(t *testing.T) { diff --git a/cmd/bpf2go/test/test_bpfeb.go b/cmd/bpf2go/test/test_bpfeb.go index 62d5b4352..be2f2e68d 100644 --- a/cmd/bpf2go/test/test_bpfeb.go +++ b/cmd/bpf2go/test/test_bpfeb.go @@ -12,6 +12,12 @@ import ( "github.com/cilium/ebpf" ) +type testBar struct { + A uint64 + B uint32 + _ [4]byte +} + type testBarfoo struct { Bar int64 Baz bool @@ -19,6 +25,8 @@ type testBarfoo struct { Boo testE } +type testBaz struct{ A uint64 } + type testE uint32 const ( @@ -26,6 +34,11 @@ const ( testEFROOD testE = 1 ) +type testUbar struct { + A uint32 + _ [4]byte +} + // loadTest returns the embedded CollectionSpec for test. func loadTest() (*ebpf.CollectionSpec, error) { reader := bytes.NewReader(_TestBytes) @@ -61,9 +74,10 @@ func loadTestObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type testSpecs struct { testProgramSpecs testMapSpecs + testVariableSpecs } -// testSpecs contains programs before they are loaded into the kernel. +// testProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type testProgramSpecs struct { @@ -77,12 +91,26 @@ type testMapSpecs struct { Map1 *ebpf.MapSpec `ebpf:"map1"` } +// testVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type testVariableSpecs struct { + AnInt *ebpf.VariableSpec `ebpf:"an_int"` + IntArray *ebpf.VariableSpec `ebpf:"int_array"` + MyConstant *ebpf.VariableSpec `ebpf:"my_constant"` + StructArray *ebpf.VariableSpec `ebpf:"struct_array"` + StructConst *ebpf.VariableSpec `ebpf:"struct_const"` + StructVar *ebpf.VariableSpec `ebpf:"struct_var"` + UnionVar *ebpf.VariableSpec `ebpf:"union_var"` +} + // testObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadTestObjects or ebpf.CollectionSpec.LoadAndAssign. type testObjects struct { testPrograms testMaps + testVariables } func (o *testObjects) Close() error { @@ -105,6 +133,19 @@ func (m *testMaps) Close() error { ) } +// testVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadTestObjects or ebpf.CollectionSpec.LoadAndAssign. +type testVariables struct { + AnInt *ebpf.Variable `ebpf:"an_int"` + IntArray *ebpf.Variable `ebpf:"int_array"` + MyConstant *ebpf.Variable `ebpf:"my_constant"` + StructArray *ebpf.Variable `ebpf:"struct_array"` + StructConst *ebpf.Variable `ebpf:"struct_const"` + StructVar *ebpf.Variable `ebpf:"struct_var"` + UnionVar *ebpf.Variable `ebpf:"union_var"` +} + // testPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadTestObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/cmd/bpf2go/test/test_bpfeb.o b/cmd/bpf2go/test/test_bpfeb.o index dffb8f859..a59e38c27 100644 Binary files a/cmd/bpf2go/test/test_bpfeb.o and b/cmd/bpf2go/test/test_bpfeb.o differ diff --git a/cmd/bpf2go/test/test_bpfel.go b/cmd/bpf2go/test/test_bpfel.go index 94efcde9b..4fb0c2280 100644 --- a/cmd/bpf2go/test/test_bpfel.go +++ b/cmd/bpf2go/test/test_bpfel.go @@ -12,6 +12,12 @@ import ( "github.com/cilium/ebpf" ) +type testBar struct { + A uint64 + B uint32 + _ [4]byte +} + type testBarfoo struct { Bar int64 Baz bool @@ -19,6 +25,8 @@ type testBarfoo struct { Boo testE } +type testBaz struct{ A uint64 } + type testE uint32 const ( @@ -26,6 +34,11 @@ const ( testEFROOD testE = 1 ) +type testUbar struct { + A uint32 + _ [4]byte +} + // loadTest returns the embedded CollectionSpec for test. func loadTest() (*ebpf.CollectionSpec, error) { reader := bytes.NewReader(_TestBytes) @@ -61,9 +74,10 @@ func loadTestObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type testSpecs struct { testProgramSpecs testMapSpecs + testVariableSpecs } -// testSpecs contains programs before they are loaded into the kernel. +// testProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type testProgramSpecs struct { @@ -77,12 +91,26 @@ type testMapSpecs struct { Map1 *ebpf.MapSpec `ebpf:"map1"` } +// testVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type testVariableSpecs struct { + AnInt *ebpf.VariableSpec `ebpf:"an_int"` + IntArray *ebpf.VariableSpec `ebpf:"int_array"` + MyConstant *ebpf.VariableSpec `ebpf:"my_constant"` + StructArray *ebpf.VariableSpec `ebpf:"struct_array"` + StructConst *ebpf.VariableSpec `ebpf:"struct_const"` + StructVar *ebpf.VariableSpec `ebpf:"struct_var"` + UnionVar *ebpf.VariableSpec `ebpf:"union_var"` +} + // testObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadTestObjects or ebpf.CollectionSpec.LoadAndAssign. type testObjects struct { testPrograms testMaps + testVariables } func (o *testObjects) Close() error { @@ -105,6 +133,19 @@ func (m *testMaps) Close() error { ) } +// testVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadTestObjects or ebpf.CollectionSpec.LoadAndAssign. +type testVariables struct { + AnInt *ebpf.Variable `ebpf:"an_int"` + IntArray *ebpf.Variable `ebpf:"int_array"` + MyConstant *ebpf.Variable `ebpf:"my_constant"` + StructArray *ebpf.Variable `ebpf:"struct_array"` + StructConst *ebpf.Variable `ebpf:"struct_const"` + StructVar *ebpf.Variable `ebpf:"struct_var"` + UnionVar *ebpf.Variable `ebpf:"union_var"` +} + // testPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadTestObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/cmd/bpf2go/test/test_bpfel.o b/cmd/bpf2go/test/test_bpfel.o index 1cc5b1e1b..9bc2674a3 100644 Binary files a/cmd/bpf2go/test/test_bpfel.o and b/cmd/bpf2go/test/test_bpfel.o differ diff --git a/cmd/bpf2go/testdata/minimal-eb.elf b/cmd/bpf2go/testdata/minimal-eb.elf index dafa0302f..8a45210ac 100644 Binary files a/cmd/bpf2go/testdata/minimal-eb.elf and b/cmd/bpf2go/testdata/minimal-eb.elf differ diff --git a/cmd/bpf2go/testdata/minimal-el.elf b/cmd/bpf2go/testdata/minimal-el.elf index 0acd3be7c..89b8e9d3a 100644 Binary files a/cmd/bpf2go/testdata/minimal-el.elf and b/cmd/bpf2go/testdata/minimal-el.elf differ diff --git a/cmd/bpf2go/testdata/minimal.c b/cmd/bpf2go/testdata/minimal.c index 1639d6ef0..d906d2408 100644 --- a/cmd/bpf2go/testdata/minimal.c +++ b/cmd/bpf2go/testdata/minimal.c @@ -12,6 +12,20 @@ typedef struct { enum e boo; } barfoo; +typedef struct { + uint64_t a; +} baz; + +struct bar { + uint64_t a; + uint32_t b; +}; + +union ubar { + uint32_t a; + uint64_t b; +}; + struct { __uint(type, BPF_MAP_TYPE_HASH); __type(key, enum e); @@ -19,9 +33,14 @@ struct { __uint(max_entries, 1); } map1 __section(".maps"); +volatile const int an_int; volatile const enum e my_constant = FROOD; - +volatile const int int_array[2]; volatile const barfoo struct_const; +volatile const baz struct_array[2]; + +volatile struct bar struct_var; +volatile union ubar union_var; __section("socket") int filter() { return my_constant + struct_const.bar; diff --git a/docs/examples/getting_started/counter_bpfeb.go b/docs/examples/getting_started/counter_bpfeb.go index b4ab10c7c..2ebc5eb52 100644 --- a/docs/examples/getting_started/counter_bpfeb.go +++ b/docs/examples/getting_started/counter_bpfeb.go @@ -47,9 +47,10 @@ func loadCounterObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type counterSpecs struct { counterProgramSpecs counterMapSpecs + counterVariableSpecs } -// counterSpecs contains programs before they are loaded into the kernel. +// counterProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type counterProgramSpecs struct { @@ -63,12 +64,19 @@ type counterMapSpecs struct { PktCount *ebpf.MapSpec `ebpf:"pkt_count"` } +// counterVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type counterVariableSpecs struct { +} + // counterObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadCounterObjects or ebpf.CollectionSpec.LoadAndAssign. type counterObjects struct { counterPrograms counterMaps + counterVariables } func (o *counterObjects) Close() error { @@ -91,6 +99,12 @@ func (m *counterMaps) Close() error { ) } +// counterVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadCounterObjects or ebpf.CollectionSpec.LoadAndAssign. +type counterVariables struct { +} + // counterPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadCounterObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/docs/examples/getting_started/counter_bpfel.go b/docs/examples/getting_started/counter_bpfel.go index 6e09ca1a5..ca57ac8d2 100644 --- a/docs/examples/getting_started/counter_bpfel.go +++ b/docs/examples/getting_started/counter_bpfel.go @@ -47,9 +47,10 @@ func loadCounterObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type counterSpecs struct { counterProgramSpecs counterMapSpecs + counterVariableSpecs } -// counterSpecs contains programs before they are loaded into the kernel. +// counterProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type counterProgramSpecs struct { @@ -63,12 +64,19 @@ type counterMapSpecs struct { PktCount *ebpf.MapSpec `ebpf:"pkt_count"` } +// counterVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type counterVariableSpecs struct { +} + // counterObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadCounterObjects or ebpf.CollectionSpec.LoadAndAssign. type counterObjects struct { counterPrograms counterMaps + counterVariables } func (o *counterObjects) Close() error { @@ -91,6 +99,12 @@ func (m *counterMaps) Close() error { ) } +// counterVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadCounterObjects or ebpf.CollectionSpec.LoadAndAssign. +type counterVariables struct { +} + // counterPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadCounterObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/docs/examples/variables/variables_bpfeb.go b/docs/examples/variables/variables_bpfeb.go index 6740bb8fd..4fd793af9 100644 --- a/docs/examples/variables/variables_bpfeb.go +++ b/docs/examples/variables/variables_bpfeb.go @@ -47,9 +47,10 @@ func loadVariablesObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type variablesSpecs struct { variablesProgramSpecs variablesMapSpecs + variablesVariableSpecs } -// variablesSpecs contains programs before they are loaded into the kernel. +// variablesProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type variablesProgramSpecs struct { @@ -64,12 +65,21 @@ type variablesProgramSpecs struct { type variablesMapSpecs struct { } +// variablesVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type variablesVariableSpecs struct { + ConstU32 *ebpf.VariableSpec `ebpf:"const_u32"` + GlobalU16 *ebpf.VariableSpec `ebpf:"global_u16"` +} + // variablesObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadVariablesObjects or ebpf.CollectionSpec.LoadAndAssign. type variablesObjects struct { variablesPrograms variablesMaps + variablesVariables } func (o *variablesObjects) Close() error { @@ -89,6 +99,14 @@ func (m *variablesMaps) Close() error { return _VariablesClose() } +// variablesVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadVariablesObjects or ebpf.CollectionSpec.LoadAndAssign. +type variablesVariables struct { + ConstU32 *ebpf.Variable `ebpf:"const_u32"` + GlobalU16 *ebpf.Variable `ebpf:"global_u16"` +} + // variablesPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadVariablesObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/docs/examples/variables/variables_bpfel.go b/docs/examples/variables/variables_bpfel.go index 6b8099921..f091b898d 100644 --- a/docs/examples/variables/variables_bpfel.go +++ b/docs/examples/variables/variables_bpfel.go @@ -47,9 +47,10 @@ func loadVariablesObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type variablesSpecs struct { variablesProgramSpecs variablesMapSpecs + variablesVariableSpecs } -// variablesSpecs contains programs before they are loaded into the kernel. +// variablesProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type variablesProgramSpecs struct { @@ -64,12 +65,21 @@ type variablesProgramSpecs struct { type variablesMapSpecs struct { } +// variablesVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type variablesVariableSpecs struct { + ConstU32 *ebpf.VariableSpec `ebpf:"const_u32"` + GlobalU16 *ebpf.VariableSpec `ebpf:"global_u16"` +} + // variablesObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadVariablesObjects or ebpf.CollectionSpec.LoadAndAssign. type variablesObjects struct { variablesPrograms variablesMaps + variablesVariables } func (o *variablesObjects) Close() error { @@ -89,6 +99,14 @@ func (m *variablesMaps) Close() error { return _VariablesClose() } +// variablesVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadVariablesObjects or ebpf.CollectionSpec.LoadAndAssign. +type variablesVariables struct { + ConstU32 *ebpf.Variable `ebpf:"const_u32"` + GlobalU16 *ebpf.Variable `ebpf:"global_u16"` +} + // variablesPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadVariablesObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/cgroup_skb/bpf_bpfeb.go b/examples/cgroup_skb/bpf_bpfeb.go index 3b716c9c0..eaa7d6797 100644 --- a/examples/cgroup_skb/bpf_bpfeb.go +++ b/examples/cgroup_skb/bpf_bpfeb.go @@ -47,9 +47,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -63,12 +64,19 @@ type bpfMapSpecs struct { PktCount *ebpf.MapSpec `ebpf:"pkt_count"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -91,6 +99,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/cgroup_skb/bpf_bpfel.go b/examples/cgroup_skb/bpf_bpfel.go index 086736dce..67f5ba473 100644 --- a/examples/cgroup_skb/bpf_bpfel.go +++ b/examples/cgroup_skb/bpf_bpfel.go @@ -47,9 +47,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -63,12 +64,19 @@ type bpfMapSpecs struct { PktCount *ebpf.MapSpec `ebpf:"pkt_count"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -91,6 +99,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/fentry/bpf_bpfeb.go b/examples/fentry/bpf_bpfeb.go index d81f533ba..fd2aeb7b5 100644 --- a/examples/fentry/bpf_bpfeb.go +++ b/examples/fentry/bpf_bpfeb.go @@ -55,9 +55,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -71,12 +72,19 @@ type bpfMapSpecs struct { Events *ebpf.MapSpec `ebpf:"events"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -99,6 +107,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/fentry/bpf_bpfel.go b/examples/fentry/bpf_bpfel.go index 467e23d4c..1b4d2a2a7 100644 --- a/examples/fentry/bpf_bpfel.go +++ b/examples/fentry/bpf_bpfel.go @@ -55,9 +55,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -71,12 +72,19 @@ type bpfMapSpecs struct { Events *ebpf.MapSpec `ebpf:"events"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -99,6 +107,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/kprobe/bpf_bpfeb.go b/examples/kprobe/bpf_bpfeb.go index 07a3b0b0d..c75e68648 100644 --- a/examples/kprobe/bpf_bpfeb.go +++ b/examples/kprobe/bpf_bpfeb.go @@ -47,9 +47,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -63,12 +64,19 @@ type bpfMapSpecs struct { KprobeMap *ebpf.MapSpec `ebpf:"kprobe_map"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -91,6 +99,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/kprobe/bpf_bpfel.go b/examples/kprobe/bpf_bpfel.go index dcbf486ec..d252db9d8 100644 --- a/examples/kprobe/bpf_bpfel.go +++ b/examples/kprobe/bpf_bpfel.go @@ -47,9 +47,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -63,12 +64,19 @@ type bpfMapSpecs struct { KprobeMap *ebpf.MapSpec `ebpf:"kprobe_map"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -91,6 +99,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/kprobe_percpu/bpf_bpfeb.go b/examples/kprobe_percpu/bpf_bpfeb.go index 07a3b0b0d..c75e68648 100644 --- a/examples/kprobe_percpu/bpf_bpfeb.go +++ b/examples/kprobe_percpu/bpf_bpfeb.go @@ -47,9 +47,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -63,12 +64,19 @@ type bpfMapSpecs struct { KprobeMap *ebpf.MapSpec `ebpf:"kprobe_map"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -91,6 +99,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/kprobe_percpu/bpf_bpfel.go b/examples/kprobe_percpu/bpf_bpfel.go index dcbf486ec..d252db9d8 100644 --- a/examples/kprobe_percpu/bpf_bpfel.go +++ b/examples/kprobe_percpu/bpf_bpfel.go @@ -47,9 +47,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -63,12 +64,19 @@ type bpfMapSpecs struct { KprobeMap *ebpf.MapSpec `ebpf:"kprobe_map"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -91,6 +99,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/kprobepin/bpf_bpfeb.go b/examples/kprobepin/bpf_bpfeb.go index 07a3b0b0d..c75e68648 100644 --- a/examples/kprobepin/bpf_bpfeb.go +++ b/examples/kprobepin/bpf_bpfeb.go @@ -47,9 +47,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -63,12 +64,19 @@ type bpfMapSpecs struct { KprobeMap *ebpf.MapSpec `ebpf:"kprobe_map"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -91,6 +99,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/kprobepin/bpf_bpfel.go b/examples/kprobepin/bpf_bpfel.go index dcbf486ec..d252db9d8 100644 --- a/examples/kprobepin/bpf_bpfel.go +++ b/examples/kprobepin/bpf_bpfel.go @@ -47,9 +47,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -63,12 +64,19 @@ type bpfMapSpecs struct { KprobeMap *ebpf.MapSpec `ebpf:"kprobe_map"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -91,6 +99,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/ringbuffer/bpf_bpfeb.go b/examples/ringbuffer/bpf_bpfeb.go index 3df7da158..8e716a87a 100644 --- a/examples/ringbuffer/bpf_bpfeb.go +++ b/examples/ringbuffer/bpf_bpfeb.go @@ -52,9 +52,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -68,12 +69,19 @@ type bpfMapSpecs struct { Events *ebpf.MapSpec `ebpf:"events"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -96,6 +104,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/ringbuffer/bpf_bpfel.go b/examples/ringbuffer/bpf_bpfel.go index f3d67dede..3a0825c35 100644 --- a/examples/ringbuffer/bpf_bpfel.go +++ b/examples/ringbuffer/bpf_bpfel.go @@ -52,9 +52,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -68,12 +69,19 @@ type bpfMapSpecs struct { Events *ebpf.MapSpec `ebpf:"events"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -96,6 +104,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/tcprtt/bpf_bpfeb.go b/examples/tcprtt/bpf_bpfeb.go index 2a5966e13..9567721ca 100644 --- a/examples/tcprtt/bpf_bpfeb.go +++ b/examples/tcprtt/bpf_bpfeb.go @@ -55,9 +55,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -71,12 +72,19 @@ type bpfMapSpecs struct { Events *ebpf.MapSpec `ebpf:"events"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -99,6 +107,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/tcprtt/bpf_bpfel.go b/examples/tcprtt/bpf_bpfel.go index d599a52e8..4eb5dcd5a 100644 --- a/examples/tcprtt/bpf_bpfel.go +++ b/examples/tcprtt/bpf_bpfel.go @@ -55,9 +55,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -71,12 +72,19 @@ type bpfMapSpecs struct { Events *ebpf.MapSpec `ebpf:"events"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -99,6 +107,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/tcprtt_sockops/bpf_bpfeb.go b/examples/tcprtt_sockops/bpf_bpfeb.go index 4db569a84..870c24cbb 100644 --- a/examples/tcprtt_sockops/bpf_bpfeb.go +++ b/examples/tcprtt_sockops/bpf_bpfeb.go @@ -68,9 +68,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -85,12 +86,19 @@ type bpfMapSpecs struct { RttEvents *ebpf.MapSpec `ebpf:"rtt_events"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -115,6 +123,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/tcprtt_sockops/bpf_bpfel.go b/examples/tcprtt_sockops/bpf_bpfel.go index 7e7e72453..c371fe554 100644 --- a/examples/tcprtt_sockops/bpf_bpfel.go +++ b/examples/tcprtt_sockops/bpf_bpfel.go @@ -68,9 +68,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -85,12 +86,19 @@ type bpfMapSpecs struct { RttEvents *ebpf.MapSpec `ebpf:"rtt_events"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -115,6 +123,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/tcx/bpf_bpfeb.go b/examples/tcx/bpf_bpfeb.go index 36b1dceb9..3883b86a6 100644 --- a/examples/tcx/bpf_bpfeb.go +++ b/examples/tcx/bpf_bpfeb.go @@ -47,9 +47,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -61,8 +62,14 @@ type bpfProgramSpecs struct { // // It can be passed ebpf.CollectionSpec.Assign. type bpfMapSpecs struct { - EgressPktCount *ebpf.MapSpec `ebpf:"egress_pkt_count"` - IngressPktCount *ebpf.MapSpec `ebpf:"ingress_pkt_count"` +} + +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { + EgressPktCount *ebpf.VariableSpec `ebpf:"egress_pkt_count"` + IngressPktCount *ebpf.VariableSpec `ebpf:"ingress_pkt_count"` } // bpfObjects contains all objects after they have been loaded into the kernel. @@ -71,6 +78,7 @@ type bpfMapSpecs struct { type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -84,15 +92,18 @@ func (o *bpfObjects) Close() error { // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfMaps struct { - EgressPktCount *ebpf.Map `ebpf:"egress_pkt_count"` - IngressPktCount *ebpf.Map `ebpf:"ingress_pkt_count"` } func (m *bpfMaps) Close() error { - return _BpfClose( - m.EgressPktCount, - m.IngressPktCount, - ) + return _BpfClose() +} + +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { + EgressPktCount *ebpf.Variable `ebpf:"egress_pkt_count"` + IngressPktCount *ebpf.Variable `ebpf:"ingress_pkt_count"` } // bpfPrograms contains all programs after they have been loaded into the kernel. diff --git a/examples/tcx/bpf_bpfeb.o b/examples/tcx/bpf_bpfeb.o index 9662849e7..928c8527e 100644 Binary files a/examples/tcx/bpf_bpfeb.o and b/examples/tcx/bpf_bpfeb.o differ diff --git a/examples/tcx/bpf_bpfel.go b/examples/tcx/bpf_bpfel.go index 7767e316d..56d03d193 100644 --- a/examples/tcx/bpf_bpfel.go +++ b/examples/tcx/bpf_bpfel.go @@ -47,9 +47,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -61,8 +62,14 @@ type bpfProgramSpecs struct { // // It can be passed ebpf.CollectionSpec.Assign. type bpfMapSpecs struct { - EgressPktCount *ebpf.MapSpec `ebpf:"egress_pkt_count"` - IngressPktCount *ebpf.MapSpec `ebpf:"ingress_pkt_count"` +} + +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { + EgressPktCount *ebpf.VariableSpec `ebpf:"egress_pkt_count"` + IngressPktCount *ebpf.VariableSpec `ebpf:"ingress_pkt_count"` } // bpfObjects contains all objects after they have been loaded into the kernel. @@ -71,6 +78,7 @@ type bpfMapSpecs struct { type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -84,15 +92,18 @@ func (o *bpfObjects) Close() error { // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfMaps struct { - EgressPktCount *ebpf.Map `ebpf:"egress_pkt_count"` - IngressPktCount *ebpf.Map `ebpf:"ingress_pkt_count"` } func (m *bpfMaps) Close() error { - return _BpfClose( - m.EgressPktCount, - m.IngressPktCount, - ) + return _BpfClose() +} + +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { + EgressPktCount *ebpf.Variable `ebpf:"egress_pkt_count"` + IngressPktCount *ebpf.Variable `ebpf:"ingress_pkt_count"` } // bpfPrograms contains all programs after they have been loaded into the kernel. diff --git a/examples/tcx/bpf_bpfel.o b/examples/tcx/bpf_bpfel.o index 5ff34587e..7acc38c25 100644 Binary files a/examples/tcx/bpf_bpfel.o and b/examples/tcx/bpf_bpfel.o differ diff --git a/examples/tcx/main.go b/examples/tcx/main.go index e0ac83d94..d31acb153 100644 --- a/examples/tcx/main.go +++ b/examples/tcx/main.go @@ -1,8 +1,7 @@ // This program demonstrates attaching an eBPF program to a network interface -// with Linux TC (Traffic Control). The program counts ingress and egress -// packets using two ARRAY maps. -// The userspace program (Go code in this file) prints the contents -// of the two maps to stdout every second. +// with Linux TCX (Traffic Control with eBPF). The program counts ingress and egress +// packets using two variables. The userspace program (Go code in this file) +// prints the contents of the two variables to stdout every second. // This example depends on tcx bpf_link, available in Linux kernel version 6.6 or newer. package main @@ -78,20 +77,19 @@ func main() { } } -func formatCounters(ingressMap, egressMap *ebpf.Map) (string, error) { +func formatCounters(ingressVar, egressVar *ebpf.Variable) (string, error) { var ( ingressPacketCount uint64 egressPacketCount uint64 - key int32 ) // retrieve value from the ingress map - if err := ingressMap.Lookup(&key, &ingressPacketCount); err != nil { + if err := ingressVar.Get(&ingressPacketCount); err != nil { return "", err } // retrieve value from the egress map - if err := egressMap.Lookup(&key, &egressPacketCount); err != nil { + if err := egressVar.Get(&egressPacketCount); err != nil { return "", err } diff --git a/examples/tcx/tcx.c b/examples/tcx/tcx.c index 61996ba02..248f0c340 100644 --- a/examples/tcx/tcx.c +++ b/examples/tcx/tcx.c @@ -4,43 +4,17 @@ char __license[] SEC("license") = "Dual MIT/GPL"; -/* Define an ARRAY map for storing ingress packet count */ -struct { - __uint(type, BPF_MAP_TYPE_ARRAY); - __type(key, __u32); - __type(value, __u64); - __uint(max_entries, 1); -} ingress_pkt_count SEC(".maps"); - -/* Define an ARRAY map for storing egress packet count */ -struct { - __uint(type, BPF_MAP_TYPE_ARRAY); - __type(key, __u32); - __type(value, __u64); - __uint(max_entries, 1); -} egress_pkt_count SEC(".maps"); - -/* -Upon arrival of each network packet, retrieve and increment -the packet count from the provided map. -Returns TC_ACT_OK, allowing the packet to proceed. -*/ -static __always_inline int update_map_pkt_count(void *map) { - __u32 key = 0; - __u64 *count = bpf_map_lookup_elem(map, &key); - if (count) { - __sync_fetch_and_add(count, 1); - } - - return TC_ACT_OK; -} +__u64 ingress_pkt_count = 0; +__u64 egress_pkt_count = 0; SEC("tc") int ingress_prog_func(struct __sk_buff *skb) { - return update_map_pkt_count(&ingress_pkt_count); + __sync_fetch_and_add(&ingress_pkt_count, 1); + return TC_ACT_OK; } SEC("tc") int egress_prog_func(struct __sk_buff *skb) { - return update_map_pkt_count(&egress_pkt_count); + __sync_fetch_and_add(&egress_pkt_count, 1); + return TC_ACT_OK; } diff --git a/examples/tracepoint_in_c/bpf_bpfeb.go b/examples/tracepoint_in_c/bpf_bpfeb.go index f422bb8f7..a2afd6fda 100644 --- a/examples/tracepoint_in_c/bpf_bpfeb.go +++ b/examples/tracepoint_in_c/bpf_bpfeb.go @@ -47,9 +47,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -63,12 +64,19 @@ type bpfMapSpecs struct { CountingMap *ebpf.MapSpec `ebpf:"counting_map"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -91,6 +99,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/tracepoint_in_c/bpf_bpfel.go b/examples/tracepoint_in_c/bpf_bpfel.go index dd9c860d8..8e3858f62 100644 --- a/examples/tracepoint_in_c/bpf_bpfel.go +++ b/examples/tracepoint_in_c/bpf_bpfel.go @@ -47,9 +47,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -63,12 +64,19 @@ type bpfMapSpecs struct { CountingMap *ebpf.MapSpec `ebpf:"counting_map"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -91,6 +99,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/uretprobe/bpf_x86_bpfel.go b/examples/uretprobe/bpf_x86_bpfel.go index 309c34113..fd8616a9d 100644 --- a/examples/uretprobe/bpf_x86_bpfel.go +++ b/examples/uretprobe/bpf_x86_bpfel.go @@ -52,9 +52,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -68,12 +69,19 @@ type bpfMapSpecs struct { Events *ebpf.MapSpec `ebpf:"events"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -96,6 +104,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/xdp/bpf_bpfeb.go b/examples/xdp/bpf_bpfeb.go index bcc09fc6a..5fbb5f0af 100644 --- a/examples/xdp/bpf_bpfeb.go +++ b/examples/xdp/bpf_bpfeb.go @@ -47,9 +47,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -63,12 +64,19 @@ type bpfMapSpecs struct { XdpStatsMap *ebpf.MapSpec `ebpf:"xdp_stats_map"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -91,6 +99,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. diff --git a/examples/xdp/bpf_bpfel.go b/examples/xdp/bpf_bpfel.go index 4541c1216..e7b326b11 100644 --- a/examples/xdp/bpf_bpfel.go +++ b/examples/xdp/bpf_bpfel.go @@ -47,9 +47,10 @@ func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { type bpfSpecs struct { bpfProgramSpecs bpfMapSpecs + bpfVariableSpecs } -// bpfSpecs contains programs before they are loaded into the kernel. +// bpfProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type bpfProgramSpecs struct { @@ -63,12 +64,19 @@ type bpfMapSpecs struct { XdpStatsMap *ebpf.MapSpec `ebpf:"xdp_stats_map"` } +// bpfVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type bpfVariableSpecs struct { +} + // bpfObjects contains all objects after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. type bpfObjects struct { bpfPrograms bpfMaps + bpfVariables } func (o *bpfObjects) Close() error { @@ -91,6 +99,12 @@ func (m *bpfMaps) Close() error { ) } +// bpfVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. +type bpfVariables struct { +} + // bpfPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign.