diff --git a/aya/src/programs/mod.rs b/aya/src/programs/mod.rs index eb583495..219e5ff4 100644 --- a/aya/src/programs/mod.rs +++ b/aya/src/programs/mod.rs @@ -93,14 +93,9 @@ pub enum ProgramError { verifier_log: String, }, - #[error("the perf_event_open syscall failed")] - PerfEventOpenError { - #[source] - io_error: io::Error, - }, - - #[error("PERF_EVENT_IOC_SET_BPF/PERF_EVENT_IOC_ENABLE failed")] - PerfEventAttachError { + #[error("`{call}` failed")] + SyscallError { + call: String, #[source] io_error: io::Error, }, @@ -108,12 +103,6 @@ pub enum ProgramError { #[error("unknown network interface {name}")] UnknownInterface { name: String }, - #[error("BPF_LINK_CREATE failed")] - BpfLinkCreateError { - #[source] - io_error: io::Error, - }, - #[error("unexpected program type")] UnexpectedProgramType, diff --git a/aya/src/programs/perf_attach.rs b/aya/src/programs/perf_attach.rs index 612cba85..1085d272 100644 --- a/aya/src/programs/perf_attach.rs +++ b/aya/src/programs/perf_attach.rs @@ -32,10 +32,18 @@ impl Drop for PerfLink { pub(crate) fn perf_attach(data: &mut ProgramData, fd: RawFd) -> Result { let prog_fd = data.fd_or_err()?; - perf_event_ioctl(fd, PERF_EVENT_IOC_SET_BPF, prog_fd) - .map_err(|(_, io_error)| ProgramError::PerfEventAttachError { io_error })?; - perf_event_ioctl(fd, PERF_EVENT_IOC_ENABLE, 0) - .map_err(|(_, io_error)| ProgramError::PerfEventAttachError { io_error })?; + perf_event_ioctl(fd, PERF_EVENT_IOC_SET_BPF, prog_fd).map_err(|(_, io_error)| { + ProgramError::SyscallError { + call: "PERF_EVENT_IOC_SET_BPF".to_owned(), + io_error, + } + })?; + perf_event_ioctl(fd, PERF_EVENT_IOC_ENABLE, 0).map_err(|(_, io_error)| { + ProgramError::SyscallError { + call: "PERF_EVENT_IOC_ENABLE".to_owned(), + io_error, + } + })?; Ok(data.link(PerfLink { perf_fd: Some(fd) })) } diff --git a/aya/src/programs/probe.rs b/aya/src/programs/probe.rs index f973a422..f7cfc312 100644 --- a/aya/src/programs/probe.rs +++ b/aya/src/programs/probe.rs @@ -44,9 +44,12 @@ pub(crate) fn attach( _ => None, }; - let fd = perf_event_open_probe(perf_ty, ret_bit, name, offset, pid) - .map_err(|(_code, io_error)| ProgramError::PerfEventOpenError { io_error })? - as i32; + let fd = perf_event_open_probe(perf_ty, ret_bit, name, offset, pid).map_err( + |(_code, io_error)| ProgramError::SyscallError { + call: "perf_event_open".to_owned(), + io_error, + }, + )? as i32; perf_attach(program_data, fd) } diff --git a/aya/src/programs/trace_point.rs b/aya/src/programs/trace_point.rs index be8d7d37..5aae6a48 100644 --- a/aya/src/programs/trace_point.rs +++ b/aya/src/programs/trace_point.rs @@ -27,9 +27,12 @@ impl TracePoint { pub fn attach(&mut self, category: &str, name: &str) -> Result { let id = read_sys_fs_trace_point_id(category, name)?; - let fd = perf_event_open_trace_point(id) - .map_err(|(_code, io_error)| ProgramError::PerfEventOpenError { io_error })? - as i32; + let fd = perf_event_open_trace_point(id).map_err(|(_code, io_error)| { + ProgramError::SyscallError { + call: "perf_event_open".to_owned(), + io_error, + } + })? as i32; perf_attach(&mut self.data, fd) } diff --git a/aya/src/programs/xdp.rs b/aya/src/programs/xdp.rs index 13dd19cc..75b89c9e 100644 --- a/aya/src/programs/xdp.rs +++ b/aya/src/programs/xdp.rs @@ -59,9 +59,12 @@ impl Xdp { let k_ver = kernel_version().unwrap(); if k_ver >= (5, 9, 0) { - let link_fd = bpf_link_create(prog_fd, if_index, BPF_XDP, flags.bits) - .map_err(|(_, io_error)| ProgramError::BpfLinkCreateError { io_error })? - as RawFd; + let link_fd = bpf_link_create(prog_fd, if_index, BPF_XDP, flags.bits).map_err( + |(_, io_error)| ProgramError::SyscallError { + call: "bpf_link_create".to_owned(), + io_error, + }, + )? as RawFd; Ok(self .data .link(XdpLink::FdLink(FdLink { fd: Some(link_fd) })))