From 4b40fad531232a1aea8aa1afedecd96fcb7c2ade Mon Sep 17 00:00:00 2001 From: Matthew Yeazel Date: Tue, 5 Sep 2023 22:41:58 +0000 Subject: [PATCH] netdog: Add none to bonds for deterministic MACs networkd will generate a new MAC Address for bonds by default. If MACAddress is set to none, then it will use the lowest one found which is closer to the behavior of wicked. Future work can be added to allow a user to specify the MAC Address used for a bond but currently its hard coded to use the value of none. Signed-off-by: Matthew Yeazel --- .../api/netdog/src/networkd/config/netdev.rs | 23 ++++++++++++++++++- .../test_data/networkd/netdev/bond0.netdev | 1 + .../test_data/networkd/netdev/bond1.netdev | 1 + .../test_data/networkd/netdev/bond2.netdev | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/sources/api/netdog/src/networkd/config/netdev.rs b/sources/api/netdog/src/networkd/config/netdev.rs index eceb6891a62..0acd8d52987 100644 --- a/sources/api/netdog/src/networkd/config/netdev.rs +++ b/sources/api/netdog/src/networkd/config/netdev.rs @@ -1,7 +1,7 @@ use super::private::{Bond, Device, Vlan}; use super::CONFIG_FILE_PREFIX; use crate::bonding::{ArpMonitoringConfigV1, ArpValidateV1, BondModeV1, MiiMonitoringConfigV1}; -use crate::interface_id::InterfaceName; +use crate::interface_id::{InterfaceName, MacAddress}; use crate::networkd::{error, Result}; use crate::vlan_id::VlanId; use snafu::{OptionExt, ResultExt}; @@ -26,6 +26,8 @@ struct NetDevSection { name: Option, #[systemd(entry = "Kind")] kind: Option, + #[systemd(entry = "MACAddress")] + mac_address: Option, } #[derive(Debug, Default, SystemdUnitSection)] @@ -122,6 +124,23 @@ impl Display for ArpAllTargets { } } +// NetDev has a special `none` which allows bonds to reuse the permanent address for the bond +#[derive(Debug)] +enum NetDevMacAddress { + #[allow(dead_code)] + MacAddress(MacAddress), + Nothing, +} + +impl Display for NetDevMacAddress { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + NetDevMacAddress::MacAddress(m) => write!(f, "{}", m.to_string()), + NetDevMacAddress::Nothing => write!(f, "none"), + } + } +} + impl NetDevConfig { const FILE_EXT: &str = "netdev"; @@ -192,6 +211,7 @@ impl NetDevBuilder { netdev: Some(NetDevSection { name: Some(name), kind: Some(NetDevKind::Bond), + mac_address: Some(NetDevMacAddress::Nothing), }), ..Default::default() }; @@ -248,6 +268,7 @@ impl NetDevBuilder { netdev: Some(NetDevSection { name: Some(name), kind: Some(NetDevKind::Vlan), + mac_address: None, }), ..Default::default() }; diff --git a/sources/api/netdog/test_data/networkd/netdev/bond0.netdev b/sources/api/netdog/test_data/networkd/netdev/bond0.netdev index efac9cd2e68..48e51847a0b 100644 --- a/sources/api/netdog/test_data/networkd/netdev/bond0.netdev +++ b/sources/api/netdog/test_data/networkd/netdev/bond0.netdev @@ -1,6 +1,7 @@ [NetDev] Name=bond0 Kind=bond +MACAddress=none [Bond] Mode=active-backup MIIMonitorSec=100 diff --git a/sources/api/netdog/test_data/networkd/netdev/bond1.netdev b/sources/api/netdog/test_data/networkd/netdev/bond1.netdev index c6fe29ed5dc..9a9e9f63bb4 100644 --- a/sources/api/netdog/test_data/networkd/netdev/bond1.netdev +++ b/sources/api/netdog/test_data/networkd/netdev/bond1.netdev @@ -1,6 +1,7 @@ [NetDev] Name=bond1 Kind=bond +MACAddress=none [Bond] Mode=active-backup ARPIntervalSec=200 diff --git a/sources/api/netdog/test_data/networkd/netdev/bond2.netdev b/sources/api/netdog/test_data/networkd/netdev/bond2.netdev index e94ac58de41..ba85e77e75e 100644 --- a/sources/api/netdog/test_data/networkd/netdev/bond2.netdev +++ b/sources/api/netdog/test_data/networkd/netdev/bond2.netdev @@ -1,6 +1,7 @@ [NetDev] Name=bond2 Kind=bond +MACAddress=none [Bond] Mode=active-backup MinLinks=2