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

chore(prog): align BPFProg API - set_type, set_expected_attach_type #467

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Changes from 2 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
26 changes: 22 additions & 4 deletions prog.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,32 @@ func (p *BPFProg) SetAttachTarget(attachProgFD int, attachFuncName string) error
return nil
}

// TODO: fix API to return error
// Deprecated: use BPFProg.SetExpectedProgramType() instead.
func (p *BPFProg) SetProgramType(progType BPFProgType) {
C.bpf_program__set_type(p.prog, C.enum_bpf_prog_type(int(progType)))
C.bpf_program__set_type(p.prog, C.enum_bpf_prog_type(C.int(progType)))
geyslan marked this conversation as resolved.
Show resolved Hide resolved
}

// TODO: fix API to return error
func (p *BPFProg) SetExpectedProgramType(progType BPFProgType) error {
geyslan marked this conversation as resolved.
Show resolved Hide resolved
retC := C.bpf_program__set_type(p.prog, C.enum_bpf_prog_type(C.int(progType)))
geyslan marked this conversation as resolved.
Show resolved Hide resolved
if retC < 0 {
return fmt.Errorf("failed to set prog_type %s for program %s: %w", progType.String(), p.Name(), syscall.Errno(-retC))
}

return nil
geyslan marked this conversation as resolved.
Show resolved Hide resolved
}

// Deprecated: use BPFProg.SetExpectedAttachType() instead.
func (p *BPFProg) SetAttachType(attachType BPFAttachType) {
C.bpf_program__set_expected_attach_type(p.prog, C.enum_bpf_attach_type(int(attachType)))
C.bpf_program__set_expected_attach_type(p.prog, C.enum_bpf_attach_type(C.int(attachType)))
}

func (p *BPFProg) SetExpectedAttachType(attachType BPFAttachType) error {
retC := C.bpf_program__set_expected_attach_type(p.prog, C.enum_bpf_attach_type(C.int(attachType)))
geyslan marked this conversation as resolved.
Show resolved Hide resolved
if retC < 0 {
return fmt.Errorf("failed to set attach_type %s for program %s: %w", attachType.String(), p.Name(), syscall.Errno(-retC))
}

return nil
}

// getCgroupDirFD returns a file descriptor for a given cgroup2 directory path
Expand Down