Skip to content

Commit

Permalink
Avoid code duplication in general network config
Browse files Browse the repository at this point in the history
  • Loading branch information
jcronenberg committed Apr 8, 2024
1 parent c431f99 commit 1febd18
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions rust/agama-server/src/network/nm/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,10 @@ pub fn connection_to_dbus<'a>(
result.insert("ipv6", ip_config_to_ipv6_dbus(&conn.ip_config));
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()),
),
("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 mut wireless_dbus = wireless_config_to_dbus(wireless);
wireless_dbus
.get_mut(WIRELESS_KEY)
.unwrap()
.extend(HashMap::from([
("mtu", Value::new(conn.mtu)),
(
"assigned-mac-address",
Value::new(conn.mac_address.to_string()),
),
]));

let wireless_dbus = wireless_config_to_dbus(wireless);
result.extend(wireless_dbus);
}
ConnectionConfig::Bond(bond) => {
Expand Down Expand Up @@ -119,6 +97,22 @@ pub fn connection_to_dbus<'a>(
_ => {}
}

let general_conn_config = HashMap::from([
(
"assigned-mac-address",
Value::new(conn.mac_address.to_string()),
),
("mtu", Value::new(conn.mtu)),
]);
if conn.is_ethernet() {
result.insert(ETHERNET_KEY, general_conn_config);
} else if let ConnectionConfig::Wireless(_) = conn.config {
result
.get_mut(WIRELESS_KEY)
.unwrap()
.extend(general_conn_config);
}

match &conn.port_config {
PortConfig::Bridge(bridge_port) => {
result.insert(BRIDGE_PORT_KEY, bridge_port_config_to_dbus(bridge_port));
Expand Down

0 comments on commit 1febd18

Please sign in to comment.