add program_info API

Add a new API macro to each aya `Program` type to allow us to fetch it's
accompanying `ProgramInfo` metadata after it's been loaded.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
reviewable/pr637/r43
Andrew Stoycos 2 years ago
parent 243d789be8
commit 0b022af9f3
No known key found for this signature in database
GPG Key ID: 66735B92BB71C096

@ -921,6 +921,58 @@ impl_try_from_program!(
CgroupDevice,
);
/// Returns information about a loaded program with the [`ProgramInfo`] structure.
///
/// This information is populated at load time by the kernel and can be used
/// to correlate a given [`Program`] to it's corresponding [`ProgramInfo`]
/// metadata.
macro_rules! impl_program_info {
($($struct_name:ident),+ $(,)?) => {
$(
impl $struct_name {
/// Returns the file descriptor of this Program.
pub fn program_info(&self) -> Result<ProgramInfo, ProgramError> {
let fd = self.fd().ok_or(ProgramError::NotLoaded)?;
bpf_prog_get_info_by_fd(fd.as_raw_fd(), &[])
.map_err(|io_error| ProgramError::SyscallError {
call: "bpf_prog_get_info_by_fd",
io_error,
})
.map(ProgramInfo)
}
}
)+
}
}
impl_program_info!(
KProbe,
UProbe,
TracePoint,
SocketFilter,
Xdp,
SkMsg,
SkSkb,
SchedClassifier,
CgroupSkb,
CgroupSysctl,
CgroupSockopt,
LircMode2,
PerfEvent,
Lsm,
RawTracePoint,
BtfTracePoint,
FEntry,
FExit,
Extension,
CgroupSockAddr,
SkLookup,
SockOps,
CgroupSock,
CgroupDevice,
);
/// Provides information about a loaded program, like name, id and statistics
#[derive(Debug)]
pub struct ProgramInfo(bpf_prog_info);

Loading…
Cancel
Save