bpf

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SETTING_ENABLE_MONITOR uint32 = 1
	SETTING_AUDIT_MODE     uint32 = 2
	SETTING_ENABLED        uint32 = 1
	SETTING_DISABLED       uint32 = 0

	TUNNEL_MODE_NONE   uint32 = 0
	TUNNEL_MODE_GENEVE uint32 = 1
	TUNNEL_MODE_VXLAN  uint32 = 2
)

Variables

View Source
var (
	// Name of the directory in /sys/fs/bpf that holds the pinned maps/progs
	BPFMountDir = "neuwerk"
)

Functions

This section is empty.

Types

type AuditEvent

type AuditEvent bpfAuditEvent

type Collection

type Collection struct {
	IngressProg *ebpf.Program
	EgressProg  *ebpf.Program

	NetworkCIDRs    *ebpf.Map
	IPPortPolicies  *ebpf.Map
	PolicyConfigMap *ebpf.Map
	PktTrack        *ebpf.Map
	MetricsMap      *ebpf.Map
	AuditEvents     *ebpf.Map
	SettingsMap     *ebpf.Map
	FlowState       *ebpf.Map
	SessionMap      *ebpf.Map
	// contains filtered or unexported fields
}

func Load

func Load(bpffs, ingressDeviceName, egressDeviceName, ingressAddr, tunnelMode string) (*Collection, error)

func (*Collection) ApplyNamedSetting

func (coll *Collection) ApplyNamedSetting(name string, value uint32) error

func (*Collection) ApplySetting

func (coll *Collection) ApplySetting(key uint32, value uint32) error

func (*Collection) Attach

func (coll *Collection) Attach() error

func (*Collection) Close

func (coll *Collection) Close() error

func (*Collection) GetNamedSetting

func (coll *Collection) GetNamedSetting(name string) (uint32, error)

func (*Collection) GetPacketCounters

func (coll *Collection) GetPacketCounters() (*PacketCounters, error)

GetPacketCounters reads packet counters from BPF metrics map

func (*Collection) GetSetting

func (coll *Collection) GetSetting(key uint32) (uint32, error)

type FlowKey

type FlowKey bpfFlowKey

type FlowMetadata

type FlowMetadata bpfFlowMetadata

type NetworkCIDR

type NetworkCIDR bpfNetworkCidr

type PacketCounters

type PacketCounters struct {
	Allowed    uint64 `json:"allowed"`
	Blocked    uint64 `json:"blocked"`
	Redirected uint64 `json:"redirected"`
}

PacketCounters holds aggregated packet metrics

type PolicyKey

type PolicyKey bpfPolicyKey

type ReplicatedSession

type ReplicatedSession struct {
	// Flow metadata (tunnel info)
	TunnelType     uint8    `json:"tunnel_type"`
	VNI            uint32   `json:"vni"`
	FlowCookie     [8]byte  `json:"flow_cookie"`     // First 8 bytes of GENEVE options
	OuterSrcIP     uint32   `json:"outer_src_ip"`    // Network byte order
	OuterDstIP     uint32   `json:"outer_dst_ip"`    // Network byte order
	OuterSrcMAC    [6]uint8 `json:"outer_src_mac"`   // Ethernet MAC addresses
	OuterDstMAC    [6]uint8 `json:"outer_dst_mac"`   // Ethernet MAC addresses
	OuterSrcPort   uint16   `json:"outer_src_port"`  // UDP port
	OuterDstPort   uint16   `json:"outer_dst_port"`  // UDP port
	IngressIfindex uint32   `json:"ingress_ifindex"` // For GCP hairpin

	// Session state (timestamps only, NO packet counters per CONTEXT.md)
	LastSeenNs uint64 `json:"last_seen_ns"` // Nanoseconds since boot

	// Replication metadata
	NodeID       string `json:"node_id"`
	ReplicatedAt int64  `json:"replicated_at"` // Unix timestamp
}

ReplicatedSession contains minimal session data for replication. Excludes packet/byte counters per CONTEXT.md: "only tunnel metadata is replicated"

type ReplicationStatus

type ReplicationStatus struct {
	LocalCount     int
	NATSCount      int
	InBoth         int
	OnlyLocal      int
	OnlyNATS       int
	LastSyncTime   time.Time
	ReplicationLag time.Duration
}

ReplicationStatus provides health metrics for session replication.

type SessionInfo

type SessionInfo struct {
	SrcIP          string
	DstIP          string
	SrcPort        uint16
	DstPort        uint16
	Proto          string
	Age            string
	TunnelType     string
	VNI            uint32
	IngressPackets uint64
	EgressPackets  uint64
	IngressBytes   uint32
	EgressBytes    uint32
}

ListSessions returns all sessions matching filters

type SessionManager

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

func NewSessionManager

func NewSessionManager(sessionMap, flowStateMap *ebpf.Map) *SessionManager

func (*SessionManager) ListSessions

func (sm *SessionManager) ListSessions(srcIPFilter, dstIPFilter string, portFilter uint16) ([]SessionInfo, error)

func (*SessionManager) StartGC

func (sm *SessionManager) StartGC(ctx context.Context) error

type SessionReplicator

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

SessionReplicator replicates BPF session state to NATS JetStream KV for HA failover. Implements debounced batch replication with periodic backup sync.

func NewSessionReplicator

func NewSessionReplicator(ctx context.Context, js jetstream.JetStream, sessionMap, flowStateMap *ebpf.Map, nodeID string) (*SessionReplicator, error)

NewSessionReplicator creates a session replicator with NATS KV bucket.

func (*SessionReplicator) Create

func (r *SessionReplicator) Create(key FlowKey, session SessionState, meta FlowMetadata)

Create replicates a new session immediately (bypasses debounce). Used on session creation to ensure rapid propagation.

func (*SessionReplicator) Delete

func (r *SessionReplicator) Delete(key FlowKey)

Delete removes a session from NATS KV immediately (bypasses debounce). Used on session deletion (GC cleanup, connection close) for rapid propagation.

func (*SessionReplicator) Flush

func (r *SessionReplicator) Flush()

Flush immediately writes all pending session updates to NATS KV. Called during graceful shutdown to ensure no data loss.

func (*SessionReplicator) GetStatus

GetStatus compares local BPF maps against NATS KV and returns health information. Used for operational observability and troubleshooting replication issues.

func (*SessionReplicator) LoadFromNATS

func (r *SessionReplicator) LoadFromNATS(ctx context.Context) error

LoadFromNATS eagerly loads all sessions from NATS KV into BPF maps on boot. Per CONTEXT.md: "Wait for session load to complete before registering with load balancer"

func (*SessionReplicator) StartPeriodicSync

func (r *SessionReplicator) StartPeriodicSync(ctx context.Context, interval time.Duration)

StartPeriodicSync starts a background goroutine that performs periodic full sync. Backup mechanism per RESEARCH.md Pattern to catch missed replication events.

func (*SessionReplicator) Update

func (r *SessionReplicator) Update(key FlowKey, session SessionState, meta FlowMetadata)

Update stores a session update in pending map and triggers debounced batch write. Multiple updates within 500ms window are coalesced into single NATS write.

type SessionState

type SessionState bpfSessionState

Jump to

Keyboard shortcuts

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