netlink_packet_route/neighbour/
state.rs

1// SPDX-License-Identifier: MIT
2
3const NUD_INCOMPLETE: u16 = 0x01;
4const NUD_REACHABLE: u16 = 0x02;
5const NUD_STALE: u16 = 0x04;
6const NUD_DELAY: u16 = 0x08;
7const NUD_PROBE: u16 = 0x10;
8const NUD_FAILED: u16 = 0x20;
9const NUD_NOARP: u16 = 0x40;
10const NUD_PERMANENT: u16 = 0x80;
11const NUD_NONE: u16 = 0x00;
12
13#[derive(Clone, Eq, PartialEq, Debug, Copy, Default)]
14#[non_exhaustive]
15pub enum NeighbourState {
16    Incomplete,
17    Reachable,
18    Stale,
19    Delay,
20    Probe,
21    Failed,
22    Noarp,
23    Permanent,
24    #[default]
25    None,
26    Other(u16),
27}
28
29impl From<NeighbourState> for u16 {
30    fn from(v: NeighbourState) -> u16 {
31        match v {
32            NeighbourState::Incomplete => NUD_INCOMPLETE,
33            NeighbourState::Reachable => NUD_REACHABLE,
34            NeighbourState::Stale => NUD_STALE,
35            NeighbourState::Delay => NUD_DELAY,
36            NeighbourState::Probe => NUD_PROBE,
37            NeighbourState::Failed => NUD_FAILED,
38            NeighbourState::Noarp => NUD_NOARP,
39            NeighbourState::Permanent => NUD_PERMANENT,
40            NeighbourState::None => NUD_NONE,
41            NeighbourState::Other(d) => d,
42        }
43    }
44}
45
46impl From<u16> for NeighbourState {
47    fn from(d: u16) -> Self {
48        match d {
49            NUD_INCOMPLETE => Self::Incomplete,
50            NUD_REACHABLE => Self::Reachable,
51            NUD_STALE => Self::Stale,
52            NUD_DELAY => Self::Delay,
53            NUD_PROBE => Self::Probe,
54            NUD_FAILED => Self::Failed,
55            NUD_NOARP => Self::Noarp,
56            NUD_PERMANENT => Self::Permanent,
57            NUD_NONE => Self::None,
58            _ => Self::Other(d),
59        }
60    }
61}
62
63impl std::fmt::Display for NeighbourState {
64    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65        match self {
66            Self::Incomplete => write!(f, "incomplete"),
67            Self::Reachable => write!(f, "reachable"),
68            Self::Stale => write!(f, "stale"),
69            Self::Delay => write!(f, "delay"),
70            Self::Probe => write!(f, "probe"),
71            Self::Failed => write!(f, "failed"),
72            Self::Noarp => write!(f, "noarp"),
73            Self::Permanent => write!(f, "permanent"),
74            Self::None => write!(f, "none"),
75            Self::Other(d) => write!(f, "other({d}"),
76        }
77    }
78}