netlink_packet_route/route/
error.rs

1// SPDX-License-Identifier: MIT
2use super::RouteLwEnCapType;
3use netlink_packet_utils::nla::NlaError;
4use netlink_packet_utils::DecodeError;
5use thiserror::Error;
6
7#[derive(Debug, Error)]
8pub enum RouteError {
9    #[error("Invalid {kind} value")]
10    InvalidValue {
11        kind: &'static str,
12        #[source]
13        error: DecodeError,
14    },
15
16    #[error("cannot parse route attributes in next-hop")]
17    ParseNextHopAttributes(#[source] DecodeError),
18
19    #[error("Invalid RTA_ENCAP for kind: {kind}")]
20    InvalidRtaEncap { kind: RouteLwEnCapType, error: NlaError },
21
22    #[error("invalid MPLS_IPTUNNEL_DST value")]
23    InvalidMplsIpTunnelTtl(#[source] DecodeError),
24
25    #[error("Invalid {kind} value")]
26    InvalidRouteMetric {
27        kind: &'static str,
28        #[source]
29        error: DecodeError,
30    },
31
32    #[error("Invalid array length. Expected={expected}, got={got}")]
33    ParseMplsLabel { expected: usize, got: usize },
34
35    #[error("Expected single u8 for route protocol")]
36    ParseRouteProtocol,
37
38    #[error("Invalid rule port range data, expecting {expected} u8 array, but got {got}")]
39    InvalidRulePortRange { expected: usize, got: usize },
40
41    #[error(transparent)]
42    ParseNla(#[from] NlaError),
43
44    #[error(transparent)]
45    Other(#[from] DecodeError),
46}
47
48impl From<RouteError> for DecodeError {
49    fn from(err: RouteError) -> Self {
50        DecodeError::Other(err.into())
51    }
52}