Add AddressData to Ipv4Config and Ipv6Config
This commit is contained in:
parent
a81830cd20
commit
4f28c3c02b
3 changed files with 52 additions and 4 deletions
|
|
@ -10,5 +10,4 @@ derive_builder = "0.10.2"
|
||||||
procfs = { version = "0.12.0", default-features = false }
|
procfs = { version = "0.12.0", default-features = false }
|
||||||
time = "0.3.7"
|
time = "0.3.7"
|
||||||
zbus = "2.0.1"
|
zbus = "2.0.1"
|
||||||
|
zvariant = "3.1.2"
|
||||||
[features]
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
use crate::interface::config::ip4::Ipv4ConfigProxy;
|
use crate::interface::config::ip4::Ipv4ConfigProxy;
|
||||||
use std::{net::Ipv4Addr, ops::Deref};
|
use std::{net::Ipv4Addr, ops::Deref, str::FromStr};
|
||||||
use zbus::Result;
|
use zbus::Result;
|
||||||
|
use zvariant::DeserializeDict;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Ipv4Config<'a>(Ipv4ConfigProxy<'a>);
|
pub struct Ipv4Config<'a>(Ipv4ConfigProxy<'a>);
|
||||||
|
|
@ -20,6 +21,24 @@ impl<'a> Ipv4Config<'a> {
|
||||||
})
|
})
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn address_data(&self) -> Result<Vec<AddressData>> {
|
||||||
|
Ok(self
|
||||||
|
.0
|
||||||
|
.address_data()
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|mut map| {
|
||||||
|
let address = {
|
||||||
|
let address_str = map.remove("address")?;
|
||||||
|
let address_str = address_str.downcast_ref::<zvariant::Str>()?;
|
||||||
|
Ipv4Addr::from_str(address_str).ok()?
|
||||||
|
};
|
||||||
|
let prefix = u64::try_from(map.remove("prefix")?).ok()? as usize;
|
||||||
|
Some(AddressData { address, prefix })
|
||||||
|
})
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Deref for Ipv4Config<'a> {
|
impl<'a> Deref for Ipv4Config<'a> {
|
||||||
|
|
@ -35,3 +54,9 @@ impl<'a> From<Ipv4ConfigProxy<'a>> for Ipv4Config<'a> {
|
||||||
Ipv4Config(config)
|
Ipv4Config(config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
|
pub struct AddressData {
|
||||||
|
pub address: Ipv4Addr,
|
||||||
|
pub prefix: usize,
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
use crate::interface::config::ip6::Ipv6ConfigProxy;
|
use crate::interface::config::ip6::Ipv6ConfigProxy;
|
||||||
use std::{net::Ipv6Addr, ops::Deref};
|
use std::{net::Ipv6Addr, ops::Deref, str::FromStr};
|
||||||
use zbus::Result;
|
use zbus::Result;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -19,6 +19,24 @@ impl<'a> Ipv6Config<'a> {
|
||||||
})
|
})
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn address_data(&self) -> Result<Vec<AddressData>> {
|
||||||
|
Ok(self
|
||||||
|
.0
|
||||||
|
.address_data()
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|mut map| {
|
||||||
|
let address = {
|
||||||
|
let address_str = map.remove("address")?;
|
||||||
|
let address_str = address_str.downcast_ref::<zvariant::Str>()?;
|
||||||
|
Ipv6Addr::from_str(address_str).ok()?
|
||||||
|
};
|
||||||
|
let prefix = u64::try_from(map.remove("prefix")?).ok()? as usize;
|
||||||
|
Some(AddressData { address, prefix })
|
||||||
|
})
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Deref for Ipv6Config<'a> {
|
impl<'a> Deref for Ipv6Config<'a> {
|
||||||
|
|
@ -34,3 +52,9 @@ impl<'a> From<Ipv6ConfigProxy<'a>> for Ipv6Config<'a> {
|
||||||
Ipv6Config(config)
|
Ipv6Config(config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
|
pub struct AddressData {
|
||||||
|
pub address: Ipv6Addr,
|
||||||
|
pub prefix: usize,
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue