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