netlink_packet_route/route/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-License-Identifier: MIT
use super::RouteLwEnCapType;
use netlink_packet_utils::nla::NlaError;
use netlink_packet_utils::DecodeError;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum RouteError {
    #[error("Invalid {kind} value")]
    InvalidValue {
        kind: &'static str,
        #[source]
        error: DecodeError,
    },

    #[error("cannot parse route attributes in next-hop")]
    ParseNextHopAttributes(#[source] DecodeError),

    #[error("Invalid RTA_ENCAP for kind: {kind}")]
    InvalidRtaEncap { kind: RouteLwEnCapType, error: NlaError },

    #[error("invalid MPLS_IPTUNNEL_DST value")]
    InvalidMplsIpTunnelTtl(#[source] DecodeError),

    #[error("Invalid {kind} value")]
    InvalidRouteMetric {
        kind: &'static str,
        #[source]
        error: DecodeError,
    },

    #[error("Invalid array length. Expected={expected}, got={got}")]
    ParseMplsLabel { expected: usize, got: usize },

    #[error("Expected single u8 for route protocol")]
    ParseRouteProtocol,

    #[error("Invalid rule port range data, expecting {expected} u8 array, but got {got}")]
    InvalidRulePortRange { expected: usize, got: usize },

    #[error(transparent)]
    ParseNla(#[from] NlaError),

    #[error(transparent)]
    Other(#[from] DecodeError),
}

impl From<RouteError> for DecodeError {
    fn from(err: RouteError) -> Self {
        DecodeError::Other(err.into())
    }
}