pub struct SchedClassifier { /* private fields */ }
Expand description
A network traffic control classifier.
SchedClassifier
programs can be used to inspect, filter or redirect
network packets in both ingress and egress. They are executed as part of the
linux network traffic control system. See
https://man7.org/linux/man-pages/man8/tc-bpf.8.html.
Examples
Minimum kernel version
The minimum kernel version required to use this feature is 4.1.
use std::convert::TryInto;
use aya::programs::{tc, SchedClassifier, TcAttachType};
// the clsact qdisc needs to be added before SchedClassifier programs can be
// attached
tc::qdisc_add_clsact("eth0")?;
let prog: &mut SchedClassifier = bpf.program_mut("redirect_ingress").unwrap().try_into()?;
prog.load()?;
prog.attach("eth0", TcAttachType::Ingress)?;
Implementations
sourceimpl SchedClassifier
impl SchedClassifier
sourcepub fn load(&mut self) -> Result<(), ProgramError>
pub fn load(&mut self) -> Result<(), ProgramError>
Loads the program inside the kernel.
sourcepub fn attach(
&mut self,
interface: &str,
attach_type: TcAttachType
) -> Result<SchedClassifierLinkId, ProgramError>
pub fn attach(
&mut self,
interface: &str,
attach_type: TcAttachType
) -> Result<SchedClassifierLinkId, ProgramError>
Attaches the program to the given interface
.
The returned value can be used to detach, see SchedClassifier::detach.
Errors
TcError::NetlinkError
is returned if attaching fails. A common cause
of failure is not having added the clsact
qdisc to the given
interface, see qdisc_add_clsact
sourcepub fn detach(
&mut self,
link_id: SchedClassifierLinkId
) -> Result<(), ProgramError>
pub fn detach(
&mut self,
link_id: SchedClassifierLinkId
) -> Result<(), ProgramError>
Detaches the program.
sourcepub fn take_link(
&mut self,
link_id: SchedClassifierLinkId
) -> Result<OwnedLink<SchedClassifierLink>, ProgramError>
pub fn take_link(
&mut self,
link_id: SchedClassifierLinkId
) -> Result<OwnedLink<SchedClassifierLink>, ProgramError>
Takes ownership of the link referenced by the provided link_id.
The link will be detached on Drop
and the caller is now responsible
for managing its lifetime.
sourceimpl SchedClassifier
impl SchedClassifier
sourcepub fn unload(&mut self) -> Result<(), ProgramError>
pub fn unload(&mut self) -> Result<(), ProgramError>
Unloads the program from the kernel.
Links will be detached before unloading the program. Note
that owned links obtained using take_link()
will not be
detached.
Trait Implementations
sourceimpl Debug for SchedClassifier
impl Debug for SchedClassifier
sourceimpl ProgramFd for SchedClassifier
impl ProgramFd for SchedClassifier
sourceimpl ProgramFd for &mut SchedClassifier
impl ProgramFd for &mut SchedClassifier
sourceimpl<'a> TryFrom<&'a Program> for &'a SchedClassifier
impl<'a> TryFrom<&'a Program> for &'a SchedClassifier
type Error = ProgramError
type Error = ProgramError
The type returned in the event of a conversion error.
sourcefn try_from(program: &'a Program) -> Result<&'a SchedClassifier, ProgramError>
fn try_from(program: &'a Program) -> Result<&'a SchedClassifier, ProgramError>
Performs the conversion.
sourceimpl<'a> TryFrom<&'a mut Program> for &'a mut SchedClassifier
impl<'a> TryFrom<&'a mut Program> for &'a mut SchedClassifier
type Error = ProgramError
type Error = ProgramError
The type returned in the event of a conversion error.
sourcefn try_from(
program: &'a mut Program
) -> Result<&'a mut SchedClassifier, ProgramError>
fn try_from(
program: &'a mut Program
) -> Result<&'a mut SchedClassifier, ProgramError>
Performs the conversion.
Auto Trait Implementations
impl RefUnwindSafe for SchedClassifier
impl Send for SchedClassifier
impl Sync for SchedClassifier
impl Unpin for SchedClassifier
impl UnwindSafe for SchedClassifier
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more