github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/docs/examples/getting_started/counter_bpfeb.go (about) 1 // Code generated by bpf2go; DO NOT EDIT. 2 //go:build mips || mips64 || ppc64 || s390x 3 4 package main 5 6 import ( 7 "bytes" 8 _ "embed" 9 "fmt" 10 "io" 11 12 "github.com/cilium/ebpf" 13 ) 14 15 // loadCounter returns the embedded CollectionSpec for counter. 16 func loadCounter() (*ebpf.CollectionSpec, error) { 17 reader := bytes.NewReader(_CounterBytes) 18 spec, err := ebpf.LoadCollectionSpecFromReader(reader) 19 if err != nil { 20 return nil, fmt.Errorf("can't load counter: %w", err) 21 } 22 23 return spec, err 24 } 25 26 // loadCounterObjects loads counter and converts it into a struct. 27 // 28 // The following types are suitable as obj argument: 29 // 30 // *counterObjects 31 // *counterPrograms 32 // *counterMaps 33 // 34 // See ebpf.CollectionSpec.LoadAndAssign documentation for details. 35 func loadCounterObjects(obj interface{}, opts *ebpf.CollectionOptions) error { 36 spec, err := loadCounter() 37 if err != nil { 38 return err 39 } 40 41 return spec.LoadAndAssign(obj, opts) 42 } 43 44 // counterSpecs contains maps and programs before they are loaded into the kernel. 45 // 46 // It can be passed ebpf.CollectionSpec.Assign. 47 type counterSpecs struct { 48 counterProgramSpecs 49 counterMapSpecs 50 } 51 52 // counterSpecs contains programs before they are loaded into the kernel. 53 // 54 // It can be passed ebpf.CollectionSpec.Assign. 55 type counterProgramSpecs struct { 56 CountPackets *ebpf.ProgramSpec `ebpf:"count_packets"` 57 } 58 59 // counterMapSpecs contains maps before they are loaded into the kernel. 60 // 61 // It can be passed ebpf.CollectionSpec.Assign. 62 type counterMapSpecs struct { 63 PktCount *ebpf.MapSpec `ebpf:"pkt_count"` 64 } 65 66 // counterObjects contains all objects after they have been loaded into the kernel. 67 // 68 // It can be passed to loadCounterObjects or ebpf.CollectionSpec.LoadAndAssign. 69 type counterObjects struct { 70 counterPrograms 71 counterMaps 72 } 73 74 func (o *counterObjects) Close() error { 75 return _CounterClose( 76 &o.counterPrograms, 77 &o.counterMaps, 78 ) 79 } 80 81 // counterMaps contains all maps after they have been loaded into the kernel. 82 // 83 // It can be passed to loadCounterObjects or ebpf.CollectionSpec.LoadAndAssign. 84 type counterMaps struct { 85 PktCount *ebpf.Map `ebpf:"pkt_count"` 86 } 87 88 func (m *counterMaps) Close() error { 89 return _CounterClose( 90 m.PktCount, 91 ) 92 } 93 94 // counterPrograms contains all programs after they have been loaded into the kernel. 95 // 96 // It can be passed to loadCounterObjects or ebpf.CollectionSpec.LoadAndAssign. 97 type counterPrograms struct { 98 CountPackets *ebpf.Program `ebpf:"count_packets"` 99 } 100 101 func (p *counterPrograms) Close() error { 102 return _CounterClose( 103 p.CountPackets, 104 ) 105 } 106 107 func _CounterClose(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 counter_bpfeb.o 119 var _CounterBytes []byte