// Code generated by bpf2go; DO NOT EDIT.
//go:build (mips || mips64 || ppc64 || s390x) && linux

package sockmap

import (
	"bytes"
	_ "embed"
	"fmt"
	"io"

	"github.com/cilium/ebpf"
)

// loadSockmap returns the embedded CollectionSpec for sockmap.
func loadSockmap() (*ebpf.CollectionSpec, error) {
	reader := bytes.NewReader(_SockmapBytes)
	spec, err := ebpf.LoadCollectionSpecFromReader(reader)
	if err != nil {
		return nil, fmt.Errorf("can't load sockmap: %w", err)
	}

	return spec, err
}

// loadSockmapObjects loads sockmap and converts it into a struct.
//
// The following types are suitable as obj argument:
//
//	*sockmapObjects
//	*sockmapPrograms
//	*sockmapMaps
//
// See ebpf.CollectionSpec.LoadAndAssign documentation for details.
func loadSockmapObjects(obj interface{}, opts *ebpf.CollectionOptions) error {
	spec, err := loadSockmap()
	if err != nil {
		return err
	}

	return spec.LoadAndAssign(obj, opts)
}

// sockmapSpecs contains maps and programs before they are loaded into the kernel.
//
// It can be passed ebpf.CollectionSpec.Assign.
type sockmapSpecs struct {
	sockmapProgramSpecs
	sockmapMapSpecs
	sockmapVariableSpecs
}

// sockmapProgramSpecs contains programs before they are loaded into the kernel.
//
// It can be passed ebpf.CollectionSpec.Assign.
type sockmapProgramSpecs struct {
	StreamParser  *ebpf.ProgramSpec `ebpf:"stream_parser"`
	StreamVerdict *ebpf.ProgramSpec `ebpf:"stream_verdict"`
}

// sockmapMapSpecs contains maps before they are loaded into the kernel.
//
// It can be passed ebpf.CollectionSpec.Assign.
type sockmapMapSpecs struct {
	Peer     *ebpf.MapSpec `ebpf:"peer"`
	Sockhash *ebpf.MapSpec `ebpf:"sockhash"`
}

// sockmapVariableSpecs contains global variables before they are loaded into the kernel.
//
// It can be passed ebpf.CollectionSpec.Assign.
type sockmapVariableSpecs struct {
}

// sockmapObjects contains all objects after they have been loaded into the kernel.
//
// It can be passed to loadSockmapObjects or ebpf.CollectionSpec.LoadAndAssign.
type sockmapObjects struct {
	sockmapPrograms
	sockmapMaps
	sockmapVariables
}

func (o *sockmapObjects) Close() error {
	return _SockmapClose(
		&o.sockmapPrograms,
		&o.sockmapMaps,
	)
}

// sockmapMaps contains all maps after they have been loaded into the kernel.
//
// It can be passed to loadSockmapObjects or ebpf.CollectionSpec.LoadAndAssign.
type sockmapMaps struct {
	Peer     *ebpf.Map `ebpf:"peer"`
	Sockhash *ebpf.Map `ebpf:"sockhash"`
}

func (m *sockmapMaps) Close() error {
	return _SockmapClose(
		m.Peer,
		m.Sockhash,
	)
}

// sockmapVariables contains all global variables after they have been loaded into the kernel.
//
// It can be passed to loadSockmapObjects or ebpf.CollectionSpec.LoadAndAssign.
type sockmapVariables struct {
}

// sockmapPrograms contains all programs after they have been loaded into the kernel.
//
// It can be passed to loadSockmapObjects or ebpf.CollectionSpec.LoadAndAssign.
type sockmapPrograms struct {
	StreamParser  *ebpf.Program `ebpf:"stream_parser"`
	StreamVerdict *ebpf.Program `ebpf:"stream_verdict"`
}

func (p *sockmapPrograms) Close() error {
	return _SockmapClose(
		p.StreamParser,
		p.StreamVerdict,
	)
}

func _SockmapClose(closers ...io.Closer) error {
	for _, closer := range closers {
		if err := closer.Close(); err != nil {
			return err
		}
	}
	return nil
}

// Do not access this directly.
//
//go:embed sockmap_bpfeb.o
var _SockmapBytes []byte
