ip: add AddressFamily enumerate

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
This commit is contained in:
Fernando Fernandez Mancera 2022-11-07 15:05:24 +01:00 committed by Fernando Fernández Mancera
parent 27f9a51951
commit 84e0b3e176
2 changed files with 29 additions and 2 deletions

View File

@ -7,6 +7,8 @@ use crate::{
BaseInterface, DnsClientState, ErrorKind, MptcpAddressFlag, NmstateError,
};
const AF_INET: u8 = 2;
const AF_INET6: u8 = 10;
const IPV4_ADDR_LEN: usize = 32;
const IPV6_ADDR_LEN: usize = 128;
@ -961,3 +963,28 @@ fn is_none_or_empty_mptcp_flags(v: &Option<Vec<MptcpAddressFlag>>) -> bool {
fn default_allow_extra_address() -> bool {
true
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
#[serde(rename_all = "lowercase")]
#[non_exhaustive]
pub enum AddressFamily {
IPv4,
IPv6,
Unknown,
}
impl From<u8> for AddressFamily {
fn from(d: u8) -> Self {
match d {
AF_INET => AddressFamily::IPv4,
AF_INET6 => AddressFamily::IPv6,
_ => AddressFamily::Unknown,
}
}
}
impl Default for AddressFamily {
fn default() -> Self {
Self::IPv4
}
}

View File

@ -138,8 +138,8 @@ pub use crate::ifaces::{
VxlanInterface,
};
pub use crate::ip::{
Dhcpv4ClientId, Dhcpv6Duid, InterfaceIpAddr, InterfaceIpv4, InterfaceIpv6,
Ipv6AddrGenMode, WaitIp,
AddressFamily, Dhcpv4ClientId, Dhcpv6Duid, InterfaceIpAddr, InterfaceIpv4,
InterfaceIpv6, Ipv6AddrGenMode, WaitIp,
};
pub use crate::lldp::{
LldpAddressFamily, LldpChassisId, LldpChassisIdType, LldpConfig,