github.com/kelleygo/clashcore@v1.0.2/component/ebpf/redir/bpf_bpfel.go (about)

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