From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 5DBC11FF13E for ; Fri, 03 Apr 2026 18:55:20 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 203FC7D4B; Fri, 3 Apr 2026 18:55:51 +0200 (CEST) From: Christoph Heiss To: pdm-devel@lists.proxmox.com Subject: [PATCH proxmox v3 06/38] network-types: add api wrapper type for std::net::IpAddr Date: Fri, 3 Apr 2026 18:53:38 +0200 Message-ID: <20260403165437.2166551-7-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: 1775235256873 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.063 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: 632I54TT5ZR4JNXJ5FTEMYHAYJDW7AQN X-Message-ID-Hash: 632I54TT5ZR4JNXJ5FTEMYHAYJDW7AQN 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: Much like the existing ones for Ipv4Addr/Ipv6Addr. Signed-off-by: Christoph Heiss --- Changes v2 -> v3: * no changes Changes v1 -> v2: * no changes proxmox-network-types/src/ip_address.rs | 64 ++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/proxmox-network-types/src/ip_address.rs b/proxmox-network-types/src/ip_address.rs index 79a92aae..d05877ee 100644 --- a/proxmox-network-types/src/ip_address.rs +++ b/proxmox-network-types/src/ip_address.rs @@ -99,8 +99,10 @@ pub mod api_types { use std::net::AddrParseError; use std::ops::{Deref, DerefMut}; - use proxmox_schema::api_types::IP_V6_SCHEMA; - use proxmox_schema::{api_types::IP_V4_SCHEMA, ApiType, UpdaterType}; + use proxmox_schema::{ + api_types::{IP_SCHEMA, IP_V4_SCHEMA, IP_V6_SCHEMA}, + ApiType, UpdaterType, + }; use serde_with::{DeserializeFromStr, SerializeDisplay}; /// A wrapper around [`std::net::Ipv4Addr`] that implements [`ApiType`]. @@ -220,6 +222,64 @@ pub mod api_types { Self(value) } } + + #[derive( + Debug, + Clone, + Copy, + Eq, + PartialEq, + Ord, + PartialOrd, + DeserializeFromStr, + SerializeDisplay, + Hash, + )] + #[repr(transparent)] + pub struct IpAddr(pub std::net::IpAddr); + + impl ApiType for IpAddr { + const API_SCHEMA: proxmox_schema::Schema = IP_SCHEMA; + } + + impl UpdaterType for IpAddr { + type Updater = Option; + } + + impl Deref for IpAddr { + type Target = std::net::IpAddr; + + fn deref(&self) -> &Self::Target { + &self.0 + } + } + + impl DerefMut for IpAddr { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } + } + + impl std::str::FromStr for IpAddr { + type Err = AddrParseError; + + fn from_str(value: &str) -> Result { + let ip_address = std::net::IpAddr::from_str(value)?; + Ok(Self(ip_address)) + } + } + + impl std::fmt::Display for IpAddr { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + self.0.fmt(f) + } + } + + impl From for IpAddr { + fn from(value: std::net::IpAddr) -> Self { + Self(value) + } + } } /// The family (v4 or v6) of an IP address or CIDR prefix. -- 2.53.0