[pbs-devel] [PATCH proxmox-network-interface-pinning 1/1] network-interface-pinning: adapt to optional mac address
Stefan Hanreich
s.hanreich at proxmox.com
Wed Aug 6 16:29:23 CEST 2025
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 at 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
More information about the pbs-devel
mailing list