github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/examples/cgroup_skb/bpf_bpfel.go (about) 1 // Code generated by bpf2go; DO NOT EDIT. 2 //go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64 3 4 package main 5 6 import ( 7 "bytes" 8 _ "embed" 9 "fmt" 10 "io" 11 12 "github.com/cilium/ebpf" 13 ) 14 15 // loadBpf returns the embedded CollectionSpec for bpf. 16 func loadBpf() (*ebpf.CollectionSpec, error) { 17 reader := bytes.NewReader(_BpfBytes) 18 spec, err := ebpf.LoadCollectionSpecFromReader(reader) 19 if err != nil { 20 return nil, fmt.Errorf("can't load bpf: %w", err) 21 } 22 23 return spec, err 24 } 25 26 // loadBpfObjects loads bpf and converts it into a struct. 27 // 28 // The following types are suitable as obj argument: 29 // 30 // *bpfObjects 31 // *bpfPrograms 32 // *bpfMaps 33 // 34 // See ebpf.CollectionSpec.LoadAndAssign documentation for details. 35 func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { 36 spec, err := loadBpf() 37 if err != nil { 38 return err 39 } 40 41 return spec.LoadAndAssign(obj, opts) 42 } 43 44 // bpfSpecs contains maps and programs before they are loaded into the kernel. 45 // 46 // It can be passed ebpf.CollectionSpec.Assign. 47 type bpfSpecs struct { 48 bpfProgramSpecs 49 bpfMapSpecs 50 } 51 52 // bpfSpecs contains programs before they are loaded into the kernel. 53 // 54 // It can be passed ebpf.CollectionSpec.Assign. 55 type bpfProgramSpecs struct { 56 CountEgressPackets *ebpf.ProgramSpec `ebpf:"count_egress_packets"` 57 } 58 59 // bpfMapSpecs contains maps before they are loaded into the kernel. 60 // 61 // It can be passed ebpf.CollectionSpec.Assign. 62 type bpfMapSpecs struct { 63 PktCount *ebpf.MapSpec `ebpf:"pkt_count"` 64 } 65 66 // bpfObjects contains all objects after they have been loaded into the kernel. 67 // 68 // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. 69 type bpfObjects struct { 70 bpfPrograms 71 bpfMaps 72 } 73 74 func (o *bpfObjects) Close() error { 75 return _BpfClose( 76 &o.bpfPrograms, 77 &o.bpfMaps, 78 ) 79 } 80 81 // bpfMaps contains all maps after they have been loaded into the kernel. 82 // 83 // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. 84 type bpfMaps struct { 85 PktCount *ebpf.Map `ebpf:"pkt_count"` 86 } 87 88 func (m *bpfMaps) Close() error { 89 return _BpfClose( 90 m.PktCount, 91 ) 92 } 93 94 // bpfPrograms contains all programs after they have been loaded into the kernel. 95 // 96 // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. 97 type bpfPrograms struct { 98 CountEgressPackets *ebpf.Program `ebpf:"count_egress_packets"` 99 } 100 101 func (p *bpfPrograms) Close() error { 102 return _BpfClose( 103 p.CountEgressPackets, 104 ) 105 } 106 107 func _BpfClose(closers ...io.Closer) error { 108 for _, closer := range closers { 109 if err := closer.Close(); err != nil { 110 return err 111 } 112 } 113 return nil 114 } 115 116 // Do not access this directly. 117 // 118 //go:embed bpf_bpfel.o 119 var _BpfBytes []byte