aya: consolidate errors into ProgramError::SyscallError

pull/1/head
Alessandro Decina 4 years ago
parent ae863bc663
commit 683a58ea6d

@ -93,14 +93,9 @@ pub enum ProgramError {
verifier_log: String, verifier_log: String,
}, },
#[error("the perf_event_open syscall failed")] #[error("`{call}` failed")]
PerfEventOpenError { SyscallError {
#[source] call: String,
io_error: io::Error,
},
#[error("PERF_EVENT_IOC_SET_BPF/PERF_EVENT_IOC_ENABLE failed")]
PerfEventAttachError {
#[source] #[source]
io_error: io::Error, io_error: io::Error,
}, },
@ -108,12 +103,6 @@ pub enum ProgramError {
#[error("unknown network interface {name}")] #[error("unknown network interface {name}")]
UnknownInterface { name: String }, UnknownInterface { name: String },
#[error("BPF_LINK_CREATE failed")]
BpfLinkCreateError {
#[source]
io_error: io::Error,
},
#[error("unexpected program type")] #[error("unexpected program type")]
UnexpectedProgramType, UnexpectedProgramType,

@ -32,10 +32,18 @@ impl Drop for PerfLink {
pub(crate) fn perf_attach(data: &mut ProgramData, fd: RawFd) -> Result<LinkRef, ProgramError> { pub(crate) fn perf_attach(data: &mut ProgramData, fd: RawFd) -> Result<LinkRef, ProgramError> {
let prog_fd = data.fd_or_err()?; let prog_fd = data.fd_or_err()?;
perf_event_ioctl(fd, PERF_EVENT_IOC_SET_BPF, prog_fd) perf_event_ioctl(fd, PERF_EVENT_IOC_SET_BPF, prog_fd).map_err(|(_, io_error)| {
.map_err(|(_, io_error)| ProgramError::PerfEventAttachError { io_error })?; ProgramError::SyscallError {
perf_event_ioctl(fd, PERF_EVENT_IOC_ENABLE, 0) call: "PERF_EVENT_IOC_SET_BPF".to_owned(),
.map_err(|(_, io_error)| ProgramError::PerfEventAttachError { io_error })?; 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) })) Ok(data.link(PerfLink { perf_fd: Some(fd) }))
} }

@ -44,9 +44,12 @@ pub(crate) fn attach(
_ => None, _ => None,
}; };
let fd = perf_event_open_probe(perf_ty, ret_bit, name, offset, pid) let fd = perf_event_open_probe(perf_ty, ret_bit, name, offset, pid).map_err(
.map_err(|(_code, io_error)| ProgramError::PerfEventOpenError { io_error })? |(_code, io_error)| ProgramError::SyscallError {
as i32; call: "perf_event_open".to_owned(),
io_error,
},
)? as i32;
perf_attach(program_data, fd) perf_attach(program_data, fd)
} }

@ -27,9 +27,12 @@ impl TracePoint {
pub fn attach(&mut self, category: &str, name: &str) -> Result<LinkRef, ProgramError> { pub fn attach(&mut self, category: &str, name: &str) -> Result<LinkRef, ProgramError> {
let id = read_sys_fs_trace_point_id(category, name)?; let id = read_sys_fs_trace_point_id(category, name)?;
let fd = perf_event_open_trace_point(id) let fd = perf_event_open_trace_point(id).map_err(|(_code, io_error)| {
.map_err(|(_code, io_error)| ProgramError::PerfEventOpenError { io_error })? ProgramError::SyscallError {
as i32; call: "perf_event_open".to_owned(),
io_error,
}
})? as i32;
perf_attach(&mut self.data, fd) perf_attach(&mut self.data, fd)
} }

@ -59,9 +59,12 @@ impl Xdp {
let k_ver = kernel_version().unwrap(); let k_ver = kernel_version().unwrap();
if k_ver >= (5, 9, 0) { if k_ver >= (5, 9, 0) {
let link_fd = bpf_link_create(prog_fd, if_index, BPF_XDP, flags.bits) let link_fd = bpf_link_create(prog_fd, if_index, BPF_XDP, flags.bits).map_err(
.map_err(|(_, io_error)| ProgramError::BpfLinkCreateError { io_error })? |(_, io_error)| ProgramError::SyscallError {
as RawFd; call: "bpf_link_create".to_owned(),
io_error,
},
)? as RawFd;
Ok(self Ok(self
.data .data
.link(XdpLink::FdLink(FdLink { fd: Some(link_fd) }))) .link(XdpLink::FdLink(FdLink { fd: Some(link_fd) })))

Loading…
Cancel
Save