netlink_packet_route/rtnl/link/nlas/
link_state.rs

1// SPDX-License-Identifier: MIT
2
3use crate::constants::*;
4
5#[derive(Debug, Clone, Copy, Eq, PartialEq)]
6pub enum State {
7    /// Status can't be determined
8    Unknown,
9    /// Some component is missing
10    NotPresent,
11    /// Down
12    Down,
13    /// Down due to state of lower layer
14    LowerLayerDown,
15    /// In some test mode
16    Testing,
17    /// Not up but pending an external event
18    Dormant,
19    /// Up, ready to send packets
20    Up,
21    /// Unrecognized value. This should go away when `TryFrom` is stable in Rust
22    // FIXME: there's not point in having this. When TryFrom is stable we'll remove it
23    Other(u8),
24}
25
26impl From<u8> for State {
27    fn from(value: u8) -> Self {
28        use self::State::*;
29        match value {
30            IF_OPER_UNKNOWN => Unknown,
31            IF_OPER_NOTPRESENT => NotPresent,
32            IF_OPER_DOWN => Down,
33            IF_OPER_LOWERLAYERDOWN => LowerLayerDown,
34            IF_OPER_TESTING => Testing,
35            IF_OPER_DORMANT => Dormant,
36            IF_OPER_UP => Up,
37            _ => Other(value),
38        }
39    }
40}
41
42impl From<State> for u8 {
43    fn from(value: State) -> Self {
44        use self::State::*;
45        match value {
46            Unknown => IF_OPER_UNKNOWN,
47            NotPresent => IF_OPER_NOTPRESENT,
48            Down => IF_OPER_DOWN,
49            LowerLayerDown => IF_OPER_LOWERLAYERDOWN,
50            Testing => IF_OPER_TESTING,
51            Dormant => IF_OPER_DORMANT,
52            Up => IF_OPER_UP,
53            Other(other) => other,
54        }
55    }
56}