Skip to content

Commit cdd3812

Browse files
author
Erich Heine
committed
Add support for tc matchall filter
This adds a new method `matchall` to the TrafficFilterNewRequest struct, equivalent to commands like `tc filter ... matchall`. The matchall filter will match every packet and apply defined actions (etc) to it.
1 parent 5e5c688 commit cdd3812

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/traffic_control/add_filter.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,32 @@ impl TrafficFilterNewRequest {
108108
self
109109
}
110110

111+
/// The matchall filter matches every packet and applies actions, etc
112+
/// Equivalent to `tc filter ... matchall`
113+
pub fn matchall(
114+
mut self,
115+
data: Vec<tc::matchall::Nla>,
116+
) -> Result<Self, Error> {
117+
if self
118+
.message
119+
.nlas
120+
.iter()
121+
.any(|nla| matches!(nla, tc::Nla::Kind(_)))
122+
{
123+
return Err(Error::InvalidNla(
124+
"message kind has already been set.".to_string(),
125+
));
126+
}
127+
128+
self.message
129+
.nlas
130+
.push(tc::Nla::Kind(tc::matchall::KIND.to_string()));
131+
self.message.nlas.push(tc::Nla::Options(
132+
data.into_iter().map(tc::TcOpt::Matchall).collect(),
133+
));
134+
Ok(self)
135+
}
136+
111137
/// The 32bit filter allows to match arbitrary bitfields in the packet.
112138
/// Equivalent to `tc filter ... u32`.
113139
pub fn u32(mut self, data: Vec<tc::u32::Nla>) -> Result<Self, Error> {

0 commit comments

Comments
 (0)