From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id D16B41FF0B6 for ; Thu, 12 Nov 2026 18:11:35 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 3B21321697; Thu, 12 Nov 2026 18:11:24 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox 2/4] network-types: add a type for network interface altnames Date: Thu, 12 Nov 2026 18:10:58 +0100 Message-ID: <20261112171102.674232-3-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261112171102.674232-1-s.hanreich@proxmox.com> References: <20261112171102.674232-1-s.hanreich@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794503477038 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.285 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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: GNPLW2TILLACYJ5YVT5XE2SW6YSL6MLG X-Message-ID-Hash: GNPLW2TILLACYJ5YVT5XE2SW6YSL6MLG X-MailFrom: s.hanreich@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 VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Altnames can be up to 127 bytes long, so places that accept either a name or an altname, like the interface of a firewall rule, cannot use NetworkInterfaceName. NetworkInterfaceAltname uses the same format with the length limit of altnames. Every name is a valid altname as well, so add a conversion from NetworkInterfaceName. Signed-off-by: Stefan Hanreich --- .../src/network_interface.rs | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/proxmox-network-types/src/network_interface.rs b/proxmox-network-types/src/network_interface.rs index 24972058..fa6d2e37 100644 --- a/proxmox-network-types/src/network_interface.rs +++ b/proxmox-network-types/src/network_interface.rs @@ -9,6 +9,10 @@ //! * `api_types::NetworkInterfaceName`: names in the API and in configuration files, and names //! that are created or passed to `ip`. Not for values that can also be altnames, and not for //! reading names from the kernel, which can be outside of the API format. +//! +//! * `api_types::NetworkInterfaceAltname`: values that can be a name or an altname, e.g. the +//! interface of a firewall rule. Resolve it to the name where only names work, e.g. for +//! `iifname` in nftables. /// API types for network interface names. /// @@ -23,6 +27,21 @@ /// /// assert!("veth999999999i31".parse::().is_err()); /// ``` +/// +/// Values that are either the name or an altname of a network interface, e.g. the interface of a +/// firewall rule, are represented by +/// [`NetworkInterfaceAltname`](api_types::NetworkInterfaceAltname): +/// +/// ``` +/// # use proxmox_network_types::network_interface::api_types::{ +/// # NetworkInterfaceAltname, NetworkInterfaceName, +/// # }; +/// let altname: NetworkInterfaceAltname = "enx0123456789abcd".parse().unwrap(); +/// assert_eq!(altname.as_str(), "enx0123456789abcd"); +/// +/// let name: NetworkInterfaceName = "eth0".parse().unwrap(); +/// assert_eq!(NetworkInterfaceAltname::from(name).as_str(), "eth0"); +/// ``` #[cfg(feature = "api-types")] pub mod api_types { use proxmox_schema::{api, api_string_type, api_types::SAFE_ID_FORMAT}; @@ -30,6 +49,9 @@ pub mod api_types { /// The size of the kernel buffer for network interface names, including the terminating NUL. const IFNAMSIZ: usize = 16; + /// The size of the kernel buffer for altnames, including the terminating NUL. + const ALTIFNAMSIZ: usize = 128; + api_string_type! { #[api(format: &SAFE_ID_FORMAT, min_length: 1, max_length: IFNAMSIZ - 1)] /// The name of a network interface. @@ -44,6 +66,27 @@ pub mod api_types { proxmox_serde::forward_deserialize_to_from_str!(NetworkInterfaceName); proxmox_serde::forward_serialize_to_display!(NetworkInterfaceName); + api_string_type! { + #[api(format: &SAFE_ID_FORMAT, min_length: 1, max_length: ALTIFNAMSIZ - 1)] + /// The name or an alternative name (altname) of a network interface. + /// + /// Same format as network interface names, but with the altname limit of 127 bytes. It + /// has to be resolved to the name of the interface where only names are accepted. + #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] + #[repr(transparent)] + pub struct NetworkInterfaceAltname(String); + } + + proxmox_serde::forward_deserialize_to_from_str!(NetworkInterfaceAltname); + proxmox_serde::forward_serialize_to_display!(NetworkInterfaceAltname); + + impl From for NetworkInterfaceAltname { + fn from(name: NetworkInterfaceName) -> Self { + // SAFETY: both schemas use the same format, and names are shorter than altnames + unsafe { Self::from_string_unchecked(name.into_string()) } + } + } + #[cfg(test)] mod tests { use super::*; @@ -98,5 +141,42 @@ pub mod api_types { ); } } + + #[test] + fn parse_network_interface_altname() { + let longest = "a".repeat(ALTIFNAMSIZ - 1); + + for name in [ + "eth0", + "bond0.100", + "uplink-a", + "abcdefghijklmnop", + "enx0123456789abcd", + longest.as_str(), + ] { + let parsed: NetworkInterfaceAltname = name.parse().expect(name); + assert_eq!(parsed.as_str(), name); + assert_eq!(parsed.to_string(), name); + } + + let too_long = "a".repeat(ALTIFNAMSIZ); + + for name in ["", ".", "-eth0", "eth 0", "eth0:1", too_long.as_str()] { + assert!(name.parse::().is_err(), "{name:?}"); + } + } + + #[test] + fn deserialize_network_interface_altname() { + let name: NetworkInterfaceAltname = + serde_plain::from_str("abcdefghijklmnop").expect("valid altname"); + assert_eq!(name.as_str(), "abcdefghijklmnop"); + assert_eq!( + serde_plain::to_string(&name).expect("serializable"), + "abcdefghijklmnop" + ); + + assert!(serde_plain::from_str::("eth0:1").is_err()); + } } } -- 2.47.3