Skip to content

Commit

Permalink
libbpf-rs: Add set_autoload to OpenProgram
Browse files Browse the repository at this point in the history
Add bpf_program__set_autoload equivalent API to libbpf-rs.
This allows user to decide which BPF program should be loaded
automatically.

Closes libbpf#175.

Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
  • Loading branch information
chenhengqi authored and insearchoflosttime committed Mar 2, 2022
1 parent 42b84c0 commit 796f93e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 0 additions & 6 deletions libbpf-rs/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,6 @@ impl Object {
let section = unsafe { libbpf_sys::bpf_program__section_name(next_ptr) };
let section = util::c_ptr_to_string(section)?;

// Get the program fd
let fd = unsafe { libbpf_sys::bpf_program__fd(next_ptr) };
if fd < 0 {
return Err(Error::System(-fd));
}

// Add the program to the hashmap
obj.progs
.insert(name.clone(), Program::new(next_ptr, name, section));
Expand Down
5 changes: 5 additions & 0 deletions libbpf-rs/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ impl OpenProgram {
pub fn section(&self) -> &str {
&self.section
}

pub fn set_autoload(&mut self, autoload: bool) -> Result<()> {
let ret = unsafe { libbpf_sys::bpf_program__set_autoload(self.ptr, autoload) };
util::parse_ret(ret)
}
}

/// Type of a [`Program`]. Maps to `enum bpf_prog_type` in kernel uapi.
Expand Down

0 comments on commit 796f93e

Please sign in to comment.