From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-network-interface-pinning 1/1] network-interface-pinning: adapt to optional mac address
Date: Wed, 6 Aug 2025 16:29:23 +0200 [thread overview]
Message-ID: <20250806142927.344007-3-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20250806142927.344007-1-s.hanreich@proxmox.com>
MAC addresses can be optional, so the return value of permanent_mac()
has changed to Option<MacAddress>. Adapt all call sites to gracefully
handle the case where a link has no permanent MAC address.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
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
next prev parent reply other threads:[~2025-08-06 14:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-06 14:29 [pbs-devel] [PATCH proxmox{, -network-interface-pinning} 0/2] fix reading ip link output for interfaces without MAC address Stefan Hanreich
2025-08-06 14:29 ` [pbs-devel] [PATCH proxmox 1/1] network-api: make address field optional Stefan Hanreich
2025-08-08 7:29 ` Christian Ebner
2025-08-08 8:01 ` Stefan Hanreich
2025-08-06 14:29 ` Stefan Hanreich [this message]
2025-08-08 11:56 ` [pbs-devel] superseded: [PATCH proxmox{, -network-interface-pinning} 0/2] fix reading ip link output for interfaces without MAC address Stefan Hanreich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250806142927.344007-3-s.hanreich@proxmox.com \
--to=s.hanreich@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox