|
1 | | -#![deny(clippy::all, clippy::pedantic)] |
2 | 1 | // SPDX-License-Identifier: MIT |
| 2 | +#![deny(clippy::all, clippy::pedantic)] |
3 | 3 | /// flower filter |
4 | 4 | use std::net::{Ipv4Addr, Ipv6Addr}; |
5 | 5 |
|
@@ -499,6 +499,8 @@ impl ErspanHwid { |
499 | 499 | Self(hwid) |
500 | 500 | } |
501 | 501 |
|
| 502 | + /// # Errors |
| 503 | + /// Returns `DecodeError` if the value is greater than 63. |
502 | 504 | pub fn new_checked(hwid: u8) -> Result<Self, DecodeError> { |
503 | 505 | if hwid >= (1 << 6) { |
504 | 506 | return Err(DecodeError::from(format!( |
@@ -815,6 +817,7 @@ struct FlowerActionList(Vec<FlowerAction>); |
815 | 817 | impl From<&Vec<TcAction>> for FlowerActionList { |
816 | 818 | fn from(actions: &Vec<TcAction>) -> Self { |
817 | 819 | Self( |
| 820 | + actions |
818 | 821 | actions |
819 | 822 | .iter() |
820 | 823 | .enumerate() |
@@ -2014,20 +2017,22 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> |
2014 | 2017 | Self::KeyMplsLabel(parse_u32(payload)?) |
2015 | 2018 | } |
2016 | 2019 | 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 | + )); |
2019 | 2025 | } |
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)) |
2022 | 2027 | } |
2023 | 2028 | TCA_FLOWER_KEY_TCP_FLAGS_MASK => { |
2024 | | - if payload.len() != 2 { |
| 2029 | + let flags = parse_u16_be(payload)?; |
| 2030 | + if flags > 0xff { |
2025 | 2031 | return Err(DecodeError::from( |
2026 | | - "invalid tcp flags mask length", |
| 2032 | + "invalid tcp flags mask value", |
2027 | 2033 | )); |
2028 | 2034 | } |
2029 | | - let flags = BigEndian::read_u16(payload); |
2030 | | - Self::KeyTcpFlagsMask(flags as u8) |
| 2035 | + Self::KeyTcpFlagsMask((flags & 0xff) as u8) |
2031 | 2036 | } |
2032 | 2037 | TCA_FLOWER_KEY_IP_TOS => { |
2033 | 2038 | if payload.len() != 1 { |
@@ -2276,7 +2281,7 @@ impl Nla for Lse { |
2276 | 2281 | } |
2277 | 2282 |
|
2278 | 2283 | fn emit_value(&self, buffer: &mut [u8]) { |
2279 | | - self.opts.as_slice().emit(buffer) |
| 2284 | + self.opts.as_slice().emit(buffer); |
2280 | 2285 | } |
2281 | 2286 |
|
2282 | 2287 | fn is_nested(&self) -> bool { |
@@ -2486,6 +2491,9 @@ impl From<L2Miss> for u8 { |
2486 | 2491 | pub struct MaintenanceDomainLevel(u8); |
2487 | 2492 |
|
2488 | 2493 | impl MaintenanceDomainLevel { |
| 2494 | + /// # Errors |
| 2495 | + /// Returns an error if the value is greater than 7 |
| 2496 | + /// (the maximum allowed value in the CFM spec). |
2489 | 2497 | pub fn new(value: u8) -> Result<Self, DecodeError> { |
2490 | 2498 | if value > 7 { |
2491 | 2499 | Err(DecodeError::from("invalid maintenance domain level")) |
|
0 commit comments