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