public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH installer v3 30/38] tree-wide: use `Cidr` type from proxmox-network-types
Date: Fri,  3 Apr 2026 18:54:02 +0200	[thread overview]
Message-ID: <20260403165437.2166551-31-c.heiss@proxmox.com> (raw)
In-Reply-To: <20260403165437.2166551-1-c.heiss@proxmox.com>

.. instead of our own variant here, as we now already depend on
proxmox-network-types anyway.

No functional changes.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
Changes v2 -> v3:
  * new patch

 proxmox-auto-installer/src/answer.rs          |  19 +--
 proxmox-auto-installer/src/utils.rs           |   2 +-
 .../ipv4_and_subnet_mask_33.json              |   2 +-
 proxmox-installer-common/src/lib.rs           |   1 -
 proxmox-installer-common/src/options.rs       |  34 ++---
 proxmox-installer-common/src/setup.rs         |  21 ++-
 proxmox-installer-common/src/utils.rs         | 141 ------------------
 proxmox-post-hook/Cargo.toml                  |   1 +
 proxmox-post-hook/src/main.rs                 |   7 +-
 proxmox-tui-installer/src/views/mod.rs        |  21 ++-
 proxmox-tui-installer/src/views/network.rs    |  13 +-
 11 files changed, 53 insertions(+), 209 deletions(-)
 delete mode 100644 proxmox-installer-common/src/utils.rs

diff --git a/proxmox-auto-installer/src/answer.rs b/proxmox-auto-installer/src/answer.rs
index 40e6557..acb0d5b 100644
--- a/proxmox-auto-installer/src/answer.rs
+++ b/proxmox-auto-installer/src/answer.rs
@@ -1,13 +1,4 @@
 use anyhow::{Result, bail, format_err};
-use proxmox_installer_common::{
-    options::{
-        BtrfsCompressOption, BtrfsRaidLevel, FsType, NetworkInterfacePinningOptions,
-        ZfsChecksumOption, ZfsCompressOption, ZfsRaidLevel,
-    },
-    utils::CidrAddress,
-};
-use proxmox_network_types::fqdn::Fqdn;
-
 use serde::{Deserialize, Serialize};
 use std::{
     collections::{BTreeMap, HashMap},
@@ -15,6 +6,12 @@ use std::{
     net::IpAddr,
 };
 
+use proxmox_installer_common::options::{
+    BtrfsCompressOption, BtrfsRaidLevel, FsType, NetworkInterfacePinningOptions, ZfsChecksumOption,
+    ZfsCompressOption, ZfsRaidLevel,
+};
+use proxmox_network_types::{Cidr, fqdn::Fqdn};
+
 // NOTE New answer file properties must use kebab-case, but should allow snake_case for backwards
 // compatibility. TODO Remove the snake_cased variants in a future major version (e.g. PVE 10).
 
@@ -201,7 +198,7 @@ pub struct NetworkInterfacePinningOptionsAnswer {
 struct NetworkInAnswer {
     #[serde(default)]
     pub source: NetworkConfigMode,
-    pub cidr: Option<CidrAddress>,
+    pub cidr: Option<Cidr>,
     pub dns: Option<IpAddr>,
     pub gateway: Option<IpAddr>,
     #[serde(default)]
@@ -293,7 +290,7 @@ pub enum NetworkSettings {
 
 #[derive(Clone, Debug)]
 pub struct NetworkManual {
-    pub cidr: CidrAddress,
+    pub cidr: Cidr,
     pub dns: IpAddr,
     pub gateway: IpAddr,
     pub filter: BTreeMap<String, String>,
diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs
index 9998491..f9cfcdd 100644
--- a/proxmox-auto-installer/src/utils.rs
+++ b/proxmox-auto-installer/src/utils.rs
@@ -73,7 +73,7 @@ fn get_network_settings(
     };
 
     if let answer::NetworkSettings::Manual(settings) = &answer.network.network_settings {
-        network_options.address = settings.cidr.clone();
+        network_options.address = settings.cidr;
         network_options.dns_server = settings.dns;
         network_options.gateway = settings.gateway;
         network_options.ifname = get_single_udev_index(&settings.filter, &udev_info.nics)?;
diff --git a/proxmox-auto-installer/tests/resources/parse_answer_fail/ipv4_and_subnet_mask_33.json b/proxmox-auto-installer/tests/resources/parse_answer_fail/ipv4_and_subnet_mask_33.json
index 6b2888b..45e1abe 100644
--- a/proxmox-auto-installer/tests/resources/parse_answer_fail/ipv4_and_subnet_mask_33.json
+++ b/proxmox-auto-installer/tests/resources/parse_answer_fail/ipv4_and_subnet_mask_33.json
@@ -1,3 +1,3 @@
 {
-    "parse-error": "error parsing answer.toml: Invalid CIDR: mask cannot be greater than 32"
+    "parse-error": "error parsing answer.toml: invalid IP address"
 }
diff --git a/proxmox-installer-common/src/lib.rs b/proxmox-installer-common/src/lib.rs
index b380f1c..7cdb1de 100644
--- a/proxmox-installer-common/src/lib.rs
+++ b/proxmox-installer-common/src/lib.rs
@@ -2,7 +2,6 @@ pub mod disk_checks;
 pub mod options;
 pub mod setup;
 pub mod sysinfo;
-pub mod utils;
 
 #[cfg(feature = "http")]
 pub mod http;
diff --git a/proxmox-installer-common/src/options.rs b/proxmox-installer-common/src/options.rs
index feb0dc4..f903f7e 100644
--- a/proxmox-installer-common/src/options.rs
+++ b/proxmox-installer-common/src/options.rs
@@ -10,8 +10,7 @@ use std::{cmp, fmt};
 use crate::disk_checks::check_raid_min_disks;
 use crate::net::{MAX_IFNAME_LEN, MIN_IFNAME_LEN};
 use crate::setup::{LocaleInfo, NetworkInfo, RuntimeInfo, SetupInfo};
-use crate::utils::CidrAddress;
-use proxmox_network_types::fqdn::Fqdn;
+use proxmox_network_types::{fqdn::Fqdn, ip_address::Cidr};
 
 #[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
 #[serde(rename_all(deserialize = "lowercase", serialize = "UPPERCASE"))]
@@ -550,7 +549,7 @@ impl NetworkInterfacePinningOptions {
 pub struct NetworkOptions {
     pub ifname: String,
     pub fqdn: Fqdn,
-    pub address: CidrAddress,
+    pub address: Cidr,
     pub gateway: IpAddr,
     pub dns_server: IpAddr,
     pub pinning_opts: Option<NetworkInterfacePinningOptions>,
@@ -576,7 +575,7 @@ impl NetworkOptions {
             ),
             // Safety: The provided IP address/mask is always valid.
             // These are the same as used in the GTK-based installer.
-            address: CidrAddress::new(Ipv4Addr::new(192, 168, 100, 2), 24).unwrap(),
+            address: Cidr::new_v4([192, 168, 100, 2], 24).unwrap(),
             gateway: Ipv4Addr::new(192, 168, 100, 1).into(),
             dns_server: Ipv4Addr::new(192, 168, 100, 1).into(),
             pinning_opts: pinning_opts.cloned(),
@@ -602,7 +601,7 @@ impl NetworkOptions {
 
             if let Some(addr) = iface.addresses.iter().find(|addr| addr.is_ipv4()) {
                 this.gateway = gw.gateway;
-                this.address = addr.clone();
+                this.address = *addr;
             } else if let Some(gw) = &routes.gateway6
                 && let Some(iface) = network.interfaces.get(&gw.dev)
                 && let Some(addr) = iface.addresses.iter().find(|addr| addr.is_ipv6())
@@ -617,7 +616,7 @@ impl NetworkOptions {
                 }
 
                 this.gateway = gw.gateway;
-                this.address = addr.clone();
+                this.address = *addr;
             }
         }
 
@@ -702,10 +701,7 @@ pub fn email_validate(email: &str) -> Result<()> {
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::{
-        setup::{Dns, Gateway, Interface, InterfaceState, NetworkInfo, Routes, SetupInfo},
-        utils::CidrAddress,
-    };
+    use crate::setup::{Dns, Gateway, Interface, InterfaceState, NetworkInfo, Routes, SetupInfo};
     use std::collections::BTreeMap;
     use std::net::{IpAddr, Ipv4Addr};
 
@@ -775,7 +771,7 @@ mod tests {
                 state: InterfaceState::Up,
                 driver: "dummy".to_owned(),
                 mac: "01:23:45:67:89:ab".to_owned(),
-                addresses: vec![CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap()],
+                addresses: vec![Cidr::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap()],
             },
         );
 
@@ -807,7 +803,7 @@ mod tests {
             NetworkOptions {
                 ifname: "eth0".to_owned(),
                 fqdn: Fqdn::from("foo.bar.com").unwrap(),
-                address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
+                address: Cidr::new_v4([192, 168, 0, 2], 24).unwrap(),
                 gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)),
                 dns_server: Ipv4Addr::new(192, 168, 100, 1).into(),
                 pinning_opts: None,
@@ -820,7 +816,7 @@ mod tests {
             NetworkOptions {
                 ifname: "eth0".to_owned(),
                 fqdn: Fqdn::from("pve.bar.com").unwrap(),
-                address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
+                address: Cidr::new_v4([192, 168, 0, 2], 24).unwrap(),
                 gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)),
                 dns_server: Ipv4Addr::new(192, 168, 100, 1).into(),
                 pinning_opts: None,
@@ -833,7 +829,7 @@ mod tests {
             NetworkOptions {
                 ifname: "eth0".to_owned(),
                 fqdn: Fqdn::from("pve.example.invalid").unwrap(),
-                address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
+                address: Cidr::new_v4([192, 168, 0, 2], 24).unwrap(),
                 gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)),
                 dns_server: Ipv4Addr::new(192, 168, 100, 1).into(),
                 pinning_opts: None,
@@ -846,7 +842,7 @@ mod tests {
             NetworkOptions {
                 ifname: "eth0".to_owned(),
                 fqdn: Fqdn::from("foo.example.invalid").unwrap(),
-                address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
+                address: Cidr::new_v4([192, 168, 0, 2], 24).unwrap(),
                 gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)),
                 dns_server: Ipv4Addr::new(192, 168, 100, 1).into(),
                 pinning_opts: None,
@@ -863,7 +859,7 @@ mod tests {
             NetworkOptions {
                 ifname: "eth0".to_owned(),
                 fqdn: Fqdn::from("foo.bar.com").unwrap(),
-                address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
+                address: Cidr::new_v4([192, 168, 0, 2], 24).unwrap(),
                 gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)),
                 dns_server: Ipv4Addr::new(192, 168, 100, 1).into(),
                 pinning_opts: None,
@@ -876,7 +872,7 @@ mod tests {
             NetworkOptions {
                 ifname: "eth0".to_owned(),
                 fqdn: Fqdn::from("foo.custom.local").unwrap(),
-                address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
+                address: Cidr::new_v4([192, 168, 0, 2], 24).unwrap(),
                 gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)),
                 dns_server: Ipv4Addr::new(192, 168, 100, 1).into(),
                 pinning_opts: None,
@@ -889,7 +885,7 @@ mod tests {
             NetworkOptions {
                 ifname: "eth0".to_owned(),
                 fqdn: Fqdn::from("foo.custom.local").unwrap(),
-                address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
+                address: Cidr::new_v4([192, 168, 0, 2], 24).unwrap(),
                 gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)),
                 dns_server: Ipv4Addr::new(192, 168, 100, 1).into(),
                 pinning_opts: None,
@@ -930,7 +926,7 @@ mod tests {
             NetworkOptions {
                 ifname: "eth0".to_owned(),
                 fqdn: Fqdn::from("pve.example.invalid").unwrap(),
-                address: CidrAddress::new(Ipv4Addr::new(192, 168, 100, 2), 24).unwrap(),
+                address: Cidr::new_v4([192, 168, 100, 2], 24).unwrap(),
                 gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 100, 1)),
                 dns_server: Ipv4Addr::new(192, 168, 100, 1).into(),
                 pinning_opts: None,
diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs
index 35949f0..35a5436 100644
--- a/proxmox-installer-common/src/setup.rs
+++ b/proxmox-installer-common/src/setup.rs
@@ -10,14 +10,12 @@ use std::{
     process::{self, Command, Stdio},
 };
 
+use proxmox_network_types::Cidr;
 use serde::{Deserialize, Deserializer, Serialize, Serializer, de};
 
-use crate::{
-    options::{
-        BtrfsBootdiskOptions, BtrfsCompressOption, Disk, FsType, NetworkInterfacePinningOptions,
-        ZfsBootdiskOptions, ZfsChecksumOption, ZfsCompressOption,
-    },
-    utils::CidrAddress,
+use crate::options::{
+    BtrfsBootdiskOptions, BtrfsCompressOption, Disk, FsType, NetworkInterfacePinningOptions,
+    ZfsBootdiskOptions, ZfsChecksumOption, ZfsCompressOption,
 };
 
 #[allow(clippy::upper_case_acronyms)]
@@ -314,14 +312,14 @@ where
         .collect())
 }
 
-fn deserialize_cidr_list<'de, D>(deserializer: D) -> Result<Vec<CidrAddress>, D::Error>
+fn deserialize_cidr_list<'de, D>(deserializer: D) -> Result<Vec<Cidr>, D::Error>
 where
     D: Deserializer<'de>,
 {
     #[derive(Deserialize)]
     struct CidrDescriptor {
         address: String,
-        prefix: usize,
+        prefix: u8,
         // family is implied anyway by parsing the address
     }
 
@@ -335,7 +333,7 @@ where
             .map_err(|err| de::Error::custom(format!("{:?}", err)))?;
 
         result.push(
-            CidrAddress::new(ip_addr, desc.prefix)
+            Cidr::new(ip_addr, desc.prefix)
                 .map_err(|err| de::Error::custom(format!("{:?}", err)))?,
         );
     }
@@ -478,7 +476,7 @@ pub struct Interface {
 
     #[serde(default)]
     #[serde(deserialize_with = "deserialize_cidr_list")]
-    pub addresses: Vec<CidrAddress>,
+    pub addresses: Vec<Cidr>,
 }
 
 impl Interface {
@@ -613,8 +611,7 @@ pub struct InstallConfig {
 
     pub hostname: String,
     pub domain: String,
-    #[serde(serialize_with = "serialize_as_display")]
-    pub cidr: CidrAddress,
+    pub cidr: Cidr,
     pub gateway: IpAddr,
     pub dns: IpAddr,
 
diff --git a/proxmox-installer-common/src/utils.rs b/proxmox-installer-common/src/utils.rs
deleted file mode 100644
index e86abdf..0000000
--- a/proxmox-installer-common/src/utils.rs
+++ /dev/null
@@ -1,141 +0,0 @@
-use std::{
-    error::Error,
-    fmt,
-    net::{AddrParseError, IpAddr},
-    str::FromStr,
-};
-
-use serde::Deserialize;
-
-/// Possible errors that might occur when parsing CIDR addresses.
-#[derive(Debug)]
-pub enum CidrAddressParseError {
-    /// No delimiter for separating address and mask was found.
-    NoDelimiter,
-    /// The IP address part could not be parsed.
-    InvalidAddr(AddrParseError),
-    /// The mask could not be parsed.
-    InvalidMask(Box<dyn Error>),
-}
-
-impl fmt::Display for CidrAddressParseError {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        write!(f, "Invalid CIDR: ")?;
-
-        match self {
-            CidrAddressParseError::NoDelimiter => {
-                write!(f, "no delimiter for separating address and mask was found")
-            }
-            CidrAddressParseError::InvalidAddr(err) => write!(f, "{err}"),
-            CidrAddressParseError::InvalidMask(err) => write!(f, "{err}"),
-        }
-    }
-}
-
-/// An IP address (IPv4 or IPv6), including network mask.
-///
-/// See the [`IpAddr`] type for more information how IP addresses are handled.
-/// The mask is appropriately enforced to be `0 <= mask <= 32` for IPv4 or
-/// `0 <= mask <= 128` for IPv6 addresses.
-///
-/// # Examples
-/// ```
-/// use std::net::{Ipv4Addr, Ipv6Addr};
-/// use proxmox_installer_common::utils::CidrAddress;
-/// let ipv4 = CidrAddress::new(Ipv4Addr::new(192, 168, 0, 1), 24).unwrap();
-/// let ipv6 = CidrAddress::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0xc0a8, 1), 32).unwrap();
-///
-/// assert_eq!(ipv4.to_string(), "192.168.0.1/24");
-/// assert_eq!(ipv6.to_string(), "2001:db8::c0a8:1/32");
-/// ```
-#[derive(Clone, Debug, PartialEq)]
-pub struct CidrAddress {
-    addr: IpAddr,
-    mask: usize,
-}
-
-impl CidrAddress {
-    /// Constructs a new CIDR address.
-    ///
-    /// It fails if the mask is invalid for the given IP address.
-    pub fn new<T: Into<IpAddr>>(addr: T, mask: usize) -> Result<Self, CidrAddressParseError> {
-        let addr = addr.into();
-
-        check_mask_limit(&addr, mask)?;
-
-        Ok(Self { addr, mask })
-    }
-
-    /// Returns only the IP address part of the address.
-    pub fn addr(&self) -> IpAddr {
-        self.addr
-    }
-
-    /// Returns `true` if this address is an IPv4 address, `false` otherwise.
-    pub fn is_ipv4(&self) -> bool {
-        self.addr.is_ipv4()
-    }
-
-    /// Returns `true` if this address is an IPv6 address, `false` otherwise.
-    pub fn is_ipv6(&self) -> bool {
-        self.addr.is_ipv6()
-    }
-
-    /// Returns only the mask part of the address.
-    pub fn mask(&self) -> usize {
-        self.mask
-    }
-}
-
-impl FromStr for CidrAddress {
-    type Err = CidrAddressParseError;
-
-    fn from_str(s: &str) -> Result<Self, Self::Err> {
-        let (addr, mask) = s
-            .split_once('/')
-            .ok_or(CidrAddressParseError::NoDelimiter)?;
-
-        let addr = addr.parse().map_err(CidrAddressParseError::InvalidAddr)?;
-
-        let mask = mask
-            .parse()
-            .map_err(|err| CidrAddressParseError::InvalidMask(Box::new(err)))?;
-
-        check_mask_limit(&addr, mask)?;
-
-        Ok(Self { addr, mask })
-    }
-}
-
-impl fmt::Display for CidrAddress {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        write!(f, "{}/{}", self.addr, self.mask)
-    }
-}
-
-impl<'de> Deserialize<'de> for CidrAddress {
-    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
-    where
-        D: serde::Deserializer<'de>,
-    {
-        let s: String = Deserialize::deserialize(deserializer)?;
-        s.parse().map_err(serde::de::Error::custom)
-    }
-}
-
-serde_plain::derive_serialize_from_display!(CidrAddress);
-
-fn mask_limit(addr: &IpAddr) -> usize {
-    if addr.is_ipv4() { 32 } else { 128 }
-}
-
-fn check_mask_limit(addr: &IpAddr, mask: usize) -> Result<(), CidrAddressParseError> {
-    let limit = mask_limit(addr);
-    if mask > limit {
-        Err(CidrAddressParseError::InvalidMask(
-            format!("mask cannot be greater than {limit}").into(),
-        ))
-    } else {
-        Ok(())
-    }
-}
diff --git a/proxmox-post-hook/Cargo.toml b/proxmox-post-hook/Cargo.toml
index 1917f38..beaaa26 100644
--- a/proxmox-post-hook/Cargo.toml
+++ b/proxmox-post-hook/Cargo.toml
@@ -14,5 +14,6 @@ homepage = "https://www.proxmox.com"
 anyhow.workspace = true
 proxmox-auto-installer.workspace = true
 proxmox-installer-common = { workspace = true, features = ["http"] }
+proxmox-network-types.workspace = true
 serde = { workspace = true, features = ["derive"] }
 serde_json.workspace = true
diff --git a/proxmox-post-hook/src/main.rs b/proxmox-post-hook/src/main.rs
index 2ee0231..71fdde2 100644
--- a/proxmox-post-hook/src/main.rs
+++ b/proxmox-post-hook/src/main.rs
@@ -20,7 +20,6 @@ use std::{
     path::PathBuf,
     process::{Command, ExitCode},
 };
-
 use proxmox_auto_installer::{
     answer::{
         Answer, FqdnConfig, FqdnExtendedConfig, FqdnSourceMode, PostNotificationHookInfo,
@@ -36,8 +35,8 @@ use proxmox_installer_common::{
         load_installer_setup_files,
     },
     sysinfo::SystemDMI,
-    utils::CidrAddress,
 };
+use proxmox_network_types::ip_address::Cidr;
 
 /// Information about the system boot status.
 #[derive(Serialize)]
@@ -83,7 +82,7 @@ struct NetworkInterfaceInfo {
     mac: String,
     /// (Designated) IP address of the interface
     #[serde(skip_serializing_if = "Option::is_none")]
-    address: Option<CidrAddress>,
+    address: Option<Cidr>,
     /// Set to true if the interface is the chosen management interface during
     /// installation.
     #[serde(skip_serializing_if = "bool_is_false")]
@@ -406,7 +405,7 @@ impl PostHookInfo {
                     mac: nic.mac.clone(),
                     // Use the actual IP address from the low-level install config, as the runtime info
                     // contains the original IP address from DHCP.
-                    address: is_management.then_some(config.cidr.clone()),
+                    address: is_management.then_some(config.cidr),
                     is_management,
                     is_pinned,
                     udev_properties,
diff --git a/proxmox-tui-installer/src/views/mod.rs b/proxmox-tui-installer/src/views/mod.rs
index 35cf53a..a343e60 100644
--- a/proxmox-tui-installer/src/views/mod.rs
+++ b/proxmox-tui-installer/src/views/mod.rs
@@ -8,8 +8,6 @@ use cursive::{
     views::{EditView, LinearLayout, NamedView, ResizedView, SelectView, TextView},
 };
 
-use proxmox_installer_common::utils::CidrAddress;
-
 mod bootdisk;
 pub use bootdisk::*;
 
@@ -20,6 +18,7 @@ mod network;
 pub use network::*;
 
 mod tabbed_view;
+use proxmox_network_types::ip_address::Cidr;
 pub use tabbed_view::*;
 
 mod table_view;
@@ -391,9 +390,9 @@ where
     }
 }
 
-impl FormViewGetValue<(IpAddr, usize)> for CidrAddressEditView {
-    // FIXME: return CidrAddress (again) with proper error handling through Result
-    fn get_value(&self) -> Option<(IpAddr, usize)> {
+impl FormViewGetValue<(IpAddr, u8)> for CidrAddressEditView {
+    // FIXME: return Cidr (again) with proper error handling through Result
+    fn get_value(&self) -> Option<(IpAddr, u8)> {
         self.get_values()
     }
 }
@@ -572,14 +571,14 @@ impl CidrAddressEditView {
         Self { view }
     }
 
-    pub fn content(mut self, cidr: CidrAddress) -> Self {
+    pub fn content(mut self, cidr: Cidr) -> Self {
         if let Some(view) = self
             .view
             .get_child_mut(0)
             .and_then(|v| v.downcast_mut::<ResizedView<EditView>>())
         {
             *view = EditView::new()
-                .content(cidr.addr().to_string())
+                .content(cidr.address().to_string())
                 .full_width();
         }
 
@@ -594,15 +593,15 @@ impl CidrAddressEditView {
         self
     }
 
-    fn mask_edit_view(content: usize) -> ResizedView<IntegerEditView> {
+    fn mask_edit_view(content: u8) -> ResizedView<IntegerEditView> {
         IntegerEditView::new()
             .max_value(128)
             .max_content_width(3)
-            .content(content)
+            .content(content.into())
             .fixed_width(4)
     }
 
-    fn get_values(&self) -> Option<(IpAddr, usize)> {
+    fn get_values(&self) -> Option<(IpAddr, u8)> {
         let addr = self
             .view
             .get_child(0)?
@@ -620,7 +619,7 @@ impl CidrAddressEditView {
             .get_content()
             .ok()?;
 
-        Some((addr, mask))
+        Some((addr, mask as u8))
     }
 }
 
diff --git a/proxmox-tui-installer/src/views/network.rs b/proxmox-tui-installer/src/views/network.rs
index 53e0d65..12cef19 100644
--- a/proxmox-tui-installer/src/views/network.rs
+++ b/proxmox-tui-installer/src/views/network.rs
@@ -16,9 +16,8 @@ use proxmox_installer_common::{
     net::MAX_IFNAME_LEN,
     options::{NetworkInterfacePinningOptions, NetworkOptions},
     setup::{Interface, NetworkInfo},
-    utils::CidrAddress,
 };
-use proxmox_network_types::fqdn::Fqdn;
+use proxmox_network_types::{fqdn::Fqdn, ip_address::Cidr};
 
 use super::{CidrAddressEditView, FormView};
 
@@ -85,7 +84,7 @@ impl NetworkOptionsView {
             )
             .child(
                 "IP address (CIDR)",
-                CidrAddressEditView::new().content(options.address.clone()),
+                CidrAddressEditView::new().content(options.address),
             )
             .child(
                 "Gateway address",
@@ -169,9 +168,7 @@ impl NetworkOptionsView {
         let address = form
             .get_value::<CidrAddressEditView, _>(2)
             .ok_or("failed to retrieve host address".to_string())
-            .and_then(|(ip_addr, mask)| {
-                CidrAddress::new(ip_addr, mask).map_err(|err| err.to_string())
-            })?;
+            .and_then(|(ip_addr, mask)| Cidr::new(ip_addr, mask).map_err(|err| err.to_string()))?;
 
         let gateway = form
             .get_value::<EditView, _>(3)
@@ -199,9 +196,9 @@ impl NetworkOptionsView {
             iface.name
         };
 
-        if address.addr().is_ipv4() != gateway.is_ipv4() {
+        if address.address().is_ipv4() != gateway.is_ipv4() {
             Err("host and gateway IP address version must not differ".to_owned())
-        } else if address.addr().is_ipv4() != dns_server.is_ipv4() {
+        } else if address.address().is_ipv4() != dns_server.is_ipv4() {
             Err("host and DNS IP address version must not differ".to_owned())
         } else if fqdn.to_string().ends_with(".invalid") {
             Err("hostname does not look valid".to_owned())
-- 
2.53.0





  parent reply	other threads:[~2026-04-03 16:57 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-03 16:53 [PATCH proxmox/yew-pwt/datacenter-manager/installer v3 00/38] add auto-installer integration Christoph Heiss
2026-04-03 16:53 ` [PATCH proxmox v3 01/38] api-macro: allow $ in identifier name Christoph Heiss
2026-04-03 16:53 ` [PATCH proxmox v3 02/38] schema: oneOf: allow single string variant Christoph Heiss
2026-04-03 16:53 ` [PATCH proxmox v3 03/38] schema: implement UpdaterType for HashMap and BTreeMap Christoph Heiss
2026-04-03 16:53 ` [PATCH proxmox v3 04/38] network-types: move `Fqdn` type from proxmox-installer-common Christoph Heiss
2026-04-03 16:53 ` [PATCH proxmox v3 05/38] network-types: implement api type for Fqdn Christoph Heiss
2026-04-03 16:53 ` [PATCH proxmox v3 06/38] network-types: add api wrapper type for std::net::IpAddr Christoph Heiss
2026-04-03 16:53 ` [PATCH proxmox v3 07/38] network-types: cidr: implement generic `IpAddr::new` constructor Christoph Heiss
2026-04-03 16:53 ` [PATCH proxmox v3 08/38] network-types: fqdn: implement standard library Error for Fqdn Christoph Heiss
2026-04-03 16:53 ` [PATCH proxmox v3 09/38] node-status: make KernelVersionInformation Clone + PartialEq Christoph Heiss
2026-04-03 16:53 ` [PATCH proxmox v3 10/38] installer-types: add common types used by the installer Christoph Heiss
2026-04-03 16:53 ` [PATCH proxmox v3 11/38] installer-types: add types used by the auto-installer Christoph Heiss
2026-04-03 16:53 ` [PATCH proxmox v3 12/38] installer-types: implement api type for all externally-used types Christoph Heiss
2026-04-03 16:53 ` [PATCH yew-widget-toolkit v3 13/38] widget: kvlist: add widget for user-modifiable data tables Christoph Heiss
2026-04-03 16:53 ` [PATCH datacenter-manager v3 14/38] api-types, cli: use ReturnType::new() instead of constructing it manually Christoph Heiss
2026-04-03 16:53 ` [PATCH datacenter-manager v3 15/38] api-types: add api types for auto-installer integration Christoph Heiss
2026-04-03 16:53 ` [PATCH datacenter-manager v3 16/38] config: add auto-installer configuration module Christoph Heiss
2026-04-03 16:53 ` [PATCH datacenter-manager v3 17/38] acl: wire up new /system/auto-installation acl path Christoph Heiss
2026-04-03 16:53 ` [PATCH datacenter-manager v3 18/38] server: api: add auto-installer integration module Christoph Heiss
2026-04-03 16:53 ` [PATCH datacenter-manager v3 19/38] server: api: auto-installer: add access token management endpoints Christoph Heiss
2026-04-03 16:53 ` [PATCH datacenter-manager v3 20/38] client: add bindings for auto-installer endpoints Christoph Heiss
2026-04-03 16:53 ` [PATCH datacenter-manager v3 21/38] ui: auto-installer: add installations overview panel Christoph Heiss
2026-04-03 16:53 ` [PATCH datacenter-manager v3 22/38] ui: auto-installer: add prepared answer configuration panel Christoph Heiss
2026-04-03 16:53 ` [PATCH datacenter-manager v3 23/38] ui: auto-installer: add access token " Christoph Heiss
2026-04-03 16:53 ` [PATCH datacenter-manager v3 24/38] docs: add documentation for auto-installer integration Christoph Heiss
2026-04-03 16:53 ` [PATCH installer v3 25/38] install: iso env: use JSON boolean literals for product config Christoph Heiss
2026-04-03 16:53 ` [PATCH installer v3 26/38] common: http: allow passing custom headers to post() Christoph Heiss
2026-04-03 16:53 ` [PATCH installer v3 27/38] common: options: move regex construction out of loop Christoph Heiss
2026-04-03 16:54 ` [PATCH installer v3 28/38] assistant: support adding an authorization token for HTTP-based answers Christoph Heiss
2026-04-03 16:54 ` [PATCH installer v3 29/38] tree-wide: used moved `Fqdn` type to proxmox-network-types Christoph Heiss
2026-04-03 16:54 ` Christoph Heiss [this message]
2026-04-03 16:54 ` [PATCH installer v3 31/38] tree-wide: switch to filesystem types from proxmox-installer-types Christoph Heiss
2026-04-03 16:54 ` [PATCH installer v3 32/38] post-hook: switch to types in proxmox-installer-types Christoph Heiss
2026-04-03 16:54 ` [PATCH installer v3 33/38] auto: sysinfo: switch to types from proxmox-installer-types Christoph Heiss
2026-04-03 16:54 ` [PATCH installer v3 34/38] fetch-answer: " Christoph Heiss
2026-04-03 16:54 ` [PATCH installer v3 35/38] fetch-answer: http: prefer json over toml for answer format Christoph Heiss
2026-04-03 16:54 ` [PATCH installer v3 36/38] fetch-answer: send auto-installer HTTP authorization token if set Christoph Heiss
2026-04-03 16:54 ` [PATCH installer v3 37/38] tree-wide: switch out `Answer` -> `AutoInstallerConfig` types Christoph Heiss
2026-04-03 16:54 ` [PATCH installer v3 38/38] auto: drop now-dead answer file definitions Christoph Heiss

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260403165437.2166551-31-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pdm-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal