This repository has been archived by the owner on Oct 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently only qdisc ingress is supported. Signed-off-by: wllenyj <wllenyj@linux.alibaba.com>
- Loading branch information
Showing
14 changed files
with
781 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
/// Handles | ||
pub const TC_H_MAJ_MASK: u32 = 0xFFFF0000; | ||
pub const TC_H_MIN_MASK: u32 = 0x0000FFFF; | ||
|
||
#[macro_export] | ||
macro_rules! TC_H_MAKE { | ||
($maj: expr, $min: expr) => { | ||
($maj & TC_H_MAJ_MASK) | ($min & TC_H_MIN_MASK) | ||
}; | ||
} | ||
|
||
pub const TC_H_UNSPEC: u32 = 0; | ||
pub const TC_H_ROOT: u32 = 0xFFFFFFFF; | ||
pub const TC_H_INGRESS: u32 = 0xFFFFFFF1; | ||
pub const TC_H_CLSACT: u32 = TC_H_INGRESS; | ||
|
||
pub const TC_H_MIN_PRIORITY: u32 = 0xFFE0; | ||
pub const TC_H_MIN_INGRESS: u32 = 0xFFF2; | ||
pub const TC_H_MIN_EGRESS: u32 = 0xFFF3; | ||
|
||
/// U32 filters | ||
pub const TCA_U32_UNSPEC: u16 = 0; | ||
pub const TCA_U32_CLASSID: u16 = 1; | ||
pub const TCA_U32_HASH: u16 = 2; | ||
pub const TCA_U32_LINK: u16 = 3; | ||
pub const TCA_U32_DIVISOR: u16 = 4; | ||
pub const TCA_U32_SEL: u16 = 5; | ||
pub const TCA_U32_POLICE: u16 = 6; | ||
pub const TCA_U32_ACT: u16 = 7; | ||
pub const TCA_U32_INDEV: u16 = 8; | ||
pub const TCA_U32_PCNT: u16 = 9; | ||
pub const TCA_U32_MARK: u16 = 10; | ||
pub const TCA_U32_FLAGS: u16 = 11; | ||
pub const TCA_U32_PAD: u16 = 12; | ||
pub const TCA_U32_MAX: u16 = TCA_U32_PAD; | ||
|
||
/// U32 Flags | ||
pub const TC_U32_TERMINAL: u8 = 1; | ||
pub const TC_U32_OFFSET: u8 = 2; | ||
pub const TC_U32_VAROFFSET: u8 = 4; | ||
pub const TC_U32_EAT: u8 = 8; | ||
pub const TC_U32_MAXDEPTH: u8 = 8; | ||
|
||
/// Action attributes | ||
pub const TCA_ACT_UNSPEC: u16 = 0; | ||
pub const TCA_ACT_KIND: u16 = 1; | ||
pub const TCA_ACT_OPTIONS: u16 = 2; | ||
pub const TCA_ACT_INDEX: u16 = 3; | ||
pub const TCA_ACT_STATS: u16 = 4; | ||
pub const TCA_ACT_PAD: u16 = 5; | ||
pub const TCA_ACT_COOKIE: u16 = 6; | ||
|
||
//TODO(wllenyj): Why not subtract 1? See `linux/pkt_cls.h` for original definition. | ||
pub const TCA_ACT_MAX: u16 = 7; | ||
pub const TCA_OLD_COMPAT: u16 = TCA_ACT_MAX + 1; | ||
pub const TCA_ACT_MAX_PRIO: u16 = 32; | ||
pub const TCA_ACT_BIND: u16 = 1; | ||
pub const TCA_ACT_NOBIND: u16 = 0; | ||
pub const TCA_ACT_UNBIND: u16 = 1; | ||
pub const TCA_ACT_NOUNBIND: u16 = 0; | ||
pub const TCA_ACT_REPLACE: u16 = 1; | ||
pub const TCA_ACT_NOREPLACE: u16 = 0; | ||
|
||
pub const TC_ACT_UNSPEC: i32 = -1; | ||
pub const TC_ACT_OK: i32 = 0; | ||
pub const TC_ACT_RECLASSIFY: i32 = 1; | ||
pub const TC_ACT_SHOT: i32 = 2; | ||
pub const TC_ACT_PIPE: i32 = 3; | ||
pub const TC_ACT_STOLEN: i32 = 4; | ||
pub const TC_ACT_QUEUED: i32 = 5; | ||
pub const TC_ACT_REPEAT: i32 = 6; | ||
pub const TC_ACT_REDIRECT: i32 = 7; | ||
pub const TC_ACT_TRAP: i32 = 8; | ||
|
||
pub const TC_ACT_VALUE_MAX: i32 = TC_ACT_TRAP; | ||
|
||
pub const TC_ACT_JUMP: i32 = 0x10000000; | ||
|
||
pub const TCA_ACT_TAB: u16 = 1; // TCA_ROOT_TAB | ||
pub const TCAA_MAX: u16 = 1; | ||
|
||
/// Mirred action attr | ||
pub const TCA_MIRRED_UNSPEC: u16 = 0; | ||
pub const TCA_MIRRED_TM: u16 = 1; | ||
pub const TCA_MIRRED_PARMS: u16 = 2; | ||
pub const TCA_MIRRED_PAD: u16 = 3; | ||
pub const TCA_MIRRED_MAX: u16 = TCA_MIRRED_PAD; | ||
|
||
pub const TCA_EGRESS_REDIR: i32 = 1; /* packet redirect to EGRESS */ | ||
pub const TCA_EGRESS_MIRROR: i32 = 2; /* mirror packet to EGRESS */ | ||
pub const TCA_INGRESS_REDIR: i32 = 3; /* packet redirect to INGRESS */ | ||
pub const TCA_INGRESS_MIRROR: i32 = 4; /* mirror packet to INGRESS */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
mod buffer; | ||
pub mod constants; | ||
mod message; | ||
pub mod nlas; | ||
|
||
pub use self::{buffer::*, message::*, nlas::*}; | ||
|
||
#[cfg(test)] | ||
mod test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: MIT | ||
use crate::{ | ||
nlas::{self, DefaultNla, NlaBuffer}, | ||
tc::ingress, | ||
traits::{Parseable, ParseableParametrized}, | ||
DecodeError, | ||
}; | ||
|
||
#[derive(Debug, PartialEq, Eq, Clone)] | ||
pub enum TcOpt { | ||
// Qdisc specific options | ||
Ingress, | ||
// Other options | ||
Other(DefaultNla), | ||
} | ||
|
||
impl nlas::Nla for TcOpt { | ||
fn value_len(&self) -> usize { | ||
match self { | ||
Self::Ingress => 0, | ||
Self::Other(o) => o.value_len(), | ||
} | ||
} | ||
|
||
fn emit_value(&self, buffer: &mut [u8]) { | ||
match self { | ||
Self::Ingress => unreachable!(), | ||
Self::Other(o) => o.emit_value(buffer), | ||
} | ||
} | ||
|
||
fn kind(&self) -> u16 { | ||
match self { | ||
Self::Ingress => unreachable!(), | ||
Self::Other(o) => o.kind(), | ||
} | ||
} | ||
} | ||
|
||
impl<'a, T, S> ParseableParametrized<NlaBuffer<&'a T>, S> for TcOpt | ||
where | ||
T: AsRef<[u8]> + ?Sized, | ||
S: AsRef<str>, | ||
{ | ||
fn parse_with_param(buf: &NlaBuffer<&'a T>, kind: S) -> Result<Self, DecodeError> { | ||
Ok(match kind.as_ref() { | ||
ingress::KIND => TcOpt::Ingress, | ||
_ => Self::Other(DefaultNla::parse(buf)?), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pub mod ingress { | ||
pub const KIND: &str = "ingress"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
//#[derive(Debug, PartialEq, Eq, Clone)] | ||
//pub enum Qdisc { | ||
// Prio(Prio), | ||
// Ingress, | ||
//} | ||
// | ||
//pub const TC_PRIO_MAX: usize = 15; | ||
//#[derive(Debug, PartialEq, Eq, Clone)] | ||
//pub struct Prio { | ||
// // Number of bands | ||
// bands: i32, | ||
// // Map: logical priority -> PRIO band | ||
// priomap: [u8; TC_PRIO_MAX + 1], | ||
//} |
Oops, something went wrong.