github.com/cilium/ebpf@v0.16.0/examples/tcx/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 EgressProgFunc *ebpf.ProgramSpec `ebpf:"egress_prog_func"` 57 IngressProgFunc *ebpf.ProgramSpec `ebpf:"ingress_prog_func"` 58 } 59 60 // bpfMapSpecs contains maps before they are loaded into the kernel. 61 // 62 // It can be passed ebpf.CollectionSpec.Assign. 63 type bpfMapSpecs struct { 64 EgressPktCount *ebpf.MapSpec `ebpf:"egress_pkt_count"` 65 IngressPktCount *ebpf.MapSpec `ebpf:"ingress_pkt_count"` 66 } 67 68 // bpfObjects contains all objects after they have been loaded into the kernel. 69 // 70 // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. 71 type bpfObjects struct { 72 bpfPrograms 73 bpfMaps 74 } 75 76 func (o *bpfObjects) Close() error { 77 return _BpfClose( 78 &o.bpfPrograms, 79 &o.bpfMaps, 80 ) 81 } 82 83 // bpfMaps contains all maps after they have been loaded into the kernel. 84 // 85 // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. 86 type bpfMaps struct { 87 EgressPktCount *ebpf.Map `ebpf:"egress_pkt_count"` 88 IngressPktCount *ebpf.Map `ebpf:"ingress_pkt_count"` 89 } 90 91 func (m *bpfMaps) Close() error { 92 return _BpfClose( 93 m.EgressPktCount, 94 m.IngressPktCount, 95 ) 96 } 97 98 // bpfPrograms contains all programs after they have been loaded into the kernel. 99 // 100 // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. 101 type bpfPrograms struct { 102 EgressProgFunc *ebpf.Program `ebpf:"egress_prog_func"` 103 IngressProgFunc *ebpf.Program `ebpf:"ingress_prog_func"` 104 } 105 106 func (p *bpfPrograms) Close() error { 107 return _BpfClose( 108 p.EgressProgFunc, 109 p.IngressProgFunc, 110 ) 111 } 112 113 func _BpfClose(closers ...io.Closer) error { 114 for _, closer := range closers { 115 if err := closer.Close(); err != nil { 116 return err 117 } 118 } 119 return nil 120 } 121 122 // Do not access this directly. 123 // 124 //go:embed bpf_bpfel.o 125 var _BpfBytes []byte