// Code generated by bpf2go; DO NOT EDIT.
//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64

package control

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

	"github.com/cilium/ebpf"
)

type bpfDomainRouting struct{ Bitmap [32]uint32 }

type bpfMatchSet struct {
	Value    [16]uint8
	Not      bool
	Type     uint8
	Outbound uint8
	Must     bool
	Mark     uint32
}

type bpfOutboundConnectivityQuery struct {
	Outbound  uint8
	L4proto   uint8
	Ipversion uint8
}

type bpfPidPname struct {
	Pid   uint32
	Pname [16]int8
}

type bpfRedirectEntry struct {
	Ifindex uint32
	Smac    [6]uint8
	Dmac    [6]uint8
	FromWan uint8
	_       [3]byte
}

type bpfRedirectTuple struct {
	Sip struct{ U6Addr8 [16]uint8 }
	Dip struct{ U6Addr8 [16]uint8 }
}

type bpfRoutingResult struct {
	Mark     uint32
	Must     uint8
	Mac      [6]uint8
	Outbound uint8
	Pname    [16]uint8
	Pid      uint32
	Dscp     uint8
	_        [3]byte
}

type bpfTuplesKey struct {
	Sip     struct{ U6Addr8 [16]uint8 }
	Dip     struct{ U6Addr8 [16]uint8 }
	Sport   uint16
	Dport   uint16
	L4proto uint8
	_       [3]byte
}

type bpfUdpConnState struct {
	IsWanIngressDirection bool
	_                     [7]byte
	Timer                 struct{ Opaque [2]uint64 }
}

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

	return spec, err
}

// loadBpfObjects loads bpf and converts it into a struct.
//
// The following types are suitable as obj argument:
//
//	*bpfObjects
//	*bpfPrograms
//	*bpfMaps
//
// See ebpf.CollectionSpec.LoadAndAssign documentation for details.
func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error {
	spec, err := loadBpf()
	if err != nil {
		return err
	}

	return spec.LoadAndAssign(obj, opts)
}

// bpfSpecs contains maps and programs before they are loaded into the kernel.
//
// It can be passed ebpf.CollectionSpec.Assign.
type bpfSpecs struct {
	bpfProgramSpecs
	bpfMapSpecs
}

// bpfSpecs contains programs before they are loaded into the kernel.
//
// It can be passed ebpf.CollectionSpec.Assign.
type bpfProgramSpecs struct {
	TproxyDae0Ingress      *ebpf.ProgramSpec `ebpf:"tproxy_dae0_ingress"`
	TproxyDae0peerIngress  *ebpf.ProgramSpec `ebpf:"tproxy_dae0peer_ingress"`
	TproxyLanEgressL2      *ebpf.ProgramSpec `ebpf:"tproxy_lan_egress_l2"`
	TproxyLanEgressL3      *ebpf.ProgramSpec `ebpf:"tproxy_lan_egress_l3"`
	TproxyLanIngressL2     *ebpf.ProgramSpec `ebpf:"tproxy_lan_ingress_l2"`
	TproxyLanIngressL3     *ebpf.ProgramSpec `ebpf:"tproxy_lan_ingress_l3"`
	TproxyWanCgConnect4    *ebpf.ProgramSpec `ebpf:"tproxy_wan_cg_connect4"`
	TproxyWanCgConnect6    *ebpf.ProgramSpec `ebpf:"tproxy_wan_cg_connect6"`
	TproxyWanCgSendmsg4    *ebpf.ProgramSpec `ebpf:"tproxy_wan_cg_sendmsg4"`
	TproxyWanCgSendmsg6    *ebpf.ProgramSpec `ebpf:"tproxy_wan_cg_sendmsg6"`
	TproxyWanCgSockCreate  *ebpf.ProgramSpec `ebpf:"tproxy_wan_cg_sock_create"`
	TproxyWanCgSockRelease *ebpf.ProgramSpec `ebpf:"tproxy_wan_cg_sock_release"`
	TproxyWanEgressL2      *ebpf.ProgramSpec `ebpf:"tproxy_wan_egress_l2"`
	TproxyWanEgressL3      *ebpf.ProgramSpec `ebpf:"tproxy_wan_egress_l3"`
	TproxyWanIngressL2     *ebpf.ProgramSpec `ebpf:"tproxy_wan_ingress_l2"`
	TproxyWanIngressL3     *ebpf.ProgramSpec `ebpf:"tproxy_wan_ingress_l3"`
}

// bpfMapSpecs contains maps before they are loaded into the kernel.
//
// It can be passed ebpf.CollectionSpec.Assign.
type bpfMapSpecs struct {
	CookiePidMap            *ebpf.MapSpec `ebpf:"cookie_pid_map"`
	DomainRoutingMap        *ebpf.MapSpec `ebpf:"domain_routing_map"`
	FastSock                *ebpf.MapSpec `ebpf:"fast_sock"`
	ListenSocketMap         *ebpf.MapSpec `ebpf:"listen_socket_map"`
	LpmArrayMap             *ebpf.MapSpec `ebpf:"lpm_array_map"`
	OutboundConnectivityMap *ebpf.MapSpec `ebpf:"outbound_connectivity_map"`
	RedirectTrack           *ebpf.MapSpec `ebpf:"redirect_track"`
	RoutingMap              *ebpf.MapSpec `ebpf:"routing_map"`
	RoutingTuplesMap        *ebpf.MapSpec `ebpf:"routing_tuples_map"`
	TgidPnameMap            *ebpf.MapSpec `ebpf:"tgid_pname_map"`
	UdpConnStateMap         *ebpf.MapSpec `ebpf:"udp_conn_state_map"`
	UnusedLpmType           *ebpf.MapSpec `ebpf:"unused_lpm_type"`
}

// bpfObjects contains all objects after they have been loaded into the kernel.
//
// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign.
type bpfObjects struct {
	bpfPrograms
	bpfMaps
}

func (o *bpfObjects) Close() error {
	return _BpfClose(
		&o.bpfPrograms,
		&o.bpfMaps,
	)
}

// bpfMaps contains all maps after they have been loaded into the kernel.
//
// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign.
type bpfMaps struct {
	CookiePidMap            *ebpf.Map `ebpf:"cookie_pid_map"`
	DomainRoutingMap        *ebpf.Map `ebpf:"domain_routing_map"`
	FastSock                *ebpf.Map `ebpf:"fast_sock"`
	ListenSocketMap         *ebpf.Map `ebpf:"listen_socket_map"`
	LpmArrayMap             *ebpf.Map `ebpf:"lpm_array_map"`
	OutboundConnectivityMap *ebpf.Map `ebpf:"outbound_connectivity_map"`
	RedirectTrack           *ebpf.Map `ebpf:"redirect_track"`
	RoutingMap              *ebpf.Map `ebpf:"routing_map"`
	RoutingTuplesMap        *ebpf.Map `ebpf:"routing_tuples_map"`
	TgidPnameMap            *ebpf.Map `ebpf:"tgid_pname_map"`
	UdpConnStateMap         *ebpf.Map `ebpf:"udp_conn_state_map"`
	UnusedLpmType           *ebpf.Map `ebpf:"unused_lpm_type"`
}

func (m *bpfMaps) Close() error {
	return _BpfClose(
		m.CookiePidMap,
		m.DomainRoutingMap,
		m.FastSock,
		m.ListenSocketMap,
		m.LpmArrayMap,
		m.OutboundConnectivityMap,
		m.RedirectTrack,
		m.RoutingMap,
		m.RoutingTuplesMap,
		m.TgidPnameMap,
		m.UdpConnStateMap,
		m.UnusedLpmType,
	)
}

// bpfPrograms contains all programs after they have been loaded into the kernel.
//
// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign.
type bpfPrograms struct {
	TproxyDae0Ingress      *ebpf.Program `ebpf:"tproxy_dae0_ingress"`
	TproxyDae0peerIngress  *ebpf.Program `ebpf:"tproxy_dae0peer_ingress"`
	TproxyLanEgressL2      *ebpf.Program `ebpf:"tproxy_lan_egress_l2"`
	TproxyLanEgressL3      *ebpf.Program `ebpf:"tproxy_lan_egress_l3"`
	TproxyLanIngressL2     *ebpf.Program `ebpf:"tproxy_lan_ingress_l2"`
	TproxyLanIngressL3     *ebpf.Program `ebpf:"tproxy_lan_ingress_l3"`
	TproxyWanCgConnect4    *ebpf.Program `ebpf:"tproxy_wan_cg_connect4"`
	TproxyWanCgConnect6    *ebpf.Program `ebpf:"tproxy_wan_cg_connect6"`
	TproxyWanCgSendmsg4    *ebpf.Program `ebpf:"tproxy_wan_cg_sendmsg4"`
	TproxyWanCgSendmsg6    *ebpf.Program `ebpf:"tproxy_wan_cg_sendmsg6"`
	TproxyWanCgSockCreate  *ebpf.Program `ebpf:"tproxy_wan_cg_sock_create"`
	TproxyWanCgSockRelease *ebpf.Program `ebpf:"tproxy_wan_cg_sock_release"`
	TproxyWanEgressL2      *ebpf.Program `ebpf:"tproxy_wan_egress_l2"`
	TproxyWanEgressL3      *ebpf.Program `ebpf:"tproxy_wan_egress_l3"`
	TproxyWanIngressL2     *ebpf.Program `ebpf:"tproxy_wan_ingress_l2"`
	TproxyWanIngressL3     *ebpf.Program `ebpf:"tproxy_wan_ingress_l3"`
}

func (p *bpfPrograms) Close() error {
	return _BpfClose(
		p.TproxyDae0Ingress,
		p.TproxyDae0peerIngress,
		p.TproxyLanEgressL2,
		p.TproxyLanEgressL3,
		p.TproxyLanIngressL2,
		p.TproxyLanIngressL3,
		p.TproxyWanCgConnect4,
		p.TproxyWanCgConnect6,
		p.TproxyWanCgSendmsg4,
		p.TproxyWanCgSendmsg6,
		p.TproxyWanCgSockCreate,
		p.TproxyWanCgSockRelease,
		p.TproxyWanEgressL2,
		p.TproxyWanEgressL3,
		p.TproxyWanIngressL2,
		p.TproxyWanIngressL3,
	)
}

func _BpfClose(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 bpf_bpfel.o
var _BpfBytes []byte
