From e7e11e73b965b7f763402b5be45317598a16d1b9 Mon Sep 17 00:00:00 2001 From: Jorik Cronenberg Date: Fri, 15 Mar 2024 16:26:04 +0100 Subject: [PATCH 1/3] Add mtu to network model --- rust/agama-server/src/network/model.rs | 2 + rust/agama-server/src/network/nm/dbus.rs | 64 ++++++++++++++++++------ 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/rust/agama-server/src/network/model.rs b/rust/agama-server/src/network/model.rs index 3199f21860..9f5a49e571 100644 --- a/rust/agama-server/src/network/model.rs +++ b/rust/agama-server/src/network/model.rs @@ -482,6 +482,7 @@ pub struct Connection { #[serde_as(as = "DisplayFromStr")] pub mac_address: MacAddress, pub firewall_zone: Option, + pub mtu: u32, pub ip_config: IpConfig, pub status: Status, pub interface: Option, @@ -551,6 +552,7 @@ impl Default for Connection { uuid: Uuid::new_v4(), mac_address: Default::default(), firewall_zone: Default::default(), + mtu: Default::default(), ip_config: Default::default(), status: Default::default(), interface: Default::default(), diff --git a/rust/agama-server/src/network/nm/dbus.rs b/rust/agama-server/src/network/nm/dbus.rs index 99454c76d3..dc35451cff 100644 --- a/rust/agama-server/src/network/nm/dbus.rs +++ b/rust/agama-server/src/network/nm/dbus.rs @@ -71,17 +71,30 @@ pub fn connection_to_dbus<'a>( result.insert("match", match_config_to_dbus(&conn.match_config)); if conn.is_ethernet() { - let ethernet_config = HashMap::from([( - "assigned-mac-address", - Value::new(conn.mac_address.to_string()), - )]); + let ethernet_config = HashMap::from([ + ( + "assigned-mac-address", + Value::new(conn.mac_address.to_string()), + ), + ("mtu", Value::new(conn.mtu)), + ]); result.insert(ETHERNET_KEY, ethernet_config); } match &conn.config { ConnectionConfig::Wireless(wireless) => { connection_dbus.insert("type", WIRELESS_KEY.into()); - let wireless_dbus = wireless_config_to_dbus(wireless, &conn.mac_address); + let mut wireless_dbus = wireless_config_to_dbus(wireless); + if let Some(wireless_dbus_key) = wireless_dbus.get_mut(WIRELESS_KEY) { + wireless_dbus_key.extend(HashMap::from([ + ("mtu", Value::new(conn.mtu)), + ( + "assigned-mac-address", + Value::new(conn.mac_address.to_string()), + ), + ])); + } + result.extend(wireless_dbus); } ConnectionConfig::Bond(bond) => { @@ -336,14 +349,10 @@ fn ip_config_to_ipv6_dbus(ip_config: &IpConfig) -> HashMap<&str, zvariant::Value ipv6_dbus } -fn wireless_config_to_dbus<'a>( - config: &'a WirelessConfig, - mac_address: &MacAddress, -) -> NestedHash<'a> { +fn wireless_config_to_dbus<'a>(config: &'a WirelessConfig) -> NestedHash<'a> { let mut wireless: HashMap<&str, zvariant::Value> = HashMap::from([ ("mode", Value::new(config.mode.to_string())), ("ssid", Value::new(config.ssid.to_vec())), - ("assigned-mac-address", Value::new(mac_address.to_string())), ("hidden", Value::new(config.hidden)), ]); @@ -568,8 +577,10 @@ fn base_connection_from_dbus(conn: &OwnedNestedHash) -> Option { if let Some(ethernet_config) = conn.get(ETHERNET_KEY) { base_connection.mac_address = mac_address_from_dbus(ethernet_config)?; + base_connection.mtu = mtu_from_dbus(ethernet_config); } else if let Some(wireless_config) = conn.get(WIRELESS_KEY) { base_connection.mac_address = mac_address_from_dbus(wireless_config)?; + base_connection.mtu = mtu_from_dbus(wireless_config); } base_connection.ip_config = ip_config_from_dbus(conn)?; @@ -591,6 +602,14 @@ fn mac_address_from_dbus(config: &HashMap) -> Option) -> u32 { + if let Some(mtu) = config.get("mtu") { + *mtu.downcast_ref::().unwrap_or(&0) + } else { + 0 + } +} + fn match_config_from_dbus( match_config: &HashMap, ) -> Option { @@ -995,6 +1014,8 @@ mod test { assert_eq!(connection.mac_address.to_string(), "12:34:56:78:9A:BC"); + assert_eq!(connection.mtu, 9000_u32); + assert_eq!( ip_config.addresses, vec![ @@ -1379,10 +1400,13 @@ mod test { Value::new("eth0".to_string()).to_owned(), ), ]); - let ethernet = HashMap::from([( - "assigned-mac-address".to_string(), - Value::new("12:34:56:78:9A:BC".to_string()).to_owned(), - )]); + let ethernet = HashMap::from([ + ( + "assigned-mac-address".to_string(), + Value::new("12:34:56:78:9A:BC".to_string()).to_owned(), + ), + ("mtu".to_string(), Value::new(9000).to_owned()), + ]); original.insert("connection".to_string(), connection); original.insert(ETHERNET_KEY.to_string(), ethernet); @@ -1398,6 +1422,7 @@ mod test { assert_eq!(connection.get("interface-name"), None); let ethernet = merged.get(ETHERNET_KEY).unwrap(); assert_eq!(ethernet.get("assigned-mac-address"), Some(&Value::from(""))); + assert_eq!(ethernet.get("mtu"), Some(&Value::from(0_u32))); } fn build_ethernet_section_from_dbus() -> HashMap { @@ -1407,6 +1432,7 @@ mod test { "assigned-mac-address".to_string(), Value::new("12:34:56:78:9A:BC").to_owned(), ), + ("mtu".to_string(), Value::new(9000_u32).to_owned()), ]) } @@ -1436,6 +1462,7 @@ mod test { id: "agama".to_string(), ip_config, mac_address, + mtu: 1500_u32, ..Default::default() } } @@ -1453,6 +1480,15 @@ mod test { .unwrap(); assert_eq!(mac_address, "FD:CB:A9:87:65:43"); + assert_eq!( + *ethernet_connection + .get("mtu") + .unwrap() + .downcast_ref::() + .unwrap(), + 1500_u32 + ); + let ipv4_dbus = conn_dbus.get("ipv4").unwrap(); let gateway4: &str = ipv4_dbus.get("gateway").unwrap().downcast_ref().unwrap(); assert_eq!(gateway4, "192.168.0.1"); From 83cf36840a305379fee2676714737c282ecac4a3 Mon Sep 17 00:00:00 2001 From: Jorik Cronenberg Date: Thu, 16 May 2024 10:56:41 +0200 Subject: [PATCH 2/3] Add mtu network setting --- rust/agama-lib/share/profile.schema.json | 5 +++++ rust/agama-lib/src/network/proxies.rs | 4 ++++ rust/agama-lib/src/network/settings.rs | 6 ++++++ rust/agama-server/src/network/model.rs | 3 +++ 4 files changed, 18 insertions(+) diff --git a/rust/agama-lib/share/profile.schema.json b/rust/agama-lib/share/profile.schema.json index 088d089b92..1d9b10512e 100644 --- a/rust/agama-lib/share/profile.schema.json +++ b/rust/agama-lib/share/profile.schema.json @@ -58,6 +58,11 @@ "description": "Custom mac-address (can also be 'preserve', 'permanent', 'random' or 'stable')", "type": "string" }, + "mtu": { + "description": "Connection MTU", + "type": "integer", + "minimum": 0 + }, "method4": { "description": "IPv4 configuration method (e.g., 'auto')", "type": "string", diff --git a/rust/agama-lib/src/network/proxies.rs b/rust/agama-lib/src/network/proxies.rs index db7de278b1..9e1de983d3 100644 --- a/rust/agama-lib/src/network/proxies.rs +++ b/rust/agama-lib/src/network/proxies.rs @@ -112,6 +112,10 @@ trait Connection { fn mac_address(&self) -> zbus::Result; #[dbus_proxy(property)] fn set_mac_address(&self, mac_address: &str) -> zbus::Result<()>; + #[dbus_proxy(property)] + fn mtu(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn set_mtu(&self, mtu: u32) -> zbus::Result<()>; } #[dbus_proxy( diff --git a/rust/agama-lib/src/network/settings.rs b/rust/agama-lib/src/network/settings.rs index 3e730f7e22..b78934f40e 100644 --- a/rust/agama-lib/src/network/settings.rs +++ b/rust/agama-lib/src/network/settings.rs @@ -103,6 +103,12 @@ pub struct NetworkConnection { pub mac_address: Option, #[serde(skip_serializing_if = "Option::is_none")] pub status: Option, + #[serde(skip_serializing_if = "is_zero", default)] + pub mtu: u32, +} + +fn is_zero(u: &u32) -> bool { + *u == 0 } impl NetworkConnection { diff --git a/rust/agama-server/src/network/model.rs b/rust/agama-server/src/network/model.rs index 9f5a49e571..51ad27fcf2 100644 --- a/rust/agama-server/src/network/model.rs +++ b/rust/agama-server/src/network/model.rs @@ -600,6 +600,7 @@ impl TryFrom for Connection { connection.ip_config.gateway4 = conn.gateway4; connection.ip_config.gateway6 = conn.gateway6; connection.interface = conn.interface; + connection.mtu = conn.mtu; Ok(connection) } @@ -620,6 +621,7 @@ impl TryFrom for NetworkConnection { let gateway6 = conn.ip_config.gateway6; let interface = conn.interface; let status = Some(conn.status); + let mtu = conn.mtu; let mut connection = NetworkConnection { id, @@ -632,6 +634,7 @@ impl TryFrom for NetworkConnection { mac_address, interface, addresses, + mtu, ..Default::default() }; From 26fc60d9ea65d2fb9d799c931bf7061e11d8d6a9 Mon Sep 17 00:00:00 2001 From: Jorik Cronenberg Date: Mon, 10 Jun 2024 16:33:36 +0200 Subject: [PATCH 3/3] Update changes --- rust/package/agama.changes | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rust/package/agama.changes b/rust/package/agama.changes index a488c5da83..5717dd3367 100644 --- a/rust/package/agama.changes +++ b/rust/package/agama.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Jun 10 14:24:33 UTC 2024 - Jorik Cronenberg + +- Add mtu property for network connections + (gh#openSUSE/agama#1101). + ------------------------------------------------------------------- Fri Jun 7 05:58:48 UTC 2024 - Michal Filka