netlink_packet_route/address/
addr_scope.rs

1// SPDX-License-Identifier: MIT
2
3const RT_SCOPE_UNIVERSE: u8 = 0;
4// 1 and 199 is user defined values
5const RT_SCOPE_SITE: u8 = 200;
6const RT_SCOPE_LINK: u8 = 253;
7const RT_SCOPE_HOST: u8 = 254;
8const RT_SCOPE_NOWHERE: u8 = 255;
9
10#[derive(Clone, Eq, PartialEq, Debug, Copy, Default)]
11#[non_exhaustive]
12#[repr(u8)]
13pub enum AddressScope {
14    #[default]
15    Universe,
16    Site,
17    Link,
18    Host,
19    Nowhere,
20    Other(u8),
21}
22
23impl From<u8> for AddressScope {
24    fn from(d: u8) -> Self {
25        match d {
26            RT_SCOPE_UNIVERSE => Self::Universe,
27            RT_SCOPE_SITE => Self::Site,
28            RT_SCOPE_LINK => Self::Link,
29            RT_SCOPE_HOST => Self::Host,
30            RT_SCOPE_NOWHERE => Self::Nowhere,
31            _ => Self::Other(d),
32        }
33    }
34}
35
36impl From<AddressScope> for u8 {
37    fn from(v: AddressScope) -> u8 {
38        match v {
39            AddressScope::Universe => RT_SCOPE_UNIVERSE,
40            AddressScope::Site => RT_SCOPE_SITE,
41            AddressScope::Link => RT_SCOPE_LINK,
42            AddressScope::Host => RT_SCOPE_HOST,
43            AddressScope::Nowhere => RT_SCOPE_NOWHERE,
44            AddressScope::Other(d) => d,
45        }
46    }
47}