Improve network checks

This commit is contained in:
2024-01-08 21:29:31 +01:00
parent 672e866897
commit e86b29c03a
4 changed files with 96 additions and 33 deletions

View File

@ -43,14 +43,6 @@ pub struct NetworkDomainXML {
pub name: String,
}
fn invalid_prefix() -> u32 {
u32::MAX
}
fn invalid_ip() -> IpAddr {
IpAddr::V4(Ipv4Addr::BROADCAST)
}
/// Network ip information
#[derive(serde::Serialize, serde::Deserialize, Debug)]
#[serde(rename = "ip")]
@ -60,12 +52,13 @@ pub struct NetworkIPXML {
#[serde(rename = "@address")]
pub address: IpAddr,
/// Network Prefix
#[serde(rename = "@prefix", default = "invalid_prefix")]
pub prefix: u32,
#[serde(rename = "@prefix")]
pub prefix: Option<u8>,
/// Network Netmask. This field is never serialized, but because we can't know if LibVirt will
/// provide us netmask or prefix, we need to handle both of these fields
#[serde(rename = "@netmask", default = "invalid_ip", skip_serializing)]
pub netmask: IpAddr,
#[serde(rename = "@netmask", skip_serializing)]
pub netmask: Option<IpAddr>,
pub dhcp: Option<NetworkDHCPXML>,
}