Skip to content

Commit

Permalink
netdog: Add none to bonds for deterministic MACs
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
yeazelm committed Sep 5, 2023
1 parent e043321 commit 4b40fad
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
23 changes: 22 additions & 1 deletion sources/api/netdog/src/networkd/config/netdev.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -26,6 +26,8 @@ struct NetDevSection {
name: Option<InterfaceName>,
#[systemd(entry = "Kind")]
kind: Option<NetDevKind>,
#[systemd(entry = "MACAddress")]
mac_address: Option<NetDevMacAddress>,
}

#[derive(Debug, Default, SystemdUnitSection)]
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -192,6 +211,7 @@ impl NetDevBuilder<Bond> {
netdev: Some(NetDevSection {
name: Some(name),
kind: Some(NetDevKind::Bond),
mac_address: Some(NetDevMacAddress::Nothing),
}),
..Default::default()
};
Expand Down Expand Up @@ -248,6 +268,7 @@ impl NetDevBuilder<Vlan> {
netdev: Some(NetDevSection {
name: Some(name),
kind: Some(NetDevKind::Vlan),
mac_address: None,
}),
..Default::default()
};
Expand Down
1 change: 1 addition & 0 deletions sources/api/netdog/test_data/networkd/netdev/bond0.netdev
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[NetDev]
Name=bond0
Kind=bond
MACAddress=none
[Bond]
Mode=active-backup
MIIMonitorSec=100
Expand Down
1 change: 1 addition & 0 deletions sources/api/netdog/test_data/networkd/netdev/bond1.netdev
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[NetDev]
Name=bond1
Kind=bond
MACAddress=none
[Bond]
Mode=active-backup
ARPIntervalSec=200
Expand Down
1 change: 1 addition & 0 deletions sources/api/netdog/test_data/networkd/netdev/bond2.netdev
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[NetDev]
Name=bond2
Kind=bond
MACAddress=none
[Bond]
Mode=active-backup
MinLinks=2
Expand Down

0 comments on commit 4b40fad

Please sign in to comment.