Address review comments

Signed-off-by: Andre Fredette <afredette@redhat.com>
pull/445/head
Andre Fredette 2 years ago
parent 849796c420
commit 65f5b76593

@ -251,6 +251,7 @@ define_link_wrapper!(
/// # /// #
/// # use aya::programs::tc::{SchedClassifierLink}; /// # use aya::programs::tc::{SchedClassifierLink};
/// # use aya::programs::{tc, Link, SchedClassifier, TcAttachType}; /// # use aya::programs::{tc, Link, SchedClassifier, TcAttachType};
/// # use std::mem;
/// let tc_link_id = prog.attach("eth0", TcAttachType::Ingress)?; /// let tc_link_id = prog.attach("eth0", TcAttachType::Ingress)?;
/// ///
/// let tc_link = prog.take_link(tc_link_id)?; /// let tc_link = prog.take_link(tc_link_id)?;
@ -259,9 +260,16 @@ define_link_wrapper!(
/// let priority = tc_link.priority(); /// let priority = tc_link.priority();
/// let handle = tc_link.handle(); /// let handle = tc_link.handle();
/// ///
/// // A new SchedClassifierLink can be constructed to access an existing attachment /// // The following call "forgets" about tc_link so that it is not detached on drop.
/// let new_tc_link = SchedClassifierLink::new("eth0", TcAttachType::Ingress, priority, handle)?; /// mem::forget(tc_link);
/// ///
/// // The link can be re-instantiated and detached as shown below.
/// let new_tc_link = SchedClassifierLink::new_tc_link(
/// "eth0",
/// TcAttachType::Ingress,
/// priority,
/// handle,
/// )?;
/// new_tc_link.detach()?; /// new_tc_link.detach()?;
/// ///
/// # Ok::<(), Error>(()) /// # Ok::<(), Error>(())
@ -274,19 +282,19 @@ impl SchedClassifierLink {
/// [SchedClassifier::attach], the output of the `tc filter` command or from the output of /// [SchedClassifier::attach], the output of the `tc filter` command or from the output of
/// another BPF loader. /// another BPF loader.
/// ///
/// # Warnings /// Note: If you create a link for a program that you do not own, detaching it may have
/// unintended consequences.
///
/// # Errors
/// - If a program is not attached with the provided parameters, calls to /// - If a program is not attached with the provided parameters, calls to
/// [`SchedClassifierLink::detach`] will return a [`TcError::NetlinkError`] /// [`SchedClassifierLink::detach`] will return a [`TcError::NetlinkError`]
/// - If you create a link for a program that you do not own, detaching it may have unintended
/// consequences.
pub fn new_tc_link( pub fn new_tc_link(
if_name: &str, if_name: &str,
attach_type: TcAttachType, attach_type: TcAttachType,
priority: u16, priority: u16,
handle: u32, handle: u32,
) -> Result<SchedClassifierLink, ProgramError> { ) -> Result<SchedClassifierLink, io::Error> {
let if_index = let if_index = ifindex_from_ifname(if_name)?;
ifindex_from_ifname(if_name).map_err(|io_error| TcError::NetlinkError { io_error })?;
Ok(SchedClassifierLink(TcLink { Ok(SchedClassifierLink(TcLink {
if_index: if_index as i32, if_index: if_index as i32,
attach_type, attach_type,

Loading…
Cancel
Save