rsmnl_linux/
if_addr.rs

1use errno::Errno;
2use mnl::{Attr, AttrTbl, MsgVec, Result};
3use std::net::{Ipv4Addr, Ipv6Addr};
4
5#[repr(C)]
6#[derive(Debug, Clone, Copy)]
7pub struct Ifaddrmsg {
8    pub ifa_family: u8,
9    pub ifa_prefixlen: u8, // The prefix length
10    pub ifa_flags: u8,     // Flags
11    pub ifa_scope: u8,     // Address scope
12    pub ifa_index: u32,    // Link index
13}
14
15// Important comment:
16// IFA_ADDRESS is prefix address, rather than local interface address.
17// It makes no difference for normally configured broadcast interfaces,
18// but for point-to-point IFA_ADDRESS is DESTINATION address,
19// local address is supplied in IFA_LOCAL attribute.
20//
21// IFA_FLAGS is a u32 attribute that extends the u8 field ifa_flags.
22// If present, the value from struct ifaddrmsg will be ignored.
23#[repr(u16)]
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, NlaType)]
25#[tbname = "IfAddrTbl"]
26pub enum IfAddr {
27    // IFA_
28    Unspec = 0,
29
30    #[nla_type(Ipv4Addr, address4)]
31    #[nla_type(Ipv6Addr, address6)]
32    Address = 1,
33
34    #[nla_type(Ipv4Addr, local4)]
35    #[nla_type(Ipv6Addr, local6)]
36    // others u8 for phonet, u16 decnet
37    Local = 2,
38
39    #[nla_type(str, label)]
40    Label = 3,
41
42    #[nla_type(Ipv4Addr, broadcast)]
43    Broadcast = 4,
44
45    #[nla_type(Ipv6Addr, anycast)]
46    Anycast = 5,
47
48    #[nla_type(IfaCacheinfo, cacheinfo)]
49    CacheInfo = 6,
50
51    #[nla_type(Ipv6Addr, multicast)]
52    Multicast = 7,
53
54    #[nla_type(u32, flags)]
55    Flags = 8,
56
57    #[nla_type(u32, rt_priority)]
58    RtPriority = 9,
59
60    #[nla_type(i32, target_netnsid)]
61    TargetNetnsid = 10,
62
63    _MAX = 11,
64}
65
66// ifa_flags
67pub const IFA_F_SECONDARY: u32 = 0x01;
68pub const IFA_F_TEMPORARY: u32 = IFA_F_SECONDARY;
69pub const IFA_F_NODAD: u32 = 0x02;
70pub const IFA_F_OPTIMISTIC: u32 = 0x04;
71pub const IFA_F_DADFAILED: u32 = 0x08;
72pub const IFA_F_HOMEADDRESS: u32 = 0x10;
73pub const IFA_F_DEPRECATED: u32 = 0x20;
74pub const IFA_F_TENTATIVE: u32 = 0x40;
75pub const IFA_F_PERMANENT: u32 = 0x80;
76pub const IFA_F_MANAGETEMPADDR: u32 = 0x100;
77pub const IFA_F_NOPREFIXROUTE: u32 = 0x200;
78pub const IFA_F_MCAUTOJOIN: u32 = 0x400;
79pub const IFA_F_STABLE_PRIVACY: u32 = 0x800;
80
81#[repr(C)]
82#[derive(Debug, Clone, Copy)]
83pub struct IfaCacheinfo {
84    pub ifa_prefered: u32,
85    pub ifa_valid: u32,
86    pub cstamp: u32, // created timestamp, hundredths of seconds
87    pub tstamp: u32, // updated timestamp, hundredths of seconds
88}