fwmark

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package fwmark applies pmark process marks to Linux socket fwmarks.

The package is an example consumer of the root package's pinned processes map. Its eBPF cgroup/sock_create program looks up the current process lifetime and copies the high 32 bits of the 64-bit pmark value into bpf_sock.mark. The Go Manager also reconciles already-open sockets through pidfd_getfd and SO_MARK when pmark emits ProcessUpdate callbacks.

Use ToMark and FromMark to convert between a 32-bit Linux fwmark and the 64-bit mark value understood by package pmark.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(mark uint32) string

func FromMark

func FromMark(mark uint64) uint32

FromMark derives the Linux fwmark from the daemon mark. Keep this in sync with fwmark.c: higher 32 bits become the socket mark.

func Parse

func Parse(markStr string) (uint32, error)

Parse converts a fwmark hex string (with or without "0x") back to a uint32.

func SetProcessSocketsMark

func SetProcessSocketsMark(pid uint32, mark uint32) error

func ToMark

func ToMark(fwmark uint32) uint64

ToMark derives the daemon mark from the Linux fwmark. Keep this in sync with fwmark.c: the socket mark becomes the higher 32 bits, leaving the lower 32 bits as 0.

Types

type Manager

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

Manager owns fwmark eBPF programs and the userspace socket reconciler.

func NewManager

func NewManager(pinPath string, logf func(format string, args ...any)) (*Manager, error)

NewManager loads fwmark programs, reuses core's pinned processes map, and attaches cgroup hooks to the root cgroup.

func (*Manager) ApplyProcessUpdate

func (m *Manager) ApplyProcessUpdate(update pmark.ProcessUpdate) error

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) ProcessUpdateCallback

func (m *Manager) ProcessUpdateCallback() func(pmark.ProcessUpdate)

ProcessUpdateCallback returns a daemon ProcessUpdate hook which reconciles already-open sockets for updated live processes.

func (*Manager) ReconcileMarkedProcesses

func (m *Manager) ReconcileMarkedProcesses() error

type SocketMarkReport

type SocketMarkReport struct {
	FDs               int
	Sockets           int
	Marked            int
	AlreadyMarked     int
	PermissionSkipped int
}

func SetProcessSocketsMarkReport

func SetProcessSocketsMarkReport(pid uint32, mark uint32) (SocketMarkReport, error)

Jump to

Keyboard shortcuts

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