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