Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sources/netdog/src/net_config/devices/bond.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub(crate) struct NetBondV1 {
#[serde(rename = "monitoring")]
pub(crate) monitoring_config: BondMonitoringConfigV1,
pub(crate) interfaces: Vec<InterfaceName>,
pub(crate) mtu: Option<u32>,
}

// Single variant enum only used to direct deserialization. If the kind is not "Bond" or "bond",
Expand Down
1 change: 1 addition & 0 deletions sources/netdog/src/net_config/devices/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub(crate) struct NetInterfaceV2 {
pub(crate) static6: Option<StaticConfigV1>,
#[serde(rename = "route")]
pub(crate) routes: Option<Vec<RouteV1>>,
pub(crate) mtu: Option<u32>,
}

impl Validate for NetInterfaceV2 {
Expand Down
1 change: 1 addition & 0 deletions sources/netdog/src/net_config/devices/vlan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub(crate) struct NetVlanV1 {
_kind: VlanKind,
pub(crate) device: InterfaceName,
pub(crate) id: VlanId,
pub(crate) mtu: Option<u32>,
}

// Single variant enum only used to direct deserialization. If the kind is not "VLAN", "Vlan", or
Expand Down
3 changes: 3 additions & 0 deletions sources/netdog/src/net_config/test_macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ pub(super) mod bonding;
#[cfg(test)]
pub(super) mod dhcp;
#[cfg(test)]
pub(super) mod mtu;
#[cfg(test)]
pub(super) mod static_address;
#[cfg(test)]
pub(super) mod vlan;

pub(super) use basic::basic_tests;
pub(super) use bonding::bonding_tests;
pub(super) use dhcp::dhcp_tests;
pub(super) use mtu::mtu_tests;
pub(super) use static_address::static_address_tests;
pub(super) use vlan::vlan_tests;

Expand Down
40 changes: 40 additions & 0 deletions sources/netdog/src/net_config/test_macros/mtu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/// The mtu_tests macro contains MTU-related net config tests. It accepts a version number,
/// and creates a module for that version containing all applicable MTU tests.
macro_rules! mtu_tests {
($version:expr) => {
mod mtu {
use $crate::net_config::deserialize_config;
use $crate::net_config::test_macros::gen_boilerplate;

gen_boilerplate!($version, "mtu");

// Only test MTU for version 3 and later
#[test]
fn mtu_configuration() {
if VERSION < 3 {
// MTU is only supported in version 3 and later
return;
}

let config_str = render_config_template(net_config().join("net_config.toml"));
let net_config = deserialize_config(&config_str);
assert!(net_config.is_ok(), "Failed to deserialize config: {:?}", net_config.err());

let net_config = net_config.unwrap();

// Check that the config has interfaces
assert!(net_config.has_interfaces());

// Convert to networkd config to ensure MTU values are passed through
let networkd_config = net_config.as_networkd_config();
assert!(networkd_config.is_ok(), "Failed to create networkd config: {:?}", networkd_config.err());

// The test passes if we can successfully deserialize and create networkd config
// with MTU values. The actual MTU values will be written to the .network files
// when the networkd config is written to disk.
}
}
};
}

pub(crate) use mtu_tests;
3 changes: 2 additions & 1 deletion sources/netdog/src/net_config/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ impl Validate for NetConfigV3 {
#[cfg(test)]
mod tests {
use crate::net_config::test_macros::{
basic_tests, bonding_tests, dhcp_tests, static_address_tests, vlan_tests,
basic_tests, bonding_tests, dhcp_tests, mtu_tests, static_address_tests, vlan_tests,
};

basic_tests!(3);
dhcp_tests!(3);
static_address_tests!(3);
vlan_tests!(3);
bonding_tests!(3);
mtu_tests!(3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to increment the schema version for the MTU-related changes:

Suggested change
mtu_tests!(3);
mtu_tests!(4);

}
7 changes: 7 additions & 0 deletions sources/netdog/src/networkd/config/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ struct LinkSection {
required: Option<bool>,
#[systemd(entry = "RequiredFamilyForOnline")]
required_family: Option<RequiredFamily>,
#[systemd(entry = "MTUBytes")]
mtu_bytes: Option<u32>,
}

#[derive(Debug, Default, SystemdUnitSection)]
Expand Down Expand Up @@ -601,6 +603,11 @@ where
self.network.route.push(route_section)
}

/// Set the MTU for the interface
pub(crate) fn with_mtu(&mut self, mtu: u32) {
self.network.link_mut().mtu_bytes = Some(mtu);
}

// =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
// The following helper methods on the `DhcpXConfig` structs exist to conveniently parse out
// the required information. Since this is the only place we parse these values, and will only
Expand Down
5 changes: 5 additions & 0 deletions sources/netdog/src/networkd/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl TryFrom<(InterfaceName, NetInterfaceV1)> for NetworkDDevice {
static4: None,
static6: None,
routes: None,
mtu: None, // v1 doesn't support MTU
}))
}
}
Expand All @@ -49,6 +50,7 @@ impl TryFrom<(InterfaceName, NetInterfaceV2)> for NetworkDDevice {
static4: config.static4,
static6: config.static6,
routes: config.routes,
mtu: config.mtu,
}))
}
}
Expand All @@ -65,6 +67,7 @@ impl TryFrom<(InterfaceId, NetInterfaceV2)> for NetworkDDevice {
static4: config.static4,
static6: config.static6,
routes: config.routes,
mtu: config.mtu,
}))
}
}
Expand Down Expand Up @@ -94,6 +97,7 @@ impl TryFrom<(InterfaceId, NetBondV1)> for NetworkDDevice {
min_links: config.min_links,
monitoring_config: config.monitoring_config,
interfaces: config.interfaces,
mtu: config.mtu,
}))
}
}
Expand Down Expand Up @@ -121,6 +125,7 @@ impl TryFrom<(InterfaceId, NetVlanV1)> for NetworkDDevice {
routes: config.routes,
device: config.device,
id: config.id,
mtu: config.mtu,
}))
}
}
6 changes: 6 additions & 0 deletions sources/netdog/src/networkd/devices/bond.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub(crate) struct NetworkDBond {
pub(crate) min_links: Option<usize>,
pub(crate) monitoring_config: BondMonitoringConfigV1,
pub(crate) interfaces: Vec<InterfaceName>,
pub(crate) mtu: Option<u32>,
}

impl NetDevFileCreator for NetworkDBond {
Expand All @@ -42,6 +43,7 @@ impl NetDevFileCreator for NetworkDBond {
min_links,
monitoring_config,
interfaces: _, // Used in .network files, not here
mtu: _, // MTU is configured in .network files, not .netdev
} = self;

let mut netdev = NetDevBuilder::new_bond(name.clone());
Expand Down Expand Up @@ -75,13 +77,17 @@ impl NetworkFileCreator for NetworkDBond {
min_links: _,
monitoring_config: _,
interfaces,
mtu,
} = self;

let mut network = NetworkBuilder::new_bond(name.clone());
network.with_dhcp(dhcp4.clone(), dhcp6.clone());
maybe_add_some!(network, with_static_config, static4);
maybe_add_some!(network, with_static_config, static6);
maybe_add_some!(network, with_routes, routes);
if let Some(m) = mtu {
network.with_mtu(*m);
}

network.with_bind_carrier(interfaces.clone());

Expand Down
7 changes: 7 additions & 0 deletions sources/netdog/src/networkd/devices/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub(crate) struct NetworkDInterface {
pub(crate) static4: Option<StaticConfigV1>,
pub(crate) static6: Option<StaticConfigV1>,
pub(crate) routes: Option<Vec<RouteV1>>,
pub(crate) mtu: Option<u32>,
}

impl NetworkDInterface {
Expand All @@ -32,12 +33,14 @@ impl NetworkDInterface {
static4,
static6,
routes,
mtu,
} = self;
dhcp4.is_none()
&& dhcp6.is_none()
&& static4.is_none()
&& static6.is_none()
&& routes.is_none()
&& mtu.is_none()
}
}

Expand All @@ -53,6 +56,7 @@ impl NetworkFileCreator for NetworkDInterface {
static4,
static6,
routes,
mtu,
} = self;

// Attach VLANs to this interface if configured with a name.
Expand All @@ -77,6 +81,9 @@ impl NetworkFileCreator for NetworkDInterface {
maybe_add_some!(network, with_static_config, static4);
maybe_add_some!(network, with_static_config, static6);
maybe_add_some!(network, with_routes, routes);
if let Some(m) = mtu {
network.with_mtu(*m);
}
if let Some(vlans) = attached_vlans {
network.with_vlans(vlans.to_vec())
}
Expand Down
6 changes: 6 additions & 0 deletions sources/netdog/src/networkd/devices/vlan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub(crate) struct NetworkDVlan {
// entry for this VLAN
pub(crate) device: InterfaceName,
pub(crate) id: VlanId,
pub(crate) mtu: Option<u32>,
}

impl NetDevFileCreator for NetworkDVlan {
Expand All @@ -40,6 +41,7 @@ impl NetDevFileCreator for NetworkDVlan {
routes: _,
device: _, // Device isn't used in .netdev files
id,
mtu: _, // MTU is configured in .network files, not .netdev
} = self;

let mut netdev = NetDevBuilder::new_vlan(name.clone());
Expand All @@ -63,13 +65,17 @@ impl NetworkFileCreator for NetworkDVlan {
routes,
device: _, // device and id aren't used in .network files
id: _,
mtu,
} = self;

let mut network = NetworkBuilder::new_vlan(name.clone());
network.with_dhcp(dhcp4.clone(), dhcp6.clone());
maybe_add_some!(network, with_static_config, static4);
maybe_add_some!(network, with_static_config, static6);
maybe_add_some!(network, with_routes, routes);
if let Some(m) = mtu {
network.with_mtu(*m);
}
Comment on lines +76 to +78
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same suggestion for the other occurrences of this pattern:

Suggested change
if let Some(m) = mtu {
network.with_mtu(*m);
}
maybe_add_some!(network, with_mut, mtu);


vec![network.build()]
}
Expand Down
1 change: 1 addition & 0 deletions sources/netdog/src/networkd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl NetworkDConfig {
static4: None,
static6: None,
routes: None,
mtu: None,
}))
}
}
Expand Down
38 changes: 38 additions & 0 deletions sources/netdog/test_data/net_config/mtu/net_config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version = {{version}}

# Interface with jumbo frames
[eno1]
dhcp4 = true
mtu = 9000
primary = true

# Interface with standard MTU
[eno2]
dhcp6 = true
mtu = 1500

# Bond with custom MTU
[bond0]
kind = "bond"
mode = "active-backup"
mtu = 1500
interfaces = ["eth0", "eth1"]
dhcp4 = true

[bond0.monitoring]
miimon-frequency-ms = 100
miimon-updelay-ms = 200
miimon-downdelay-ms = 200

# VLAN with custom MTU
[vlan100]
kind = "vlan"
device = "eno1"
id = 100
mtu = 1500
dhcp4 = true

# Interface without MTU specified (will use default)
[eno3]
dhcp4 = true
dhcp6 = true