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 18D3B1FF17C for ; Wed, 6 Aug 2025 16:30:14 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C752D3CEA0; Wed, 6 Aug 2025 16:31:46 +0200 (CEST) From: Stefan Hanreich To: pbs-devel@lists.proxmox.com Date: Wed, 6 Aug 2025 16:29:23 +0200 Message-ID: <20250806142927.344007-3-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250806142927.344007-1-s.hanreich@proxmox.com> References: <20250806142927.344007-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. [main.rs] Subject: [pbs-devel] [PATCH proxmox-network-interface-pinning 1/1] network-interface-pinning: adapt to optional mac address 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" MAC addresses can be optional, so the return value of permanent_mac() has changed to Option. Adapt all call sites to gracefully handle the case where a link has no permanent MAC address. Signed-off-by: Stefan Hanreich --- src/main.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4e1fa4f..bff0660 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,7 +63,12 @@ impl InterfaceMapping { for ip_link in sorted_links { if let Some(new_name) = self.mapping.get(ip_link.name()) { - let link_file = LinkFile::new_ether(ip_link.permanent_mac(), new_name.to_string()); + let link_file = LinkFile::new_ether( + ip_link + .permanent_mac() + .ok_or_else(|| anyhow!("trying to pin interface without a MAC address!"))?, + new_name.to_string(), + ); std::fs::write( format!("{}/{}", SYSTEMD_LINK_FILE_PATH, link_file.file_name()), @@ -407,10 +412,11 @@ impl PinningTool { .get(interface_name) .ok_or_else(|| anyhow!("cannot find interface with name {interface_name}"))?; - if self - .pinned_interfaces - .contains_key(&ip_link.permanent_mac()) - { + let Some(mac_address) = ip_link.permanent_mac() else { + bail!("Interface does not have a MAC address, so it cannot be pinned!"); + }; + + if self.pinned_interfaces.contains_key(&mac_address) { bail!("pin already exists for interface {interface_name}"); } @@ -483,11 +489,12 @@ impl PinningTool { .ip_links .values() .filter(|ip_link| { - ip_link.is_physical() - && self - .pinned_interfaces - .get(&ip_link.permanent_mac()) - .is_none() + if let Some(mac_address) = ip_link.permanent_mac() { + return ip_link.is_physical() + && self.pinned_interfaces.get(&mac_address).is_none(); + } + + false }) .cloned() .map(IpLink::from) -- 2.47.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel