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