Skip to content

Commit

Permalink
Support reconstruction of SchedClassifierLink
Browse files Browse the repository at this point in the history
This is the proposed solution for Step 2 of issue #414

“For cases where you have done program.take_link() to manage
ownership of TcLink we need an API similar to PinnedLink::from_pin
that can reconstruct a TcLink”

As long as a user application continues to run after executing
`take_link()`, the `SchedClassifierLink` returned can be used to
detach the program.  However, if we want to handle cases where the
application exits or crashes, we need a way to save and reconstruct
the link, and to do that, we also need to know the information
required for the reconstruction -- namely, the `interface`,
`attach_type`, `priority`, and `handle`.  The user knows the first
two because they are required to execute `attach()` in the first
place; however, the user will not know the others if they let the
system choose them.

This pr solves the problems by adding an `impl` for
`SchedClassifierLink` with an accessor for `tc_options` and a `new()`
function.

Signed-off-by: Andre Fredette <afredette@redhat.com>
  • Loading branch information
anfredette committed Jan 25, 2023
1 parent 1899d5f commit f46fd17
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions aya/src/programs/tc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,33 @@ define_link_wrapper!(
TcLinkId
);

impl SchedClassifierLink {
/// Creates a new SchedClassifierLink instance
pub fn new(
interface: &str,
attach_type: TcAttachType,
priority: u16,
handle: u32,
) -> Result<SchedClassifierLink, ProgramError> {
let if_index = ifindex_from_ifname(interface)
.map_err(|io_error| TcError::NetlinkError { io_error })?;
Ok(SchedClassifierLink(TcLink {
if_index: if_index as i32,
attach_type,
priority,
handle,
}))
}

/// Returns options for a SchedClassifierLink
pub fn tc_options(&self) -> TcOptions {
TcOptions {
priority: self.0.priority,
handle: self.0.handle,
}
}
}

/// Add the `clasct` qdisc to the given interface.
///
/// The `clsact` qdisc must be added to an interface before [`SchedClassifier`]
Expand Down

0 comments on commit f46fd17

Please sign in to comment.