Add helper methods to get useful information from the ProgramInfo
object which is returned by the `loaded_programs()` API. Specifically
this code mirrors the bpftool program in terms of useful fields.
The methods here are not exhaustive and may expand in the future.
Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
/// The name of the program as a &str. If the name was not valid unicode, None is returned
/// The name of the program as a &str. If the name was not valid unicode, None is returned.
pubfnname_as_str(&self)-> Option<&str>{
std::str::from_utf8(self.name()).ok()
}
@ -947,6 +949,80 @@ impl ProgramInfo {
self.0.id
}
/// The program tag is a SHA sum of the program's instructions which can be
/// used as another program identifier.
pubfntag(&self)-> u64{
u64::from_be_bytes(self.0.tag)
}
/// The program type as defined by the linux kernel enum [`bpf_prog_type`](https://elixir.bootlin.com/linux/v6.4.4/source/include/uapi/linux/bpf.h#L948).
pubfnprogram_type(&self)-> u32{
self.0.type_
}
/// Returns true if the program is defined with a GPL-compatible license.
pubfngpl_compatible(&self)-> bool{
self.0.gpl_compatible()!=0
}
/// Returns the ids of the maps maps used by the program.