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 A89551FF15C for ; Fri, 8 Aug 2025 12:22:34 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 50E6813B6A; Fri, 8 Aug 2025 12:24:07 +0200 (CEST) From: Stefan Hanreich To: pbs-devel@lists.proxmox.com Date: Fri, 8 Aug 2025 12:23:30 +0200 Message-ID: <20250808102333.121994-3-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250808102333.121994-1-s.hanreich@proxmox.com> References: <20250808102333.121994-1-s.hanreich@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.192 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 KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [helper.rs] Subject: [pbs-devel] [PATCH proxmox v2 2/2] config: helper: document public API X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Add docstrings to the public API members for network interface parsing, where they were missing before. Signed-off-by: Stefan Hanreich --- proxmox-network-api/src/config/helper.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/proxmox-network-api/src/config/helper.rs b/proxmox-network-api/src/config/helper.rs index 6d372b26..cc2f3dd0 100644 --- a/proxmox-network-api/src/config/helper.rs +++ b/proxmox-network-api/src/config/helper.rs @@ -119,11 +119,13 @@ pub(crate) fn parse_address_or_cidr(cidr: &str) -> Result<(String, Option, b } } +/// Struct representing the info_slave_data field inside link_info, as returned by `ip -details -json link show`. #[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, serde::Deserialize)] pub struct SlaveData { perm_hw_addr: Option, } +/// Struct representing the link_info field, as returned by `ip -details -json link show`. #[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, serde::Deserialize)] pub struct LinkInfo { info_slave_data: Option, @@ -178,6 +180,7 @@ pub struct IpLink { } impl IpLink { + /// The index of the interface. pub fn index(&self) -> i64 { self.ifindex } @@ -204,6 +207,7 @@ impl IpLink { PHYSICAL_NIC_REGEX.is_match(&self.ifname) } + /// The name of the interface (ifname / IFLA_IFNAME). pub fn name(&self) -> &str { &self.ifname } @@ -227,15 +231,18 @@ impl IpLink { None } + /// Returns an iterator over the altnames of an interface. pub fn altnames(&self) -> impl Iterator { self.altnames.iter() } + /// Returns whether the interface is currently in an UP state. pub fn active(&self) -> bool { self.operstate == "UP" } } +/// A mapping of altnames to the interfaces' ifname. #[derive(Debug, Clone, serde::Deserialize)] pub struct AltnameMapping { mapping: HashMap, @@ -263,6 +270,10 @@ impl FromIterator for AltnameMapping { } } +/// Returns a list of all network interfaces currently available on the host. +/// +/// This parses the output of `ip -details -json link show` and returns a map of the ifname to the +/// [`IpLink`] for that interface. pub fn get_network_interfaces() -> Result, Error> { let output = std::process::Command::new("ip") .arg("-details") -- 2.47.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel