Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): update module github.com/cilium/ebpf to v0.17.1 (main) #3206

Merged
merged 3 commits into from
Jan 2, 2025
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
32 changes: 8 additions & 24 deletions cmd/tetra/debug/progs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"log"
"os"
"path"
Expand All @@ -24,6 +25,7 @@ import (
"github.com/cilium/ebpf"
"github.com/cilium/ebpf/btf"
"github.com/cilium/ebpf/link"
"github.com/cilium/ebpf/pin"
"github.com/spf13/cobra"
"golang.org/x/sys/unix"
"golang.org/x/term"
Expand Down Expand Up @@ -403,26 +405,20 @@ func getTetragonProgs(base string) ([]*prog, error) {
var progs []*prog

// Walk bpffs/tetragon and look for programs
err := filepath.Walk(base,
func(path string, finfo os.FileInfo, err error) error {
err := pin.WalkDir(base,
func(path string, finfo fs.DirEntry, obj pin.Pinner, err error) error {
if err != nil {
return err
}
if finfo.IsDir() {
return nil
}
if strings.HasSuffix(path, "/link") || strings.HasSuffix(path, "/link_override") {
return nil // skip BPF links, they make the syscall fail since cilium/ebpf@78074c59
}
p, err := ebpf.LoadPinnedProgram(path, nil)
if err != nil {
return err
}
defer p.Close()

if !isProg(p.FD()) {
p, ok := obj.(*ebpf.Program)
if !ok {
return nil
}
defer p.Close()

info, err := p.Info()
if err != nil {
Expand All @@ -440,7 +436,7 @@ func getTetragonProgs(base string) ([]*prog, error) {
progs = append(progs, &prog{
id: uint32(id),
name: getName(p, info),
pin: path,
pin: filepath.Join(base, path),
cnt: runCnt,
time: runTime,
alive: true,
Expand All @@ -450,18 +446,6 @@ func getTetragonProgs(base string) ([]*prog, error) {
return progs, err
}

func isProg(fd int) bool {
return isBPFObject("prog", fd)
}

func isBPFObject(object string, fd int) bool {
readlink, err := os.Readlink(fmt.Sprintf("/proc/self/fd/%d", fd))
if err != nil {
return false
}
return readlink == fmt.Sprintf("anon_inode:bpf-%s", object)
}

func getName(p *ebpf.Program, info *ebpf.ProgramInfo) string {
handle, err := p.Handle()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/alecthomas/kong v1.6.0
github.com/bombsimon/logrusr/v4 v4.1.0
github.com/cilium/cilium v1.17.0-pre.3
github.com/cilium/ebpf v0.16.1-0.20241205185900-f0eec7efba9d
github.com/cilium/ebpf v0.17.1
github.com/cilium/little-vm-helper v0.0.19
github.com/cilium/lumberjack/v2 v2.4.1
github.com/cilium/tetragon/api v0.0.0-00010101000000-000000000000
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cilium/cilium v1.17.0-pre.3 h1:3wZkE1S6MPY7Sw0yqo8i2f2sENgIGebKjkQ//W+wNmo=
github.com/cilium/cilium v1.17.0-pre.3/go.mod h1:rsmS3OsYDHg6bGnr9qVeB/qij+j7pi++G1WzoQqjicE=
github.com/cilium/ebpf v0.16.1-0.20241205185900-f0eec7efba9d h1:f1E6PeQ/j1Xd2ZNlffKOfscx+daNInIUAJObbiU+7aQ=
github.com/cilium/ebpf v0.16.1-0.20241205185900-f0eec7efba9d/go.mod h1:vay2FaYSmIlv3r8dNACd4mW/OCaZLJKJOo+IHBvCIO8=
github.com/cilium/ebpf v0.17.1 h1:G8mzU81R2JA1nE5/8SRubzqvBMmAmri2VL8BIZPWvV0=
github.com/cilium/ebpf v0.17.1/go.mod h1:vay2FaYSmIlv3r8dNACd4mW/OCaZLJKJOo+IHBvCIO8=
github.com/cilium/hive v0.0.0-20241122120553-e90d0875ae01 h1:eNOjtUsqu2W/nTZlInLAj+zyIg/HIQ1K7norewaxsgM=
github.com/cilium/hive v0.0.0-20241122120553-e90d0875ae01/go.mod h1:pI2GJ1n3SLKIQVFrKF7W6A6gb6BQkZ+3Hp4PAEo5SuI=
github.com/cilium/little-vm-helper v0.0.19 h1:eJeJM/03MGLrLUXXTBDZo2JoX5cIbm5+9iWjoHgpy/M=
Expand Down
89 changes: 20 additions & 69 deletions pkg/bugtool/maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import (
"iter"
"maps"
"os"
"path/filepath"
"slices"
"sort"
"strings"
"syscall"

"github.com/cilium/ebpf"
"github.com/cilium/ebpf/pin"
"github.com/cilium/tetragon/pkg/bpf"
)

Expand Down Expand Up @@ -90,27 +89,20 @@ func FindAllMaps() ([]bpf.ExtendedMapInfo, error) {
// specified as argument.
func FindPinnedMaps(path string) ([]bpf.ExtendedMapInfo, error) {
var infos []bpf.ExtendedMapInfo
err := filepath.WalkDir(path, func(path string, d fs.DirEntry, err error) error {

err := pin.WalkDir(path, func(_ string, d fs.DirEntry, obj pin.Pinner, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil // skip directories
}
m, err := ebpf.LoadPinnedMap(path, nil)
if err != nil {
return fmt.Errorf("failed to load pinned map %q: %w", path, err)
}
defer m.Close()

// check if it's really a map because ebpf.LoadPinnedMap does not return
// an error but garbage info on doing this on a prog
if ok, err := isMap(m.FD()); err != nil || !ok {
if err != nil {
return err
}
m, ok := obj.(*ebpf.Map)
if !ok {
return nil // skip non map
}
defer m.Close()

xInfo, err := bpf.ExtendedInfoFromMap(m)
if err != nil {
Expand Down Expand Up @@ -153,58 +145,33 @@ func mapIDsFromProgs(prog *ebpf.Program) (iter.Seq[int], error) {
func mapIDsFromPinnedProgs(path string) (iter.Seq[int], error) {
mapSet := map[int]bool{}
progArrays := []*ebpf.Map{}
err := filepath.WalkDir(path, func(path string, d fs.DirEntry, err error) error {
err := pin.WalkDir(path, func(_ string, d fs.DirEntry, obj pin.Pinner, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil // skip directories
}
if strings.HasSuffix(path, "/link") || strings.HasSuffix(path, "/link_override") {
return nil // skip BPF links, they make the syscall fail since cilium/ebpf@78074c59
}
prog, err := ebpf.LoadPinnedProgram(path, nil)
if err != nil {
return fmt.Errorf("failed to load pinned object %q: %w", path, err)
}
defer prog.Close()

if ok, err := isProg(prog.FD()); err != nil || !ok {
switch typedObj := obj.(type) {
case *ebpf.Program:
newIDs, err := mapIDsFromProgs(typedObj)
if err != nil {
return err
return fmt.Errorf("failed to retrieve map IDs from prog: %w", err)
}

// we want to keep a ref to prog array containing tail calls to
// search reference to map inside
ok, err := isMap(prog.FD())
if err != nil {
return err
typedObj.Close()
for id := range newIDs {
mapSet[id] = true
}
if ok {
m, err := ebpf.LoadPinnedMap(path, &ebpf.LoadPinOptions{
ReadOnly: true,
})
if err != nil {
return fmt.Errorf("failed to load pinned map %q: %w", path, err)
}
if m.Type() == ebpf.ProgramArray {
progArrays = append(progArrays, m)
// don't forget to close those files when used later on
} else {
m.Close()
}
case *ebpf.Map:
if typedObj.Type() == ebpf.ProgramArray {
progArrays = append(progArrays, typedObj)
// don't forget to close those files when used later on
} else {
typedObj.Close()
}

return nil // skip the non-prog
}

newIDs, err := mapIDsFromProgs(prog)
if err != nil {
return fmt.Errorf("failed to retrieve map IDs from prog: %w", err)
}
for id := range newIDs {
mapSet[id] = true
}
return nil
})
if err != nil {
Expand Down Expand Up @@ -248,22 +215,6 @@ func mapIDsFromPinnedProgs(path string) (iter.Seq[int], error) {
return maps.Keys(mapSet), nil
}

func isProg(fd int) (bool, error) {
return isBPFObject("prog", fd)
}

func isMap(fd int) (bool, error) {
return isBPFObject("map", fd)
}

func isBPFObject(object string, fd int) (bool, error) {
readlink, err := os.Readlink(fmt.Sprintf("/proc/self/fd/%d", fd))
if err != nil {
return false, fmt.Errorf("failed to readlink the fd (%d): %w", fd, err)
}
return readlink == fmt.Sprintf("anon_inode:bpf-%s", object), nil
}

const TetragonBPFFS = "/sys/fs/bpf/tetragon"

type DiffMap struct {
Expand Down
1 change: 0 additions & 1 deletion vendor/github.com/cilium/ebpf/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/cilium/ebpf/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/github.com/cilium/ebpf/btf/format.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions vendor/github.com/cilium/ebpf/btf/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions vendor/github.com/cilium/ebpf/collection.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions vendor/github.com/cilium/ebpf/elf_reader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading