github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/examples/tcprtt_sockops/bpf_bpfeb.go (about)

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