Address review comments

- Removed LinkId and associated constructor functions
- Changed ConversionError to a TryFromError

Signed-off-by: Andre Fredette <afredette@redhat.com>
reviewable/pr921/r13
Andre Fredette 7 months ago
parent 0de59a4b41
commit 5f03569fff

@ -397,19 +397,6 @@ pub enum LinkError {
SyscallError(#[from] SyscallError), SyscallError(#[from] SyscallError),
} }
/// A [`Link`] identifier.
pub struct LinkId(u32);
impl LinkId {
/// Create a new [`LinkId`] from its kernel id.
///
/// This method is unsafe since it doesn't check that the given `id` is a an
/// existing link id.
pub unsafe fn new(id: u32) -> Self {
Self(id)
}
}
#[derive(Debug)] #[derive(Debug)]
pub(crate) enum LinkRef { pub(crate) enum LinkRef {
Id(u32), Id(u32),
@ -496,22 +483,6 @@ impl LinkOrder {
}) })
} }
/// Attach before the link with the given id.
pub fn before_link_id(id: LinkId) -> Result<Self, LinkError> {
Ok(Self {
link_ref: LinkRef::Id(id.0),
flags: MprogFlags::BEFORE | MprogFlags::LINK | MprogFlags::ID,
})
}
/// Attach after the link with the given id.
pub fn after_link_id(id: LinkId) -> Result<Self, LinkError> {
Ok(Self {
link_ref: LinkRef::Id(id.0),
flags: MprogFlags::AFTER | MprogFlags::LINK | MprogFlags::ID,
})
}
/// Attach before the given program. /// Attach before the given program.
pub fn before_program<P: MultiProgProgram>(program: &P) -> Result<Self, ProgramError> { pub fn before_program<P: MultiProgProgram>(program: &P) -> Result<Self, ProgramError> {
Ok(Self { Ok(Self {

@ -72,6 +72,7 @@ pub mod xdp;
use std::{ use std::{
ffi::CString, ffi::CString,
io, io,
num::TryFromIntError,
os::fd::{AsFd, AsRawFd, BorrowedFd}, os::fd::{AsFd, AsRawFd, BorrowedFd},
path::{Path, PathBuf}, path::{Path, PathBuf},
sync::Arc, sync::Arc,
@ -218,14 +219,9 @@ pub enum ProgramError {
#[error(transparent)] #[error(transparent)]
IOError(#[from] io::Error), IOError(#[from] io::Error),
/// An error occurred when attmpting to convert a type. /// A checked integral type conversion failed.
#[error("conversion error from {from} to {to}")] #[error(transparent)]
ConversionError { TryFromIntError(#[from] TryFromIntError),
/// The type being converted from.
from: String,
/// The type being converted to.
to: String,
},
} }
/// A [`Program`] file descriptor. /// A [`Program`] file descriptor.

@ -269,12 +269,7 @@ impl SchedClassifier {
let name = CString::new(name).unwrap(); let name = CString::new(name).unwrap();
let (priority, handle) = unsafe { let (priority, handle) = unsafe {
netlink_qdisc_attach( netlink_qdisc_attach(
if_index if_index.try_into().map_err(ProgramError::TryFromIntError)?,
.try_into()
.map_err(|_| ProgramError::ConversionError {
from: "u32".to_string(),
to: "i32".to_string(),
})?,
&attach_type, &attach_type,
prog_fd, prog_fd,
&name, &name,
@ -366,13 +361,10 @@ impl Link for NlLink {
} }
fn detach(self) -> Result<(), ProgramError> { fn detach(self) -> Result<(), ProgramError> {
let if_index: i32 = let if_index: i32 = self
self.if_index .if_index
.try_into() .try_into()
.map_err(|_| ProgramError::ConversionError { .map_err(ProgramError::TryFromIntError)?;
from: "u32".to_string(),
to: "i32".to_string(),
})?;
unsafe { netlink_qdisc_detach(if_index, &self.attach_type, self.priority, self.handle) } unsafe { netlink_qdisc_detach(if_index, &self.attach_type, self.priority, self.handle) }
.map_err(|io_error| TcError::NetlinkError { io_error })?; .map_err(|io_error| TcError::NetlinkError { io_error })?;
Ok(()) Ok(())

Loading…
Cancel
Save