| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package main |
| 5 |
|
| 6 |
import ( |
| 7 |
"bytes" |
| 8 |
_ "embed" |
| 9 |
"fmt" |
| 10 |
"io" |
| 11 |
|
| 12 |
"github.com/cilium/ebpf" |
| 13 |
) |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
const ( |
| 19 |
variablesProgConstExample = "const_example" |
| 20 |
variablesProgGlobalExample = "global_example" |
| 21 |
variablesProgHiddenExample = "hidden_example" |
| 22 |
variablesVarConstU32 = "const_u32" |
| 23 |
variablesVarGlobalU16 = "global_u16" |
| 24 |
) |
| 25 |
|
| 26 |
|
| 27 |
func loadVariables() (*ebpf.CollectionSpec, error) { |
| 28 |
reader := bytes.NewReader(_VariablesBytes) |
| 29 |
spec, err := ebpf.LoadCollectionSpecFromReader(reader) |
| 30 |
if err != nil { |
| 31 |
return nil, fmt.Errorf("can't load variables: %w", err) |
| 32 |
} |
| 33 |
|
| 34 |
return spec, err |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
func loadVariablesObjects(obj any, opts *ebpf.CollectionOptions) error { |
| 47 |
spec, err := loadVariables() |
| 48 |
if err != nil { |
| 49 |
return err |
| 50 |
} |
| 51 |
|
| 52 |
return spec.LoadAndAssign(obj, opts) |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
type variablesSpecs struct { |
| 59 |
variablesProgramSpecs |
| 60 |
variablesMapSpecs |
| 61 |
variablesVariableSpecs |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
type variablesProgramSpecs struct { |
| 68 |
ConstExample *ebpf.ProgramSpec `ebpf:"const_example"` |
| 69 |
GlobalExample *ebpf.ProgramSpec `ebpf:"global_example"` |
| 70 |
HiddenExample *ebpf.ProgramSpec `ebpf:"hidden_example"` |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
type variablesMapSpecs struct { |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
type variablesVariableSpecs struct { |
| 83 |
ConstU32 *ebpf.VariableSpec `ebpf:"const_u32"` |
| 84 |
GlobalU16 *ebpf.VariableSpec `ebpf:"global_u16"` |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
type variablesObjects struct { |
| 91 |
variablesPrograms |
| 92 |
variablesMaps |
| 93 |
variablesVariables |
| 94 |
} |
| 95 |
|
| 96 |
func (o *variablesObjects) Close() error { |
| 97 |
return _VariablesClose( |
| 98 |
&o.variablesPrograms, |
| 99 |
&o.variablesMaps, |
| 100 |
) |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
type variablesMaps struct { |
| 107 |
} |
| 108 |
|
| 109 |
func (m *variablesMaps) Close() error { |
| 110 |
return _VariablesClose() |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
type variablesVariables struct { |
| 117 |
ConstU32 *ebpf.Variable `ebpf:"const_u32"` |
| 118 |
GlobalU16 *ebpf.Variable `ebpf:"global_u16"` |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
type variablesPrograms struct { |
| 125 |
ConstExample *ebpf.Program `ebpf:"const_example"` |
| 126 |
GlobalExample *ebpf.Program `ebpf:"global_example"` |
| 127 |
HiddenExample *ebpf.Program `ebpf:"hidden_example"` |
| 128 |
} |
| 129 |
|
| 130 |
func (p *variablesPrograms) Close() error { |
| 131 |
return _VariablesClose( |
| 132 |
p.ConstExample, |
| 133 |
p.GlobalExample, |
| 134 |
p.HiddenExample, |
| 135 |
) |
| 136 |
} |
| 137 |
|
| 138 |
func _VariablesClose(closers ...io.Closer) error { |
| 139 |
for _, closer := range closers { |
| 140 |
if err := closer.Close(); err != nil { |
| 141 |
return err |
| 142 |
} |
| 143 |
} |
| 144 |
return nil |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
var _VariablesBytes []byte |