leshybpf

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PendingSrcMapName   = "l4_pending_src"
	StatsMapName        = "l4_stats"
	ActiveFlowsMapName  = "l4_active_flows"
	GuardedPortsMapName = "l4_guarded_port"
	LogsMapName         = "l4_logs"

	ProgramName   = "l4_filter"
	PinnedProgRel = "l4_filter" // имя pinned файла в BPFPinPath
)

Имя мапы не может превышать 15 символов!

Variables

This section is empty.

Functions

func AttachBPFWithTC

func AttachBPFWithTC(
	ctx context.Context,
	iface, bpfPinPath, bpfProgramPath string,
	pendingMap, guardedPortsMap, statsMap, activeFlowsMap **ebpf.Map,
) error

AttachBPFWithTC загружает и прикрепляет BPF программу к TC. возвращает карты из коллекции, чтобы контроллер использовал те же карты, что и программа.

func AttachBPFWithTCWithOptions

func AttachBPFWithTCWithOptions(
	ctx context.Context,
	iface, bpfPinPath, bpfProgramPath string,
	opts AttachOptions,
	pendingMap, guardedPortsMap, statsMap, activeFlowsMap **ebpf.Map,
) error

func GetGuardedPorts

func GetGuardedPorts(m *ebpf.Map) []uint16

GetGuardedPorts returns the list of guarded ports in HOST BYTE ORDER.

func HostToNetworkPort

func HostToNetworkPort(port uint16) uint16

HostToNetworkPort converts port from host to network byte order.

func InitializeGuardedPorts

func InitializeGuardedPorts(portsRange string, m *ebpf.Map) error

InitializeGuardedPorts initializes guarded ports from port range.

func InsertPendingSrcPort

func InsertPendingSrcPort(m *ebpf.Map, ip net.IP, port uint16, window time.Duration) error

InsertPendingSrcPort inserts an IP+port into the pending map with expiration.

func IsPortGuarded

func IsPortGuarded(m *ebpf.Map, port uint16) bool

IsPortGuarded checks if a port is in the guarded ports list (uses NETWORK byte order).

func RunDiagnostics

func RunDiagnostics(ctx context.Context, opts DiagnosticsOptions) error

RunDiagnostics — для отладки: bpftool prog/map list + сравнение map_ids + проверка pinned путей.

Types

type AttachOptions

type AttachOptions struct {
	Debug bool
}

type AttachResult

type AttachResult struct {
	PendingMap      *ebpf.Map
	GuardedPortsMap *ebpf.Map
	StatsMap        *ebpf.Map
	ActiveFlowsMap  *ebpf.Map
}

type DiagnosticsOptions

type DiagnosticsOptions struct {
	Iface    string
	PinPath  string
	Program  string
	MapNames []string
}

type FilterBackend

type FilterBackend struct {
	// contains filtered or unexported fields
}

func NewFilterBackend

func NewFilterBackend(pending, guarded, stats *ebpf.Map) *FilterBackend

func (*FilterBackend) InsertPending

func (b *FilterBackend) InsertPending(ctx context.Context, ip net.IP, port uint16, window time.Duration) error

func (*FilterBackend) IsPortGuarded

func (b *FilterBackend) IsPortGuarded(ctx context.Context, port uint16) (bool, error)

func (*FilterBackend) Stats

func (b *FilterBackend) Stats(ctx context.Context) (filter.Counters, error)

func (*FilterBackend) VerifyPending

func (b *FilterBackend) VerifyPending(ctx context.Context, ip net.IP, port uint16) error

type IpPortKey

type IpPortKey struct {
	Saddr uint32 // source IP
	Dport uint16 // destination port (network byte order)
	Pad   uint16
}

IpPortKey — ключ для pending map (eBPF).

type Manager

type Manager struct {
	Pending     *ebpf.Map
	Guarded     *ebpf.Map
	Stats       *ebpf.Map
	ActiveFlows *ebpf.Map
	Program     *ebpf.Program
	// contains filtered or unexported fields
}

func NewManagerAndAttach

func NewManagerAndAttach(
	ctx context.Context,
	iface, bpfPinPath, bpfProgramPath string,
	opts AttachOptions,
	pendingMap, guardedPortsMap, statsMap, activeFlowsMap **ebpf.Map,
) (*Manager, error)

func (*Manager) AttachWithOptions

func (m *Manager) AttachWithOptions(
	ctx context.Context,
	iface, bpfPinPath, bpfProgramPath string,
	opts AttachOptions,
	pendingMap, guardedPortsMap, statsMap, activeFlowsMap **ebpf.Map,
) error

func (*Manager) Close

func (m *Manager) Close() error

Close releases collection.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL