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(refactor): load eBPF objects using function generated in wrapper files instead #368

Closed
wants to merge 10 commits into from
24 changes: 5 additions & 19 deletions pkg/plugin/dropreason/dropreason_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,37 +117,23 @@ func (dr *dropReason) Compile(ctx context.Context) error {
}

func (dr *dropReason) Init() error {
var err error

if err = rlimit.RemoveMemlock(); err != nil {
dr.l.Error("RemoveMemLock failed:%w", zap.Error(err))
return err
}

// Get the absolute path to this file during runtime.
dir, err := absPath()
if err != nil {
return err
}

bpfOutputFile := fmt.Sprintf("%s/%s", dir, bpfObjectFileName)

objs := &kprobeObjects{} //nolint:typecheck
spec, err := ebpf.LoadCollectionSpec(bpfOutputFile)
err := rlimit.RemoveMemlock()
if err != nil {
dr.l.Error("remove memlock failed", zap.Error(err))
return err
}

objs := &kprobeObjects{}
// TODO remove the opts
if err := spec.LoadAndAssign(objs, &ebpf.CollectionOptions{
if err = loadKprobeObjects(objs, &ebpf.CollectionOptions{
Programs: ebpf.ProgramOptions{
LogLevel: 2,
},
Maps: ebpf.MapOptions{
PinPath: plugincommon.FilterMapPath,
},
}); err != nil {
dr.l.Error("Error loading objects: %w", zap.Error(err))
dr.l.Error("failed to load kprobe objects", zap.Error(err))
return err
}

Expand Down
22 changes: 5 additions & 17 deletions pkg/plugin/packetforward/packetforward_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
kcfg "github.com/microsoft/retina/pkg/config"

hubblev1 "github.com/cilium/cilium/pkg/hubble/api/v1"
"github.com/cilium/ebpf"
"github.com/cilium/ebpf/rlimit"
"github.com/microsoft/retina/pkg/loader"
"github.com/microsoft/retina/pkg/log"
Expand Down Expand Up @@ -132,28 +131,17 @@ func (p *packetForward) Compile(ctx context.Context) error {
}

func (p *packetForward) Init() error {
if err := rlimit.RemoveMemlock(); err != nil {
p.l.Error("RemoveMemLock failed:%w", zap.Error(err))
return err
}

// Get the absolute path to this file during runtime.
dir, err := absPath()
err := rlimit.RemoveMemlock()
if err != nil {
p.l.Error("remove memlock failed", zap.Error(err))
return err
}

bpfOutputFile := fmt.Sprintf("%s/%s", dir, bpfObjectFileName)
objs := &packetforwardObjects{}

objs := &packetforwardObjects{} //nolint:typecheck
spec, err := ebpf.LoadCollectionSpec(bpfOutputFile)
err = loadPacketforwardObjects(objs, nil)
if err != nil {
p.l.Error("Error loading collection specs: %w", zap.Error(err))
return err
}

if err := spec.LoadAndAssign(objs, nil); err != nil {
p.l.Error("Error assigning specs: %w", zap.Error(err))
p.l.Error("failed to load packetforward objects", zap.Error(err))
return err
}

Expand Down
24 changes: 6 additions & 18 deletions pkg/plugin/packetparser/packetparser_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,37 +110,25 @@ func (p *packetParser) Compile(ctx context.Context) error {
}

func (p *packetParser) Init() error {
var err error
if !p.cfg.EnablePodLevel {
p.l.Warn("packet parser and latency plugin will not init because pod level is disabled")
return nil
}

if err := rlimit.RemoveMemlock(); err != nil {
p.l.Error("RemoveMemLock failed:%w", zap.Error(err))
return err
}

// Get the absolute path to this file during runtime.
dir, err := absPath()
err := rlimit.RemoveMemlock()
if err != nil {
p.l.Error("remove memlock failed", zap.Error(err))
return err
}

bpfOutputFile := fmt.Sprintf("%s/%s", dir, bpfObjectFileName)

objs := &packetparserObjects{}
spec, err := ebpf.LoadCollectionSpec(bpfOutputFile)
if err != nil {
return err
}
//nolint:typecheck
if err := spec.LoadAndAssign(objs, &ebpf.CollectionOptions{ //nolint:typecheck

if err = loadPacketparserObjects(objs, &ebpf.CollectionOptions{
Maps: ebpf.MapOptions{
PinPath: plugincommon.FilterMapPath,
},
}); err != nil { //nolint:typecheck
p.l.Error("Error loading objects: %w", zap.Error(err))
}); err != nil {
p.l.Error("failed to load packetparser objects", zap.Error(err))
return err
}
p.objs = objs
Expand Down
Loading