Skip to content

Commit 4ecba1e

Browse files
committed
Cleanup round 2
1 parent cd2c2b3 commit 4ecba1e

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/tc/filters/cls_flower.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#![deny(clippy::all, clippy::pedantic)]
21
// SPDX-License-Identifier: MIT
2+
#![deny(clippy::all, clippy::pedantic)]
33
/// flower filter
44
use std::net::{Ipv4Addr, Ipv6Addr};
55

@@ -499,6 +499,8 @@ impl ErspanHwid {
499499
Self(hwid)
500500
}
501501

502+
/// # Errors
503+
/// Returns `DecodeError` if the value is greater than 63.
502504
pub fn new_checked(hwid: u8) -> Result<Self, DecodeError> {
503505
if hwid >= (1 << 6) {
504506
return Err(DecodeError::from(format!(
@@ -815,6 +817,7 @@ struct FlowerActionList(Vec<FlowerAction>);
815817
impl From<&Vec<TcAction>> for FlowerActionList {
816818
fn from(actions: &Vec<TcAction>) -> Self {
817819
Self(
820+
actions
818821
actions
819822
.iter()
820823
.enumerate()
@@ -2014,20 +2017,22 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>>
20142017
Self::KeyMplsLabel(parse_u32(payload)?)
20152018
}
20162019
TCA_FLOWER_KEY_TCP_FLAGS => {
2017-
if payload.len() != 2 {
2018-
return Err(DecodeError::from("invalid tcp flags length"));
2020+
let flags = parse_u16_be(payload)?;
2021+
if flags > 0xff {
2022+
return Err(DecodeError::from(
2023+
"invalid tcp flags value",
2024+
));
20192025
}
2020-
let flags = BigEndian::read_u16(payload);
2021-
Self::KeyTcpFlags(TcpFlags::from_bits_retain(flags as u8))
2026+
Self::KeyTcpFlags(TcpFlags::from_bits_retain((flags & 0xff) as u8))
20222027
}
20232028
TCA_FLOWER_KEY_TCP_FLAGS_MASK => {
2024-
if payload.len() != 2 {
2029+
let flags = parse_u16_be(payload)?;
2030+
if flags > 0xff {
20252031
return Err(DecodeError::from(
2026-
"invalid tcp flags mask length",
2032+
"invalid tcp flags mask value",
20272033
));
20282034
}
2029-
let flags = BigEndian::read_u16(payload);
2030-
Self::KeyTcpFlagsMask(flags as u8)
2035+
Self::KeyTcpFlagsMask((flags & 0xff) as u8)
20312036
}
20322037
TCA_FLOWER_KEY_IP_TOS => {
20332038
if payload.len() != 1 {
@@ -2276,7 +2281,7 @@ impl Nla for Lse {
22762281
}
22772282

22782283
fn emit_value(&self, buffer: &mut [u8]) {
2279-
self.opts.as_slice().emit(buffer)
2284+
self.opts.as_slice().emit(buffer);
22802285
}
22812286

22822287
fn is_nested(&self) -> bool {
@@ -2486,6 +2491,9 @@ impl From<L2Miss> for u8 {
24862491
pub struct MaintenanceDomainLevel(u8);
24872492

24882493
impl MaintenanceDomainLevel {
2494+
/// # Errors
2495+
/// Returns an error if the value is greater than 7
2496+
/// (the maximum allowed value in the CFM spec).
24892497
pub fn new(value: u8) -> Result<Self, DecodeError> {
24902498
if value > 7 {
24912499
Err(DecodeError::from("invalid maintenance domain level"))

0 commit comments

Comments
 (0)