|
| 1 | +//! Per-address IPv6 state flags, normalized across platforms. |
| 2 | +
|
| 3 | +/// State flags for a single IPv6 address. |
| 4 | +/// |
| 5 | +/// All fields default to `false` when the platform does not provide the |
| 6 | +/// corresponding information. |
| 7 | +/// |
| 8 | +/// Flags are collected from platform-specific sources: |
| 9 | +/// |
| 10 | +/// - **Linux/Android**: netlink `IFA_FLAGS` attribute (`IFA_F_*` from [`<linux/if_addr.h>`]) |
| 11 | +/// - **macOS/iOS**: `SIOCGIFAFLAG_IN6` ioctl (`IN6_IFF_*` from [`<netinet6/in6_var.h>`][xnu]) |
| 12 | +/// - **FreeBSD/OpenBSD/NetBSD**: `SIOCGIFAFLAG_IN6` ioctl (`IN6_IFF_*` from [`<netinet6/in6_var.h>`][freebsd]) |
| 13 | +/// - **Windows**: [`NL_DAD_STATE`] and [`NL_SUFFIX_ORIGIN`] from `IP_ADAPTER_UNICAST_ADDRESS` |
| 14 | +/// |
| 15 | +/// [`<linux/if_addr.h>`]: https://github.com/torvalds/linux/blob/master/include/uapi/linux/if_addr.h |
| 16 | +/// [xnu]: https://github.com/apple-oss-distributions/xnu/blob/main/bsd/netinet6/in6_var.h |
| 17 | +/// [freebsd]: https://github.com/freebsd/freebsd-src/blob/main/sys/netinet6/in6_var.h |
| 18 | +/// [`NL_DAD_STATE`]: https://learn.microsoft.com/en-us/windows/win32/api/nldef/ne-nldef-nl_dad_state |
| 19 | +/// [`NL_SUFFIX_ORIGIN`]: https://learn.microsoft.com/en-us/windows/win32/api/nldef/ne-nldef-nl_suffix_origin |
| 20 | +#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)] |
| 21 | +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
| 22 | +pub struct Ipv6AddrFlags { |
| 23 | + /// Preferred lifetime expired; should not be used for new connections. |
| 24 | + /// |
| 25 | + /// Sourced from `IFA_F_DEPRECATED` (Linux), `IN6_IFF_DEPRECATED` (BSD), |
| 26 | + /// or `IpDadStateDeprecated` (Windows). |
| 27 | + pub deprecated: bool, |
| 28 | + /// Privacy address ([RFC 4941](https://datatracker.ietf.org/doc/html/rfc4941)). |
| 29 | + /// |
| 30 | + /// Sourced from `IFA_F_TEMPORARY` (Linux), `IN6_IFF_TEMPORARY` (BSD), |
| 31 | + /// or `IpSuffixOriginRandom` (Windows). |
| 32 | + pub temporary: bool, |
| 33 | + /// Undergoing duplicate address detection. |
| 34 | + /// |
| 35 | + /// Sourced from `IFA_F_TENTATIVE` (Linux), `IN6_IFF_TENTATIVE` (BSD), |
| 36 | + /// or `IpDadStateTentative` (Windows). |
| 37 | + pub tentative: bool, |
| 38 | + /// Duplicate address detection failed. |
| 39 | + /// |
| 40 | + /// Sourced from `IFA_F_DADFAILED` (Linux), `IN6_IFF_DUPLICATED` (BSD), |
| 41 | + /// or `IpDadStateDuplicate` (Windows). |
| 42 | + pub duplicated: bool, |
| 43 | + /// Manually configured, not from SLAAC. |
| 44 | + /// |
| 45 | + /// Sourced from `IFA_F_PERMANENT` (Linux). Not available on BSD or Windows. |
| 46 | + pub permanent: bool, |
| 47 | +} |
| 48 | + |
| 49 | +// Platform dispatch for `get_ipv6_addr_flags`, called from `unix_interfaces()`. |
| 50 | + |
| 51 | +#[cfg(target_vendor = "apple")] |
| 52 | +pub(crate) use crate::os::darwin::ipv6_addr_flags::*; |
| 53 | + |
| 54 | +#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))] |
| 55 | +pub(crate) use crate::os::bsd::ipv6_addr_flags::*; |
| 56 | + |
| 57 | +// On Linux/Android flags come from netlink; this is only reached via the |
| 58 | +// `unix_interfaces()` fallback when netlink is unavailable. |
| 59 | +#[cfg(any(target_os = "linux", target_os = "android"))] |
| 60 | +pub(crate) fn get_ipv6_addr_flags(_ifname: &str, _addr: &std::net::Ipv6Addr) -> Ipv6AddrFlags { |
| 61 | + Ipv6AddrFlags::default() |
| 62 | +} |
0 commit comments