Skip to content

Commit

Permalink
Merge pull request #3415 from yeazelm/bonding_macs
Browse files Browse the repository at this point in the history
netdog: Add none to bonds for deterministic MACs
  • Loading branch information
yeazelm authored Sep 6, 2023
2 parents d1766a1 + 4b40fad commit 34901a2
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 34901a2

Please sign in to comment.