From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 0DBC91FF13E for ; Fri, 03 Apr 2026 18:57:28 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CDAB991A5; Fri, 3 Apr 2026 18:57:58 +0200 (CEST) From: Christoph Heiss 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 Message-ID: <20260403165437.2166551-31-c.heiss@proxmox.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260403165437.2166551-1-c.heiss@proxmox.com> References: <20260403165437.2166551-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1775235380850 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.067 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: ORXA4K3GTJ4NHBPLR5HPDN3PYQZWOPIF X-Message-ID-Hash: ORXA4K3GTJ4NHBPLR5HPDN3PYQZWOPIF X-MailFrom: c.heiss@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: .. instead of our own variant here, as we now already depend on proxmox-network-types anyway. No functional changes. Signed-off-by: Christoph Heiss --- 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, + pub cidr: Option, pub dns: Option, pub gateway: Option, #[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, 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, @@ -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, D::Error> +fn deserialize_cidr_list<'de, D>(deserializer: D) -> Result, 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, + pub addresses: Vec, } 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), -} - -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>(addr: T, mask: usize) -> Result { - 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 { - 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(deserializer: D) -> Result - 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, + address: Option, /// 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::>()) { *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 { + fn mask_edit_view(content: u8) -> ResizedView { 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::(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::(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