bpfprogram

package
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BPFMapPinPath is the directory where BPF maps are pinned
	BPFMapPinPath = "/sys/fs/bpf/azure-block-iptables"
	// EventCounterMapName is the name used for pinning the event counter map
	EventCounterMapName = "iptables_block_event_counter"
	// IptablesLegacyBlockProgramName is the name used for pinning the legacy iptables block program
	IptablesLegacyBlockProgramName = "iptables_legacy_block"
	// IptablesNftablesBlockProgramName is the name used for pinning the nftables block program
	IptablesNftablesBlockProgramName = "iptables_nftables_block"
	// NetNSPath is the path to the host network namespace
	NetNSPath = "/proc/self/ns/net"
)

Variables

View Source
var ErrEventCounterMapNotLoaded = errors.New("event counter map not loaded")

Functions

This section is empty.

Types

type Attacher

type Attacher interface {
	// Attach attaches the BPF program to LSM hooks and pins the links and maps
	Attach() error

	// Unpins the links and maps (causes detachment)
	Detach() error

	// IsAttached returns true if the BPF program is currently attached
	IsAttached() bool

	// Close cleans up all resources
	Close()
}

Attacher defines the interface for BPF program attachment operations. This interface allows for dependency injection and easier testing with mock implementations.

func NewProgram

func NewProgram() Attacher

NewProgram creates a new BPF program manager instance.

type AttacherFactory

type AttacherFactory func() Attacher

AttacherFactory defines a function type for creating Attacher instances. This allows for easier dependency injection in applications.

type MockProgram

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

MockProgram provides a mock implementation of the Manager interface for testing.

func NewMockProgram

func NewMockProgram() *MockProgram

NewMockProgram creates a new mock BPF program manager instance.

func (*MockProgram) Attach

func (m *MockProgram) Attach() error

Attach simulates attaching the BPF program.

func (*MockProgram) AttachCallCount

func (m *MockProgram) AttachCallCount() int

AttachCallCount returns the number of times Attach() was called.

func (*MockProgram) Close

func (m *MockProgram) Close()

Close simulates cleanup.

func (*MockProgram) Detach

func (m *MockProgram) Detach() error

Detach simulates detaching the BPF program.

func (*MockProgram) DetachCallCount

func (m *MockProgram) DetachCallCount() int

DetachCallCount returns the number of times Detach() was called.

func (*MockProgram) IsAttached

func (m *MockProgram) IsAttached() bool

IsAttached returns the mock's attached state.

func (*MockProgram) Reset

func (m *MockProgram) Reset()

Reset resets the mock's state.

func (*MockProgram) SetAttachError

func (m *MockProgram) SetAttachError(err error)

SetAttachError sets the error to return from Attach() calls.

func (*MockProgram) SetDetachError

func (m *MockProgram) SetDetachError(err error)

SetDetachError sets the error to return from Detach() calls.

type Program

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

Program implements the Manager interface for real BPF program operations.

func (*Program) Attach

func (p *Program) Attach() error

Attach attaches the BPF program to LSM hooks.

func (*Program) Close

func (p *Program) Close()

Close cleans up all resources.

func (*Program) CreatePinPath

func (p *Program) CreatePinPath() error

CreatePinPath ensures the BPF map pin directory exists.

func (*Program) Detach

func (p *Program) Detach() error

func (*Program) IsAttached

func (p *Program) IsAttached() bool

IsAttached returns true if the BPF program is currently attached.

Jump to

Keyboard shortcuts

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