// Code generated by bpf2go; DO NOT EDIT.
//go:build (386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64 || wasm) && !dae_stub_ebpf

package control

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

	"github.com/cilium/ebpf"
)

type bpfConnState struct {
	_                     structs.HostLayout
	IsWanIngressDirection bool
	State                 uint8
	_                     [6]byte
	LastSeenNs            uint64
	Meta                  struct {
		_    structs.HostLayout
		Data struct {
			_          structs.HostLayout
			Mark       uint32
			Outbound   uint8
			Must       uint8
			Dscp       uint8
			HasRouting uint8
		}
	}
	Mac     [6]uint8
	Padding [2]uint8
	Pname   [16]uint8
	Pid     uint32
	_       [4]byte
}

type bpfConntrackArgs struct {
	_        structs.HostLayout
	Flags    uint8
	Outbound uint8
	Must     uint8
	Dscp     uint8
	Mark     uint32
	Pid      uint32
	Mac      [6]uint8
	Padding  [2]uint8
	Pname    [16]uint8
}

type bpfDaeParam struct {
	_                    structs.HostLayout
	TproxyPort           uint32
	ControlPlanePid      uint32
	Dae0Ifindex          uint32
	DaeNetnsId           uint32
	Dae0peerMac          [6]uint8
	PaddingAfterMac      [2]uint8
	UseRedirectPeer      uint8
	HasBpfGetCurrentTask uint8
	Padding2             uint16
	DaeSocketMark        uint32
}

type bpfDomainRouting struct {
	_      structs.HostLayout
	Bitmap [32]uint32
}

type bpfMatchSet struct {
	_        structs.HostLayout
	Value    [16]uint8
	Not      uint8
	Type     uint8
	Outbound uint8
	Must     uint8
	Mark     uint32
}

type bpfParseTransportCtx struct {
	_    structs.HostLayout
	Ethh struct {
		_        structs.HostLayout
		H_dest   [6]uint8
		H_source [6]uint8
		H_proto  uint16
	}
	_   [2]byte
	Iph struct {
		_        structs.HostLayout
		_        [1]byte /* unsupported bitfield */
		Tos      uint8
		TotLen   uint16
		Id       uint16
		FragOff  uint16
		Ttl      uint8
		Protocol uint8
		Check    uint16
		Saddr    uint32
		Daddr    uint32
	}
	Ipv6h struct {
		_          structs.HostLayout
		_          [1]byte /* unsupported bitfield */
		FlowLbl    [3]uint8
		PayloadLen uint16
		Nexthdr    uint8
		HopLimit   uint8
		Saddr      struct {
			_    structs.HostLayout
			In6U struct {
				_       structs.HostLayout
				U6Addr8 [16]uint8
			}
		}
		Daddr struct {
			_    structs.HostLayout
			In6U struct {
				_       structs.HostLayout
				U6Addr8 [16]uint8
			}
		}
	}
	Icmp6h struct {
		_           structs.HostLayout
		Icmp6Type   uint8
		Icmp6Code   uint8
		Icmp6Cksum  uint16
		Icmp6Dataun struct {
			_        structs.HostLayout
			UnData32 [1]uint32
		}
	}
	Tcph struct {
		_      structs.HostLayout
		Source uint16
		Dest   uint16
		Seq    uint32
		AckSeq uint32
		_      [2]byte /* unsupported bitfield */
		Window uint16
		Check  uint16
		UrgPtr uint16
	}
	Udph struct {
		_      structs.HostLayout
		Source uint16
		Dest   uint16
		Len    uint16
		Check  uint16
	}
	Ihl             uint8
	L4proto         uint8
	ListenerL4proto uint8
	Pad             uint8
}

type bpfParsedPacket struct {
	_    structs.HostLayout
	Ethh struct {
		_        structs.HostLayout
		H_dest   [6]uint8
		H_source [6]uint8
		H_proto  uint16
	}
	_      [2]byte
	Tuples struct {
		_    structs.HostLayout
		Five bpfTuplesKey
		Dscp uint8
		_    [7]byte
	}
	Tcph struct {
		_      structs.HostLayout
		Source uint16
		Dest   uint16
		Seq    uint32
		AckSeq uint32
		_      [2]byte /* unsupported bitfield */
		Window uint16
		Check  uint16
		UrgPtr uint16
	}
	Udph struct {
		_      structs.HostLayout
		Source uint16
		Dest   uint16
		Len    uint16
		Check  uint16
	}
	L4proto         uint8
	ListenerL4proto uint8
	_               [2]byte
}

type bpfPidPname struct {
	_          structs.HostLayout
	LastSeenNs uint64
	Pid        uint32
	Pname      [16]int8
	_          [4]byte
}

type bpfPortRange struct {
	_         structs.HostLayout
	PortStart uint16
	PortEnd   uint16
}

type bpfRedirectEntry struct {
	_          structs.HostLayout
	Ifindex    uint32
	Smac       [6]uint8
	Dmac       [6]uint8
	FromWan    uint8
	Padding    [3]uint8
	_          [4]byte
	LastSeenNs uint64
}

type bpfRedirectTuple struct {
	_   structs.HostLayout
	Sip struct {
		_       structs.HostLayout
		U6Addr8 [16]uint8
	}
	Dip struct {
		_       structs.HostLayout
		U6Addr8 [16]uint8
	}
}

type bpfRouteCtx struct {
	_           structs.HostLayout
	Flag        [8]uint32
	IsWan       uint8
	_           [3]byte
	Mac         [4]uint32
	H_dport     uint16
	H_sport     uint16
	Result      int64
	LpmKeySaddr struct {
		_         structs.HostLayout
		Prefixlen uint32
		Data      [4]uint32
	}
	LpmKeyDaddr struct {
		_         structs.HostLayout
		Prefixlen uint32
		Data      [4]uint32
	}
	LpmKeyMac struct {
		_         structs.HostLayout
		Prefixlen uint32
		Data      [4]uint32
	}
	DomainWordIdx    uint32
	DomainWordBits   uint32
	DomainWordCached bool
	RouteState       uint8
	_                [2]byte
}

type bpfRoutingHandoffEntry struct {
	_          structs.HostLayout
	LastSeenNs uint64
	Result     struct {
		_        structs.HostLayout
		Mark     uint32
		Must     uint8
		Mac      [6]uint8
		Outbound uint8
		Pname    [16]uint8
		Pid      uint32
		Dscp     uint8
		_        [3]byte
	}
	_ [4]byte
}

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

type bpfWanEgressRouteScratch struct {
	_       structs.HostLayout
	Flag    [8]uint32
	MacBe   [4]uint32
	IsWan   uint8
	MustVal uint8
	Mac     [6]uint8
}

// 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
	bpfVariableSpecs
}

// bpfProgramSpecs 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"`
	TproxySkMsgRedir       *ebpf.ProgramSpec `ebpf:"tproxy_sk_msg_redir"`
	TproxySockops          *ebpf.ProgramSpec `ebpf:"tproxy_sockops"`
	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 {
	BpfStatsMap              *ebpf.MapSpec `ebpf:"bpf_stats_map"`
	ConnStateMap             *ebpf.MapSpec `ebpf:"conn_state_map"`
	ConntrackArgsMap         *ebpf.MapSpec `ebpf:"conntrack_args_map"`
	CookiePidMap             *ebpf.MapSpec `ebpf:"cookie_pid_map"`
	DomainRoutingMap         *ebpf.MapSpec `ebpf:"domain_routing_map"`
	EventRingbuf             *ebpf.MapSpec `ebpf:"event_ringbuf"`
	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"`
	ParseCtxScratchMap       *ebpf.MapSpec `ebpf:"parse_ctx_scratch_map"`
	PktScratchMap            *ebpf.MapSpec `ebpf:"pkt_scratch_map"`
	RedirectTrack            *ebpf.MapSpec `ebpf:"redirect_track"`
	RouteCtxScratchMap       *ebpf.MapSpec `ebpf:"route_ctx_scratch_map"`
	RoutingHandoffMap        *ebpf.MapSpec `ebpf:"routing_handoff_map"`
	RoutingMap               *ebpf.MapSpec `ebpf:"routing_map"`
	RoutingMetaMap           *ebpf.MapSpec `ebpf:"routing_meta_map"`
	UnusedLpmType            *ebpf.MapSpec `ebpf:"unused_lpm_type"`
	WanEgressRouteScratchMap *ebpf.MapSpec `ebpf:"wan_egress_route_scratch_map"`
}

// bpfVariableSpecs contains global variables before they are loaded into the kernel.
//
// It can be passed ebpf.CollectionSpec.Assign.
type bpfVariableSpecs struct {
	PARAM *ebpf.VariableSpec `ebpf:"PARAM"`
}

// 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
	bpfVariables
}

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 {
	BpfStatsMap              *ebpf.Map `ebpf:"bpf_stats_map"`
	ConnStateMap             *ebpf.Map `ebpf:"conn_state_map"`
	ConntrackArgsMap         *ebpf.Map `ebpf:"conntrack_args_map"`
	CookiePidMap             *ebpf.Map `ebpf:"cookie_pid_map"`
	DomainRoutingMap         *ebpf.Map `ebpf:"domain_routing_map"`
	EventRingbuf             *ebpf.Map `ebpf:"event_ringbuf"`
	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"`
	ParseCtxScratchMap       *ebpf.Map `ebpf:"parse_ctx_scratch_map"`
	PktScratchMap            *ebpf.Map `ebpf:"pkt_scratch_map"`
	RedirectTrack            *ebpf.Map `ebpf:"redirect_track"`
	RouteCtxScratchMap       *ebpf.Map `ebpf:"route_ctx_scratch_map"`
	RoutingHandoffMap        *ebpf.Map `ebpf:"routing_handoff_map"`
	RoutingMap               *ebpf.Map `ebpf:"routing_map"`
	RoutingMetaMap           *ebpf.Map `ebpf:"routing_meta_map"`
	UnusedLpmType            *ebpf.Map `ebpf:"unused_lpm_type"`
	WanEgressRouteScratchMap *ebpf.Map `ebpf:"wan_egress_route_scratch_map"`
}

func (m *bpfMaps) Close() error {
	return _BpfClose(
		m.BpfStatsMap,
		m.ConnStateMap,
		m.ConntrackArgsMap,
		m.CookiePidMap,
		m.DomainRoutingMap,
		m.EventRingbuf,
		m.FastSock,
		m.ListenSocketMap,
		m.LpmArrayMap,
		m.OutboundConnectivityMap,
		m.ParseCtxScratchMap,
		m.PktScratchMap,
		m.RedirectTrack,
		m.RouteCtxScratchMap,
		m.RoutingHandoffMap,
		m.RoutingMap,
		m.RoutingMetaMap,
		m.UnusedLpmType,
		m.WanEgressRouteScratchMap,
	)
}

// bpfVariables contains all global variables after they have been loaded into the kernel.
//
// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign.
type bpfVariables struct {
	PARAM *ebpf.Variable `ebpf:"PARAM"`
}

// 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"`
	TproxySkMsgRedir       *ebpf.Program `ebpf:"tproxy_sk_msg_redir"`
	TproxySockops          *ebpf.Program `ebpf:"tproxy_sockops"`
	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.TproxySkMsgRedir,
		p.TproxySockops,
		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
