Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/daemonset/agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ spec:
volumeMounts:
- name: bpf
mountPath: /sys/fs/bpf
mountPropagation: Bidirectional
- name: cgroup
mountPath: /sys/fs/cgroup
readOnly: true
Expand Down
38 changes: 38 additions & 0 deletions internal/ebpf/mount_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ebpf

import (
"fmt"
"os"

"golang.org/x/sys/unix"
)

// mountBPFFS ensures that /sys/fs/bpf is mounted as a BPF filesystem.
func mountBPFFS() error {
const bpfPath = "/sys/fs/bpf"

// Check if directory exists, create if not
if err := os.MkdirAll(bpfPath, 0o750); err != nil {
return fmt.Errorf("create bpf mount point: %w", err)
}

// Check if already mounted
var stat unix.Statfs_t
if err := unix.Statfs(bpfPath, &stat); err != nil {
return fmt.Errorf("statfs %s: %w", bpfPath, err)
}

// Magic number for BPF_FS is 0xCAFE4A11
const bpfFsMagic = 0xCAFE4A11
if stat.Type == bpfFsMagic {
return nil // Already mounted
}

// Mount it
// mount(source, target, fstype, flags, data)
if err := unix.Mount("bpf", bpfPath, "bpf", 0, "mode=0700"); err != nil {
return fmt.Errorf("mount bpffs: %w", err)
}

return nil
}
7 changes: 7 additions & 0 deletions internal/ebpf/preflight.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ func (r PreflightReport) HasErrors() bool {
func Preflight(cfg config.Config) PreflightReport {
report := PreflightReport{}

if err := mountBPFFS(); err != nil {
report.Issues = append(report.Issues, PreflightIssue{
Component: "bpffs",
Message: fmt.Sprintf("failed to mount bpffs: %v", err),
})
}

if err := rlimit.RemoveMemlock(); err != nil {
report.Issues = append(report.Issues, PreflightIssue{
Component: "memlock",
Expand Down